Class: Page

Inherits:
Object
  • Object
show all
Includes:
LocalizedKeys, Mongoid::Document, Mongoid::Timestamps, Mongoid::Tree
Defined in:
app/models/page.rb

Instance Method Summary collapse

Instance Method Details

#permalink=(permalink) ⇒ Object

Sets permalink only if custom permalink is enabled.



46
47
48
# File 'app/models/page.rb', line 46

def permalink=(permalink)
  write_attribute(:permalink, permalink) if self.custom_permalink?
end

#preferred_contentObject



54
55
56
57
58
59
60
61
# File 'app/models/page.rb', line 54

def preferred_content
  lang = I18n.locale.to_s
  if content(lang).present?
    content(lang)
  else
    content
  end
end

#title=(new_title) ⇒ Object

Sets title and generates permalink if custom permalink is disabled.



40
41
42
43
# File 'app/models/page.rb', line 40

def title=(new_title)
  write_attribute(:permalink, Permalink.from(new_title)) unless self.custom_permalink?
  write_attribute(:title, new_title)
end

#to_htmlObject



63
64
65
66
67
68
69
70
71
72
# File 'app/models/page.rb', line 63

def to_html
  content = I18n.locale
  filters = { 'markdown' => BlueCloth,
              'textile'  => RedCloth }
  if filters.include?(self.filter)
    filters[self.filter].new(self.preferred_content).to_html
  else
    self.preferred_content
  end
end

#to_sObject



50
51
52
# File 'app/models/page.rb', line 50

def to_s
  title
end