Sha256: 377482d5d976e90cbbf7ad9dbd192d0050717d06b64fff5bd0bbe52595b7bec3
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 KB
Contents
module Landable class Template < ActiveRecord::Base include Landable::TableName include Landable::Librarian # attributes attr_accessor :temp_author validates_presence_of :name, :slug, :description validates_uniqueness_of :name, case_sensitive: false validates_uniqueness_of :slug, case_sensitive: false belongs_to :published_revision, class_name: 'Landable::TemplateRevision' has_many :revisions, class_name: 'Landable::TemplateRevision' before_save -> template { template.is_publishable = true unless template.published_revision_id_changed? } def deactivate publish!(author_id: temp_author.id, notes: "This template has been trashed") super end def name= val self[:name] = val self[:slug] ||= (val && val.underscore.gsub(/[^\w_]/, '_').gsub(/_{2,}/, '_')) end def partial? file.present? end def publish!(options) transaction do published_revision.unpublish! if published_revision revision = revisions.create! options update_attributes!(published_revision: revision, is_publishable: false) end end def revert_to!(revision) self.name = revision.name self.body = revision.body self.description = revision.description self.slug = revision.slug save! end class << self def create_from_partials! Partial.all.map(&:to_template) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
landable-1.9.0.rc1 | app/models/landable/template.rb |
landable-1.8.0 | app/models/landable/template.rb |