2006-09-29 18:39:13 +00:00
|
|
|
require File.dirname(__FILE__) + '/engine'
|
2006-10-14 22:24:53 +00:00
|
|
|
require 'active_support'
|
|
|
|
require 'action_view'
|
2006-09-29 18:39:13 +00:00
|
|
|
|
|
|
|
module Haml
|
|
|
|
class Template
|
|
|
|
def initialize(view)
|
|
|
|
@view = view
|
|
|
|
end
|
2006-10-05 15:18:35 +00:00
|
|
|
|
2006-09-29 18:39:13 +00:00
|
|
|
def render(template, local_assigns={})
|
|
|
|
assigns = @view.assigns.dup
|
|
|
|
|
|
|
|
# Do content for layout on its own to keep things working in partials
|
|
|
|
if content_for_layout = @view.instance_variable_get("@content_for_layout")
|
|
|
|
assigns['content_for_layout'] = content_for_layout
|
|
|
|
end
|
|
|
|
|
|
|
|
# Get inside the view object's world
|
|
|
|
@view.instance_eval do
|
|
|
|
# Set all the instance variables
|
|
|
|
assigns.each do |key,val|
|
|
|
|
instance_variable_set "@#{key}", val
|
|
|
|
end
|
|
|
|
# Set all the local assigns
|
|
|
|
local_assigns.each do |key,val|
|
|
|
|
class << self; self; end.send(:define_method, key) { val }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-09-29 19:57:35 +00:00
|
|
|
Haml::Engine.new(template, :scope_object => @view).to_html
|
2006-09-29 18:39:13 +00:00
|
|
|
end
|
|
|
|
end
|
2006-10-14 22:24:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
module ActionView
|
|
|
|
class Base
|
|
|
|
attr :haml_filename, true
|
|
|
|
|
|
|
|
alias haml_old_render_file render_file
|
|
|
|
def render_file(template_path, use_full_path = true, local_assigns = {})
|
|
|
|
@haml_filename = File.basename(template_path)
|
|
|
|
haml_old_render_file(template_path, use_full_path, local_assigns)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|