Class: Landable::Partial
- Inherits:
-
Object
- Object
- Landable::Partial
- Defined in:
- lib/landable/partial.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file) ⇒ Partial
constructor
A new instance of Partial.
- #process ⇒ Object
- #to_template ⇒ Object
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
.all ⇒ Object
38 39 40 |
# File 'lib/landable/partial.rb', line 38 def all files.map { |file| new(file) } end |
.files ⇒ Object
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
#process ⇒ Object
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_template ⇒ Object
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.find_or_create_by(username: 'TrogdorAdmin', email: '[email protected]', first_name: 'Marley', last_name: 'Pants') template.publish! author: template end |