Sha256: bc4dfc810fd8da07be2477ddc037903e2aa99a332cd38248801fc801e2e8902a

Contents?: true

Size: 1.59 KB

Versions: 6

Compression:

Stored size: 1.59 KB

Contents

class SpudPagePartial < ActiveRecord::Base
	belongs_to :spud_page, :touch => true
	has_many :spud_liquid_tags, :as => :attachment, :dependent => :destroy
	validates :name,:presence => true
	before_save :maintain_revisions
	before_save :update_symbol_name
	acts_as_spud_liquid_content

	def update_symbol_name
		self.symbol_name = self.name.parameterize.underscore
	end

	def symbol_name
		return @symbol_name || self.name.parameterize.underscore
	end

	def postprocess_content
		@_template = Liquid::Template.parse(self.content)
		self.content_processed = @_template.render('page' => self.spud_page)
	end

	def content_processed=(content)
		write_attribute(:content_processed,content)
	end

	def content_processed
		if read_attribute(:content_processed).blank?
			if self.new_record?
				self.content_processed = postprocess_content()
			else
				self.update_column(:content_processed, postprocess_content)
			end
		end
		return read_attribute(:content_processed)
	end

	def maintain_revisions
		if !self.changed.include?('content')
			return true
		end
		revision = SpudPagePartialRevision.new(:spud_page_id => self.spud_page_id,:name => self.name,:format => self.format,:content => self.content)
			revision.save
			if Spud::Cms.max_revisions > 0
				revision_count = SpudPagePartialRevision.where(:spud_page_id => self.spud_page_id,:name => self.name).count
				if revision_count > Spud::Cms.max_revisions
					revision_bye = SpudPagePartialRevision.where(:spud_page_id => self.spud_page_id,:name => self.name).order("created_at ASC").first
					revision_bye.destroy if !revision_bye.blank?
				end
			end
		return true
	end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tb_cms-1.1.5 app/models/spud_page_partial.rb
tb_cms-1.1.4 app/models/spud_page_partial.rb
tb_cms-1.1.3 app/models/spud_page_partial.rb
tb_cms-1.1.2 app/models/spud_page_partial.rb
tb_cms-1.1.1 app/models/spud_page_partial.rb
tb_cms-1.1.0 app/models/spud_page_partial.rb