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: [ { :identifier => ‘block_1’, :content => ‘block content’ }, { :identifier => ‘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.
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 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[: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_was ⇒ Object
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. = [] # resetting if layout ComfortableMexicanSofa::Tag.process_content( self, ComfortableMexicanSofa::Tag.sanitize_irb(layout.merged_content) ) else '' end 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
121 122 123 |
# File 'app/models/cms/page.rb', line 121 def url "http://#{self.site.hostname}#{self.full_path}" end |