1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Fixed class variable assignment issue for 1.5dev branch.

git-svn-id: svn://hamptoncatlin.com/haml/branches/1.5dev@183 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2006-12-03 22:18:33 +00:00
parent 485197ade8
commit cbc6a81113
5 changed files with 54 additions and 15 deletions

View file

@ -47,19 +47,18 @@ module Haml
# with <tt>local_assigns</tt> available as local variables within the template.
# Returns the result as a string.
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
unless @view.instance_variable_get("@assigns_added")
assigns = @view.assigns.dup
# 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
end
@view.instance_variable_set("@assigns_added", true)
end
options = @@options.dup

View file

@ -0,0 +1,20 @@
<p>
@foo =
value one
</p>
<p>
@foo =
value two
</p>
<p>
@foo =
value two
</p>
<p>
@foo =
value three
</p>
<p>
@foo =
value three
</p>

View file

@ -9,14 +9,15 @@ require File.dirname(__FILE__) + '/../lib/haml/template'
require File.dirname(__FILE__) + '/mocks/article'
class TemplateTest < Test::Unit::TestCase
@@templates = %w{ very_basic standard helpers
whitespace_handling original_engine list helpful
silent_script tag_parsing just_stuff}
@@templates = %w{ very_basic standard helpers
whitespace_handling original_engine list helpful
silent_script tag_parsing just_stuff partials }
def setup
ActionView::Base.register_template_handler("haml", Haml::Template)
@base = ActionView::Base.new(File.dirname(__FILE__) + "/../test/templates/")
@base.instance_variable_set("@article", Article.new)
@base.instance_variable_set("@foo", 'value one')
end
def render(text)

View file

@ -0,0 +1,7 @@
%p
@foo =
= @foo
- @foo = 'value three'
%p
@foo =
= @foo

View file

@ -0,0 +1,12 @@
%p
@foo =
= @foo
- @foo = 'value two'
%p
@foo =
= @foo
= render :file => "_partial.haml"
%p
@foo =
= @foo
- @foo = 'value one'