Class: Smithy::PageContent
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Smithy::PageContent
- Defined in:
- app/models/smithy/page_content.rb
Instance Method Summary collapse
- #attributes=(attributes = {}) ⇒ Object
- #content_block_attributes=(attributes) ⇒ Object
- #render(liquid_context) ⇒ Object
- #templates ⇒ Object
- #to_liquid ⇒ Object
Instance Method Details
#attributes=(attributes = {}) ⇒ Object
19 20 21 22 |
# File 'app/models/smithy/page_content.rb', line 19 def attributes=(attributes = {}) self.content_block_type = attributes[:content_block_type] super end |
#content_block_attributes=(attributes) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/models/smithy/page_content.rb', line 24 def content_block_attributes=(attributes) return unless attributes.present? klass = content_block_type.safe_constantize || "Smithy::#{content_block_type}".safe_constantize if klass self.content_block = klass.find_or_initialize_by(id: attributes.delete(:id)) self.content_block.attributes = attributes self.content_block end end |
#render(liquid_context) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/models/smithy/page_content.rb', line 34 def render(liquid_context) liquid_context.stack do # push the default assigns into a smithy namespace. They'll still be in the # scopes as the original values as well, but this ensures they don't get clobbered liquid_context.merge('smithy' => liquid_context.scopes.last) liquid_context.merge(self.to_liquid) content_block_template.liquid_template.render(liquid_context) end end |
#templates ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'app/models/smithy/page_content.rb', line 52 def templates unless @templates @templates = [] if Smithy::ContentBlock.find_by_name(self.content_block_type.demodulize) @templates = Smithy::ContentBlock.find_by_name(self.content_block_type.demodulize).templates end end @templates end |
#to_liquid ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/models/smithy/page_content.rb', line 44 def to_liquid if content_block.respond_to?(:to_liquid) content_block.to_liquid else content_block.attributes end end |