Module: HomePage::ApplicationHelper
- Includes:
- AutoHtml
- Defined in:
- app/helpers/home_page/application_helper.rb
Instance Method Summary collapse
-
#bootstrap_flash_raw ⇒ Object
Taken from github.com/seyhunak/twitter-bootstrap-rails Modified to support html in flash message.
- #markdown(text) ⇒ Object
- #syntax_highlighter(html) ⇒ Object
Instance Method Details
#bootstrap_flash_raw ⇒ Object
Taken from github.com/seyhunak/twitter-bootstrap-rails Modified to support html in flash message
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/home_page/application_helper.rb', line 7 def bootstrap_flash_raw = [] flash.each do |type, | flash.delete(type) # Skip Devise :timeout and :timedout flags next if type == :timeout next if type == :timedout content = type.to_s == "filter" ? "" : content_tag(:button, raw("×"), :class => "close", "data-dismiss" => "alert") type = :success if ["notice", "filter"].include? type.to_s type = :danger if ["alert", "error", "recaptcha_error"].include? type.to_s content += raw() text = content_tag(:div, content, :class => "alert fade in alert-#{type}") << text if end .join("\n").html_safe end |
#markdown(text) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/home_page/application_helper.rb', line 28 def markdown(text) syntax_highlighter( auto_html(text) do youtube(width: 515, height: 300) dailymotion(width: 515, height: 300) vimeo(width: 515, height: 300) google_video(width: 515, height: 300) image redcarpet( renderer: Redcarpet::Render::XHTML.new( no_images: true, no_styles: true, hard_wrap: true, with_toc_data: true ), markdown_options: { no_intra_emphasis: true, autolink: true, fenced_code_blocks: true } ) link :target => "_blank", :rel => "nofollow" end.gsub(/(>https?:\/\/[^\<\\]+)/) do |match| truncate(match) end.gsub('<pre>', '').gsub('</pre>', '') ).html_safe end |
#syntax_highlighter(html) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/home_page/application_helper.rb', line 50 def syntax_highlighter(html) doc = Nokogiri::HTML(html) doc.search("//code[@class]").each do |code| code.replace Albino.colorize(code.text.rstrip, code[:class]) end doc.to_s end |