Class: Cms::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::Page
- Includes:
- Base
- Defined in:
- app/models/cms/page.rb
Instance Attribute Summary collapse
-
#blocks_attributes_changed ⇒ Object
Returns the value of attribute blocks_attributes_changed.
-
#cached_content ⇒ Object
Returns the value of attribute cached_content.
-
#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.
- #clear_cached_content! ⇒ Object
-
#content ⇒ Object
Cached content accessor.
-
#full_path ⇒ Object
– Instance Methods —————————————————– For previewing purposes sometimes we need to have full_path set.
-
#identifier ⇒ Object
Somewhat unique method of identifying a page that is not a full_path.
-
#render ⇒ Object
Processing content will return rendered content and will populate self.cms_tags with instances of CmsTag.
-
#url ⇒ Object
Full url for a page.
Instance Attribute Details
#blocks_attributes_changed ⇒ Object
Returns the value of attribute blocks_attributes_changed.
11 12 13 |
# File 'app/models/cms/page.rb', line 11 def blocks_attributes_changed @blocks_attributes_changed end |
#cached_content ⇒ Object
Returns the value of attribute cached_content.
11 12 13 |
# File 'app/models/cms/page.rb', line 11 def cached_content @cached_content 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
130 131 132 |
# File 'app/models/cms/page.rb', line 130 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
54 55 56 57 58 59 60 61 62 |
# File 'app/models/cms/page.rb', line 54 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 if current_page.children_count.nonzero? 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.
78 79 80 81 82 83 84 85 |
# File 'app/models/cms/page.rb', line 78 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' }
]
92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/models/cms/page.rb', line 92 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
141 142 143 |
# File 'app/models/cms/page.rb', line 141 def blocks_attributes_was blocks_attributes(true) end |
#clear_cached_content! ⇒ Object
124 125 126 |
# File 'app/models/cms/page.rb', line 124 def clear_cached_content! self.update_column(:content, nil) end |
#content ⇒ Object
Cached content accessor
116 117 118 119 120 121 122 |
# File 'app/models/cms/page.rb', line 116 def content if (@cached_content = read_attribute(:content)).nil? @cached_content = self.render update_column(:content, @cached_content) unless self.new_record? end @cached_content end |
#full_path ⇒ Object
– Instance Methods —————————————————– For previewing purposes sometimes we need to have full_path set. This full path take care of the pages and its childs but not of the site path
67 68 69 |
# File 'app/models/cms/page.rb', line 67 def full_path self.read_attribute(:full_path) || self.assign_full_path end |
#identifier ⇒ Object
Somewhat unique method of identifying a page that is not a full_path
72 73 74 |
# File 'app/models/cms/page.rb', line 72 def identifier self.parent_id.blank?? 'index' : self.full_path[1..-1].slugify end |
#render ⇒ Object
Processing content will return rendered content and will populate self.cms_tags with instances of CmsTag
106 107 108 109 110 111 112 113 |
# File 'app/models/cms/page.rb', line 106 def render @tags = [] # resetting return '' unless layout ComfortableMexicanSofa::Tag.process_content( self, ComfortableMexicanSofa::Tag.sanitize_irb(layout.merged_content) ) end |
#url ⇒ Object
Full url for a page
136 137 138 |
# File 'app/models/cms/page.rb', line 136 def url "//" + "#{self.site.hostname}/#{self.site.path}/#{self.full_path}".squeeze("/") end |