sass 3.1.0.alpha.25 → 3.1.0.alpha.26

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- 3.1.0.alpha.25
1
+ 3.1.0.alpha.26
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.alpha.25
1
+ 3.1.0.alpha.26
@@ -7,6 +7,7 @@ require 'sass/tree/rule_node'
7
7
  require 'sass/tree/comment_node'
8
8
  require 'sass/tree/prop_node'
9
9
  require 'sass/tree/directive_node'
10
+ require 'sass/tree/media_node'
10
11
  require 'sass/tree/variable_node'
11
12
  require 'sass/tree/mixin_def_node'
12
13
  require 'sass/tree/mixin_node'
@@ -645,6 +646,8 @@ WARNING
645
646
  raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath charset directives.",
646
647
  :line => @line + 1) unless line.children.empty?
647
648
  Tree::CharsetNode.new(name)
649
+ elsif directive == "media"
650
+ Tree::MediaNode.new(value)
648
651
  else
649
652
  Tree::DirectiveNode.new(line.text)
650
653
  end
@@ -253,7 +253,7 @@ module Sass
253
253
 
254
254
  def media_directive
255
255
  val = str {media_query_list}.strip
256
- block(node(Sass::Tree::DirectiveNode.new("@media #{val}")), :directive)
256
+ block(node(Sass::Tree::MediaNode.new(val)), :directive)
257
257
  end
258
258
 
259
259
  # http://www.w3.org/TR/css3-mediaqueries/#syntax
@@ -0,0 +1,72 @@
1
+ module Sass::Tree
2
+ # A static node representing a `@media` rule.
3
+ # `@media` rules behave differently from other directives
4
+ # in that when they're nested within rules,
5
+ # they bubble up to top-level.
6
+ #
7
+ # @see Sass::Tree
8
+ class MediaNode < DirectiveNode
9
+ # The media query (e.g. `print` or `screen`).
10
+ #
11
+ # @return [String]
12
+ attr_accessor :query
13
+
14
+ # @see RuleNode#tabs
15
+ attr_accessor :tabs
16
+
17
+ # @see RuleNode#group_end
18
+ attr_accessor :group_end
19
+
20
+ # @param query [String] See \{#query}
21
+ def initialize(query)
22
+ @query = query
23
+ @tabs = 0
24
+ super('')
25
+ end
26
+
27
+ # @see DirectiveNode#value
28
+ def value
29
+ "@media #{query}"
30
+ end
31
+
32
+ # Pass on the parent if it's a RuleNode.
33
+ #
34
+ # @see Node#cssize
35
+ def cssize(extends, parent = nil)
36
+ _cssize(extends, (parent if [MediaNode, RuleNode].include?(parent.class)))
37
+ rescue Sass::SyntaxError => e
38
+ e.modify_backtrace(:filename => filename, :line => line)
39
+ raise e
40
+ end
41
+
42
+ protected
43
+
44
+ # Merge nested media queries.
45
+ #
46
+ # @see Node#_cssize
47
+ def _cssize(extends, parent)
48
+ node = super
49
+ media = node.children.select {|c| c.is_a?(MediaNode)}
50
+ node.children.reject! {|c| c.is_a?(MediaNode)}
51
+ media.each {|n| n.query = "#{query} and #{n.query}"}
52
+ (node.children.empty? ? [] : [node]) + media
53
+ end
54
+
55
+ # If we're passed a parent, bubble it down.
56
+ #
57
+ # @see Node#cssize
58
+ def cssize!(extends, parent)
59
+ return super unless parent.is_a?(RuleNode)
60
+ new_rule = parent.dup
61
+ new_rule.children = self.children
62
+ self.children = Array(new_rule.cssize(extends, self))
63
+ end
64
+
65
+ # @see Node#to_s
66
+ def _to_s(tabs)
67
+ str = super(tabs + self.tabs)
68
+ str.gsub!(/\n\Z/, '') unless style == :compressed || group_end
69
+ str
70
+ end
71
+ end
72
+ end
@@ -53,11 +53,8 @@ module Sass::Tree
53
53
  # @param rule [Array<String, Sass::Script::Node>]
54
54
  # The CSS rule. See \{#rule}
55
55
  def initialize(rule)
56
- #p rule
57
56
  merged = Sass::Util.merge_adjacent_strings(rule)
58
- #p merged
59
57
  @rule = Sass::Util.strip_string_array(merged)
60
- #p @rule
61
58
  @tabs = 0
62
59
  super()
63
60
  end
@@ -200,8 +197,8 @@ module Sass::Tree
200
197
  # or nil if the parent isn't a {RuleNode}
201
198
  def _cssize(extends, parent)
202
199
  node = super
203
- rules = node.children.grep(RuleNode)
204
- props = node.children.reject {|c| c.is_a?(RuleNode) || c.invisible?}
200
+ rules = node.children.select {|c| c.is_a?(RuleNode) || c.is_a?(MediaNode)}
201
+ props = node.children.reject {|c| c.is_a?(RuleNode) || c.is_a?(MediaNode) || c.invisible?}
205
202
 
