Module: Lines::ApplicationHelper
- Defined in:
- app/helpers/lines/application_helper.rb
Defined Under Namespace
Classes: HTMLwithPygments
Instance Method Summary collapse
-
#display_article_authors(article, with_info = false) ⇒ Object
Returns HTML with all authors of an article.
-
#format_code(text) ⇒ Object
Returns HTML for code blocks formatted with Pygment.
-
#get_action_link ⇒ Object
Returns site name for actionbar, dependend on current site.
-
#markdown(text) ⇒ Object
Returns formatted and highlighted code fragments.
-
#nav_link(link_text, link_path) ⇒ Object
Returns links in active or inactive state for highlighting current page.
-
#render_navbar(&block) ⇒ Object
Renders the navigation bar for logged in users.
-
#render_teaser(article, article_counter = 0) ⇒ Object
Renders the teaser for an article.
Instance Method Details
#display_article_authors(article, with_info = false) ⇒ Object
Returns HTML with all authors of an article
58 59 60 61 62 63 64 |
# File 'app/helpers/lines/application_helper.rb', line 58 def (article, with_info=false) = article..map{|| .gplus_profile.blank? ? .name : link_to(.name, .gplus_profile)}.to_sentence(two_words_connector: " & ", last_word_connector: " & ").html_safe if with_info += (" — " + article..map{|| content_tag(:span, "#{.description}", class: 'author_description') }.join(" — ")).html_safe end end |
#format_code(text) ⇒ Object
Returns HTML for code blocks formatted with Pygment
120 121 122 |
# File 'app/helpers/lines/application_helper.rb', line 120 def format_code(text) simple_format( truncate( Sanitize.clean(markdown(text)).html_safe, escape: false, length: 300, separator: ' ', omission: ' …' )) end |
#get_action_link ⇒ Object
Returns site name for actionbar, dependend on current site
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/helpers/lines/application_helper.rb', line 101 def get_action_link if controller_path == 'admin/articles' case action_name when 'index' then t('lines/buttons/all_articles').html_safe when 'new' then t('lines/buttons/new_article').html_safe when 'edit' then t('lines/buttons/edit_article').html_safe when 'show' then t('lines/buttons/preview').html_safe end elsif controller_path == 'admin/authors' case action_name when 'index' then t('lines/buttons/all_authors').html_safe when 'new' then t('lines/buttons/new_author').html_safe when 'edit' then t('lines/buttons/edit_author').html_safe when 'show' then t('lines/buttons/author').html_safe end end end |
#markdown(text) ⇒ Object
Returns formatted and highlighted code fragments
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/lines/application_helper.rb', line 33 def markdown(text) renderer = HTMLwithPygments.new(hard_wrap: true, filter_html: false, with_toc_data: false) = { autolink: true, no_intra_emphasis: true, fenced_code_blocks: true, lax_html_blocks: true, tables: true, strikethrough: true, superscript: true, xhtml: true } Redcarpet::Markdown.new(renderer, ).render(text).html_safe end |
#nav_link(link_text, link_path) ⇒ Object
Returns links in active or inactive state for highlighting current page
49 50 51 52 53 54 55 |
# File 'app/helpers/lines/application_helper.rb', line 49 def nav_link(link_text, link_path) recognized = Rails.application.routes.recognize_path(link_path) class_name = recognized[:controller] == params[:controller] ? 'active' : '' content_tag(:li, class: class_name) do link_to link_text, link_path end end |
#render_navbar(&block) ⇒ Object
Renders the navigation bar for logged in users
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/helpers/lines/application_helper.rb', line 67 def (&block) action_link = get_action_link if !action_link action_link = CONFIG[:title_short] end html = content_tag(:div, id: 'navbar') do content_tag(:div, class: 'navbar-inner') do if current_lines_user content_tag(:span, class: 'buttons', &block) + "<div class='btn-menu'><div class='stripes'></div></div>".html_safe + "<div class='submenu'> <div class='submenu-inner'> <ul> <li>#{link_to("Dashboard", admin_articles_path)}</li> <li>#{link_to(t('activerecord.models.lines/author', count: 2).html_safe, )}</li> </ul> <ul> <li class='small'>#{t('lines.logged_in_as').html_safe} #{current_lines_user.email}</li> <li>#{link_to(t('lines.buttons.logout').html_safe, logout_path)}</li> </ul> <ul> <li>#{link_to(t('lines.buttons.formating_help').html_safe, "#", class: "btn-cheatsheet")}</li> <li>#{link_to(t('lines.buttons.about').html_safe, "http://lines.opoloo.com")}</li> </ul> </div> </div>".html_safe else content_tag(:span, link_to('', lines.root_path), class: 'backlink') + content_tag(:span, action_link, class: 'actionlink') end end end html end |
#render_teaser(article, article_counter = 0) ⇒ Object
Renders the teaser for an article.
9 10 11 12 13 14 15 16 |
# File 'app/helpers/lines/application_helper.rb', line 9 def (article, article_counter=0) if article_counter < 0 = article. && article..present? ? markdown(article.) : nil else = article. && article..present? ? format_code(article.) : format_code(article.content) end end |