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:
parent
485197ade8
commit
cbc6a81113
5 changed files with 54 additions and 15 deletions
|
@ -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
|
||||
|
|
20
test/results/partials.xhtml
Normal file
20
test/results/partials.xhtml
Normal 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>
|
|
@ -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)
|
||||
|
|
7
test/templates/_partial.haml
Normal file
7
test/templates/_partial.haml
Normal file
|
@ -0,0 +1,7 @@
|
|||
%p
|
||||
@foo =
|
||||
= @foo
|
||||
- @foo = 'value three'
|
||||
%p
|
||||
@foo =
|
||||
= @foo
|
12
test/templates/partials.haml
Normal file
12
test/templates/partials.haml
Normal file
|
@ -0,0 +1,12 @@
|
|||
%p
|
||||
@foo =
|
||||
= @foo
|
||||
- @foo = 'value two'
|
||||
%p
|
||||
@foo =
|
||||
= @foo
|
||||
= render :file => "_partial.haml"
|
||||
%p
|
||||
@foo =
|
||||
= @foo
|
||||
- @foo = 'value one'
|
Loading…
Reference in a new issue