206
203
  unless props.empty?
207
204
  node.children = props
@@ -223,7 +220,8 @@ module Sass::Tree
223
220
  # or nil if the parent isn't a {RuleNode}
224
221
  # @raise [Sass::SyntaxError] if the rule has no parents but uses `&`
225
222
  def cssize!(extends, parent)
226
- self.resolved_rules = @parsed_rules.resolve_parent_refs(parent && parent.resolved_rules)
223
+ # It's possible for resolved_rules to be set if we've duplicated this node during @media bubbling
224
+ self.resolved_rules ||= @parsed_rules.resolve_parent_refs(parent && parent.resolved_rules)
227
225
  super
228
226
  end
229
227
 
@@ -2241,6 +2241,138 @@ foo
2241
2241
  SASS
2242
2242
  end
2243
2243
 
2244
+ def test_media_bubbling
2245
+ assert_equal <<CSS, render(<<SASS)
2246
+ .foo {
2247
+ a: b; }
2248
+ @media bar {
2249
+ .foo {
2250
+ c: d; } }
2251
+ .foo .baz {
2252
+ e: f; }
2253
+ @media bip {
2254
+ .foo .baz {
2255
+ g: h; } }
2256
+
2257
+ .other {
2258
+ i: j; }
2259
+ CSS
2260
+ .foo
2261
+ a: b
2262
+ @media bar
2263
+ c: d
2264
+ .baz
2265
+ e: f
2266
+ @media bip
2267
+ g: h
2268
+
2269
+ .other
2270
+ i: j
2271
+ SASS
2272
+
2273
+ assert_equal <<CSS, render(<<SASS, :style => :compact)
2274
+ .foo { a: b; }
2275
+ @media bar { .foo { c: d; } }
2276
+ .foo .baz { e: f; }
2277
+ @media bip { .foo .baz { g: h; } }
2278
+
2279
+ .other { i: j; }
2280
+ CSS
2281
+ .foo
2282
+ a: b
2283
+ @media bar
2284
+ c: d
2285
+ .baz
2286
+ e: f
2287
+ @media bip
2288
+ g: h
2289
+
2290
+ .other
2291
+ i: j
2292
+ SASS
2293
+
2294
+ assert_equal <<CSS, render(<<SASS, :style => :expanded)
2295
+ .foo {
2296
+ a: b;
2297
+ }
2298
+ @media bar {
2299
+ .foo {
2300
+ c: d;
2301
+ }
2302
+ }
2303
+ .foo .baz {
2304
+ e: f;
2305
+ }
2306
+ @media bip {
2307
+ .foo .baz {
2308
+ g: h;
2309
+ }
2310
+ }
2311
+
2312
+ .other {
2313
+ i: j;
2314
+ }
2315
+ CSS
2316
+ .foo
2317
+ a: b
2318
+ @media bar
2319
+ c: d
2320
+ .baz
2321
+ e: f
2322
+ @media bip
2323
+ g: h
2324
+
2325
+ .other
2326
+ i: j
2327
+ SASS
2328
+ end
2329
+
2330
+ def test_double_media_bubbling
2331
+ assert_equal <<CSS, render(<<SASS)
2332
+ @media bar and baz {
2333
+ .foo {
2334
+ c: d; } }
2335
+ CSS
2336
+ @media bar
2337
+ @media baz
2338
+ .foo
2339
+ c: d
2340
+ SASS
2341
+
2342
+ assert_equal <<CSS, render(<<SASS)
2343
+ @media bar {
2344
+ .foo {
2345
+ a: b; } }
2346
+ @media bar and baz {
2347
+ .foo {
2348
+ c: d; } }
2349
+ CSS
2350
+ .foo
2351
+ @media bar
2352
+ a: b
2353
+ @media baz
2354
+ c: d
2355
+ SASS
2356
+ end
2357
+
2358
+ def test_rule_media_rule_bubbling
2359
+ assert_equal <<CSS, render(<<SASS)
2360
+ @media bar {
2361
+ .foo {
2362
+ a: b;
2363
+ e: f; }
2364
+ .foo .baz {
2365
+ c: d; } }
2366
+ CSS
2367
+ .foo
2368
+ @media bar
2369
+ a: b
2370
+ .baz
2371
+ c: d
2372
+ e: f
2373
+ SASS
2374
+ end
2375
+
2244
2376
  # Encodings
2245
2377
 
2246
2378
  unless Sass::Util.ruby1_8?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.alpha.25
4
+ version: 3.1.0.alpha.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum
@@ -121,6 +121,7 @@ files:
121
121
  - lib/sass/tree/warn_node.rb
122
122
  - lib/sass/tree/while_node.rb
123
123
  - lib/sass/tree/each_node.rb
124
+ - lib/sass/tree/media_node.rb
124
125
  - lib/sass/util.rb
125
126
  - lib/sass/util/subset_map.rb
126
127
  - lib/sass/version.rb