class Rory::Renderer

Public Class Methods

new(template_name, options = {}) click to toggle source
# File lib/rory/renderer.rb, line 6
def initialize(template_name, options = {})
  @template_name = template_name
  @options = options
  @app = options[:app]
end

Public Instance Methods

layout_path() click to toggle source
# File lib/rory/renderer.rb, line 33
def layout_path
  return nil unless @options[:layout]
  File.join('layouts', @options[:layout].to_s)
end
render(&block) click to toggle source
# File lib/rory/renderer.rb, line 12
def render(&block)
  erb = ERB.new(view_template)
  output = erb.result(view_binding(&block))
  if layout_path
    layout_renderer = self.class.new(layout_path, @options.merge(:layout => false))
    output = layout_renderer.render { output }
  end
  output
end
view_binding() { |args| ... } click to toggle source
# File lib/rory/renderer.rb, line 22
def view_binding
  render_context = Context.new(@options)
  render_context.get_binding { |*args|
    yield(args) if block_given?
  }
end
view_path() click to toggle source
# File lib/rory/renderer.rb, line 38
def view_path
  root = @app ? @app.root : Rory.root
  File.expand_path(File.join('views', "#{@template_name}.html.erb"), root)
end
view_template() click to toggle source
# File lib/rory/renderer.rb, line 29
def view_template
  File.read(view_path)
end