Files
nairobi/app/helpers/application_helper.rb

69 lines
2.3 KiB
Ruby

module ApplicationHelper
def home_page?
return false if user_signed_in?
# Using path because fullpath yields false negatives since it contains
# parameters too
request.path == '/'
end
def opendata_page?
request.path == '/opendata'
end
def header_css
home_page? || opendata_page? ? '' : 'results'
end
# 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))
end
def markdown(text)
render_options = {
# will remove from the output HTML tags inputted by user
filter_html: false,
# will insert <br /> tags in paragraphs where are newlines
# (ignored by default)
hard_wrap: true,
# hash for extra link options, for example 'nofollow'
link_attributes: { }
# more
# will remove <img> tags from output
# no_images: true
# will remove <a> tags from output
# no_links: true
# will remove <style> tags from output
# no_styles: true
# generate links for only safe protocols
# safe_links_only: true
# and more ... (prettify, with_toc_data, xhtml)
}
renderer = Redcarpet::Render::HTML.new(render_options)
extensions = {
#will parse links without need of enclosing them
autolink: true,
# blocks delimited with 3 ` or ~ will be considered as code block.
# No need to indent. You can provide language name too.
# ```ruby
# block of code
# ```
fenced_code_blocks: true,
# will ignore standard require for empty lines surrounding HTML blocks
lax_spacing: true,
# will not generate emphasis inside of words, for example no_emph_no
no_intra_emphasis: true,
# will parse strikethrough from ~~, for example: ~~bad~~
strikethrough: true,
# will parse superscript after ^, you can wrap superscript in ()
superscript: true
# will require a space after # in defining headers
# space_after_headers: true
}
Redcarpet::Markdown.new(renderer, extensions).render(text).html_safe
end
end