2010-04-25 00:33:38 +00:00
|
|
|
class PagePart
|
2010-06-01 00:06:46 +00:00
|
|
|
|
2010-04-25 00:33:38 +00:00
|
|
|
include Mongoid::Document
|
|
|
|
|
|
|
|
## fields ##
|
2010-06-10 14:50:50 +00:00
|
|
|
field :name
|
|
|
|
field :slug
|
|
|
|
field :value
|
2010-04-25 00:33:38 +00:00
|
|
|
field :disabled, :type => Boolean, :default => false
|
2010-06-10 14:50:50 +00:00
|
|
|
field :value
|
2010-04-25 00:33:38 +00:00
|
|
|
|
|
|
|
## associations ##
|
|
|
|
embedded_in :page, :inverse_of => :parts
|
2010-07-13 00:46:17 +00:00
|
|
|
|
2010-04-25 00:33:38 +00:00
|
|
|
## validations ##
|
|
|
|
validates_presence_of :name, :slug
|
|
|
|
|
2010-05-09 12:44:53 +00:00
|
|
|
## named scopes ##
|
|
|
|
named_scope :enabled, where(:disabled => false)
|
|
|
|
|
|
|
|
## methods ##
|
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
def template
|
|
|
|
"{% capture content_for_#{self.slug} %}#{self.value}{% endcapture %}"
|
|
|
|
end
|
|
|
|
|
2010-05-09 12:44:53 +00:00
|
|
|
def self.build_body_part
|
2010-05-10 22:39:52 +00:00
|
|
|
self.new({
|
|
|
|
:name => I18n.t('attributes.defaults.page_parts.name'),
|
|
|
|
:value => I18n.t('attributes.defaults.pages.other.body'),
|
|
|
|
:slug => 'layout'
|
|
|
|
})
|
2010-05-09 12:44:53 +00:00
|
|
|
end
|
2010-05-30 23:57:33 +00:00
|
|
|
|
2010-04-25 00:33:38 +00:00
|
|
|
end
|