Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support general SassScript expressions in @media query expr values.

Closes #284
  • Loading branch information...
commit 93bc3afbece40545d653eccfa5b280debb3f5171 1 parent bec6c46
@nex3 nex3 authored
View
5 doc-src/SASS_REFERENCE.md
@@ -1227,9 +1227,8 @@ is compiled to:
}
Finally, `@media` queries can contain Sass variables in place of the media type,
-feature names, and feature values.
-For example:
-
+feature names, and feature values. The feature value can also contain more
+complex SassScript expressions, such as functions or operators. For example:
$media: screen;
$feature: -webkit-min-device-pixel-ratio;
View
12 lib/sass/media.rb
@@ -216,7 +216,7 @@ class Expression
# The value of the feature.
#
- # @return [Array<String, Sass::Script::Node>]
+ # @return [Sass::Script::Node]
attr_accessor :value
# The value of the feature after any SassScript has been resolved.
@@ -226,7 +226,7 @@ class Expression
attr_accessor :resolved_value
# @param name [Array<String, Sass::Script::Node>] See \{#name}
- # @param value [Array<String, Sass::Script::Node>] See \{#value}
+ # @param value [Sass::Script::Node] See \{#value}
def initialize(name, value)
@name = name
@value = value
@@ -240,7 +240,7 @@ def initialize(name, value)
# @yieldreturn [String] The interpolated value.
def perform
@resolved_name = yield name
- @resolved_value = yield value
+ @resolved_value = yield value ? [value] : []
end
# Returns the CSS for the expression.
@@ -261,7 +261,7 @@ def to_css
def to_src(options)
src = '('
src << Sass::Media._interp_or_var_to_src(name, options)
- src << ': ' << Sass::Media._interp_or_var_to_src(value, options) unless value.empty?
+ src << ': ' << value.to_sass(options) if value
src << ')'
src
end
@@ -272,7 +272,7 @@ def to_src(options)
def deep_copy
Expression.new(
name.map {|c| c.is_a?(Sass::Script::Node) ? c.deep_copy : c},
- value.map {|c| c.is_a?(Sass::Script::Node) ? c.deep_copy : c})
+ value && value.deep_copy)
end
# Sets the options hash for the script nodes in the expression.
@@ -280,7 +280,7 @@ def deep_copy
# @param options [{Symbol => Object}] The options has to set.
def options=(options)
name.each {|n| n.options = options if n.is_a?(Sass::Script::Node)}
- value.each {|v| v.options = options if v.is_a?(Sass::Script::Node)}
+ value.options = options if value
end
end
View
4 lib/sass/scss/parser.rb
@@ -372,12 +372,12 @@ def media_expr
ss
if tok(/:/)
- ss; value = expr!(:expr)
+ ss; value = sass_script(:parse)
end
tok!(/\)/)
ss
- Sass::Media::Expression.new(name, value || [])
+ Sass::Media::Expression.new(name, value)
end
def charset_directive
View
10 test/sass/scss/scss_test.rb
@@ -894,7 +894,7 @@ def test_media_interpolation
SCSS
end
- def test_variables_in_media
+ def test_script_in_media
assert_equal <<CSS, render(<<SCSS)
@media screen and (-webkit-min-device-pixel-ratio: 20), only print {
a: b; }
@@ -905,6 +905,14 @@ def test_variables_in_media
$val: 20;
@media $media1 and ($var: $val), only $media2 {a: b}
SCSS
+
+ assert_equal <<CSS, render(<<SCSS)
+@media screen and (-webkit-min-device-pixel-ratio: 13) {
+ a: b; }
+CSS
+$vals: 1 2 3;
+@media screen and (-webkit-min-device-pixel-ratio: 5 + 6 + nth($vals, 2)) {a: b}
+SCSS
end
## Errors
Please sign in to comment.
Something went wrong with that request. Please try again.