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

Don't rely on ActionView's partial-rendering code.

This commit is contained in:
Nathan Weizenbaum 2008-06-11 12:45:20 -07:00
parent 7c13afdeb7
commit 9bae479302
6 changed files with 20 additions and 16 deletions

View file

@ -17,7 +17,6 @@ Embedded? one af"t"er another!
<p>Embedded? true!</p> <p>Embedded? true!</p>
<p>Embedded? twice! true!</p> <p>Embedded? twice! true!</p>
<p>Embedded? one af"t"er another!</p> <p>Embedded? one af"t"er another!</p>
<div class='render'><em>wow!</em></div>
stuff followed by whitespace stuff followed by whitespace
<strong>block with whitespace</strong> <strong>block with whitespace</strong>
<p> <p>

View file

@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/../test_helper'
require 'haml/template' require 'haml/template'
require File.dirname(__FILE__) + '/mocks/article' require File.dirname(__FILE__) + '/mocks/article'
module Haml::Filters::Test module Haml::Filters::Test
include Haml::Filters::Base include Haml::Filters::Base
@ -12,14 +11,21 @@ module Haml::Filters::Test
end end
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 class TemplateTest < Test::Unit::TestCase
TEMPLATE_PATH = File.join(File.dirname(__FILE__), "templates")
@@templates = %w{ very_basic standard helpers @@templates = %w{ very_basic standard helpers
whitespace_handling original_engine list helpful whitespace_handling original_engine list helpful
silent_script tag_parsing just_stuff partials silent_script tag_parsing just_stuff partials
filters nuke_outer_whitespace nuke_inner_whitespace } filters nuke_outer_whitespace nuke_inner_whitespace }
def setup 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) @base.send(:evaluate_assigns)
# This is used by form_for. # This is used by form_for.

View file

@ -43,7 +43,7 @@ click
- form_tag '' do - form_tag '' do
%div= submit_tag 'save' %div= submit_tag 'save'
- @foo = 'value one' - @foo = 'value one'
= render :partial => './partial' = test_partial 'partial'
- form_for :article, @article, :url => '' do |f| - form_for :article, @article, :url => '' do |f|
Title: Title:
= f.text_field :title = f.text_field :title

View file

@ -19,7 +19,6 @@
%p== Embedded? #{embedded}! %p== Embedded? #{embedded}!
%p== Embedded? #{"twice! #{true}"}! %p== Embedded? #{"twice! #{true}"}!
%p== Embedded? #{"one"} af"t"er #{"another"}! %p== Embedded? #{"one"} af"t"er #{"another"}!
.render= render :inline => "%em= 'wow!'", :type => :haml
= "stuff followed by whitespace" = "stuff followed by whitespace"
- if true - if true

View file

@ -6,7 +6,7 @@
%p %p
@foo = @foo =
= @foo = @foo
= render :file => "_partial.haml" = test_partial "partial"
%p %p
@foo = @foo =
= @foo = @foo

View file

@ -1,9 +1,9 @@
#whitespace_test #whitespace_test
= render :file => "_text_area.haml", :locals => { :value => "Oneline" } = test_partial "text_area", :value => "Oneline"
= render :file => "_text_area.haml", :locals => { :value => "Two\nlines" } = test_partial "text_area", :value => "Two\nlines"
~ render :file => "_text_area.haml", :locals => { :value => "Oneline" } ~ test_partial "text_area", :value => "Oneline"
~ render :file => "_text_area.haml", :locals => { :value => "Two\nlines" } ~ test_partial "text_area", :value => "Two\nlines"
#flattened~ render :file => "_text_area.haml", :locals => { :value => "Two\nlines" } #flattened~ test_partial "text_area", :value => "Two\nlines"
.hithere .hithere
~ "Foo bar" ~ "Foo bar"
~ "<pre>foo bar</pre>" ~ "<pre>foo bar</pre>"
@ -15,11 +15,11 @@
~ ['a', 'b', 'c'].map do |a| ~ ['a', 'b', 'c'].map do |a|
- "<textarea>\n#{a}\n</textarea>" - "<textarea>\n#{a}\n</textarea>"
#whitespace_test #whitespace_test
= render :file => "_text_area.haml", :locals => { :value => "Oneline" } = test_partial "text_area", :value => "Oneline"
= render :file => "_text_area.haml", :locals => { :value => "Two\nlines" } = test_partial "text_area", :value => "Two\nlines"
= find_and_preserve render(:file => "_text_area.haml", :locals => { :value => "Oneline" }) = find_and_preserve test_partial("text_area", :value => "Oneline")
= find_and_preserve render(:file => "_text_area.haml", :locals => { :value => "Two\nlines" }) = find_and_preserve test_partial("text_area", :value => "Two\nlines")
#flattened= find_and_preserve render(:file => "_text_area.haml", :locals => { :value => "Two\nlines" }) #flattened= find_and_preserve test_partial("text_area", :value => "Two\nlines")
.hithere .hithere
= find_and_preserve("Foo bar") = find_and_preserve("Foo bar")
= find_and_preserve("<pre>foo bar</pre>") = find_and_preserve("<pre>foo bar</pre>")