drnic-haml 2.3.0
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.
- data/.yardopts +5 -0
- data/CONTRIBUTING +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +347 -0
- data/REVISION +1 -0
- data/Rakefile +371 -0
- data/VERSION +1 -0
- data/VERSION_NAME +1 -0
- data/bin/css2sass +7 -0
- data/bin/haml +9 -0
- data/bin/html2haml +7 -0
- data/bin/sass +8 -0
- data/extra/haml-mode.el +663 -0
- data/extra/sass-mode.el +205 -0
- data/extra/update_watch.rb +13 -0
- data/init.rb +8 -0
- data/lib/haml.rb +40 -0
- data/lib/haml/buffer.rb +307 -0
- data/lib/haml/engine.rb +301 -0
- data/lib/haml/error.rb +22 -0
- data/lib/haml/exec.rb +470 -0
- data/lib/haml/filters.rb +341 -0
- data/lib/haml/helpers.rb +560 -0
- data/lib/haml/helpers/action_view_extensions.rb +40 -0
- data/lib/haml/helpers/action_view_mods.rb +176 -0
- data/lib/haml/herb.rb +96 -0
- data/lib/haml/html.rb +308 -0
- data/lib/haml/precompiler.rb +997 -0
- data/lib/haml/shared.rb +78 -0
- data/lib/haml/template.rb +51 -0
- data/lib/haml/template/patch.rb +58 -0
- data/lib/haml/template/plugin.rb +71 -0
- data/lib/haml/util.rb +244 -0
- data/lib/haml/version.rb +64 -0
- data/lib/sass.rb +24 -0
- data/lib/sass/css.rb +423 -0
- data/lib/sass/engine.rb +491 -0
- data/lib/sass/environment.rb +79 -0
- data/lib/sass/error.rb +162 -0
- data/lib/sass/files.rb +133 -0
- data/lib/sass/plugin.rb +170 -0
- data/lib/sass/plugin/merb.rb +57 -0
- data/lib/sass/plugin/rails.rb +23 -0
- data/lib/sass/repl.rb +58 -0
- data/lib/sass/script.rb +55 -0
- data/lib/sass/script/bool.rb +17 -0
- data/lib/sass/script/color.rb +183 -0
- data/lib/sass/script/funcall.rb +50 -0
- data/lib/sass/script/functions.rb +199 -0
- data/lib/sass/script/lexer.rb +191 -0
- data/lib/sass/script/literal.rb +177 -0
- data/lib/sass/script/node.rb +14 -0
- data/lib/sass/script/number.rb +381 -0
- data/lib/sass/script/operation.rb +45 -0
- data/lib/sass/script/parser.rb +222 -0
- data/lib/sass/script/string.rb +12 -0
- data/lib/sass/script/unary_operation.rb +34 -0
- data/lib/sass/script/variable.rb +31 -0
- data/lib/sass/tree/comment_node.rb +84 -0
- data/lib/sass/tree/debug_node.rb +30 -0
- data/lib/sass/tree/directive_node.rb +70 -0
- data/lib/sass/tree/for_node.rb +48 -0
- data/lib/sass/tree/if_node.rb +54 -0
- data/lib/sass/tree/import_node.rb +69 -0
- data/lib/sass/tree/mixin_def_node.rb +29 -0
- data/lib/sass/tree/mixin_node.rb +48 -0
- data/lib/sass/tree/node.rb +252 -0
- data/lib/sass/tree/prop_node.rb +106 -0
- data/lib/sass/tree/root_node.rb +56 -0
- data/lib/sass/tree/rule_node.rb +220 -0
- data/lib/sass/tree/variable_node.rb +34 -0
- data/lib/sass/tree/while_node.rb +31 -0
- data/rails/init.rb +1 -0
- data/test/benchmark.rb +99 -0
- data/test/haml/engine_test.rb +1129 -0
- data/test/haml/helper_test.rb +282 -0
- data/test/haml/html2haml_test.rb +258 -0
- data/test/haml/markaby/standard.mab +52 -0
- data/test/haml/mocks/article.rb +6 -0
- data/test/haml/results/content_for_layout.xhtml +12 -0
- data/test/haml/results/eval_suppressed.xhtml +9 -0
- data/test/haml/results/filters.xhtml +62 -0
- data/test/haml/results/helpers.xhtml +93 -0
- data/test/haml/results/helpful.xhtml +10 -0
- data/test/haml/results/just_stuff.xhtml +68 -0
- data/test/haml/results/list.xhtml +12 -0
- data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
- data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
- data/test/haml/results/original_engine.xhtml +20 -0
- data/test/haml/results/partial_layout.xhtml +5 -0
- data/test/haml/results/partials.xhtml +21 -0
- data/test/haml/results/render_layout.xhtml +3 -0
- data/test/haml/results/silent_script.xhtml +74 -0
- data/test/haml/results/standard.xhtml +162 -0
- data/test/haml/results/tag_parsing.xhtml +23 -0
- data/test/haml/results/very_basic.xhtml +5 -0
- data/test/haml/results/whitespace_handling.xhtml +89 -0
- data/test/haml/rhtml/_av_partial_1.rhtml +12 -0
- data/test/haml/rhtml/_av_partial_2.rhtml +8 -0
- data/test/haml/rhtml/action_view.rhtml +62 -0
- data/test/haml/rhtml/standard.rhtml +54 -0
- data/test/haml/spec_test.rb +44 -0
- data/test/haml/template_test.rb +217 -0
- data/test/haml/templates/_av_partial_1.haml +9 -0
- data/test/haml/templates/_av_partial_1_ugly.haml +9 -0
- data/test/haml/templates/_av_partial_2.haml +5 -0
- data/test/haml/templates/_av_partial_2_ugly.haml +5 -0
- data/test/haml/templates/_layout.erb +3 -0
- data/test/haml/templates/_layout_for_partial.haml +3 -0
- data/test/haml/templates/_partial.haml +8 -0
- data/test/haml/templates/_text_area.haml +3 -0
- data/test/haml/templates/action_view.haml +47 -0
- data/test/haml/templates/action_view_ugly.haml +47 -0
- data/test/haml/templates/breakage.haml +8 -0
- data/test/haml/templates/content_for_layout.haml +8 -0
- data/test/haml/templates/eval_suppressed.haml +11 -0
- data/test/haml/templates/filters.haml +66 -0
- data/test/haml/templates/helpers.haml +95 -0
- data/test/haml/templates/helpful.haml +11 -0
- data/test/haml/templates/just_stuff.haml +83 -0
- data/test/haml/templates/list.haml +12 -0
- data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
- data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
- data/test/haml/templates/original_engine.haml +17 -0
- data/test/haml/templates/partial_layout.haml +3 -0
- data/test/haml/templates/partialize.haml +1 -0
- data/test/haml/templates/partials.haml +12 -0
- data/test/haml/templates/render_layout.haml +2 -0
- data/test/haml/templates/silent_script.haml +40 -0
- data/test/haml/templates/standard.haml +42 -0
- data/test/haml/templates/standard_ugly.haml +42 -0
- data/test/haml/templates/tag_parsing.haml +21 -0
- data/test/haml/templates/very_basic.haml +4 -0
- data/test/haml/templates/whitespace_handling.haml +87 -0
- data/test/haml/util_test.rb +92 -0
- data/test/linked_rails.rb +12 -0
- data/test/sass/css2sass_test.rb +294 -0
- data/test/sass/engine_test.rb +956 -0
- data/test/sass/functions_test.rb +126 -0
- data/test/sass/more_results/more1.css +9 -0
- data/test/sass/more_results/more1_with_line_comments.css +26 -0
- data/test/sass/more_results/more_import.css +29 -0
- data/test/sass/more_templates/_more_partial.sass +2 -0
- data/test/sass/more_templates/more1.sass +23 -0
- data/test/sass/more_templates/more_import.sass +11 -0
- data/test/sass/plugin_test.rb +229 -0
- data/test/sass/results/alt.css +4 -0
- data/test/sass/results/basic.css +9 -0
- data/test/sass/results/compact.css +5 -0
- data/test/sass/results/complex.css +87 -0
- data/test/sass/results/compressed.css +1 -0
- data/test/sass/results/expanded.css +19 -0
- data/test/sass/results/import.css +29 -0
- data/test/sass/results/line_numbers.css +49 -0
- data/test/sass/results/mixins.css +95 -0
- data/test/sass/results/multiline.css +24 -0
- data/test/sass/results/nested.css +22 -0
- data/test/sass/results/parent_ref.css +13 -0
- data/test/sass/results/script.css +16 -0
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
- data/test/sass/results/subdir/subdir.css +3 -0
- data/test/sass/results/units.css +11 -0
- data/test/sass/script_test.rb +261 -0
- data/test/sass/templates/_partial.sass +2 -0
- data/test/sass/templates/alt.sass +16 -0
- data/test/sass/templates/basic.sass +23 -0
- data/test/sass/templates/bork1.sass +2 -0
- data/test/sass/templates/bork2.sass +2 -0
- data/test/sass/templates/bork3.sass +2 -0
- data/test/sass/templates/compact.sass +17 -0
- data/test/sass/templates/complex.sass +307 -0
- data/test/sass/templates/compressed.sass +15 -0
- data/test/sass/templates/expanded.sass +17 -0
- data/test/sass/templates/import.sass +11 -0
- data/test/sass/templates/importee.sass +19 -0
- data/test/sass/templates/line_numbers.sass +13 -0
- data/test/sass/templates/mixins.sass +76 -0
- data/test/sass/templates/multiline.sass +20 -0
- data/test/sass/templates/nested.sass +25 -0
- data/test/sass/templates/nested_bork1.sass +2 -0
- data/test/sass/templates/nested_bork2.sass +2 -0
- data/test/sass/templates/nested_bork3.sass +2 -0
- data/test/sass/templates/parent_ref.sass +25 -0
- data/test/sass/templates/script.sass +101 -0
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
- data/test/sass/templates/subdir/subdir.sass +6 -0
- data/test/sass/templates/units.sass +11 -0
- data/test/test_helper.rb +44 -0
- metadata +298 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'sass/script/literal'
|
|
2
|
+
|
|
3
|
+
module Sass::Script
|
|
4
|
+
# A SassScript object representing a string of text.
|
|
5
|
+
class String < Literal
|
|
6
|
+
# The Ruby value of the string.
|
|
7
|
+
#
|
|
8
|
+
# @return [String]
|
|
9
|
+
attr_reader :value
|
|
10
|
+
alias_method :to_s, :value
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Sass::Script
|
|
2
|
+
# A SassScript parse node representing a unary operation,
|
|
3
|
+
# such as `-!b` or `not true`.
|
|
4
|
+
#
|
|
5
|
+
# Currently only `-`, `/`, and `not` are unary operators.
|
|
6
|
+
class UnaryOperation < Node
|
|
7
|
+
# @param operand [Script::Node] The parse-tree node
|
|
8
|
+
# for the object of the operator
|
|
9
|
+
# @param operator [Symbol] The operator to perform
|
|
10
|
+
def initialize(operand, operator)
|
|
11
|
+
@operand = operand
|
|
12
|
+
@operator = operator
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return [String] A human-readable s-expression representation of the operation
|
|
16
|
+
def inspect
|
|
17
|
+
"(#{@operator.inspect} #{@operand.inspect})"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Evaluates the operation.
|
|
21
|
+
#
|
|
22
|
+
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
|
|
23
|
+
# @return [Literal] The SassScript object that is the value of the operation
|
|
24
|
+
# @raise [Sass::SyntaxError] if the operation is undefined for the operand
|
|
25
|
+
def perform(environment)
|
|
26
|
+
operator = "unary_#{@operator}"
|
|
27
|
+
literal = @operand.perform(environment)
|
|
28
|
+
literal.send(operator)
|
|
29
|
+
rescue NoMethodError => e
|
|
30
|
+
raise e unless e.name.to_s == operator.to_s
|
|
31
|
+
raise Sass::SyntaxError.new("Undefined unary operation: \"#{@operator} #{literal}\".")
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Sass
|
|
2
|
+
module Script
|
|
3
|
+
# A SassScript parse node representing a variable.
|
|
4
|
+
class Variable < Node
|
|
5
|
+
# The name of the variable.
|
|
6
|
+
#
|
|
7
|
+
# @return [String]
|
|
8
|
+
attr_reader :name
|
|
9
|
+
|
|
10
|
+
# @param name [String] See \{#name}
|
|
11
|
+
def initialize(name)
|
|
12
|
+
@name = name
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return [String] A string representation of the variable
|
|
16
|
+
def inspect
|
|
17
|
+
"!#{name}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Evaluates the variable.
|
|
21
|
+
#
|
|
22
|
+
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
|
|
23
|
+
# @return [Literal] The SassScript object that is the value of the variable
|
|
24
|
+
# @raise [Sass::SyntaxError] if the variable is undefined
|
|
25
|
+
def perform(environment)
|
|
26
|
+
(val = environment.var(name)) && (return val)
|
|
27
|
+
raise SyntaxError.new("Undefined variable: \"!#{name}\".")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require 'sass/tree/node'
|
|
2
|
+
|
|
3
|
+
module Sass::Tree
|
|
4
|
+
# A static node representing a Sass comment (silent or loud).
|
|
5
|
+
#
|
|
6
|
+
# @see Sass::Tree
|
|
7
|
+
class CommentNode < Node
|
|
8
|
+
# The lines of text nested beneath the comment.
|
|
9
|
+
#
|
|
10
|
+
# @return [Array<Sass::Engine::Line>]
|
|
11
|
+
attr_accessor :lines
|
|
12
|
+
|
|
13
|
+
# The text on the same line as the comment starter.
|
|
14
|
+
#
|
|
15
|
+
# @return [String]
|
|
16
|
+
attr_accessor :value
|
|
17
|
+
|
|
18
|
+
# Whether or not the comment is silent (that is, doesn't output to CSS).
|
|
19
|
+
#
|
|
20
|
+
# @return [Boolean]
|
|
21
|
+
attr_accessor :silent
|
|
22
|
+
|
|
23
|
+
# @param value [String] See \{#value}
|
|
24
|
+
# @param silent [Boolean] See \{#silent}
|
|
25
|
+
def initialize(value, silent)
|
|
26
|
+
@lines = []
|
|
27
|
+
@value = value[2..-1].strip
|
|
28
|
+
@silent = silent
|
|
29
|
+
super()
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Compares the contents of two comments.
|
|
33
|
+
#
|
|
34
|
+
# @param other [Object] The object to compare with
|
|
35
|
+
# @return [Boolean] Whether or not this node and the other object
|
|
36
|
+
# are the same
|
|
37
|
+
def ==(other)
|
|
38
|
+
self.class == other.class && value == other.value && silent == other.silent && lines == other.lines
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Returns `true` if this is a silent comment
|
|
42
|
+
# or the current style doesn't render comments.
|
|
43
|
+
#
|
|
44
|
+
# @return [Boolean]
|
|
45
|
+
def invisible?
|
|
46
|
+
style == :compressed || @silent
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
protected
|
|
50
|
+
|
|
51
|
+
# Computes the CSS for the comment.
|
|
52
|
+
#
|
|
53
|
+
# Returns `nil` if this is a silent comment
|
|
54
|
+
# or the current style doesn't render comments.
|
|
55
|
+
#
|
|
56
|
+
# @overload to_s(tabs = 0)
|
|
57
|
+
# @param tabs [Fixnum] The level of indentation for the CSS
|
|
58
|
+
# @return [String, nil] The resulting CSS
|
|
59
|
+
# @see #invisible?
|
|
60
|
+
def _to_s(tabs = 0, _ = nil)
|
|
61
|
+
return if invisible?
|
|
62
|
+
spaces = ' ' * (tabs - 1)
|
|
63
|
+
|
|
64
|
+
content = (value.split("\n") + lines.map {|l| l.text})
|
|
65
|
+
return spaces + "/* */" if content.empty?
|
|
66
|
+
content.map! {|l| (l.empty? ? "" : " ") + l}
|
|
67
|
+
content.first.gsub!(/^ /, '')
|
|
68
|
+
content.last.gsub!(%r{ ?\*/ *$}, '')
|
|
69
|
+
|
|
70
|
+
spaces + "/* " + content.join(style == :compact ? '' : "\n#{spaces} *") + " */"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Removes this node from the tree if it's a silent comment.
|
|
74
|
+
#
|
|
75
|
+
# @param environment [Sass::Environment] The lexical environment containing
|
|
76
|
+
# variable and mixin values
|
|
77
|
+
# @return [Tree::Node, Array<Tree::Node>] The resulting static nodes
|
|
78
|
+
# @see Sass::Tree
|
|
79
|
+
def _perform(environment)
|
|
80
|
+
return [] if @silent
|
|
81
|
+
self
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Sass
|
|
2
|
+
module Tree
|
|
3
|
+
# A dynamic node representing a Sass `@debug` statement.
|
|
4
|
+
#
|
|
5
|
+
# @see Sass::Tree
|
|
6
|
+
class DebugNode < Node
|
|
7
|
+
# @param expr [Script::Node] The expression to print
|
|
8
|
+
def initialize(expr)
|
|
9
|
+
@expr = expr
|
|
10
|
+
super()
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
protected
|
|
14
|
+
|
|
15
|
+
# Prints the expression to STDERR.
|
|
16
|
+
#
|
|
17
|
+
# @param environment [Sass::Environment] The lexical environment containing
|
|
18
|
+
# variable and mixin values
|
|
19
|
+
def _perform(environment)
|
|
20
|
+
res = @expr.perform(environment)
|
|
21
|
+
if filename
|
|
22
|
+
STDERR.puts "#{filename}:#{line} DEBUG: #{res}"
|
|
23
|
+
else
|
|
24
|
+
STDERR.puts "Line #{line} DEBUG: #{res}"
|
|
25
|
+
end
|
|
26
|
+
[]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module Sass::Tree
|
|
2
|
+
# A static node representing an unproccessed Sass `@`-directive.
|
|
3
|
+
# Directives known to Sass, like `@for` and `@debug`,
|
|
4
|
+
# are handled by their own nodes;
|
|
5
|
+
# only CSS directives like `@media` and `@font-face` become {DirectiveNode}s.
|
|
6
|
+
#
|
|
7
|
+
# `@import` is a bit of a weird case;
|
|
8
|
+
# it becomes an {ImportNode}.
|
|
9
|
+
#
|
|
10
|
+
# @see Sass::Tree
|
|
11
|
+
class DirectiveNode < Node
|
|
12
|
+
# The text of the directive, `@` and all.
|
|
13
|
+
#
|
|
14
|
+
# @return [String]
|
|
15
|
+
attr_accessor :value
|
|
16
|
+
|
|
17
|
+
# @param value [String] See \{#value}
|
|
18
|
+
def initialize(value)
|
|
19
|
+
@value = value
|
|
20
|
+
super()
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
protected
|
|
24
|
+
|
|
25
|
+
# Computes the CSS for the directive.
|
|
26
|
+
#
|
|
27
|
+
# @param tabs [Fixnum] The level of indentation for the CSS
|
|
28
|
+
# @return [String] The resulting CSS
|
|
29
|
+
def _to_s(tabs)
|
|
30
|
+
if children.empty?
|
|
31
|
+
value + ";"
|
|
32
|
+
else
|
|
33
|
+
result = if style == :compressed
|
|
34
|
+
"#{value}{"
|
|
35
|
+
else
|
|
36
|
+
"#{' ' * (tabs - 1)}#{value} {" + (style == :compact ? ' ' : "\n")
|
|
37
|
+
end
|
|
38
|
+
was_prop = false
|
|
39
|
+
first = true
|
|
40
|
+
children.each do |child|
|
|
41
|
+
next if child.invisible?
|
|
42
|
+
if style == :compact
|
|
43
|
+
if child.is_a?(PropNode)
|
|
44
|
+
result << "#{child.to_s(first || was_prop ? 1 : tabs + 1)} "
|
|
45
|
+
else
|
|
46
|
+
if was_prop
|
|
47
|
+
result[-1] = "\n"
|
|
48
|
+
end
|
|
49
|
+
rendered = child.to_s(tabs + 1)
|
|
50
|
+
rendered.lstrip! if first
|
|
51
|
+
result << rendered
|
|
52
|
+
end
|
|
53
|
+
was_prop = child.is_a?(PropNode)
|
|
54
|
+
first = false
|
|
55
|
+
elsif style == :compressed
|
|
56
|
+
result << (was_prop ? ";#{child.to_s(1)}" : child.to_s(1))
|
|
57
|
+
was_prop = child.is_a?(PropNode)
|
|
58
|
+
else
|
|
59
|
+
result << child.to_s(tabs + 1) + "\n"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
result.rstrip + if style == :compressed
|
|
63
|
+
"}"
|
|
64
|
+
else
|
|
65
|
+
(style == :expanded ? "\n" : " ") + "}\n"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
# Runs the child nodes once for each time through the loop,
|
|
24
|
+
# varying the variable each time.
|
|
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
|
+
from = @from.perform(environment)
|
|
32
|
+
to = @to.perform(environment)
|
|
33
|
+
from.assert_int!
|
|
34
|
+
to.assert_int!
|
|
35
|
+
|
|
36
|
+
to = to.coerce(from.numerator_units, from.denominator_units)
|
|
37
|
+
range = Range.new(from.to_i, to.to_i, @exclusive)
|
|
38
|
+
|
|
39
|
+
children = []
|
|
40
|
+
environment = Sass::Environment.new(environment)
|
|
41
|
+
range.each do |i|
|
|
42
|
+
environment.set_local_var(@var, Sass::Script::Number.new(i, from.numerator_units, from.denominator_units))
|
|
43
|
+
children += perform_children(environment)
|
|
44
|
+
end
|
|
45
|
+
children
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
def options=(options)
|
|
34
|
+
super
|
|
35
|
+
self.else.options = options if self.else
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
protected
|
|
39
|
+
|
|
40
|
+
# Runs the child nodes if the conditional expression is true;
|
|
41
|
+
# otherwise, tries the \{#else} nodes.
|
|
42
|
+
#
|
|
43
|
+
# @param environment [Sass::Environment] The lexical environment containing
|
|
44
|
+
# variable and mixin values
|
|
45
|
+
# @return [Array<Tree::Node>] The resulting static nodes
|
|
46
|
+
# @see Sass::Tree
|
|
47
|
+
def _perform(environment)
|
|
48
|
+
environment = Sass::Environment.new(environment)
|
|
49
|
+
return perform_children(environment) if @expr.nil? || @expr.perform(environment).to_bool
|
|
50
|
+
return @else.perform(environment) if @else
|
|
51
|
+
[]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
# @param imported_filename [String] The name of the imported file
|
|
8
|
+
def initialize(imported_filename)
|
|
9
|
+
@imported_filename = imported_filename
|
|
10
|
+
super(nil)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def invisible?; to_s.empty?; end
|
|
14
|
+
|
|
15
|
+
protected
|
|
16
|
+
|
|
17
|
+
# Computes the CSS for the imported file.
|
|
18
|
+
#
|
|
19
|
+
# @param args [Array] Ignored
|
|
20
|
+
def _to_s(*args)
|
|
21
|
+
@to_s ||= (style == :compressed ? super.strip : super)
|
|
22
|
+
rescue Sass::SyntaxError => e
|
|
23
|
+
e.modify_backtrace(:filename => children.first.filename)
|
|
24
|
+
e.add_backtrace(:filename => @filename, :line => @line)
|
|
25
|
+
raise e
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Parses the imported file
|
|
29
|
+
# and runs the dynamic Sass for it.
|
|
30
|
+
#
|
|
31
|
+
# @param environment [Sass::Environment] The lexical environment containing
|
|
32
|
+
# variable and mixin values
|
|
33
|
+
def perform!(environment)
|
|
34
|
+
return unless full_filename = import
|
|
35
|
+
root = Sass::Files.tree_for(full_filename, @options)
|
|
36
|
+
@template = root.template
|
|
37
|
+
self.children = root.children
|
|
38
|
+
self.children = perform_children(environment)
|
|
39
|
+
rescue Sass::SyntaxError => e
|
|
40
|
+
e.modify_backtrace(:filename => full_filename)
|
|
41
|
+
e.add_backtrace(:filename => @filename, :line => @line)
|
|
42
|
+
raise e
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def import_paths
|
|
48
|
+
paths = (@options[:load_paths] || []).dup
|
|
49
|
+
paths.unshift(File.dirname(@options[:filename])) if @options[:filename]
|
|
50
|
+
paths
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def import
|
|
54
|
+
begin
|
|
55
|
+
full_filename = Sass::Files.find_file_to_import(@imported_filename, import_paths)
|
|
56
|
+
rescue Exception => e
|
|
57
|
+
raise SyntaxError.new(e.message, :line => self.line, :filename => @filename)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
if full_filename =~ /\.css$/
|
|
61
|
+
@to_s = "@import url(#{full_filename});"
|
|
62
|
+
return false
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
return full_filename
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
# Loads the mixin into the environment.
|
|
20
|
+
#
|
|
21
|
+
# @param environment [Sass::Environment] The lexical environment containing
|
|
22
|
+
# variable and mixin values
|
|
23
|
+
def _perform(environment)
|
|
24
|
+
environment.set_mixin(@name, Sass::Mixin.new(@name, @args, environment, children))
|
|
25
|
+
[]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|