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:
parent
23f8e7d42e
commit
c73ab70e86
3 changed files with 67 additions and 14 deletions
|
@ -191,30 +191,63 @@ module Haml
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# open_tag helps you construct HTML in your helpers.
|
|
||||||
# It can be used this way
|
|
||||||
#
|
#
|
||||||
# open_tag :table do
|
# call-seq:
|
||||||
# open_tag :tr do
|
# open(name, attributes = {}) {...}
|
||||||
# open_tag :td do
|
# 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"
|
# puts "data"
|
||||||
# end
|
# end
|
||||||
# open_tag :td do
|
# open :td do
|
||||||
# puts "more_data"
|
# puts "more_data"
|
||||||
# end
|
# end
|
||||||
# end
|
# 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!!!!
|
# TODO: TEST!!!!
|
||||||
def open(name, text = nil, attributes = {}, &block)
|
def open(name, attributes = {}, alt_atts = {}, &block)
|
||||||
puts "<#{name}#{Haml::Buffer.build_attributes(attributes)}>"
|
text = nil
|
||||||
|
if attributes.is_a? String
|
||||||
|
text = attributes
|
||||||
|
attributes = alt_atts
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "<#{name}#{buffer.build_attributes(attributes)}>"
|
||||||
tab_up
|
tab_up
|
||||||
# Print out either the text (using push_text) or call the block and add an endline
|
# Print out either the text (using push_text) or call the block and add an endline
|
||||||
if text
|
if text
|
||||||
puts(text)
|
puts(text)
|
||||||
else
|
elsif block
|
||||||
lock.call
|
block.call
|
||||||
end
|
end
|
||||||
tab_down
|
tab_down
|
||||||
puts "</#{name}>"
|
puts "</#{name}>"
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
click
|
click
|
||||||
<a href='thing'>here</a>.
|
<a href='thing'>here</a>.
|
||||||
<p>baz</p>
|
<p>baz</p>
|
||||||
<p>boom</p>
|
<p>boom</p>
|
||||||
foo
|
foo
|
||||||
<p>
|
<p>
|
||||||
<form action="hello/world" method="post">
|
<form action="hello/world" method="post">
|
||||||
|
@ -69,3 +69,16 @@ foo
|
||||||
baz
|
baz
|
||||||
boom, again
|
boom, again
|
||||||
</p>
|
</p>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td class='cell'>
|
||||||
|
<strong>
|
||||||
|
strong!
|
||||||
|
</strong>
|
||||||
|
data
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
more_data
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
|
@ -31,10 +31,10 @@ click
|
||||||
= succeed '.' do
|
= succeed '.' do
|
||||||
%a{:href=>"thing"} here
|
%a{:href=>"thing"} here
|
||||||
%p baz
|
%p baz
|
||||||
- tab_up
|
- buffer.tabulation = 10
|
||||||
%p boom
|
%p boom
|
||||||
- concat "foo\n"
|
- concat "foo\n"
|
||||||
- tab_down
|
- buffer.tabulation = 0
|
||||||
- def url_for(*stuff); stuff.join(' '); end
|
- def url_for(*stuff); stuff.join(' '); end
|
||||||
%p
|
%p
|
||||||
= form_tag 'hello/world'
|
= form_tag 'hello/world'
|
||||||
|
@ -54,3 +54,10 @@ click
|
||||||
- puts "boom"
|
- puts "boom"
|
||||||
baz
|
baz
|
||||||
- puts "boom, again"
|
- 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"
|
||||||
|
|
Loading…
Add table
Reference in a new issue