Module: Cadmus::Layout::ClassMethods
- Defined in:
- lib/cadmus/layout.rb
Instance Method Summary collapse
-
#cadmus_layout(options = {}) ⇒ Object
Sets up a model to behave as a Cadmus layout.
Instance Method Details
#cadmus_layout(options = {}) ⇒ Object
Sets up a model to behave as a Cadmus layout. This will add the following behaviors:
- A name field that determines the name of the layout for administrative UI
- An optional, polymorphic +parent+ field
- A scope called +global+ that returns instances of this class that have no parent
- A +liquid_template+ method that parses the value of this model's +content+ field as a Liquid template
- A validator that ensure that this layout has a name
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cadmus/layout.rb', line 20 def cadmus_layout( = {}) model_with_parent cattr_accessor :name_field self.name_field = (.delete(:name_field) || :name).to_s validates_uniqueness_of name_field, scope: [:parent_id, :parent_type] liquid_template_field :liquid_template, :content validates_template_validity :content unless [:skip_template_validation] end |