2010-06-01 00:06:46 +00:00
|
|
|
class LiquidTemplate
|
|
|
|
|
|
|
|
include Locomotive::Mongoid::Document
|
2010-05-02 23:33:17 +00:00
|
|
|
|
|
|
|
## fields ##
|
|
|
|
field :name
|
|
|
|
field :slug
|
|
|
|
field :value
|
|
|
|
|
|
|
|
## associations ##
|
|
|
|
belongs_to_related :site
|
|
|
|
|
|
|
|
## callbacks ##
|
|
|
|
before_validate :normalize_slug
|
|
|
|
|
|
|
|
## validations ##
|
|
|
|
validates_presence_of :site, :name, :slug, :value
|
2010-05-30 23:57:33 +00:00
|
|
|
validates_uniqueness_of :slug, :scope => :site_id
|
|
|
|
|
2010-06-01 00:06:46 +00:00
|
|
|
## behaviours ##
|
|
|
|
liquify_template :value
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-06-01 00:06:46 +00:00
|
|
|
## methods ##
|
|
|
|
|
2010-05-02 23:33:17 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def normalize_slug
|
|
|
|
self.slug = self.name.clone if self.slug.blank? && self.name.present?
|
|
|
|
self.slug.slugify!(:without_extension => true, :downcase => true) if self.slug.present?
|
|
|
|
end
|
2010-06-01 00:06:46 +00:00
|
|
|
|
2010-05-02 23:33:17 +00:00
|
|
|
end
|