Module: Texthelpers::ViewHelpers
- Defined in:
- lib/texthelpers/view_helpers.rb
Instance Method Summary collapse
- #markdown(text) ⇒ Object
- #text_for(page, options = {}) ⇒ Object
- #title_for(page, options = {}) ⇒ Object
Instance Method Details
#markdown(text) ⇒ Object
3 4 5 |
# File 'lib/texthelpers/view_helpers.rb', line 3 def markdown(text) raw BlueCloth.new(raw text).to_html end |
#text_for(page, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/texthelpers/view_helpers.rb', line 22 def text_for(page, = {}) [:markdown] ||= "yes" [:field] ||= "text" text = page.send("#{[:field]}_#{I18n.locale}") if text.blank? text = page.send("#{[:field]}_#{I18n.default_locale.to_s}") end if [:truncate] text = truncate text, :length => [:truncate] end if [:markdown] == "yes" raw BlueCloth.new(raw text).to_html else text end end |
#title_for(page, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/texthelpers/view_helpers.rb', line 7 def title_for(page, = {}) [:field] ||= "title" begin title = page.send("#{[:field]}_#{I18n.locale}") # Return default language title if no translation available if title.blank? title = page.send("#{[:field]}_#{I18n.default_locale.to_s}") end title rescue nil end end |