Module: Cadmus::Layout::ClassMethods

Defined in:
lib/cadmus/layout.rb

Instance Method Summary collapse

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

Parameters:

  • options (Hash) (defaults to: {})

    options to modify the default behavior

Options Hash (options):

  • :name_field (Object)

    the name of the field to be used as the layout name. Defaults to +:name+.

  • :skip_template_validation (Object)

    if present, skips the validation of the content template.



20
21
22
23
24
25
26
27
28
29
# File 'lib/cadmus/layout.rb', line 20

def cadmus_layout(options = {})
  model_with_parent

  cattr_accessor :name_field
  self.name_field = (options.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 options[:skip_template_validation]
end