Class: SpudSnippet
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SpudSnippet
- Defined in:
- app/models/spud_snippet.rb
Instance Method Summary collapse
- #content_processed ⇒ Object
- #content_processed=(content) ⇒ Object
- #expire_cache ⇒ Object
- #postprocess_content ⇒ Object
- #update_taglist ⇒ Object
Instance Method Details
#content_processed ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/models/spud_snippet.rb', line 30 def content_processed if read_attribute(:content_processed).blank? self.update_column(:content_processed, postprocess_content) end template = Liquid::Template.parse(read_attribute(:content_processed)) # Parses and compiles the template return template.render() end |
#content_processed=(content) ⇒ Object
26 27 28 |
# File 'app/models/spud_snippet.rb', line 26 def content_processed=(content) write_attribute(:content_processed,content) end |
#expire_cache ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'app/models/spud_snippet.rb', line 53 def expire_cache # Now Time to Update Parent Entries old_name = self.name_was values = [self.name] values << old_name if !old_name.blank? SpudPageLiquidTag.where(:tag_name => "snippet",:value => values).includes(:attachment).each do |tag| partial = tag.touch end end |
#postprocess_content ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'app/models/spud_snippet.rb', line 15 def postprocess_content rendererClass = Spud::Core.renderer(self.format) if rendererClass renderer = rendererClass.new() self.content_processed = renderer.render self.content else self.content_processed = content end end |
#update_taglist ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/spud_snippet.rb', line 39 def update_taglist template = Liquid::Template.parse(self.content) # Parses and compiles the template self..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..create(:tag_name => node.tag_name,:value => node.tag_value) end end end |