Sha256: 413534df755fe50cd5d12b05cb48d13e5a3fa416301482febc5770ba711c4b3e

Contents?: true

Size: 876 Bytes

Versions: 5

Compression:

Stored size: 876 Bytes

Contents

class PagePart
  
  include Mongoid::Document

  ## fields ##
  field :name, :type => String
  field :slug, :type => String
  field :value, :type => String
  field :disabled, :type => Boolean, :default => false
  field :value, :type => String
    
  ## associations ##
  embedded_in :page, :inverse_of => :parts
  
  ## callbacks ##
  # before_validate  { |p| p.slug ||= p.name.slugify if p.name.present? }  
  
  ## validations ##
  validates_presence_of :name, :slug
  
  ## named scopes ##
  named_scope :enabled, where(:disabled => false)
  
  ## methods ##
  
  def template
    "{% capture content_for_#{self.slug} %}#{self.value}{% endcapture %}"
  end
  
  def self.build_body_part
    self.new({
      :name => I18n.t('attributes.defaults.page_parts.name'), 
      :value => I18n.t('attributes.defaults.pages.other.body'), 
      :slug => 'layout'
    })
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
locomotive_cms-0.0.1.4 app/models/page_part.rb
locomotive_cms-0.0.1.3 app/models/page_part.rb
locomotive_cms-0.0.1.2 app/models/page_part.rb
locomotive_cms-0.0.1.1 app/models/page_part.rb
locomotive_cms-0.0.1 app/models/page_part.rb