sass 3.1.0.alpha.48 → 3.1.0.alpha.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- 3.1.0.alpha.48
1
+ 3.1.0.alpha.49
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.alpha.48
1
+ 3.1.0.alpha.49
@@ -21,6 +21,11 @@ require 'sass/tree/debug_node'
21
21
  require 'sass/tree/warn_node'
22
22
  require 'sass/tree/import_node'
23
23
  require 'sass/tree/charset_node'
24
+ require 'sass/tree/visitors/base'
25
+ require 'sass/tree/visitors/perform'
26
+ require 'sass/tree/visitors/cssize'
27
+ require 'sass/tree/visitors/convert'
28
+ require 'sass/tree/visitors/to_css'
24
29
  require 'sass/selector'
25
30
  require 'sass/environment'
26
31
  require 'sass/script'
@@ -38,9 +38,8 @@ module Sass
38
38
  end.flatten)
39
39
  end
40
40
 
41
- # Non-destrucively extends this selector
42
- # with the extensions specified in a hash
43
- # (which should be populated via {Sass::Tree::Node#cssize}).
41
+ # Non-destrucively extends this selector with the extensions specified in a hash
42
+ # (which should come from {Sass::Tree::Visitors::Cssize}).
44
43
  #
45
44
  # @todo Link this to the reference documentation on `@extend`
46
45
  # when such a thing exists.
@@ -65,9 +65,8 @@ module Sass
65
65
  end.flatten)
66
66
  end
67
67
 
68
- # Non-destructively extends this selector
69
- # with the extensions specified in a hash
70
- # (which should be populated via {Sass::Tree::Node#cssize}).
68
+ # Non-destructively extends this selector with the extensions specified in a hash
69
+ # (which should come from {Sass::Tree::Visitors::Cssize}).
71
70
  #
72
71
  # @overload def do_extend(extends)
73
72
  # @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
@@ -51,9 +51,8 @@ module Sass
51
51
  [SimpleSequence.new(super_seq.members.last.members + @members[1..-1])]
52
52
  end
53
53
 
54
- # Non-destrucively extends this selector
55
- # with the extensions specified in a hash
56
- # (which should be populated via {Sass::Tree::Node#cssize}).
54
+ # Non-destrucively extends this selector with the extensions specified in a hash
55
+ # (which should come from {Sass::Tree::Visitors::Cssize}).
57
56
  #
58
57
  # @overload def do_extend(extends)
59
58
  # @param extends [{Selector::Simple => Selector::Sequence}]
@@ -18,20 +18,5 @@ module Sass::Tree
18
18
  def invisible?
19
19
  !Sass::Util.ruby1_8?
20
20
  end
21
-
22
- protected
23
-
24
- # @see Node#to_src
25
- def to_src(tabs, opts, fmt)
26
- "#{' ' * tabs}@charset \"#{name}\"#{semi fmt}\n"
27
- end
28
-
29
- # Computes the CSS for the directive.
30
- #
31
- # @param tabs [Fixnum] The level of indentation for the CSS
32
- # @return [String] The resulting CSS
33
- def _to_s(tabs)
34
- "@charset \"#{name}\";"
35
- end
36
21
  end
37
22
  end
@@ -41,78 +41,6 @@ module Sass::Tree
41
41
  style == :compressed || @silent
42
42
  end
43
43
 
