Module: Conred::Helpers
Instance Method Summary collapse
- #action_view ⇒ Object
- #external_url(link) ⇒ Object
- #sanitize_and_trim(text = "", word_count = nil, omission = '...') ⇒ Object
- #sanitize_body(text = "") ⇒ Object
Instance Method Details
#action_view ⇒ Object
9 10 11 |
# File 'lib/conred/helpers.rb', line 9 def action_view @action_view ||= ActionView::Base.new end |
#external_url(link) ⇒ Object
27 28 29 |
# File 'lib/conred/helpers.rb', line 27 def external_url(link) /^http/.match(link) ? link : "http://#{link}" end |
#sanitize_and_trim(text = "", word_count = nil, omission = '...') ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/conred/helpers.rb', line 13 def sanitize_and_trim(text = "", word_count = nil, omission = '...') text = action_view.(text) if word_count action_view.truncate(text, :length => word_count, :omission => omission).to_s.html_safe else text.to_s.html_safe end end |
#sanitize_body(text = "") ⇒ Object
22 23 24 25 |
# File 'lib/conred/helpers.rb', line 22 def sanitize_body(text = "") text = action_view.sanitize(text, :tags => %w(p a strong ul ol li blockquote strike u em), :attributes => %w(href)) text.to_s.html_safe end |