Class: Layout

Inherits:
Object
  • Object
show all
Defined in:
lib/engine_of_war/layout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ Layout

Returns a new instance of Layout.



4
5
6
# File 'lib/engine_of_war/layout.rb', line 4

def initialize(page)
  @page = page
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



2
3
4
# File 'lib/engine_of_war/layout.rb', line 2

def page
  @page
end

Instance Method Details

#default_layoutObject



26
27
28
# File 'lib/engine_of_war/layout.rb', line 26

def default_layout
  "application"
end

#layout_from_directoryObject



18
19
20
# File 'lib/engine_of_war/layout.rb', line 18

def layout_from_directory
  File.dirname(page.request_path).sub!(%r{^[/.]}, "")
end

#layout_from_metaObject



22
23
24
# File 'lib/engine_of_war/layout.rb', line 22

def layout_from_meta
  page.meta[:layout]
end

#nameObject



8
9
10
# File 'lib/engine_of_war/layout.rb', line 8

def name
  potential_layouts.first + ".html"
end

#potential_layoutsObject



12
13
14
15
16
# File 'lib/engine_of_war/layout.rb', line 12

def potential_layouts
  [layout_from_directory, layout_from_meta, default_layout].reject(&:blank?).compact.select do |f|
    File.exists?(File.join(page.views_root, "layouts", "#{f}.html.haml"))
  end
end