From c73ab70e869c5b376a8b6288f849ecad9c35c424 Mon Sep 17 00:00:00 2001
From: nex3
Date: Fri, 16 Mar 2007 03:02:33 +0000
Subject: [PATCH] open_tag works, and is renamed open.
git-svn-id: svn://hamptoncatlin.com/haml/trunk@410 7063305b-7217-0410-af8c-cdc13e5119b9
---
lib/haml/helpers.rb | 55 +++++++++++++++++++++++++-------
test/haml/results/helpers.xhtml | 15 ++++++++-
test/haml/templates/helpers.haml | 11 +++++--
3 files changed, 67 insertions(+), 14 deletions(-)
diff --git a/lib/haml/helpers.rb b/lib/haml/helpers.rb
index 9d679196..56ba09c6 100644
--- a/lib/haml/helpers.rb
+++ b/lib/haml/helpers.rb
@@ -191,30 +191,63 @@ module Haml
nil
end
- # open_tag helps you construct HTML in your helpers.
- # It can be used this way
#
- # open_tag :table do
- # open_tag :tr do
- # open_tag :td do
+ # call-seq:
+ # open(name, attributes = {}) {...}
+ # open(name, text, attributes = {}) {...}
+ #
+ # Creates an HTML tag with the given name and optionally text and attributes.
+ # Can take a block that will be executed
+ # between when the opening and closing tags are output.
+ # If the block is a Haml block or outputs text using puts,
+ # the text will be properly indented.
+ #
+ # For example,
+ #
+ # open :table do
+ # open :tr do
+ # open :td, {:class => 'cell'} do
+ # open :strong, "strong!"
# puts "data"
# end
- # open_tag :td do
+ # open :td do
# puts "more_data"
# end
# end
# end
#
- # TODO: Make it output with better tabulation
+ # outputs
+ #
+ #
+ #
+ #
+ #
+ # strong!
+ #
+ # data
+ # |
+ #
+ # more_data
+ # |
+ #
+ #
+ #
+ #
# TODO: TEST!!!!
- def open(name, text = nil, attributes = {}, &block)
- puts "<#{name}#{Haml::Buffer.build_attributes(attributes)}>"
+ def open(name, attributes = {}, alt_atts = {}, &block)
+ text = nil
+ if attributes.is_a? String
+ text = attributes
+ attributes = alt_atts
+ end
+
+ puts "<#{name}#{buffer.build_attributes(attributes)}>"
tab_up
# Print out either the text (using push_text) or call the block and add an endline
if text
puts(text)
- else
- lock.call
+ elsif block
+ block.call
end
tab_down
puts "#{name}>"
diff --git a/test/haml/results/helpers.xhtml b/test/haml/results/helpers.xhtml
index 230c4ee4..cd274752 100644
--- a/test/haml/results/helpers.xhtml
+++ b/test/haml/results/helpers.xhtml
@@ -45,7 +45,7 @@
click
here.
baz
- boom
+ boom
foo
+
+
+
+
+ strong!
+
+ data
+ |
+
+ more_data
+ |
+
+
diff --git a/test/haml/templates/helpers.haml b/test/haml/templates/helpers.haml
index fce2282b..85dd3ac0 100644
--- a/test/haml/templates/helpers.haml
+++ b/test/haml/templates/helpers.haml
@@ -31,10 +31,10 @@ click
= succeed '.' do
%a{:href=>"thing"} here
%p baz
-- tab_up
+- buffer.tabulation = 10
%p boom
- concat "foo\n"
-- tab_down
+- buffer.tabulation = 0
- def url_for(*stuff); stuff.join(' '); end
%p
= form_tag 'hello/world'
@@ -54,3 +54,10 @@ click
- puts "boom"
baz
- puts "boom, again"
+- open :table do
+ - open :tr do
+ - open :td, {:class => 'cell'} do
+ - open :strong, "strong!"
+ - puts "data"
+ - open :td do
+ - puts "more_data"