class Amber::Render::Layout

Public Class Methods

[](layout) click to toggle source
# File lib/amber/render/layout.rb, line 32
def self.[](layout)
  @layouts[layout]
end
load(layout_dir=nil) click to toggle source
# 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
new(file_path, &block) click to toggle source
# 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
reload() click to toggle source
# 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

Public Instance Methods

render(view, &block) click to toggle source
# File lib/amber/render/layout.rb, line 45
def render(view, &block)
  @template.render(view, &block)
end