Class: Amber::Render::Layout

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

Direct Known Subclasses

DefaultLayout

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, &block) ⇒ Layout

Returns a new instance of Layout.



36
37
38
39
40
41
42
43
# File 'lib/amber/render/layout.rb', line 36

def initialize(file_path, &block)
  if file_path =~ /\.haml$/
    ugly = Amber.env != :test
    @template = Tilt::HamlTemplate.new(file_path, {:format => :html5, :ugly => ugly})
  else
    @template = Tilt.new(file_path, &block)
  end
end

Class Method Details

.[](layout) ⇒ Object



32
33
34
# File 'lib/amber/render/layout.rb', line 32

def self.[](layout)
  @layouts[layout]
end

.load(layout_dir = nil) ⇒ Object



15
16
17
18
19
# File 'lib/amber/render/layout.rb', line 15

def self.load(layout_dir=nil)
  @layout_dirs ||= []
  @layout_dirs << layout_dir if layout_dir
  reload
end

.reloadObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/amber/render/layout.rb', line 21

def self.reload
  @layouts ||= {}
  @layouts['default'] = DefaultLayout.new
  @layout_dirs.each do |dir|
    Dir.glob("#{dir}/*").each do |layout_file|
      name = File.basename(layout_file).sub(/^([^\.]*).*$/, "\\1")
      @layouts[name] = Layout.new(layout_file)
    end
  end
end

Instance Method Details

#render(view, &block) ⇒ Object



45
46
47
# File 'lib/amber/render/layout.rb', line 45

def render(view, &block)
  @template.render(view, &block)
end