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



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

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

#content_processed=(content) ⇒ Object



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

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

#maintain_revisionsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/spud_page_partial.rb', line 37

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

#postprocess_contentObject



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

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

#symbol_nameObject



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

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

#update_symbol_nameObject



9
10
11
# File 'app/models/spud_page_partial.rb', line 9

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