Class: SpudPagePartial

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

Instance Method Summary collapse

Instance Method Details

#content_processedObject



43
44
45
46
47
48
# File 'app/models/spud_page_partial.rb', line 43

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



39
40
41
# File 'app/models/spud_page_partial.rb', line 39

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

#maintain_revisionsObject



50
51
52
53
54
55
56
57
# File 'app/models/spud_page_partial.rb', line 50

def maintain_revisions
  if self.changed.include?('content')
    revision = SpudPagePartialRevision.create(:spud_page_id => self.spud_page_id,:name => self.name,:format => self.format,:content => self.content)
    drop_old_revisions if Spud::Cms.max_revisions > 0
  end

  return true
end

#postprocess_contentObject



20
21
22
23
24
# File 'app/models/spud_page_partial.rb', line 20

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

  self.content_processed = template.render('page' => self.spud_page)
end

#symbol_nameObject



16
17
18
# File 'app/models/spud_page_partial.rb', line 16

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

#update_symbol_nameObject



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

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

#update_taglistObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/spud_page_partial.rb', line 26

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