Module: ComfortableMexicanSofa::CmsManageable::InstanceMethods
- Defined in:
- lib/comfortable_mexican_sofa/extensions/cms_manageable.rb
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_content_cache ⇒ Object
- #clear_content_cache! ⇒ Object
-
#content_cache ⇒ Object
Cached content accessor.
-
#render ⇒ Object
Processing content will return rendered content and will populate self.cms_tags with instances of CmsTag.
-
#tags(force_reload = false) ⇒ Object
Array of cms_tags for a page.
- #tags=(tags) ⇒ Object
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.
34 35 36 37 38 39 40 41 |
# File 'lib/comfortable_mexican_sofa/extensions/cms_manageable.rb', line 34 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' }
]
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/comfortable_mexican_sofa/extensions/cms_manageable.rb', line 48 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
83 84 85 |
# File 'lib/comfortable_mexican_sofa/extensions/cms_manageable.rb', line 83 def blocks_attributes_was blocks_attributes(true) end |
#clear_content_cache ⇒ Object
100 101 102 |
# File 'lib/comfortable_mexican_sofa/extensions/cms_manageable.rb', line 100 def clear_content_cache write_attribute(:content_cache, nil) if self.has_attribute?(:content_cache) end |
#clear_content_cache! ⇒ Object
96 97 98 |
# File 'lib/comfortable_mexican_sofa/extensions/cms_manageable.rb', line 96 def clear_content_cache! self.update_column(:content_cache, nil) end |
#content_cache ⇒ Object
Cached content accessor
88 89 90 91 92 93 94 |
# File 'lib/comfortable_mexican_sofa/extensions/cms_manageable.rb', line 88 def content_cache if (@content_cache = read_attribute(:content_cache)).nil? @content_cache = self.render update_column(:content_cache, @content_cache) unless self.new_record? end @content_cache end |
#render ⇒ Object
Processing content will return rendered content and will populate self.cms_tags with instances of CmsTag
62 63 64 65 66 67 68 69 |
# File 'lib/comfortable_mexican_sofa/extensions/cms_manageable.rb', line 62 def render @tags = [] # resetting return '' unless layout ComfortableMexicanSofa::Tag.process_content( self, ComfortableMexicanSofa::Tag.sanitize_irb(layout.merged_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
77 78 79 80 |
# File 'lib/comfortable_mexican_sofa/extensions/cms_manageable.rb', line 77 def (force_reload = false) self.render if force_reload @tags ||= [] end |
#tags=(tags) ⇒ Object
71 72 73 |
# File 'lib/comfortable_mexican_sofa/extensions/cms_manageable.rb', line 71 def () @tags = end |