Class: Cms::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/cms/page.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blocks_attributes_changedObject

Returns the value of attribute blocks_attributes_changed.



12
13
14
# File 'app/models/cms/page.rb', line 12

def blocks_attributes_changed
  @blocks_attributes_changed
end

#tags(force_reload = false) ⇒ Object

Array of cms_tags for a page. Content generation is called if forced. These also include initialized cms_blocks if present



115
116
117
# File 'app/models/cms/page.rb', line 115

def tags
  @tags
end

Class Method Details

.options_for_select(site, page = nil, current_page = nil, depth = 0, exclude_self = true, spacer = '. . ') ⇒ Object

– Class Methods ——————————————————– Tree-like structure for pages



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

def self.options_for_select(site, page = nil, current_page = nil, depth = 0, exclude_self = true, spacer = '. . ')
  return [] if (current_page ||= site.pages.root) == page && exclude_self || !current_page
  out = []
  out << [ "#{spacer*depth}#{current_page.label}", current_page.id ] unless current_page == page
  current_page.children.each do |child|
    out += options_for_select(site, page, child, depth + 1, exclude_self, spacer)
  end
  return out.compact
end

Instance Method Details

#blocks_attributes(was = false) ⇒ Object

Transforms existing cms_block information into a hash that can be used during form processing. That’s the only way to modify cms_blocks.



70
71
72
73
74
75
76
77
# File 'app/models/cms/page.rb', line 70

def blocks_attributes(was = false)
  self.blocks.collect do |block|
    block_attr = {}
    block_attr[:identifier] = block.identifier
    block_attr[:content]    = was ? block.content_was : block.content
    block_attr
  end
end

#blocks_attributes=(block_hashes = []) ⇒ Object

Array of block hashes in the following format:

[
  { :identifier => 'block_1', :content => 'block content' },
  { :identifier => 'block_2', :content => 'block content' }
]


84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/cms/page.rb', line 84

def blocks_attributes=(block_hashes = [])
  block_hashes = block_hashes.values if block_hashes.is_a?(Hash)
  block_hashes.each do |block_hash|
    block_hash.symbolize_keys! unless block_hash.is_a?(HashWithIndifferentAccess)
    block = 
      self.blocks.detect{|b| b.identifier == block_hash[:identifier]} || 
      self.blocks.build(:identifier => block_hash[:identifier])
    block.content = block_hash[:content]
    self.blocks_attributes_changed = self.blocks_attributes_changed || block.content_changed?
  end
end

#blocks_attributes_wasObject

Method to collect prevous state of blocks for revisions



126
127
128
# File 'app/models/cms/page.rb', line 126

def blocks_attributes_was
  blocks_attributes(true)
end

#content(force_reload = false) ⇒ Object

Processing content will return rendered content and will populate self.cms_tags with instances of CmsTag



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/models/cms/page.rb', line 98

def content(force_reload = false)
  @content = force_reload ? nil : read_attribute(:content)
  @content ||= begin
    self.tags = [] # resetting
    if layout
      ComfortableMexicanSofa::Tag.process_content(
        self,
        ComfortableMexicanSofa::Tag.sanitize_irb(layout.merged_content)
      )
    else
      ''
    end
  end
end

#full_pathObject

– Instance Methods —————————————————– For previewing purposes sometimes we need to have full_path set



64
65
66
# File 'app/models/cms/page.rb', line 64

def full_path
  self.read_attribute(:full_path) || self.assign_full_path
end

#urlObject

Full url for a page



121
122
123
# File 'app/models/cms/page.rb', line 121

def url
  "http://#{self.site.hostname}#{self.full_path}"
end