mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Fix url() conversion.
This commit is contained in:
parent
35cf34d3d2
commit
74afa38bb7
6 changed files with 25 additions and 3 deletions
|
@ -19,6 +19,8 @@ now allow whitespace before the colon. For example:
|
|||
|
||||
* `#{}` interpolation is now allowed within `url()`.
|
||||
|
||||
* `url()`s within Sass2 properties are properly converted to Sass 3 or SCSS now.
|
||||
|
||||
* Don't consider e.g. `foo ($bar + $baz)` to be a function call.
|
||||
Function calls can't have whitespace between the name and the parentheses.
|
||||
|
||||
|
|
|
@ -17,6 +17,15 @@ module Sass
|
|||
# @return [Array<Script::Node>]
|
||||
attr_reader :args
|
||||
|
||||
# Don't set the context for child nodes if this is `url()`,
|
||||
# since `url()` allows quoted strings.
|
||||
#
|
||||
# @param context [Symbol]
|
||||
# @see Node#context=
|
||||
def context=(context)
|
||||
super unless @name == "url"
|
||||
end
|
||||
|
||||
# @param name [String] See \{#name}
|
||||
# @param name [Array<Script::Node>] See \{#args}
|
||||
def initialize(name, args)
|
||||
|
|
|
@ -35,7 +35,7 @@ module Sass::Script
|
|||
children.each {|c| c.options = options}
|
||||
end
|
||||
|
||||
# Sets the options hash for this node,
|
||||
# Sets the context for this node,
|
||||
# as well as for all child nodes.
|
||||
#
|
||||
# @param context [Symbol]
|
||||
|
|
|
@ -52,7 +52,8 @@ module Sass::Script
|
|||
def to_sass(opts = {})
|
||||
type = opts[:type] || self.type
|
||||
if type == :identifier
|
||||
if context == :equals && Sass::SCSS::RX.escape_ident(self.value).include?(?\\)
|
||||
if context == :equals && self.value !~ Sass::SCSS::RX::URI &&
|
||||
Sass::SCSS::RX.escape_ident(self.value).include?(?\\)
|
||||
return "unquote(#{Sass::Script::String.new(self.value, :string).to_sass})"
|
||||
elsif context == :equals && self.value.size == 0
|
||||
return %q{""}
|
||||
|
|
|
@ -65,7 +65,7 @@ module Sass
|
|||
NAME = /#{NMCHAR}+/
|
||||
NUM = /[0-9]+|[0-9]*.[0-9]+/
|
||||
STRING = /#{STRING1}|#{STRING2}/
|
||||
URLCHAR = /[!#%&*-~]|#{NONASCII}|#{ESCAPE}/
|
||||
URLCHAR = /[#%&*-~]|#{NONASCII}|#{ESCAPE}/
|
||||
URL = /(#{URLCHAR}*)/
|
||||
W = /[ \t\r\n\f]*/
|
||||
|
||||
|
|
|
@ -186,6 +186,16 @@ RUBY
|
|||
assert_equal "unquote(\"f'o\#{$bar}b\\\"z\")", render("'f\\'o\#{$bar}b\\\"z'", :context => :equals)
|
||||
end
|
||||
|
||||
def test_sass2_urls
|
||||
Haml::Util.silence_haml_warnings do
|
||||
assert_equal 'url(foo/bar.gif)', render('url(foo/bar.gif)', :context => :equals)
|
||||
assert_equal 'url("foo/bar.gif")', render('url("foo/bar.gif")', :context => :equals)
|
||||
|
||||
assert_equal 'url($var)', render('url(!var)', :context => :equals)
|
||||
assert_equal 'url("#{$var}/flip.gif")', render('url("#{!var}/flip.gif")', :context => :equals)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_renders(script, options = {})
|
||||
|
|
Loading…
Add table
Reference in a new issue