Class: Landable::Layout
- Inherits:
-
Object
- Object
- Landable::Layout
- Defined in:
- lib/landable/layout.rb
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(file) ⇒ Layout
constructor
A new instance of Layout.
- #process ⇒ Object
- #to_theme ⇒ Object
Constructor Details
#initialize(file) ⇒ Layout
Returns a new instance of Layout.
7 8 9 |
# File 'lib/landable/layout.rb', line 7 def initialize(file) @file = file end |
Class Method Details
.all ⇒ Object
47 48 49 |
# File 'lib/landable/layout.rb', line 47 def all files.map { |file| new(file) } end |
.files ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/landable/layout.rb', line 51 def files files = [] paths.map do |path| files << Dir[path + "/**/[^_]*.html.*"] files << Dir[path + "/**/application*"] end files.flatten.uniq end |
.paths ⇒ Object
62 63 64 |
# File 'lib/landable/layout.rb', line 62 def paths @paths ||= Dir[Rails.root.join('app/views/layouts').to_s] end |
Instance Method Details
#description ⇒ Object
42 43 44 |
# File 'lib/landable/layout.rb', line 42 def description "Defined in #@path.html.#@extension" end |
#process ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/landable/layout.rb', line 11 def process return if @processed path = @file.dup self.class.paths.each { |p| path.sub!(p, '') } path.sub!(/^\//, '') @path, @extension = path.split('.html.', 2) @body = File.read(@file) @processed = true end |
#to_theme ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/landable/layout.rb', line 26 def to_theme process unless @processed theme = Theme.where(file: @path).first_or_initialize theme.name ||= @path.gsub('/', ' ').titlecase theme.extension = @extension theme.description = description if theme.description.blank? || theme.description =~ /^Defined in/ theme.body = @body theme.editable = false theme.thumbnail_url ||= "http://placehold.it/300x200" theme.save! theme end |