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 self[:content_processed].blank?
    if new_record?
      self.content_processed = postprocess_content()
    else
      update_column(:content_processed, postprocess_content)
    end
  end
  return self[:content_processed]
end

#content_processed=(content) ⇒ Object



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

def content_processed=(content)
  self[:content_processed] = content
end

#maintain_revisionsObject



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

def maintain_revisions
  return true unless changed.include?('content')
  revision = SpudPagePartialRevision.new(spud_page_id: spud_page_id, name: name, format: format, content: content)
  revision.save
  if Spud::Cms.max_revisions > 0
    revision_count = SpudPagePartialRevision.where(spud_page_id: spud_page_id, name: name).count
    if revision_count > Spud::Cms.max_revisions
      revision_bye = SpudPagePartialRevision.where(spud_page_id: spud_page_id, name: name).order('created_at ASC').first
      revision_bye.destroy unless 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(content)
  self.content_processed = @_template.render('page' => spud_page)
end

#symbol_nameObject



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

def symbol_name
  return @symbol_name || 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 = name.parameterize.underscore
end