mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Haml] [html2haml] Add support for the :css filter as well.
This commit is contained in:
parent
d851ff5b19
commit
68bf3acfdb
3 changed files with 23 additions and 3 deletions
|
@ -55,6 +55,7 @@ including the line number and the offending character.
|
|||
Flip #{bang}.
|
||||
|
||||
* `<script>` tags are now transformed into `:javascript` filters,
|
||||
and `<style>` tags into `:css` filters.
|
||||
and indentation is preserved.
|
||||
For example:
|
||||
|
||||
|
|
|
@ -216,7 +216,11 @@ module Haml
|
|||
if name == "script" &&
|
||||
(attributes['type'].nil? || attributes['type'] == "text/javascript") &&
|
||||
(attributes.keys - ['type']).empty?
|
||||
return script_to_haml(tabs, options)
|
||||
return to_haml_filter(:javascript, tabs, options)
|
||||
elsif name == "style" &&
|
||||
(attributes['type'].nil? || attributes['type'] == "text/css") &&
|
||||
(attributes.keys - ['type']).empty?
|
||||
return to_haml_filter(:css, tabs, options)
|
||||
end
|
||||
|
||||
output = "#{tabulate(tabs)}"
|
||||
|
@ -272,7 +276,7 @@ module Haml
|
|||
end
|
||||
end
|
||||
|
||||
def script_to_haml(tabs, options)
|
||||
def to_haml_filter(filter, tabs, options)
|
||||
content =
|
||||
if children.first.is_a?(::Hpricot::CData)
|
||||
children.first.content
|
||||
|
@ -287,7 +291,7 @@ module Haml
|
|||
content.gsub!(/^#{original_indent}/, tabulate(tabs + 1))
|
||||
end
|
||||
|
||||
"#{tabulate(tabs)}:javascript\n#{content}"
|
||||
"#{tabulate(tabs)}:#{filter}\n#{content}"
|
||||
end
|
||||
|
||||
def haml_tag_loud(text)
|
||||
|
|
|
@ -178,6 +178,21 @@ HAML
|
|||
HTML
|
||||
end
|
||||
|
||||
def test_erb_in_style
|
||||
assert_equal(<<HAML.rstrip, render_erb(<<HTML))
|
||||
:css
|
||||
foo {
|
||||
bar: baz;
|
||||
}
|
||||
HAML
|
||||
<style type="text/css">
|
||||
foo {
|
||||
bar: baz;
|
||||
}
|
||||
</style>
|
||||
HTML
|
||||
end
|
||||
|
||||
def test_erb_in_line
|
||||
assert_equal 'foo bar #{baz}', render_erb('foo bar <%= baz %>')
|
||||
assert_equal 'foo bar #{baz}! Bang.', render_erb('foo bar <%= baz %>! Bang.')
|
||||
|
|
Loading…
Add table
Reference in a new issue