haml 3.0.21 → 3.0.22
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of haml might be problematic. Click here for more details.
- data/Rakefile +1 -41
- data/VERSION +1 -1
- data/lib/haml/precompiler.rb +8 -6
- data/lib/haml/template/plugin.rb +16 -6
- data/lib/sass/less.rb +31 -12
- data/lib/sass/script/funcall.rb +2 -1
- data/lib/sass/script/operation.rb +10 -5
- data/lib/sass/script/parser.rb +9 -0
- data/test/haml/engine_test.rb +25 -0
- data/test/sass/less_conversion_test.rb +24 -3
- data/test/sass/script_conversion_test.rb +60 -0
- metadata +243 -426
- data/vendor/sass/CONTRIBUTING +0 -3
- data/vendor/sass/MIT-LICENSE +0 -20
- data/vendor/sass/README.md +0 -201
- data/vendor/sass/Rakefile +0 -363
- data/vendor/sass/TODO +0 -39
- data/vendor/sass/VERSION +0 -1
- data/vendor/sass/VERSION_NAME +0 -1
- data/vendor/sass/bin/css2sass +0 -13
- data/vendor/sass/bin/sass +0 -8
- data/vendor/sass/bin/sass-convert +0 -7
- data/vendor/sass/doc-src/FAQ.md +0 -35
- data/vendor/sass/doc-src/INDENTED_SYNTAX.md +0 -210
- data/vendor/sass/doc-src/SASS_CHANGELOG.md +0 -1870
- data/vendor/sass/doc-src/SASS_REFERENCE.md +0 -1713
- data/vendor/sass/doc-src/SCSS_FOR_SASS_USERS.md +0 -155
- data/vendor/sass/ext/extconf.rb +0 -10
- data/vendor/sass/extra/update_watch.rb +0 -13
- data/vendor/sass/init.rb +0 -18
- data/vendor/sass/lib/sass.rb +0 -71
- data/vendor/sass/lib/sass/cache_store.rb +0 -208
- data/vendor/sass/lib/sass/callbacks.rb +0 -66
- data/vendor/sass/lib/sass/css.rb +0 -294
- data/vendor/sass/lib/sass/engine.rb +0 -792
- data/vendor/sass/lib/sass/environment.rb +0 -143
- data/vendor/sass/lib/sass/error.rb +0 -201
- data/vendor/sass/lib/sass/exec.rb +0 -619
- data/vendor/sass/lib/sass/importers.rb +0 -22
- data/vendor/sass/lib/sass/importers/base.rb +0 -138
- data/vendor/sass/lib/sass/importers/filesystem.rb +0 -121
- data/vendor/sass/lib/sass/less.rb +0 -363
- data/vendor/sass/lib/sass/plugin.rb +0 -126
- data/vendor/sass/lib/sass/plugin/compiler.rb +0 -346
- data/vendor/sass/lib/sass/plugin/configuration.rb +0 -123
- data/vendor/sass/lib/sass/plugin/generic.rb +0 -15
- data/vendor/sass/lib/sass/plugin/merb.rb +0 -48
- data/vendor/sass/lib/sass/plugin/rack.rb +0 -47
- data/vendor/sass/lib/sass/plugin/rails.rb +0 -41
- data/vendor/sass/lib/sass/plugin/staleness_checker.rb +0 -145
- data/vendor/sass/lib/sass/railtie.rb +0 -8
- data/vendor/sass/lib/sass/repl.rb +0 -58
- data/vendor/sass/lib/sass/root.rb +0 -7
- data/vendor/sass/lib/sass/script.rb +0 -63
- data/vendor/sass/lib/sass/script/bool.rb +0 -18
- data/vendor/sass/lib/sass/script/color.rb +0 -491
- data/vendor/sass/lib/sass/script/css_lexer.rb +0 -29
- data/vendor/sass/lib/sass/script/css_parser.rb +0 -31
- data/vendor/sass/lib/sass/script/funcall.rb +0 -79
- data/vendor/sass/lib/sass/script/functions.rb +0 -852
- data/vendor/sass/lib/sass/script/interpolation.rb +0 -70
- data/vendor/sass/lib/sass/script/lexer.rb +0 -337
- data/vendor/sass/lib/sass/script/literal.rb +0 -236
- data/vendor/sass/lib/sass/script/node.rb +0 -101
- data/vendor/sass/lib/sass/script/number.rb +0 -423
- data/vendor/sass/lib/sass/script/operation.rb +0 -92
- data/vendor/sass/lib/sass/script/parser.rb +0 -392
- data/vendor/sass/lib/sass/script/string.rb +0 -67
- data/vendor/sass/lib/sass/script/string_interpolation.rb +0 -93
- data/vendor/sass/lib/sass/script/unary_operation.rb +0 -57
- data/vendor/sass/lib/sass/script/variable.rb +0 -48
- data/vendor/sass/lib/sass/scss.rb +0 -17
- data/vendor/sass/lib/sass/scss/css_parser.rb +0 -51
- data/vendor/sass/lib/sass/scss/parser.rb +0 -838
- data/vendor/sass/lib/sass/scss/rx.rb +0 -126
- data/vendor/sass/lib/sass/scss/sass_parser.rb +0 -11
- data/vendor/sass/lib/sass/scss/script_lexer.rb +0 -15
- data/vendor/sass/lib/sass/scss/script_parser.rb +0 -25
- data/vendor/sass/lib/sass/scss/static_parser.rb +0 -40
- data/vendor/sass/lib/sass/selector.rb +0 -361
- data/vendor/sass/lib/sass/selector/abstract_sequence.rb +0 -62
- data/vendor/sass/lib/sass/selector/comma_sequence.rb +0 -82
- data/vendor/sass/lib/sass/selector/sequence.rb +0 -236
- data/vendor/sass/lib/sass/selector/simple.rb +0 -113
- data/vendor/sass/lib/sass/selector/simple_sequence.rb +0 -135
- data/vendor/sass/lib/sass/shared.rb +0 -78
- data/vendor/sass/lib/sass/tree/comment_node.rb +0 -128
- data/vendor/sass/lib/sass/tree/debug_node.rb +0 -36
- data/vendor/sass/lib/sass/tree/directive_node.rb +0 -75
- data/vendor/sass/lib/sass/tree/extend_node.rb +0 -65
- data/vendor/sass/lib/sass/tree/for_node.rb +0 -67
- data/vendor/sass/lib/sass/tree/if_node.rb +0 -81
- data/vendor/sass/lib/sass/tree/import_node.rb +0 -124
- data/vendor/sass/lib/sass/tree/mixin_def_node.rb +0 -60
- data/vendor/sass/lib/sass/tree/mixin_node.rb +0 -123
- data/vendor/sass/lib/sass/tree/node.rb +0 -490
- data/vendor/sass/lib/sass/tree/prop_node.rb +0 -220
- data/vendor/sass/lib/sass/tree/root_node.rb +0 -125
- data/vendor/sass/lib/sass/tree/rule_node.rb +0 -273
- data/vendor/sass/lib/sass/tree/variable_node.rb +0 -39
- data/vendor/sass/lib/sass/tree/warn_node.rb +0 -42
- data/vendor/sass/lib/sass/tree/while_node.rb +0 -48
- data/vendor/sass/lib/sass/util.rb +0 -700
- data/vendor/sass/lib/sass/util/subset_map.rb +0 -101
- data/vendor/sass/lib/sass/version.rb +0 -109
- data/vendor/sass/rails/init.rb +0 -1
- data/vendor/sass/sass.gemspec +0 -32
- data/vendor/sass/test/sass/cache_test.rb +0 -74
- data/vendor/sass/test/sass/callbacks_test.rb +0 -61
- data/vendor/sass/test/sass/conversion_test.rb +0 -1210
- data/vendor/sass/test/sass/css2sass_test.rb +0 -364
- data/vendor/sass/test/sass/data/hsl-rgb.txt +0 -319
- data/vendor/sass/test/sass/engine_test.rb +0 -2283
- data/vendor/sass/test/sass/extend_test.rb +0 -1348
- data/vendor/sass/test/sass/functions_test.rb +0 -565
- data/vendor/sass/test/sass/importer_test.rb +0 -104
- data/vendor/sass/test/sass/less_conversion_test.rb +0 -632
- data/vendor/sass/test/sass/mock_importer.rb +0 -49
- data/vendor/sass/test/sass/more_results/more1.css +0 -9
- data/vendor/sass/test/sass/more_results/more1_with_line_comments.css +0 -26
- data/vendor/sass/test/sass/more_results/more_import.css +0 -29
- data/vendor/sass/test/sass/more_templates/_more_partial.sass +0 -2
- data/vendor/sass/test/sass/more_templates/more1.sass +0 -23
- data/vendor/sass/test/sass/more_templates/more_import.sass +0 -11
- data/vendor/sass/test/sass/plugin_test.rb +0 -430
- data/vendor/sass/test/sass/results/alt.css +0 -4
- data/vendor/sass/test/sass/results/basic.css +0 -9
- data/vendor/sass/test/sass/results/compact.css +0 -5
- data/vendor/sass/test/sass/results/complex.css +0 -86
- data/vendor/sass/test/sass/results/compressed.css +0 -1
- data/vendor/sass/test/sass/results/expanded.css +0 -19
- data/vendor/sass/test/sass/results/import.css +0 -31
- data/vendor/sass/test/sass/results/line_numbers.css +0 -49
- data/vendor/sass/test/sass/results/mixins.css +0 -95
- data/vendor/sass/test/sass/results/multiline.css +0 -24
- data/vendor/sass/test/sass/results/nested.css +0 -22
- data/vendor/sass/test/sass/results/options.css +0 -1
- data/vendor/sass/test/sass/results/parent_ref.css +0 -13
- data/vendor/sass/test/sass/results/script.css +0 -16
- data/vendor/sass/test/sass/results/scss_import.css +0 -31
- data/vendor/sass/test/sass/results/scss_importee.css +0 -2
- data/vendor/sass/test/sass/results/subdir/nested_subdir/nested_subdir.css +0 -1
- data/vendor/sass/test/sass/results/subdir/subdir.css +0 -3
- data/vendor/sass/test/sass/results/units.css +0 -11
- data/vendor/sass/test/sass/results/warn.css +0 -0
- data/vendor/sass/test/sass/results/warn_imported.css +0 -0
- data/vendor/sass/test/sass/script_conversion_test.rb +0 -254
- data/vendor/sass/test/sass/script_test.rb +0 -470
- data/vendor/sass/test/sass/scss/css_test.rb +0 -897
- data/vendor/sass/test/sass/scss/rx_test.rb +0 -156
- data/vendor/sass/test/sass/scss/scss_test.rb +0 -1088
- data/vendor/sass/test/sass/scss/test_helper.rb +0 -37
- data/vendor/sass/test/sass/templates/_partial.sass +0 -2
- data/vendor/sass/test/sass/templates/alt.sass +0 -16
- data/vendor/sass/test/sass/templates/basic.sass +0 -23
- data/vendor/sass/test/sass/templates/bork1.sass +0 -2
- data/vendor/sass/test/sass/templates/bork2.sass +0 -2
- data/vendor/sass/test/sass/templates/bork3.sass +0 -2
- data/vendor/sass/test/sass/templates/bork4.sass +0 -2
- data/vendor/sass/test/sass/templates/compact.sass +0 -17
- data/vendor/sass/test/sass/templates/complex.sass +0 -305
- data/vendor/sass/test/sass/templates/compressed.sass +0 -15
- data/vendor/sass/test/sass/templates/expanded.sass +0 -17
- data/vendor/sass/test/sass/templates/import.sass +0 -12
- data/vendor/sass/test/sass/templates/importee.less +0 -2
- data/vendor/sass/test/sass/templates/importee.sass +0 -19
- data/vendor/sass/test/sass/templates/line_numbers.sass +0 -13
- data/vendor/sass/test/sass/templates/mixin_bork.sass +0 -5
- data/vendor/sass/test/sass/templates/mixins.sass +0 -76
- data/vendor/sass/test/sass/templates/multiline.sass +0 -20
- data/vendor/sass/test/sass/templates/nested.sass +0 -25
- data/vendor/sass/test/sass/templates/nested_bork1.sass +0 -2
- data/vendor/sass/test/sass/templates/nested_bork2.sass +0 -2
- data/vendor/sass/test/sass/templates/nested_bork3.sass +0 -2
- data/vendor/sass/test/sass/templates/nested_bork4.sass +0 -2
- data/vendor/sass/test/sass/templates/nested_mixin_bork.sass +0 -6
- data/vendor/sass/test/sass/templates/options.sass +0 -2
- data/vendor/sass/test/sass/templates/parent_ref.sass +0 -25
- data/vendor/sass/test/sass/templates/script.sass +0 -101
- data/vendor/sass/test/sass/templates/scss_import.scss +0 -11
- data/vendor/sass/test/sass/templates/scss_importee.scss +0 -1
- data/vendor/sass/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +0 -2
- data/vendor/sass/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +0 -3
- data/vendor/sass/test/sass/templates/subdir/subdir.sass +0 -6
- data/vendor/sass/test/sass/templates/units.sass +0 -11
- data/vendor/sass/test/sass/templates/warn.sass +0 -3
- data/vendor/sass/test/sass/templates/warn_imported.sass +0 -4
- data/vendor/sass/test/sass/test_helper.rb +0 -8
- data/vendor/sass/test/sass/util/subset_map_test.rb +0 -91
- data/vendor/sass/test/sass/util_test.rb +0 -275
- data/vendor/sass/test/test_helper.rb +0 -64
- data/vendor/sass/yard/callbacks.rb +0 -29
- data/vendor/sass/yard/default/fulldoc/html/css/common.sass +0 -26
- data/vendor/sass/yard/default/layout/html/footer.erb +0 -12
- data/vendor/sass/yard/inherited_hash.rb +0 -41
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'sass/tree/node'
|
2
|
-
|
3
|
-
module Sass::Tree
|
4
|
-
# A static node reprenting an `@extend` directive.
|
5
|
-
#
|
6
|
-
# @see Sass::Tree
|
7
|
-
class ExtendNode < Node
|
8
|
-
# @param selector [Array<String, Sass::Script::Node>]
|
9
|
-
# The CSS selector to extend,
|
10
|
-
# interspersed with {Sass::Script::Node}s
|
11
|
-
# representing `#{}`-interpolation.
|
12
|
-
def initialize(selector)
|
13
|
-
@selector = selector
|
14
|
-
super()
|
15
|
-
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
|
-
end
|
65
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'sass/tree/node'
|
2
|
-
|
3
|
-
module Sass::Tree
|
4
|
-
# A dynamic node representing a Sass `@for` loop.
|
5
|
-
#
|
6
|
-
# @see Sass::Tree
|
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
|
13
|
-
def initialize(var, from, to, exclusive)
|
14
|
-
@var = var
|
15
|
-
@from = from
|
16
|
-
@to = to
|
17
|
-
@exclusive = exclusive
|
18
|
-
super()
|
19
|
-
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
|
-
|
55
|
-
# Returns an error message if the given child node is invalid,
|
56
|
-
# and false otherwise.
|
57
|
-
#
|
58
|
-
# {ExtendNode}s are valid within {ForNode}s.
|
59
|
-
#
|
60
|
-
# @param child [Tree::Node] A potential child node.
|
61
|
-
# @return [Boolean, String] Whether or not the child node is valid,
|
62
|
-
# as well as the error message to display if it is invalid
|
63
|
-
def invalid_child?(child)
|
64
|
-
super unless child.is_a?(ExtendNode)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'sass/tree/node'
|
2
|
-
|
3
|
-
module Sass::Tree
|
4
|
-
# A dynamic node representing a Sass `@if` statement.
|
5
|
-
#
|
6
|
-
# {IfNode}s are a little odd, in that they also represent `@else` and `@else if`s.
|
7
|
-
# This is done as a linked list:
|
8
|
-
# each {IfNode} has a link (\{#else}) to the next {IfNode}.
|
9
|
-
#
|
10
|
-
# @see Sass::Tree
|
11
|
-
class IfNode < Node
|
12
|
-
# The next {IfNode} in the if-else list, or `nil`.
|
13
|
-
#
|
14
|
-
# @return [IfNode]
|
15
|
-
attr_accessor :else
|
16
|
-
|
17
|
-
# @param expr [Script::Expr] The conditional expression.
|
18
|
-
# If this is nil, this is an `@else` node, not an `@else if`
|
19
|
-
def initialize(expr)
|
20
|
-
@expr = expr
|
21
|
-
@last_else = self
|
22
|
-
super()
|
23
|
-
end
|
24
|
-
|
25
|
-
# Append an `@else` node to the end of the list.
|
26
|
-
#
|
27
|
-
# @param node [IfNode] The `@else` node to append
|
28
|
-
def add_else(node)
|
29
|
-
@last_else.else = node
|
30
|
-
@last_else = node
|
31
|
-
end
|
32
|
-
|
33
|
-
# @see Node#options=
|
34
|
-
def options=(options)
|
35
|
-
super
|
36
|
-
self.else.options = options if self.else
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
# @see Node#to_src
|
42
|
-
def to_src(tabs, opts, fmt, is_else = false)
|
43
|
-
name =
|
44
|
-
if !is_else; "if"
|
45
|
-
elsif @expr; "else if"
|
46
|
-
else; "else"
|
47
|
-
end
|
48
|
-
str = "#{' ' * tabs}@#{name}"
|
49
|
-
str << " #{@expr.to_sass(opts)}" if @expr
|
50
|
-
str << children_to_src(tabs, opts, fmt)
|
51
|
-
str << @else.send(:to_src, tabs, opts, fmt, true) if @else
|
52
|
-
str
|
53
|
-
end
|
54
|
-
|
55
|
-
# Runs the child nodes if the conditional expression is true;
|
56
|
-
# otherwise, tries the \{#else} nodes.
|
57
|
-
#
|
58
|
-
# @param environment [Sass::Environment] The lexical environment containing
|
59
|
-
# variable and mixin values
|
60
|
-
# @return [Array<Tree::Node>] The resulting static nodes
|
61
|
-
# @see Sass::Tree
|
62
|
-
def _perform(environment)
|
63
|
-
environment = Sass::Environment.new(environment)
|
64
|
-
return perform_children(environment) if @expr.nil? || @expr.perform(environment).to_bool
|
65
|
-
return @else.perform(environment) if @else
|
66
|
-
[]
|
67
|
-
end
|
68
|
-
|
69
|
-
# Returns an error message if the given child node is invalid,
|
70
|
-
# and false otherwise.
|
71
|
-
#
|
72
|
-
# {ExtendNode}s are valid within {IfNode}s.
|
73
|
-
#
|
74
|
-
# @param child [Tree::Node] A potential child node.
|
75
|
-
# @return [Boolean, String] Whether or not the child node is valid,
|
76
|
-
# as well as the error message to display if it is invalid
|
77
|
-
def invalid_child?(child)
|
78
|
-
super unless child.is_a?(ExtendNode)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,124 +0,0 @@
|
|
1
|
-
module Sass
|
2
|
-
module Tree
|
3
|
-
# A static node that wraps the {Sass::Tree} for an `@import`ed file.
|
4
|
-
# It doesn't have a functional purpose other than to add the `@import`ed file
|
5
|
-
# to the backtrace if an error occurs.
|
6
|
-
class ImportNode < RootNode
|
7
|
-
# The name of the imported file as it appears in the Sass document.
|
8
|
-
#
|
9
|
-
# @return [String]
|
10
|
-
attr_reader :imported_filename
|
11
|
-
|
12
|
-
# @param imported_filename [String] The name of the imported file
|
13
|
-
def initialize(imported_filename)
|
14
|
-
@imported_filename = imported_filename
|
15
|
-
super(nil)
|
16
|
-
end
|
17
|
-
|
18
|
-
def invisible?; to_s.empty?; end
|
19
|
-
|
20
|
-
# Returns the imported file.
|
21
|
-
#
|
22
|
-
# @return [Sass::Engine]
|
23
|
-
# @raise [Sass::SyntaxError] If no file could be found to import.
|
24
|
-
def imported_file
|
25
|
-
@imported_file ||= import
|
26
|
-
end
|
27
|
-
|
28
|
-
# @see Node#to_sass
|
29
|
-
def to_sass(tabs = 0, opts = {})
|
30
|
-
"#{' ' * tabs}@import #{@imported_filename}\n"
|
31
|
-
end
|
32
|
-
|
33
|
-
# @see Node#to_scss
|
34
|
-
def to_scss(tabs = 0, opts = {})
|
35
|
-
"#{' ' * tabs}@import \"#{@imported_filename}\";\n"
|
36
|
-
end
|
37
|
-
|
38
|
-
# @see Node#cssize
|
39
|
-
def cssize(*args)
|
40
|
-
super.first
|
41
|
-
end
|
42
|
-
|
43
|
-
# Returns whether or not this import should emit a CSS @import declaration
|
44
|
-
#
|
45
|
-
# @return [Boolean] Whether or not this is a simple CSS @import declaration.
|
46
|
-
def css_import?
|
47
|
-
if @imported_filename =~ /\.css$/
|
48
|
-
@imported_filename
|
49
|
-
elsif imported_file.is_a?(String) && imported_file =~ /\.css$/
|
50
|
-
imported_file
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
protected
|
55
|
-
|
56
|
-
# @see Node#_cssize
|
57
|
-
def _cssize(*args)
|
58
|
-
super.children
|
59
|
-
rescue Sass::SyntaxError => e
|
60
|
-
e.modify_backtrace(:filename => children.first.filename)
|
61
|
-
e.add_backtrace(:filename => @filename, :line => @line)
|
62
|
-
raise e
|
63
|
-
end
|
64
|
-
|
65
|
-
# Returns a static DirectiveNode if this is importing a CSS file,
|
66
|
-
# or parses and includes the imported Sass file.
|
67
|
-
#
|
68
|
-
# @param environment [Sass::Environment] The lexical environment containing
|
69
|
-
# variable and mixin values
|
70
|
-
def _perform(environment)
|
71
|
-
if path = css_import?
|
72
|
-
return DirectiveNode.new("@import url(#{path})")
|
73
|
-
end
|
74
|
-
super
|
75
|
-
end
|
76
|
-
|
77
|
-
# Parses the imported file and runs the dynamic Sass for it.
|
78
|
-
#
|
79
|
-
# @param environment [Sass::Environment] The lexical environment containing
|
80
|
-
# variable and mixin values
|
81
|
-
def perform!(environment)
|
82
|
-
environment.push_frame(:filename => @filename, :line => @line)
|
83
|
-
# TODO: re-enable caching
|
84
|
-
root = imported_file.to_tree
|
85
|
-
self.children = root.children
|
86
|
-
self.children = perform_children(environment)
|
87
|
-
rescue Sass::SyntaxError => e
|
88
|
-
e.modify_backtrace(:filename => imported_file.options[:filename])
|
89
|
-
e.add_backtrace(:filename => @filename, :line => @line)
|
90
|
-
raise e
|
91
|
-
ensure
|
92
|
-
environment.pop_frame
|
93
|
-
end
|
94
|
-
|
95
|
-
private
|
96
|
-
|
97
|
-
def import
|
98
|
-
paths = @options[:load_paths]
|
99
|
-
|
100
|
-
if @options[:importer]
|
101
|
-
f = @options[:importer].find_relative(
|
102
|
-
@imported_filename, @options[:filename], @options.dup)
|
103
|
-
return f if f
|
104
|
-
end
|
105
|
-
|
106
|
-
paths.each do |p|
|
107
|
-
if f = p.find(@imported_filename, @options.dup)
|
108
|
-
return f
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
message = "File to import not found or unreadable: #{@imported_filename}.\n"
|
113
|
-
if paths.size == 1
|
114
|
-
message << "Load path: #{paths.first}"
|
115
|
-
else
|
116
|
-
message << "Load paths:\n " << paths.join("\n ")
|
117
|
-
end
|
118
|
-
raise SyntaxError.new(message)
|
119
|
-
rescue SyntaxError => e
|
120
|
-
raise SyntaxError.new(e.message, :line => self.line, :filename => @filename)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module Sass
|
2
|
-
module Tree
|
3
|
-
# A dynamic node representing a mixin definition.
|
4
|
-
#
|
5
|
-
# @see Sass::Tree
|
6
|
-
class MixinDefNode < Node
|
7
|
-
# @param name [String] The mixin name
|
8
|
-
# @param args [Array<(Script::Node, Script::Node)>] The arguments for the mixin.
|
9
|
-
# Each element is a tuple containing the variable for argument
|
10
|
-
# and the parse tree for the default value of the argument
|
11
|
-
def initialize(name, args)
|
12
|
-
@name = name
|
13
|
-
@args = args
|
14
|
-
super()
|
15
|
-
end
|
16
|
-
|
17
|
-
protected
|
18
|
-
|
19
|
-
# @see Node#to_src
|
20
|
-
def to_src(tabs, opts, fmt)
|
21
|
-
args =
|
22
|
-
if @args.empty?
|
23
|
-
""
|
24
|
-
else
|
25
|
-
'(' + @args.map do |v, d|
|
26
|
-
if d
|
27
|
-
"#{v.to_sass(opts)}: #{d.to_sass(opts)}"
|
28
|
-
else
|
29
|
-
v.to_sass(opts)
|
30
|
-
end
|
31
|
-
end.join(", ") + ')'
|
32
|
-
end
|
33
|
-
|
34
|
-
"#{' ' * tabs}#{fmt == :sass ? '=' : '@mixin '}#{dasherize(@name, opts)}#{args}" +
|
35
|
-
children_to_src(tabs, opts, fmt)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Loads the mixin into the environment.
|
39
|
-
#
|
40
|
-
# @param environment [Sass::Environment] The lexical environment containing
|
41
|
-
# variable and mixin values
|
42
|
-
def _perform(environment)
|
43
|
-
environment.set_mixin(@name, Sass::Mixin.new(@name, @args, environment, children))
|
44
|
-
[]
|
45
|
-
end
|
46
|
-
|
47
|
-
# Returns an error message if the given child node is invalid,
|
48
|
-
# and false otherwise.
|
49
|
-
#
|
50
|
-
# {ExtendNode}s are valid within {MixinDefNode}s.
|
51
|
-
#
|
52
|
-
# @param child [Tree::Node] A potential child node.
|
53
|
-
# @return [Boolean, String] Whether or not the child node is valid,
|
54
|
-
# as well as the error message to display if it is invalid
|
55
|
-
def invalid_child?(child)
|
56
|
-
super unless child.is_a?(ExtendNode)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,123 +0,0 @@
|
|
1
|
-
require 'sass/tree/node'
|
2
|
-
|
3
|
-
module Sass::Tree
|
4
|
-
# A static node representing a mixin include.
|
5
|
-
# When in a static tree, the sole purpose is to wrap exceptions
|
6
|
-
# to add the mixin to the backtrace.
|
7
|
-
#
|
8
|
-
# @see Sass::Tree
|
9
|
-
class MixinNode < Node
|
10
|
-
# @see Node#options=
|
11
|
-
def options=(opts)
|
12
|
-
super
|
13
|
-
@args.each {|a| a.context = :equals} if opts[:sass2]
|
14
|
-
end
|
15
|
-
|
16
|
-
# @param name [String] The name of the mixin
|
17
|
-
# @param args [Array<Script::Node>] The arguments to the mixin
|
18
|
-
def initialize(name, args)
|
19
|
-
@name = name
|
20
|
-
@args = args
|
21
|
-
super()
|
22
|
-
end
|
23
|
-
|
24
|
-
# @see Node#cssize
|
25
|
-
def cssize(extends, parent = nil)
|
26
|
-
_cssize(extends, parent) # Pass on the parent even if it's not a MixinNode
|
27
|
-
end
|
28
|
-
|
29
|
-
protected
|
30
|
-
|
31
|
-
# Returns an error message if the given child node is invalid,
|
32
|
-
# and false otherwise.
|
33
|
-
#
|
34
|
-
# {ExtendNode}s are valid within {MixinNode}s.
|
35
|
-
#
|
36
|
-
# @param child [Tree::Node] A potential child node
|
37
|
-
# @return [Boolean, String] Whether or not the child node is valid,
|
38
|
-
# as well as the error message to display if it is invalid
|
39
|
-
def invalid_child?(child)
|
40
|
-
super unless child.is_a?(ExtendNode)
|
41
|
-
end
|
42
|
-
|
43
|
-
# @see Node#to_src
|
44
|
-
def to_src(tabs, opts, fmt)
|
45
|
-
args = '(' + @args.map {|a| a.to_sass(opts)}.join(", ") + ')' unless @args.empty?
|
46
|
-
"#{' ' * tabs}#{fmt == :sass ? '+' : '@include '}#{dasherize(@name, opts)}#{args}#{semi fmt}\n"
|
47
|
-
end
|
48
|
-
|
49
|
-
# @see Node#_cssize
|
50
|
-
def _cssize(extends, parent)
|
51
|
-
children.map do |c|
|
52
|
-
parent.check_child! c
|
53
|
-
c.cssize(extends, parent)
|
54
|
-
end.flatten
|
55
|
-
rescue Sass::SyntaxError => e
|
56
|
-
e.modify_backtrace(:mixin => @name, :filename => filename, :line => line)
|
57
|
-
e.add_backtrace(:filename => filename, :line => line)
|
58
|
-
raise e
|
59
|
-
end
|
60
|
-
|
61
|
-
# Runs the mixin.
|
62
|
-
#
|
63
|
-
# @param environment [Sass::Environment] The lexical environment containing
|
64
|
-
# variable and mixin values
|
65
|
-
# @raise [Sass::SyntaxError] if there is no mixin with the given name
|
66
|
-
# @raise [Sass::SyntaxError] if an incorrect number of arguments was passed
|
67
|
-
# @see Sass::Tree
|
68
|
-
def perform!(environment)
|
69
|
-
handle_include_loop!(environment) if environment.mixins_in_use.include?(@name)
|
70
|
-
|
71
|
-
original_env = environment
|
72
|
-
original_env.push_frame(:filename => filename, :line => line)
|
73
|
-
original_env.prepare_frame(:mixin => @name)
|
74
|
-
raise Sass::SyntaxError.new("Undefined mixin '#{@name}'.") unless mixin = environment.mixin(@name)
|
75
|
-
|
76
|
-
raise Sass::SyntaxError.new(<<END.gsub("\n", "")) if mixin.args.size < @args.size
|
77
|
-
Mixin #{@name} takes #{mixin.args.size} argument#{'s' if mixin.args.size != 1}
|
78
|
-
but #{@args.size} #{@args.size == 1 ? 'was' : 'were'} passed.
|
79
|
-
END
|
80
|
-
environment = mixin.args.zip(@args).
|
81
|
-
inject(Sass::Environment.new(mixin.environment)) do |env, ((var, default), value)|
|
82
|
-
env.set_local_var(var.name,
|
83
|
-
if value
|
84
|
-
value.perform(environment)
|
85
|
-
elsif default
|
86
|
-
val = default.perform(env)
|
87
|
-
if default.context == :equals && val.is_a?(Sass::Script::String)
|
88
|
-
val = Sass::Script::String.new(val.value)
|
89
|
-
end
|
90
|
-
val
|
91
|
-
end)
|
92
|
-
raise Sass::SyntaxError.new("Mixin #{@name} is missing parameter #{var.inspect}.") unless env.var(var.name)
|
93
|
-
env
|
94
|
-
end
|
95
|
-
|
96
|
-
self.children = mixin.tree.map {|c| c.perform(environment)}.flatten
|
97
|
-
rescue Sass::SyntaxError => e
|
98
|
-
if original_env # Don't add backtrace info if this is an @include loop
|
99
|
-
e.modify_backtrace(:mixin => @name, :line => @line)
|
100
|
-
e.add_backtrace(:line => @line)
|
101
|
-
end
|
102
|
-
raise e
|
103
|
-
ensure
|
104
|
-
original_env.pop_frame if original_env
|
105
|
-
end
|
106
|
-
|
107
|
-
private
|
108
|
-
|
109
|
-
def handle_include_loop!(environment)
|
110
|
-
msg = "An @include loop has been found:"
|
111
|
-
mixins = environment.stack.map {|s| s[:mixin]}.compact
|
112
|
-
if mixins.size == 2 && mixins[0] == mixins[1]
|
113
|
-
raise Sass::SyntaxError.new("#{msg} #{@name} includes itself")
|
114
|
-
end
|
115
|
-
|
116
|
-
mixins << @name
|
117
|
-
msg << "\n" << Sass::Util.enum_cons(mixins, 2).map do |m1, m2|
|
118
|
-
" #{m1} includes #{m2}"
|
119
|
-
end.join("\n")
|
120
|
-
raise Sass::SyntaxError.new(msg)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|