Class: SpudSnippet

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spud_snippet.rb

Instance Method Summary collapse

Instance Method Details

#content_processedObject



21
22
23
24
25
26
# File 'app/models/spud_snippet.rb', line 21

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

#content_processed=(content) ⇒ Object



17
18
19
# File 'app/models/spud_snippet.rb', line 17

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

#postprocess_contentObject



12
13
14
15
# File 'app/models/spud_snippet.rb', line 12

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

#update_taglistObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/spud_snippet.rb', line 29

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