Class: Cms::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::Page
- Defined in:
- app/models/cms/page.rb
Instance Attribute Summary collapse
-
#blocks_attributes_changed ⇒ Object
Returns the value of attribute blocks_attributes_changed.
-
#tags(force_reload = false) ⇒ Object
Array of cms_tags for a page.
Class Method Summary collapse
-
.options_for_select(site, page = nil, current_page = nil, depth = 0, exclude_self = true, spacer = '. . ') ⇒ Object
– Class Methods ——————————————————– Tree-like structure for pages.
Instance Method Summary collapse
-
#blocks_attributes(was = false) ⇒ Object
Transforms existing cms_block information into a hash that can be used during form processing.
-
#blocks_attributes=(block_hashes = []) ⇒ Object
Array of block hashes in the following format: [ { :label => ‘block_1’, :content => ‘block content’ }, { :label => ‘block_2’, :content => ‘block content’ } ].
-
#blocks_attributes_was ⇒ Object
Method to collect prevous state of blocks for revisions.
-
#content(force_reload = false) ⇒ Object
Processing content will return rendered content and will populate self.cms_tags with instances of CmsTag.
-
#full_path ⇒ Object
– Instance Methods —————————————————– For previewing purposes sometimes we need to have full_path set.
-
#url ⇒ Object
Full url for a page.
Instance Attribute Details
#blocks_attributes_changed ⇒ Object
Returns the value of attribute blocks_attributes_changed.
9 10 11 |
# File 'app/models/cms/page.rb', line 9 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
106 107 108 |
# File 'app/models/cms/page.rb', line 106 def @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.(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 += (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[:label] = block.label 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:
[
{ :label => 'block_1', :content => 'block content' },
{ :label => 'block_2', :content => 'block content' }
]
84 85 86 87 88 89 90 91 |
# File 'app/models/cms/page.rb', line 84 def blocks_attributes=(block_hashes = []) block_hashes.each do |block_hash| block_hash.symbolize_keys! unless block_hash.is_a?(HashWithIndifferentAccess) block = self.blocks.detect{|b| b.label == block_hash[:label]} || self.blocks.build(:label => block_hash[:label]) block.content = block_hash[:content] self.blocks_attributes_changed = self.blocks_attributes_changed || block.content_changed? end end |
#blocks_attributes_was ⇒ Object
Method to collect prevous state of blocks for revisions
117 118 119 |
# File 'app/models/cms/page.rb', line 117 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
95 96 97 98 99 100 101 102 |
# File 'app/models/cms/page.rb', line 95 def content(force_reload = false) @content = read_attribute(:content) @content = nil if force_reload @content ||= begin self. = [] # resetting layout ? ComfortableMexicanSofa::Tag.process_content(self, layout.merged_content) : '' end end |
#full_path ⇒ Object
– 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 |
#url ⇒ Object
Full url for a page
112 113 114 |
# File 'app/models/cms/page.rb', line 112 def url "http://#{self.site.hostname}#{self.full_path}" end |