* Add Tables option to Redcarpet in Legislation draft * Allow table tags in Admin Legislation Sanitizer * Add Test to render markdown tables in Legislation drafts * Add Test for Admin Legislation Sanitizer We include test for image, table and h1 to h6 tags and additional tests to strengthen the allowed and disallowed parameters * Add Table from markdown test in System and Factories * Add test to render tables for admin user * Remove comment line about Redcarpet options * Edit custom css for legislation draft table to make it responsive
84 lines
2.5 KiB
Ruby
84 lines
2.5 KiB
Ruby
module ApplicationHelper
|
|
# if current path is /debates current_path_with_query_params(foo: "bar") returns /debates?foo=bar
|
|
# notice: if query_params have a param which also exist in current path,
|
|
# it "overrides" (query_params is merged last)
|
|
def current_path_with_query_params(query_parameters)
|
|
url_for(request.query_parameters.merge(query_parameters).merge(only_path: true))
|
|
end
|
|
|
|
def rtl?(locale = I18n.locale)
|
|
%i[ar fa he].include?(locale)
|
|
end
|
|
|
|
def markdown(text)
|
|
return text if text.blank?
|
|
|
|
render_options = {
|
|
filter_html: false,
|
|
hard_wrap: true,
|
|
link_attributes: { target: "_blank" }
|
|
}
|
|
renderer = Redcarpet::Render::HTML.new(render_options)
|
|
extensions = {
|
|
autolink: true,
|
|
fenced_code_blocks: true,
|
|
lax_spacing: true,
|
|
no_intra_emphasis: true,
|
|
strikethrough: true,
|
|
superscript: true
|
|
}
|
|
|
|
AdminLegislationSanitizer.new.sanitize(Redcarpet::Markdown.new(renderer, extensions).render(text))
|
|
end
|
|
|
|
def wysiwyg(text)
|
|
WYSIWYGSanitizer.new.sanitize(text)
|
|
end
|
|
|
|
def author_of?(authorable, user)
|
|
return false if authorable.blank? || user.blank?
|
|
|
|
authorable.author_id == user.id
|
|
end
|
|
|
|
def back_link_to(destination = :back, text = t("shared.back"))
|
|
link_to destination, class: "back" do
|
|
tag.span(class: "icon-angle-left") + text
|
|
end
|
|
end
|
|
|
|
def image_path_for(filename)
|
|
image = SiteCustomization::Image.image_for(filename)
|
|
|
|
if image
|
|
polymorphic_path(image)
|
|
elsif AssetFinder.find_asset(File.join(Tenant.subfolder_path, filename))
|
|
File.join(Tenant.subfolder_path, filename)
|
|
else
|
|
filename
|
|
end
|
|
end
|
|
|
|
def content_block(name, locale = I18n.locale)
|
|
SiteCustomization::ContentBlock.block_for(name, locale)
|
|
end
|
|
|
|
def self.asset_data_base64(path)
|
|
asset = (Rails.application.assets || ::Sprockets::Railtie.build_environment(Rails.application))
|
|
.find_asset(path)
|
|
throw "Could not find asset '#{path}'" if asset.nil?
|
|
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
|
|
"data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
|
|
end
|
|
|
|
def render_custom_partial(partial_name)
|
|
controller_action = @virtual_path.split("/").last
|
|
custom_partial_path = "custom/#{@virtual_path.remove(controller_action)}#{partial_name}"
|
|
render custom_partial_path if lookup_context.exists?(custom_partial_path, [], true)
|
|
end
|
|
|
|
def management_controller?
|
|
controller.class.to_s.include?("Management")
|
|
end
|
|
end
|