Class: Landable::Partial

Inherits:
Object
  • Object
show all
Defined in:
lib/landable/partial.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Partial

Returns a new instance of Partial.



3
4
5
# File 'lib/landable/partial.rb', line 3

def initialize(file)
  @file = file
end

Class Method Details

.allObject



38
39
40
# File 'lib/landable/partial.rb', line 38

def all
  files.map { |file| new(file) }
end

.filesObject



42
43
44
45
46
47
48
# File 'lib/landable/partial.rb', line 42

def files
  files = []

  Landable.configuration.partials_to_templates.each do |path|
    files << path
  end
end

Instance Method Details

#processObject



7
8
9
10
11
12
13
# File 'lib/landable/partial.rb', line 7

def process
  @name        = @file.gsub('/', ' ').titlecase
  @description = "The Code for this template can be seen at #{@file} in the source code"
  @slug        = @file.gsub(/[^\w]/, '_')

  @processed = true
end

#to_templateObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/landable/partial.rb', line 15

def to_template
  process unless @processed

  template                 = Template.where(file: @file).first_or_initialize
  template.body            = ''
  template.name            = @name
  template.slug            = @slug
  template.description     = @description
  template.editable        = false
  template.is_layout       = false
  template.thumbnail_url ||= 'http://placehold.it/300x200'

  # Save!
  template.save!

  # Publish!
  author = Author.find_or_create_by(username: 'TrogdorAdmin', email: '[email protected]', first_name: 'Marley', last_name: 'Pants')
  template.publish! author: author

  template
end