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

open_tag works, and is renamed open.

git-svn-id: svn://hamptoncatlin.com/haml/trunk@410 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2007-03-16 03:02:33 +00:00
parent 23f8e7d42e
commit c73ab70e86
3 changed files with 67 additions and 14 deletions

View file

@ -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
#
# <table>
# <tr>
# <td class='cell'>
# <strong>
# strong!
# </strong>
# data
# </td>
# <td>
# more_data
# </td>
# </tr>
# </table>
#
#
# 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}>"

View file

@ -45,7 +45,7 @@
click
<a href='thing'>here</a>.
<p>baz</p>
<p>boom</p>
<p>boom</p>
foo
<p>
<form action="hello/world" method="post">
@ -69,3 +69,16 @@ foo
baz
boom, again
</p>
<table>
<tr>
<td class='cell'>
<strong>
strong!
</strong>
data
</td>
<td>
more_data
</td>
</tr>
</table>

View file

@ -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"