Sha256: d3d8d1b615242de13575e581f68734828a5e6d780e8341be440faa5b995ad72c

Contents?: true

Size: 1.25 KB

Versions: 18

Compression:

Stored size: 1.25 KB

Contents

class SpudSnippet < ActiveRecord::Base
  attr_accessible :content, :content_processed, :format, :name
  has_many :spud_page_liquid_tags, :as => :attachment, :dependent => :destroy

  validates :name, :presence => true
  validates_uniqueness_of :name, :scope => :site_id

  scope :site, lambda {|sid| where(:site_id => sid)}

  before_save :postprocess_content
  after_save :update_taglist
  def postprocess_content
    template = Liquid::Template.parse(self.content) # Parses and compiles the template
    self.content_processed = template.render()
  end

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

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


  def update_taglist
    template = Liquid::Template.parse(self.content) # Parses and compiles the template

    self.spud_page_liquid_tags.all.each do |tag|
      tag.destroy
    end
    template.root.nodelist.each do |node|
      if !node.is_a?(String) && defined?(node.tag_name) && defined?(node.tag_value)
        self.spud_page_liquid_tags.create(:tag_name => node.tag_name,:value => node.tag_value)
      end
    end
  end

end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
tb_cms-1.0.3 app/models/spud_snippet.rb
spud_cms-0.9.21 app/models/spud_snippet.rb
spud_cms-0.9.20 app/models/spud_snippet.rb
tb_cms-1.0.2 app/models/spud_snippet.rb
tb_cms-1.0.1 app/models/spud_snippet.rb
spud_cms-0.9.18 app/models/spud_snippet.rb
tb_cms-1.0 app/models/spud_snippet.rb
tb_cms-0.9.18 app/models/spud_snippet.rb
spud_cms-0.9.17 app/models/spud_snippet.rb
spud_cms-0.9.15 app/models/spud_snippet.rb
spud_cms-0.9.14 app/models/spud_snippet.rb
spud_cms-0.9.13 app/models/spud_snippet.rb
spud_cms-0.9.12 app/models/spud_snippet.rb
spud_cms-0.9.11 app/models/spud_snippet.rb
spud_cms-0.9.10 app/models/spud_snippet.rb
spud_cms-0.9.9 app/models/spud_snippet.rb
spud_cms-0.9.8 app/models/spud_snippet.rb
spud_cms-0.9.7 app/models/spud_snippet.rb