mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Insert newline inside tag
This commit is contained in:
parent
db016c48c6
commit
15ae22e3b2
2 changed files with 49 additions and 37 deletions
|
@ -2,6 +2,9 @@ module Hamlit
|
||||||
class WhitespaceHandler
|
class WhitespaceHandler
|
||||||
def compile_children(node, &block)
|
def compile_children(node, &block)
|
||||||
temple = [:multi]
|
temple = [:multi]
|
||||||
|
return temple if node.children.empty?
|
||||||
|
|
||||||
|
temple << [:static, "\n"] if prepend_whitespace?(node)
|
||||||
node.children.each do |n|
|
node.children.each do |n|
|
||||||
temple << yield(n)
|
temple << yield(n)
|
||||||
temple << [:static, "\n"] if insert_whitespace?(n)
|
temple << [:static, "\n"] if insert_whitespace?(n)
|
||||||
|
@ -11,6 +14,15 @@ module Hamlit
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def prepend_whitespace?(node)
|
||||||
|
case node.type
|
||||||
|
when :tag
|
||||||
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def insert_whitespace?(node)
|
def insert_whitespace?(node)
|
||||||
case node.type
|
case node.type
|
||||||
when :doctype
|
when :doctype
|
||||||
|
|
|
@ -173,37 +173,37 @@ tags with unusual CSS identifiers:
|
||||||
# <p>text</p>
|
# <p>text</p>
|
||||||
# </div>
|
# </div>
|
||||||
# </div>
|
# </div>
|
||||||
# tags with nested content:
|
tags with nested content:
|
||||||
# Nested content simple tag:
|
Nested content simple tag:
|
||||||
# haml: |-
|
haml: |-
|
||||||
# %p
|
%p
|
||||||
# hello
|
hello
|
||||||
# html: |-
|
html: |-
|
||||||
# <p>
|
<p>
|
||||||
# hello
|
hello
|
||||||
# </p>
|
</p>
|
||||||
# Nested content tag with CSS:
|
Nested content tag with CSS:
|
||||||
# haml: |-
|
haml: |-
|
||||||
# %p.class1
|
%p.class1
|
||||||
# hello
|
hello
|
||||||
# html: |-
|
html: |-
|
||||||
# <p class='class1'>
|
<p class='class1'>
|
||||||
# hello
|
hello
|
||||||
# </p>
|
</p>
|
||||||
# Nested content multiple simple tags:
|
Nested content multiple simple tags:
|
||||||
# haml: |-
|
haml: |-
|
||||||
# %div
|
%div
|
||||||
# %div
|
%div
|
||||||
# %p
|
%p
|
||||||
# text
|
text
|
||||||
# html: |-
|
html: |-
|
||||||
# <div>
|
<div>
|
||||||
# <div>
|
<div>
|
||||||
# <p>
|
<p>
|
||||||
# text
|
text
|
||||||
# </p>
|
</p>
|
||||||
# </div>
|
</div>
|
||||||
# </div>
|
</div>
|
||||||
tags with HTML-style attributes:
|
tags with HTML-style attributes:
|
||||||
HTML-style one attribute:
|
HTML-style one attribute:
|
||||||
haml: "%p(a='b')"
|
haml: "%p(a='b')"
|
||||||
|
@ -477,17 +477,17 @@ Ruby-style interpolation:
|
||||||
# html: <"&>
|
# html: <"&>
|
||||||
# config:
|
# config:
|
||||||
# escape_html: 'true'
|
# escape_html: 'true'
|
||||||
# boolean attributes:
|
boolean attributes:
|
||||||
# boolean attribute with XHTML:
|
# boolean attribute with XHTML:
|
||||||
# haml: "%input(checked=true)"
|
# haml: "%input(checked=true)"
|
||||||
# html: "<input checked='checked' />"
|
# html: "<input checked='checked' />"
|
||||||
# config:
|
# config:
|
||||||
# format: xhtml
|
# format: xhtml
|
||||||
# boolean attribute with HTML:
|
boolean attribute with HTML:
|
||||||
# haml: "%input(checked=true)"
|
haml: "%input(checked=true)"
|
||||||
# html: "<input checked>"
|
html: "<input checked>"
|
||||||
# config:
|
config:
|
||||||
# format: html5
|
format: html5
|
||||||
# whitespace preservation:
|
# whitespace preservation:
|
||||||
# following the '~' operator:
|
# following the '~' operator:
|
||||||
# haml: ~ "Foo\n<pre>Bar\nBaz</pre>"
|
# haml: ~ "Foo\n<pre>Bar\nBaz</pre>"
|
||||||
|
|
Loading…
Add table
Reference in a new issue