Class: Page

Inherits:
Object
  • Object
show all
Includes:
ContentItem, Mongoid::FullTextSearch, Translator
Defined in:
app/models/page.rb

Instance Method Summary (collapse)

Methods included from Translator

included

Methods included from ContentItem

included, #markdown, #normalized_tags_with_weight

Instance Method Details

- (Boolean) derived?

True if this page is derived from another page and the original page still exists!

Returns:

  • (Boolean)

    true if this page is derived from another page and the original page still exists!



76
77
78
# File 'app/models/page.rb', line 76

def derived?
  return self.template_id != nil && self.template != nil
end

- (Object) fulltext



36
37
38
39
40
41
42
43
# File 'app/models/page.rb', line 36

def fulltext
  [
    title,
    body,
    comments.map(&:comment).join(" "),
    (page_components.any? ? page_components.map{|c| c.body}.join(" ") : "")
  ].join(' ')
end

- (Object) page_template

Return the CSS PageTemplate of this page



99
100
101
# File 'app/models/page.rb', line 99

def page_template
  PageTemplate.where(:_id => self.page_template_id.to_s).first if self.page_template_id
end

- (Object) page_template=(new_template)

Assign a CSS Template to this Page



104
105
106
# File 'app/models/page.rb', line 104

def page_template=(new_template)
  self.page_template_id = new_template.id if new_template
end

- (Object) page_with_edit_component_buttons(view_context, &block)



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/models/page.rb', line 126

def page_with_edit_component_buttons(view_context, &block )
  rc = self.render_body(view_context,false)
  rc.gsub(/\[EDIT_COMPONENT_LINK:(\S+)\]/) { |component_id|
    _component_id = component_id.gsub(/\[EDIT_COMPONENT_LINK:/,'').gsub(/\]$/,'')
    if view_context && view_context.can?(:edit, self)
      component = self.page_components.find(_component_id)
      unless block_given?
        if view_context
          view_context.ui_button( 'edit',
            I18n.translate(:edit),
            view_context.edit_page_page_component_path(self,_component_id),
            :remote => true, :title => I18n.translate(:edit_component)
          )
        else
          "<a href='/pages/#{self.page.id.to_s}/page_component/#{self.id.to_s}/edit' data-remote='true' class='button edit tiny'>#{I18n.translate(:edit)}</a>"
        end
      else
        yield(component)
      end
    else
      ""
    end
  }
end

- (Object) render_body(view_context = nil, interpret = false)

Render the body with RedCloth or Discount



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/page.rb', line 111

def render_body(view_context=nil,interpret=false)
  @view_context = view_context unless view_context.nil?
  unless self.page_template
    parts = [self.title_and_flags, self.t(I18n.locale,:body),"\nPLUSONE"]
    self.page_components.each do |component|
      parts << [component.render_body(view_context)]
    end
    rc=self.render_for_html( parts.join("\n"), @view_context)
  else
    rc=render_with_template
  end
  rc
end

- (Object) short_title_for_url

Same as short_title but will append a $-sign instead of ’…’ … smells in URLs and one can not see the difference if … is just part of the title or comes from truncation.



154
155
156
# File 'app/models/page.rb', line 154

def short_title_for_url
  title.truncate(CONSTANTS['title_max_length'].to_i, :omission => '$' )
end

- (Object) template

If this page is derived from a Page(Template) this method returns the template-page



51
52
53
54
55
56
57
# File 'app/models/page.rb', line 51

def template
  if self.template_id
    Page.templates.find(self.template_id)
  else
    nil
  end
end

- (Object) template=(new_template)

Set the template id

Parameters:

  • new_template (Page)

    is the page to be used as template for this page



61
62
63
64
65
66
67
# File 'app/models/page.rb', line 61

def template=(new_template)
  if new_template
    self.template_id = new_template.id
  else
    self.template_id = nil
  end
end

- (Object) template_by_name=(new_template)

Set the template by name @param[String] new_template the name of the new template



71
72
73
# File 'app/models/page.rb', line 71

def template_by_name=(new_template)
  self.template_id = PageTemplate.where(:name => new_template).first.id
end