mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Haml] Add a :css filter.
This commit is contained in:
parent
a47f627d76
commit
7ef8110c22
4 changed files with 42 additions and 0 deletions
|
@ -29,6 +29,11 @@ Haml and `html2haml` now produce more descriptive errors
|
|||
when given a template with invalid byte sequences for that template's encoding,
|
||||
including the line number and the offending character.
|
||||
|
||||
### `:css` Filter
|
||||
|
||||
Haml now supports a {file:HAML_REFERENCE.md#css-filter `:css` filter}
|
||||
that surrounds the filtered text with `<style>` and CDATA tags.
|
||||
|
||||
### `html2haml` Improvements
|
||||
|
||||
* Ruby blocks within ERB are now supported.
|
||||
|
|
|
@ -1081,6 +1081,11 @@ when you don't want lines starting with `.` or `-` to be parsed.
|
|||
Surrounds the filtered text with `<script>` and CDATA tags.
|
||||
Useful for including inline Javascript.
|
||||
|
||||
{#css-filter}
|
||||
### `:css`
|
||||
Surrounds the filtered text with `<style>` and CDATA tags.
|
||||
Useful for including inline CSS.
|
||||
|
||||
{#cdata-filter}
|
||||
### `:cdata`
|
||||
Surrounds the filtered text with CDATA tags.
|
||||
|
|
|
@ -200,6 +200,23 @@ END
|
|||
end
|
||||
end
|
||||
|
||||
# Surrounds the filtered text with `<style>` and CDATA tags.
|
||||
# Useful for including inline CSS.
|
||||
module Css
|
||||
include Base
|
||||
|
||||
# @see Base#render_with_options
|
||||
def render_with_options(text, options)
|
||||
<<END
|
||||
<style type=#{options[:attr_wrapper]}text/css#{options[:attr_wrapper]}>
|
||||
/*<![CDATA[*/
|
||||
#{text.rstrip.gsub("\n", "\n ")}
|
||||
/*]]>*/
|
||||
</style>
|
||||
END
|
||||
end
|
||||
end
|
||||
|
||||
# Surrounds the filtered text with CDATA tags.
|
||||
module Cdata
|
||||
include Base
|
||||
|
|
|
@ -909,6 +909,21 @@ END
|
|||
END
|
||||
end
|
||||
|
||||
def test_css_filter
|
||||
assert_equal(<<CSS, render(<<SASS))
|
||||
<style type='text/css'>
|
||||
/*<![CDATA[*/
|
||||
#foo {
|
||||
bar: baz; }
|
||||
/*]]>*/
|
||||
</style>
|
||||
CSS
|
||||
:css
|
||||
#foo {
|
||||
bar: baz; }
|
||||
SASS
|
||||
end
|
||||
|
||||
def test_local_assigns_dont_modify_class
|
||||
assert_equal("bar\n", render("= foo", :locals => {:foo => 'bar'}))
|
||||
assert_equal(nil, defined?(foo))
|
||||
|
|
Loading…
Add table
Reference in a new issue