Class: Landable::Template

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Librarian, TableName
Defined in:
app/models/landable/template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Librarian

#nuke!, #reactivate

Instance Attribute Details

#temp_authorObject

attributes



7
8
9
# File 'app/models/landable/template.rb', line 7

def temp_author
  @temp_author
end

Class Method Details

.create_from_partials!Object



54
55
56
# File 'app/models/landable/template.rb', line 54

def create_from_partials!
  Partial.all.map(&:to_template)
end

Instance Method Details

#deactivateObject



21
22
23
24
25
# File 'app/models/landable/template.rb', line 21

def deactivate
  publish!(author_id: temp_author.id, notes: "This template has been trashed")

  super
end

#name=(val) ⇒ Object



27
28
29
30
# File 'app/models/landable/template.rb', line 27

def name= val
  self[:name] = val
  self[:slug] ||= (val && val.underscore.gsub(/[^\w_]/, '_').gsub(/_{2,}/, '_'))
end

#partial?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/landable/template.rb', line 32

def partial?
  file.present?
end

#publish!(options) ⇒ Object



36
37
38
39
40
41
42
# File 'app/models/landable/template.rb', line 36

def publish!(options)
  transaction do
    published_revision.unpublish! if published_revision
    revision = revisions.create! options
    update_attributes!(published_revision: revision, is_publishable: false)
  end
end

#revert_to!(revision) ⇒ Object



44
45
46
47
48
49
50
51
# File 'app/models/landable/template.rb', line 44

def revert_to!(revision)
  self.name          = revision.name
  self.body          = revision.body
  self.description   = revision.description
  self.slug          = revision.slug

  save!
end