Module: Cadmus::Page::ClassMethods
- Defined in:
- lib/cadmus/page.rb
Instance Method Summary collapse
-
#cadmus_page(options = {}) ⇒ Object
Sets up a model to behave as a Cadmus page.
Instance Method Details
#cadmus_page(options = {}) ⇒ Object
Sets up a model to behave as a Cadmus page. This will add the following behaviors:
- A slug and slug generator field using HasSlug
- A name field that determines the name of the page 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
- Validators that ensure that this page has a name, that this page's slug is unique within the parent object, and that the slug isn't "pages" or "edit" (which are used for admin UI)
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cadmus/page.rb', line 28 def cadmus_page(={}) [:slug_generator_field] = [:name_field] unless .has_key?(:slug_generator_field) has_slug() cattr_accessor :name_field self.name_field = (.delete(:name_field) || :name).to_s belongs_to :parent, :polymorphic => true validates_presence_of name_field validates_uniqueness_of slug_field, :scope => [:parent_id, :parent_type] validates_exclusion_of slug_field, :in => %w(pages edit) scope :global, lambda { where(:parent_id => nil, :parent_type => nil) } class_eval do def liquid_template Liquid::Template.parse(content) end end end |