Skip to content

Commit

Permalink
[Sass] Fix more #options bugs.
Browse files Browse the repository at this point in the history
Closes gh-288.
  • Loading branch information
nex3 committed Sep 29, 2010
1 parent 6509162 commit e101dfa
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 10 deletions.
4 changes: 4 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Expand Up @@ -3,6 +3,10 @@
* Table of contents
{:toc}

## 3.0.21 (Unreleased)

* Fix more `#options` attribute errors.

## 3.0.20

[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.20).
Expand Down
7 changes: 2 additions & 5 deletions lib/sass/script/funcall.rb
Expand Up @@ -63,13 +63,10 @@ def _perform(environment)
args = self.args.map {|a| a.perform(environment)}
ruby_name = name.gsub('-', '_')
unless Haml::Util.has?(:public_instance_method, Functions, ruby_name) && ruby_name !~ /^__/
result = Script::String.new("#{name}(#{args.map {|a| a.perform(environment)}.join(', ')})")
opts(Script::String.new("#{name}(#{args.map {|a| a.perform(environment)}.join(', ')})"))
else
result = Functions::EvaluationContext.new(environment.options).send(ruby_name, *args)
opts(Functions::EvaluationContext.new(environment.options).send(ruby_name, *args))
end

result.options = environment.options
return result
rescue ArgumentError => e
raise e unless e.backtrace.any? {|t| t =~ /:in `(block in )?(#{name}|perform)'$/}
raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/script/interpolation.rb
Expand Up @@ -64,7 +64,7 @@ def _perform(environment)
res << (val.is_a?(Sass::Script::String) ? val.value : val.to_s)
res << " " if @after && @whitespace_after
res << @after.perform(environment).to_s if @after
Sass::Script::String.new(res)
opts(Sass::Script::String.new(res))
end
end
end
11 changes: 11 additions & 0 deletions lib/sass/script/node.rb
Expand Up @@ -90,12 +90,23 @@ def dasherize(s, opts)
end

# Evaluates this node.
# Note that all {Literal} objects created within this method
# should have their \{#options} attribute set, probably via \{#opts}.
#
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
# @return [Literal] The SassScript object that is the value of the SassScript
# @see #perform
def _perform(environment)
raise NotImplementedError.new("All subclasses of Sass::Script::Node must override #_perform.")
end

# Sets the \{#options} field on the given literal and returns it
#
# @param literal [Literal]
# @return [Literal]
def opts(literal)
literal.options = options
literal
end
end
end
4 changes: 1 addition & 3 deletions lib/sass/script/operation.rb
Expand Up @@ -72,9 +72,7 @@ def _perform(environment)
end

begin
res = literal1.send(@operator, literal2)
res.options = environment.options
res
opts(literal1.send(@operator, literal2))
rescue NoMethodError => e
raise e unless e.name.to_s == @operator.to_s
raise Sass::SyntaxError.new("Undefined operation: \"#{literal1} #{@operator} #{literal2}\".")
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/script/string_interpolation.rb
Expand Up @@ -72,7 +72,7 @@ def _perform(environment)
mid = @mid.perform(environment)
res << (mid.is_a?(Sass::Script::String) ? mid.value : mid.to_s)
res << @after.perform(environment).value
Sass::Script::String.new(res, before.type)
opts(Sass::Script::String.new(res, before.type))
end

private
Expand Down
22 changes: 22 additions & 0 deletions test/sass/engine_test.rb
Expand Up @@ -2083,6 +2083,28 @@ def test_function_output_with_comma
SASS
end

def test_interpolation_with_comma
assert_equal <<CSS, render(<<SASS)
foo {
a: foo, bar; }
CSS
$foo: foo
foo
a: \#{$foo}, bar
SASS
end

def test_string_interpolation_with_comma
assert_equal <<CSS, render(<<SASS)
foo {
a: "bip foo bap", bar; }
CSS
$foo: foo
foo
a: "bip \#{$foo} bap", bar
SASS
end

# Encodings

unless Haml::Util.ruby1_8?
Expand Down

0 comments on commit e101dfa

Please sign in to comment.