44
- # @see Node#to_sass
45
- def to_sass(tabs, opts = {})
46
- content = value.gsub(/\*\/$/, '').rstrip
47
- if content =~ /\A[ \t]/
48
- # Re-indent SCSS comments like this:
49
- # /* foo
50
- # bar
51
- # baz */
52
- content.gsub!(/^/, ' ')
53
- content.sub!(/\A([ \t]*)\/\*/, '/*\1')
54
- end
55
-
56
- content =
57
- unless content.include?("\n")
58
- content
59
- else
60
- content.gsub!(/\n( \*|\/\/)/, "\n ")
61
- spaces = content.scan(/\n( *)/).map {|s| s.first.size}.min
62
- sep = silent ? "\n//" : "\n *"
63
- if spaces >= 2
64
- content.gsub(/\n /, sep)
65
- else
66
- content.gsub(/\n#{' ' * spaces}/, sep)
67
- end
68
- end
69
-
70
- content.gsub!(/\A\/\*/, '//') if silent
71
- content.gsub!(/^/, ' ' * tabs)
72
- content.rstrip + "\n"
73
- end
74
-
75
- # @see Node#to_scss
76
- def to_scss(tabs, opts = {})
77
- spaces = (' ' * [tabs - value[/^ */].size, 0].max)
78
- if silent
79
- value.gsub(/^[\/ ]\*/, '//').gsub(/ *\*\/$/, '')
80
- else
81
- value
82
- end.gsub(/^/, spaces) + "\n"
83
- end
84
-
85
- protected
86
-
87
- # Computes the CSS for the comment.
88
- #
89
- # Returns `nil` if this is a silent comment
90
- # or the current style doesn't render comments.
91
- #
92
- # @overload to_s(tabs = 0)
93
- # @param tabs [Fixnum] The level of indentation for the CSS
94
- # @return [String, nil] The resulting CSS
95
- # @see #invisible?
96
- def _to_s(tabs = 0, _ = nil)
97
- return if invisible?
98
- spaces = (' ' * [tabs - 1 - value[/^ */].size, 0].max)
99
-
100
- content = value.gsub(/^/, spaces)
101
- content.gsub!(/\n +(\* *(?!\/))?/, ' ') if style == :compact
102
- content
103
- end
104
-
105
- # Removes this node from the tree if it's a silent comment.
106
- #
107
- # @param environment [Sass::Environment] The lexical environment containing
108
- # variable and mixin values
109
- # @return [Tree::Node, Array<Tree::Node>] The resulting static nodes
110
- # @see Sass::Tree
111
- def _perform(environment)
112
- return [] if @silent
113
- self
114
- end
115
-
116
44
  private
117
45
 
118
46
  def normalize_indentation(str)
@@ -4,33 +4,15 @@ module Sass
4
4
  #
5
5
  # @see Sass::Tree
6
6
  class DebugNode < Node
7
+ # The expression to print.
8
+ # @return [Script::Node]
9
+ attr_reader :expr
10
+
7
11
  # @param expr [Script::Node] The expression to print
8
12
  def initialize(expr)
9
13
  @expr = expr
10
14
  super()
11
15
  end
12
-
13
- protected
14
-
15
- # @see Node#to_src
16
- def to_src(tabs, opts, fmt)
17
- "#{' ' * tabs}@debug #{@expr.to_sass(opts)}#{semi fmt}\n"
18
- end
19
-
20
- # Prints the expression to STDERR.
21
- #
22
- # @param environment [Sass::Environment] The lexical environment containing
23
- # variable and mixin values
24
- def _perform(environment)
25
- res = @expr.perform(environment)
26
- res = res.value if res.is_a?(Sass::Script::String)
27
- if filename
28
- $stderr.puts "#{filename}:#{line} DEBUG: #{res}"
29
- else
30
- $stderr.puts "Line #{line} DEBUG: #{res}"
31
- end
32
- []
33
- end
34
16
  end
35
17
  end
36
18
  end
@@ -19,57 +19,5 @@ module Sass::Tree
19
19
  @value = value
20
20
  super()
21
21
  end
22
-
23
- protected
24
-
25
- # @see Node#to_src
26
- def to_src(tabs, opts, fmt)
27
- res = "#{' ' * tabs}#{value}"
28
- return res + "#{semi fmt}\n" unless has_children
29
- res + children_to_src(tabs, opts, fmt) + "\n"
30
- end
31
-
32
- # Computes the CSS for the directive.
33
- #
34
- # @param tabs [Fixnum] The level of indentation for the CSS
35
- # @return [String] The resulting CSS
36
- def _to_s(tabs)
37
- return value + ";" unless has_children
38
- return value + " {}" if children.empty?
39
- result = if style == :compressed
40
- "#{value}{"
41
- else
42
- "#{' ' * (tabs - 1)}#{value} {" + (style == :compact ? ' ' : "\n")
43
- end
44
- was_prop = false
45
- first = true
46
- children.each do |child|
47
- next if child.invisible?
48
- if style == :compact
49
- if child.is_a?(PropNode)
50
- result << "#{child.to_s(first || was_prop ? 1 : tabs + 1)} "
51
- else
52
- if was_prop
53
- result[-1] = "\n"
54
- end
55
- rendered = child.to_s(tabs + 1).dup
56
- rendered = rendered.lstrip if first
57
- result << rendered.rstrip + "\n"
58
- end
59
- was_prop = child.is_a?(PropNode)
60
- first = false
61
- elsif style == :compressed
62
- result << (was_prop ? ";#{child.to_s(1)}" : child.to_s(1))
63
- was_prop = child.is_a?(PropNode)
64
- else
65
- result << child.to_s(tabs + 1) + "\n"
66
- end
67
- end
68
- result.rstrip + if style == :compressed
69
- "}"
70
- else
71
- (style == :expanded ? "\n" : " ") + "}\n"
72
- end
73
- end
74
22
  end
75
23
  end
@@ -5,6 +5,14 @@ module Sass::Tree
5
5
  #
6
6
  # @see Sass::Tree
7
7
  class EachNode < Node
8
+ # The name of the loop variable.
9
+ # @return [String]
10
+ attr_reader :var
11
+
12
+ # The parse tree for the list.
13
+ # @param [Script::Node]
14
+ attr_reader :list
15
+
8
16
  # @param var [String] The name of the loop variable
9
17
  # @param list [Script::Node] The parse tree for the list
10
18
  def initialize(var, list)
@@ -15,30 +23,6 @@ module Sass::Tree
15
23
 
16
24
  protected
17
25
 
18
- # @see Node#to_src
19
- def to_src(tabs, opts, fmt)
20
- "#{' ' * tabs}@each $#{dasherize(@var, opts)} in #{@list.to_sass(opts)}" +
21
- children_to_src(tabs, opts, fmt)
22
- end
23
-
24
- # Runs the child nodes once for each value in the list.
25
- #
26
- # @param environment [Sass::Environment] The lexical environment containing
27
- # variable and mixin values
28
- # @return [Array<Tree::Node>] The resulting static nodes
29
- # @see Sass::Tree
30
- def _perform(environment)
31
- list = @list.perform(environment)
32
-
33
- children = []
34
- environment = Sass::Environment.new(environment)
35
- list.to_a.each do |v|
36
- environment.set_local_var(@var, v)
37
- children += perform_children(environment)
38
- end
39
- children
40
- end
41
-
42
26
  # Returns an error message if the given child node is invalid,
43
27
  # and false otherwise.
44
28
  #
@@ -5,6 +5,18 @@ module Sass::Tree
5
5
  #
6
6
  # @see Sass::Tree
7
7
  class ExtendNode < Node
8
+ # The parsed selector after interpolation has been resolved.
9
+ # Only set once {Tree::Visitors::Perform} has been run.
10
+ #
11
+ # @return [Selector::CommaSequence]
12
+ attr_accessor :resolved_selector
13
+
14
+ # The CSS selector to extend, interspersed with {Sass::Script::Node}s
15
+ # representing `#{}`-interpolation.
16
+ #
17
+ # @return [Array<String, Sass::Script::Node>]
18
+ attr_reader :selector
19
+
8
20
  # @param selector [Array<String, Sass::Script::Node>]
9
21
  # The CSS selector to extend,
10
22
  # interspersed with {Sass::Script::Node}s
@@ -13,53 +25,5 @@ module Sass::Tree
13
25
  @selector = selector
14
26
  super()
15
27
  end
16
-
17
- # Registers this extension in the `extends` subset map.
18
- #
19
- # @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
20
- # The extensions defined for this tree
21
- # @param parent [RuleNode] The parent node of this node
22
- # @see Node#cssize
23
- def cssize(extends, parent)
24
- @resolved_selector.members.each do |seq|
25
- if seq.members.size > 1
26
- raise Sass::SyntaxError.new("Can't extend #{seq.to_a.join}: can't extend nested selectors")
27
- end
28
-
29
- sseq = seq.members.first
30
- if !sseq.is_a?(Sass::Selector::SimpleSequence)
31
- raise Sass::SyntaxError.new("Can't extend #{seq.to_a.join}: invalid selector")
32
- end
33
-
34
- sel = sseq.members
35
- parent.resolved_rules.members.each do |seq|
36
- if !seq.members.last.is_a?(Sass::Selector::SimpleSequence)
37
- raise Sass::SyntaxError.new("#{seq} can't extend: invalid selector")
38
- end
39
-
40
- extends[sel] = seq
41
- end
42
- end
43
-
44
- []
45
- end
46
-
47
- protected
48
-
49
- # @see Node#to_src
50
- def to_src(tabs, opts, fmt)
51
- "#{' ' * tabs}@extend #{selector_to_src(@selector, tabs, opts, fmt).lstrip}#{semi fmt}\n"
52
- end
53
-
54
- # Runs SassScript interpolation in the selector,
55
- # and then parses the result into a {Sass::Selector::CommaSequence}.
56
- #
57
- # @param environment [Sass::Environment] The lexical environment containing
58
- # variable and mixin values
59
- def perform!(environment)
60
- @resolved_selector = Sass::SCSS::CssParser.new(run_interp(@selector, environment), self.line).
61
- parse_selector(self.filename)
62
- super
63
- end
64
28
  end
65
29
  end
@@ -5,11 +5,26 @@ module Sass::Tree
5
5
  #
6
6
  # @see Sass::Tree
7
7
  class ForNode < Node
8
- # @param var [String] The name of the loop variable
9
- # @param from [Script::Node] The parse tree for the initial expression
10
- # @param to [Script::Node] The parse tree for the final expression
11
- # @param exclusive [Boolean] Whether to include `to` in the loop
12
- # or stop just before
8
+ # The name of the loop variable.
9
+ # @return [String]
10
+ attr_reader :var
11
+
12
+ # The parse tree for the initial expression.
13
+ # @return [Script::Node]
14
+ attr_reader :from
15
+
16
+ # The parse tree for the final expression.
17
+ # @return [Script::Node]
18
+ attr_reader :to
19
+
20
+ # Whether to include `to` in the loop or stop just before.
21
+ # @return [Boolean]
22
+ attr_reader :exclusive
23
+
24
+ # @param var [String] See \{#var}
25
+ # @param from [Script::Node] See \{#from}
26
+ # @param to [Script::Node] See \{#to}
27
+ # @param exclusive [Boolean] See \{#exclusive}
13
28
  def initialize(var, from, to, exclusive)
14
29
  @var = var
15
30
  @from = from
@@ -17,39 +32,5 @@ module Sass::Tree
17
32
  @exclusive = exclusive
18
33
  super()
19
34
  end
20
-
21
- protected
22
-
23
- # @see Node#to_src
24
- def to_src(tabs, opts, fmt)
25
- to = @exclusive ? "to" : "through"
26
- "#{' ' * tabs}@for $#{dasherize(@var, opts)} from #{@from.to_sass(opts)} #{to} #{@to.to_sass(opts)}" +
27
- children_to_src(tabs, opts, fmt)
28
- end
29
-
30
- # Runs the child nodes once for each time through the loop,
31
- # varying the variable each time.
32
- #
33
- # @param environment [Sass::Environment] The lexical environment containing
34
- # variable and mixin values
35
- # @return [Array<Tree::Node>] The resulting static nodes
36
- # @see Sass::Tree
37
- def _perform(environment)
38
- from = @from.perform(environment)
39
- to = @to.perform(environment)
40
- from.assert_int!
41
- to.assert_int!
42
-
43
- to = to.coerce(from.numerator_units, from.denominator_units)
44
- range = Range.new(from.to_i, to.to_i, @exclusive)
45
-
46
- children = []
47
- environment = Sass::Environment.new(environment)
48
- range.each do |i|
49
- environment.set_local_var(@var, Sass::Script::Number.new(i, from.numerator_units, from.denominator_units))
50
- children += perform_children(environment)
51
- end
52
- children
53
- end
54
35
  end
55
36
  end
@@ -9,13 +9,18 @@ module Sass::Tree
9
9
  #
10
10
  # @see Sass::Tree
11
11
  class IfNode < Node
12
+ # The conditional expression.
13
+ # If this is nil, this is an `@else` node, not an `@else if`.
14
+ #
15
+ # @return [Script::Expr]
16
+ attr_reader :expr
17
+
12
18
  # The next {IfNode} in the if-else list, or `nil`.
13
19
  #
14
20
  # @return [IfNode]
15
21
  attr_accessor :else
16
22
 
17
- # @param expr [Script::Expr] The conditional expression.
18
- # If this is nil, this is an `@else` node, not an `@else if`
23
+ # @param expr [Script::Expr] See \{#expr}
19
24
  def initialize(expr)
20
25
  @expr = expr
21
26
  @last_else = self
@@ -54,35 +59,5 @@ module Sass::Tree
54
59
  @else = Sass::Util.load(@else)
55
60
  @last_else = (@last_else ? Sass::Util.load(@last_else) : self)
56
61
  end
57
-
58
- protected
59
-
60
- # @see Node#to_src
61
- def to_src(tabs, opts, fmt, is_else = false)
62
- name =
63
- if !is_else; "if"
64
- elsif @expr; "else if"
65
- else; "else"
66
- end
67
- str = "#{' ' * tabs}@#{name}"
68
- str << " #{@expr.to_sass(opts)}" if @expr
69
- str << children_to_src(tabs, opts, fmt)
70
- str << @else.send(:to_src, tabs, opts, fmt, true) if @else
71
- str
72
- end
73
-
74
- # Runs the child nodes if the conditional expression is true;
75
- # otherwise, tries the \{#else} nodes.
76
- #
77
- # @param environment [Sass::Environment] The lexical environment containing
78
- # variable and mixin values
79
- # @return [Array<Tree::Node>] The resulting static nodes
80
- # @see Sass::Tree
81
- def _perform(environment)
82
- environment = Sass::Environment.new(environment)
83
- return perform_children(environment) if @expr.nil? || @expr.perform(environment).to_bool
84
- return @else.perform(environment) if @else
85
- []
86
- end
87
62
  end
88
63
  end