Module: Texthelpers::ViewHelpers

Defined in:
lib/texthelpers/view_helpers.rb

Instance Method Summary collapse

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, options = {})
  options[:markdown] ||= "yes"
  options[:field] ||= "text"

  text = page.send("#{options[:field]}_#{I18n.locale}")

  if text.blank?
    text = page.send("#{options[:field]}_#{I18n.default_locale.to_s}")
  end

  if options[:truncate] 
    text = truncate text, :length => options[:truncate]
  end

  if options[: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, options = {})
  options[:field] ||= "title"
  begin
    title = page.send("#{options[:field]}_#{I18n.locale}")
    # Return default language title if no translation available
    if title.blank?
      title = page.send("#{options[:field]}_#{I18n.default_locale.to_s}")
    end

    title
  rescue
    nil
  end
end