Skip to content

Commit

Permalink
Don't rely on ActionView's partial-rendering code.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Jun 11, 2008
1 parent 7c13afd commit 9bae479
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
1 change: 0 additions & 1 deletion test/haml/results/just_stuff.xhtml
Expand Up @@ -17,7 +17,6 @@ Embedded? one af"t"er another!
<p>Embedded? true!</p>
<p>Embedded? twice! true!</p>
<p>Embedded? one af"t"er another!</p>
<div class='render'><em>wow!</em></div>
stuff followed by whitespace
<strong>block with whitespace</strong>
<p>
Expand Down
10 changes: 8 additions & 2 deletions test/haml/template_test.rb
Expand Up @@ -3,7 +3,6 @@
require 'haml/template'
require File.dirname(__FILE__) + '/mocks/article'


module Haml::Filters::Test
include Haml::Filters::Base

Expand All @@ -12,14 +11,21 @@ def render(text)
end
end

module Haml::Helpers
def test_partial(name, locals = {})
Haml::Engine.new(File.read(File.join(TemplateTest::TEMPLATE_PATH, "_#{name}.haml"))).render(self, locals)
end
end

class TemplateTest < Test::Unit::TestCase
TEMPLATE_PATH = File.join(File.dirname(__FILE__), "templates")
@@templates = %w{ very_basic standard helpers
whitespace_handling original_engine list helpful
silent_script tag_parsing just_stuff partials
filters nuke_outer_whitespace nuke_inner_whitespace }

def setup
@base = ActionView::Base.new(File.dirname(__FILE__) + "/templates/", {'article' => Article.new, 'foo' => 'value one'})
@base = ActionView::Base.new(TEMPLATE_PATH, 'article' => Article.new, 'foo' => 'value one')
@base.send(:evaluate_assigns)

# This is used by form_for.
Expand Down
2 changes: 1 addition & 1 deletion test/haml/templates/helpers.haml
Expand Up @@ -43,7 +43,7 @@ click
- form_tag '' do
%div= submit_tag 'save'
- @foo = 'value one'
= render :partial => './partial'
= test_partial 'partial'
- form_for :article, @article, :url => '' do |f|
Title:
= f.text_field :title
Expand Down
1 change: 0 additions & 1 deletion test/haml/templates/just_stuff.haml
Expand Up @@ -19,7 +19,6 @@
%p== Embedded? #{embedded}!
%p== Embedded? #{"twice! #{true}"}!
%p== Embedded? #{"one"} af"t"er #{"another"}!
.render= render :inline => "%em= 'wow!'", :type => :haml
= "stuff followed by whitespace"

- if true
Expand Down
2 changes: 1 addition & 1 deletion test/haml/templates/partials.haml
Expand Up @@ -6,7 +6,7 @@
%p
@foo =
= @foo
= render :file => "_partial.haml"
= test_partial "partial"
%p
@foo =
= @foo
20 changes: 10 additions & 10 deletions test/haml/templates/whitespace_handling.haml
@@ -1,9 +1,9 @@
#whitespace_test
= render :file => "_text_area.haml", :locals => { :value => "Oneline" }
= render :file => "_text_area.haml", :locals => { :value => "Two\nlines" }
~ render :file => "_text_area.haml", :locals => { :value => "Oneline" }
~ render :file => "_text_area.haml", :locals => { :value => "Two\nlines" }
#flattened~ render :file => "_text_area.haml", :locals => { :value => "Two\nlines" }
= test_partial "text_area", :value => "Oneline"
= test_partial "text_area", :value => "Two\nlines"
~ test_partial "text_area", :value => "Oneline"
~ test_partial "text_area", :value => "Two\nlines"
#flattened~ test_partial "text_area", :value => "Two\nlines"
.hithere
~ "Foo bar"
~ "<pre>foo bar</pre>"
Expand All @@ -15,11 +15,11 @@
~ ['a', 'b', 'c'].map do |a|
- "<textarea>\n#{a}\n</textarea>"
#whitespace_test
= render :file => "_text_area.haml", :locals => { :value => "Oneline" }
= render :file => "_text_area.haml", :locals => { :value => "Two\nlines" }
= find_and_preserve render(:file => "_text_area.haml", :locals => { :value => "Oneline" })
= find_and_preserve render(:file => "_text_area.haml", :locals => { :value => "Two\nlines" })
#flattened= find_and_preserve render(:file => "_text_area.haml", :locals => { :value => "Two\nlines" })
= test_partial "text_area", :value => "Oneline"
= test_partial "text_area", :value => "Two\nlines"
= find_and_preserve test_partial("text_area", :value => "Oneline")
= find_and_preserve test_partial("text_area", :value => "Two\nlines")
#flattened= find_and_preserve test_partial("text_area", :value => "Two\nlines")
.hithere
= find_and_preserve("Foo bar")
= find_and_preserve("<pre>foo bar</pre>")
Expand Down

0 comments on commit 9bae479

Please sign in to comment.