haml 3.0.25 → 3.1.0.alpha.2

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.

Files changed (212) hide show
  1. data/.yardopts +1 -1
  2. data/CONTRIBUTING +0 -1
  3. data/EDGE_GEM_VERSION +1 -0
  4. data/MIT-LICENSE +1 -1
  5. data/README.md +10 -175
  6. data/Rakefile +56 -84
  7. data/VERSION +1 -1
  8. data/VERSION_NAME +1 -1
  9. data/init.rb +1 -1
  10. data/lib/haml.rb +14 -12
  11. data/lib/haml/engine.rb +1 -1
  12. data/lib/haml/exec.rb +19 -316
  13. data/lib/haml/helpers/action_view_extensions.rb +1 -1
  14. data/lib/haml/html.rb +69 -76
  15. data/lib/haml/precompiler.rb +34 -41
  16. data/lib/haml/railtie.rb +4 -6
  17. data/lib/haml/template/plugin.rb +6 -16
  18. data/lib/haml/util.rb +91 -107
  19. data/lib/haml/version.rb +7 -0
  20. data/test/benchmark.rb +2 -9
  21. data/test/haml/engine_test.rb +195 -92
  22. data/test/haml/html2haml/erb_tests.rb +0 -14
  23. data/test/haml/util_test.rb +32 -0
  24. data/test/test_helper.rb +0 -39
  25. metadata +96 -324
  26. data/bin/css2sass +0 -13
  27. data/bin/sass +0 -8
  28. data/bin/sass-convert +0 -7
  29. data/extra/haml-mode.el +0 -753
  30. data/extra/sass-mode.el +0 -207
  31. data/lib/haml/util/subset_map.rb +0 -101
  32. data/lib/sass.rb +0 -29
  33. data/lib/sass/callbacks.rb +0 -52
  34. data/lib/sass/css.rb +0 -294
  35. data/lib/sass/engine.rb +0 -720
  36. data/lib/sass/environment.rb +0 -143
  37. data/lib/sass/error.rb +0 -198
  38. data/lib/sass/files.rb +0 -160
  39. data/lib/sass/less.rb +0 -382
  40. data/lib/sass/plugin.rb +0 -279
  41. data/lib/sass/plugin/configuration.rb +0 -221
  42. data/lib/sass/plugin/generic.rb +0 -15
  43. data/lib/sass/plugin/merb.rb +0 -37
  44. data/lib/sass/plugin/rack.rb +0 -47
  45. data/lib/sass/plugin/rails.rb +0 -32
  46. data/lib/sass/plugin/staleness_checker.rb +0 -123
  47. data/lib/sass/repl.rb +0 -58
  48. data/lib/sass/script.rb +0 -63
  49. data/lib/sass/script/bool.rb +0 -18
  50. data/lib/sass/script/color.rb +0 -491
  51. data/lib/sass/script/css_lexer.rb +0 -29
  52. data/lib/sass/script/css_parser.rb +0 -31
  53. data/lib/sass/script/funcall.rb +0 -77
  54. data/lib/sass/script/functions.rb +0 -861
  55. data/lib/sass/script/interpolation.rb +0 -70
  56. data/lib/sass/script/lexer.rb +0 -337
  57. data/lib/sass/script/literal.rb +0 -236
  58. data/lib/sass/script/node.rb +0 -112
  59. data/lib/sass/script/number.rb +0 -423
  60. data/lib/sass/script/operation.rb +0 -95
  61. data/lib/sass/script/parser.rb +0 -401
  62. data/lib/sass/script/string.rb +0 -67
  63. data/lib/sass/script/string_interpolation.rb +0 -93
  64. data/lib/sass/script/unary_operation.rb +0 -57
  65. data/lib/sass/script/variable.rb +0 -48
  66. data/lib/sass/scss.rb +0 -17
  67. data/lib/sass/scss/css_parser.rb +0 -46
  68. data/lib/sass/scss/parser.rb +0 -855
  69. data/lib/sass/scss/rx.rb +0 -126
  70. data/lib/sass/scss/sass_parser.rb +0 -11
  71. data/lib/sass/scss/script_lexer.rb +0 -15
  72. data/lib/sass/scss/script_parser.rb +0 -25
  73. data/lib/sass/scss/static_parser.rb +0 -40
  74. data/lib/sass/selector.rb +0 -361
  75. data/lib/sass/selector/abstract_sequence.rb +0 -62
  76. data/lib/sass/selector/comma_sequence.rb +0 -82
  77. data/lib/sass/selector/sequence.rb +0 -237
  78. data/lib/sass/selector/simple.rb +0 -113
  79. data/lib/sass/selector/simple_sequence.rb +0 -136
  80. data/lib/sass/tree/charset_node.rb +0 -37
  81. data/lib/sass/tree/comment_node.rb +0 -128
  82. data/lib/sass/tree/debug_node.rb +0 -36
  83. data/lib/sass/tree/directive_node.rb +0 -75
  84. data/lib/sass/tree/extend_node.rb +0 -65
  85. data/lib/sass/tree/for_node.rb +0 -55
  86. data/lib/sass/tree/if_node.rb +0 -69
  87. data/lib/sass/tree/import_node.rb +0 -102
  88. data/lib/sass/tree/mixin_def_node.rb +0 -48
  89. data/lib/sass/tree/mixin_node.rb +0 -111
  90. data/lib/sass/tree/node.rb +0 -464
  91. data/lib/sass/tree/prop_node.rb +0 -220
  92. data/lib/sass/tree/root_node.rb +0 -163
  93. data/lib/sass/tree/rule_node.rb +0 -261
  94. data/lib/sass/tree/variable_node.rb +0 -39
  95. data/lib/sass/tree/warn_node.rb +0 -42
  96. data/lib/sass/tree/while_node.rb +0 -36
  97. data/test/haml/util/subset_map_test.rb +0 -91
  98. data/test/sass/callbacks_test.rb +0 -61
  99. data/test/sass/conversion_test.rb +0 -1218
  100. data/test/sass/css2sass_test.rb +0 -364
  101. data/test/sass/data/hsl-rgb.txt +0 -319
  102. data/test/sass/engine_test.rb +0 -2267
  103. data/test/sass/extend_test.rb +0 -1348
  104. data/test/sass/functions_test.rb +0 -556
  105. data/test/sass/less_conversion_test.rb +0 -653
  106. data/test/sass/more_results/more1.css +0 -9
  107. data/test/sass/more_results/more1_with_line_comments.css +0 -26
  108. data/test/sass/more_results/more_import.css +0 -29
  109. data/test/sass/more_templates/_more_partial.sass +0 -2
  110. data/test/sass/more_templates/more1.sass +0 -23
  111. data/test/sass/more_templates/more_import.sass +0 -11
  112. data/test/sass/plugin_test.rb +0 -433
  113. data/test/sass/results/alt.css +0 -4
  114. data/test/sass/results/basic.css +0 -9
  115. data/test/sass/results/compact.css +0 -5
  116. data/test/sass/results/complex.css +0 -86
  117. data/test/sass/results/compressed.css +0 -1
  118. data/test/sass/results/expanded.css +0 -19
  119. data/test/sass/results/import.css +0 -31
  120. data/test/sass/results/import_charset.css +0 -4
  121. data/test/sass/results/import_charset_1_8.css +0 -4
  122. data/test/sass/results/import_charset_ibm866.css +0 -4
  123. data/test/sass/results/line_numbers.css +0 -49
  124. data/test/sass/results/mixins.css +0 -95
  125. data/test/sass/results/multiline.css +0 -24
  126. data/test/sass/results/nested.css +0 -22
  127. data/test/sass/results/options.css +0 -1
  128. data/test/sass/results/parent_ref.css +0 -13
  129. data/test/sass/results/script.css +0 -16
  130. data/test/sass/results/scss_import.css +0 -31
  131. data/test/sass/results/scss_importee.css +0 -2
  132. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +0 -1
  133. data/test/sass/results/subdir/subdir.css +0 -3
  134. data/test/sass/results/units.css +0 -11
  135. data/test/sass/results/warn.css +0 -0
  136. data/test/sass/results/warn_imported.css +0 -0
  137. data/test/sass/script_conversion_test.rb +0 -314
  138. data/test/sass/script_test.rb +0 -470
  139. data/test/sass/scss/css_test.rb +0 -916
  140. data/test/sass/scss/rx_test.rb +0 -156
  141. data/test/sass/scss/scss_test.rb +0 -1122
  142. data/test/sass/scss/test_helper.rb +0 -37
  143. data/test/sass/templates/_imported_charset_ibm866.sass +0 -4
  144. data/test/sass/templates/_imported_charset_utf8.sass +0 -4
  145. data/test/sass/templates/_partial.sass +0 -2
  146. data/test/sass/templates/alt.sass +0 -16
  147. data/test/sass/templates/basic.sass +0 -23
  148. data/test/sass/templates/bork1.sass +0 -2
  149. data/test/sass/templates/bork2.sass +0 -2
  150. data/test/sass/templates/bork3.sass +0 -2
  151. data/test/sass/templates/bork4.sass +0 -2
  152. data/test/sass/templates/compact.sass +0 -17
  153. data/test/sass/templates/complex.sass +0 -305
  154. data/test/sass/templates/compressed.sass +0 -15
  155. data/test/sass/templates/expanded.sass +0 -17
  156. data/test/sass/templates/import.sass +0 -12
  157. data/test/sass/templates/import_charset.sass +0 -7
  158. data/test/sass/templates/import_charset_1_8.sass +0 -4
  159. data/test/sass/templates/import_charset_ibm866.sass +0 -9
  160. data/test/sass/templates/importee.less +0 -2
  161. data/test/sass/templates/importee.sass +0 -19
  162. data/test/sass/templates/line_numbers.sass +0 -13
  163. data/test/sass/templates/mixin_bork.sass +0 -5
  164. data/test/sass/templates/mixins.sass +0 -76
  165. data/test/sass/templates/multiline.sass +0 -20
  166. data/test/sass/templates/nested.sass +0 -25
  167. data/test/sass/templates/nested_bork1.sass +0 -2
  168. data/test/sass/templates/nested_bork2.sass +0 -2
  169. data/test/sass/templates/nested_bork3.sass +0 -2
  170. data/test/sass/templates/nested_bork4.sass +0 -2
  171. data/test/sass/templates/nested_mixin_bork.sass +0 -6
  172. data/test/sass/templates/options.sass +0 -2
  173. data/test/sass/templates/parent_ref.sass +0 -25
  174. data/test/sass/templates/script.sass +0 -101
  175. data/test/sass/templates/scss_import.scss +0 -11
  176. data/test/sass/templates/scss_importee.scss +0 -1
  177. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +0 -2
  178. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +0 -3
  179. data/test/sass/templates/subdir/subdir.sass +0 -6
  180. data/test/sass/templates/units.sass +0 -11
  181. data/test/sass/templates/warn.sass +0 -3
  182. data/test/sass/templates/warn_imported.sass +0 -4
  183. data/vendor/fssm/LICENSE +0 -20
  184. data/vendor/fssm/README.markdown +0 -55
  185. data/vendor/fssm/Rakefile +0 -59
  186. data/vendor/fssm/VERSION.yml +0 -5
  187. data/vendor/fssm/example.rb +0 -9
  188. data/vendor/fssm/fssm.gemspec +0 -77
  189. data/vendor/fssm/lib/fssm.rb +0 -33
  190. data/vendor/fssm/lib/fssm/backends/fsevents.rb +0 -36
  191. data/vendor/fssm/lib/fssm/backends/inotify.rb +0 -26
  192. data/vendor/fssm/lib/fssm/backends/polling.rb +0 -25
  193. data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +0 -131
  194. data/vendor/fssm/lib/fssm/monitor.rb +0 -26
  195. data/vendor/fssm/lib/fssm/path.rb +0 -91
  196. data/vendor/fssm/lib/fssm/pathname.rb +0 -502
  197. data/vendor/fssm/lib/fssm/state/directory.rb +0 -57
  198. data/vendor/fssm/lib/fssm/state/file.rb +0 -24
  199. data/vendor/fssm/lib/fssm/support.rb +0 -63
  200. data/vendor/fssm/lib/fssm/tree.rb +0 -176
  201. data/vendor/fssm/profile/prof-cache.rb +0 -40
  202. data/vendor/fssm/profile/prof-fssm-pathname.html +0 -1231
  203. data/vendor/fssm/profile/prof-pathname.rb +0 -68
  204. data/vendor/fssm/profile/prof-plain-pathname.html +0 -988
  205. data/vendor/fssm/profile/prof.html +0 -2379
  206. data/vendor/fssm/spec/path_spec.rb +0 -75
  207. data/vendor/fssm/spec/root/duck/quack.txt +0 -0
  208. data/vendor/fssm/spec/root/file.css +0 -0
  209. data/vendor/fssm/spec/root/file.rb +0 -0
  210. data/vendor/fssm/spec/root/file.yml +0 -0
  211. data/vendor/fssm/spec/root/moo/cow.txt +0 -0
  212. data/vendor/fssm/spec/spec_helper.rb +0 -14
@@ -1,70 +0,0 @@
1
- module Sass::Script
2
- # A SassScript object representing `#{}` interpolation outside a string.
3
- #
4
- # @see StringInterpolation
5
- class Interpolation < Node
6
- # Interpolation in a property is of the form `before #{mid} after`.
7
- #
8
- # @param before [Node] The SassScript before the interpolation
9
- # @param mid [Node] The SassScript within the interpolation
10
- # @param after [Node] The SassScript after the interpolation
11
- # @param wb [Boolean] Whether there was whitespace between `before` and `#{`
12
- # @param wa [Boolean] Whether there was whitespace between `}` and `after`
13
- # @param originally_text [Boolean]
14
- # Whether the original format of the interpolation was plain text,
15
- # not an interpolation.
16
- # This is used when converting back to SassScript.
17
- def initialize(before, mid, after, wb, wa, originally_text = false)
18
- @before = before
19
- @mid = mid
20
- @after = after
21
- @whitespace_before = wb
22
- @whitespace_after = wa
23
- @originally_text = originally_text
24
- end
25
-
26
- # @return [String] A human-readable s-expression representation of the interpolation
27
- def inspect
28
- "(interpolation #{@before.inspect} #{@mid.inspect} #{@after.inspect})"
29
- end
30
-
31
- # @see Node#to_sass
32
- def to_sass(opts = {})
33
- res = ""
34
- res << @before.to_sass(opts) if @before
35
- res << ' ' if @before && @whitespace_before
36
- res << '#{' unless @originally_text
37
- res << @mid.to_sass(opts)
38
- res << '}' unless @originally_text
39
- res << ' ' if @after && @whitespace_after
40
- res << @after.to_sass(opts) if @after
41
- res
42
- end
43
-
44
- # Returns the three components of the interpolation, `before`, `mid`, and `after`.
45
- #
46
- # @return [Array<Node>]
47
- # @see #initialize
48
- # @see Node#children
49
- def children
50
- [@before, @mid, @after].compact
51
- end
52
-
53
- protected
54
-
55
- # Evaluates the interpolation.
56
- #
57
- # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
58
- # @return [Sass::Script::String] The SassScript string that is the value of the interpolation
59
- def _perform(environment)
60
- res = ""
61
- res << @before.perform(environment).to_s if @before
62
- res << " " if @before && @whitespace_before
63
- val = @mid.perform(environment)
64
- res << (val.is_a?(Sass::Script::String) ? val.value : val.to_s)
65
- res << " " if @after && @whitespace_after
66
- res << @after.perform(environment).to_s if @after
67
- opts(Sass::Script::String.new(res))
68
- end
69
- end
70
- end
@@ -1,337 +0,0 @@
1
- require 'sass/scss/rx'
2
-
3
- require 'strscan'
4
-
5
- module Sass
6
- module Script
7
- # The lexical analyzer for SassScript.
8
- # It takes a raw string and converts it to individual tokens
9
- # that are easier to parse.
10
- class Lexer
11
- include Sass::SCSS::RX
12
-
13
- # A struct containing information about an individual token.
14
- #
15
- # `type`: \[`Symbol`\]
16
- # : The type of token.
17
- #
18
- # `value`: \[`Object`\]
19
- # : The Ruby object corresponding to the value of the token.
20
- #
21
- # `line`: \[`Fixnum`\]
22
- # : The line of the source file on which the token appears.
23
- #
24
- # `offset`: \[`Fixnum`\]
25
- # : The number of bytes into the line the SassScript token appeared.
26
- #
27
- # `pos`: \[`Fixnum`\]
28
- # : The scanner position at which the SassScript token appeared.
29
- Token = Struct.new(:type, :value, :line, :offset, :pos)
30
-
31
- # The line number of the lexer's current position.
32
- #
33
- # @return [Fixnum]
34
- attr_reader :line
35
-
36
- # The number of bytes into the current line
37
- # of the lexer's current position.
38
- #
39
- # @return [Fixnum]
40
- attr_reader :offset
41
-
42
- # A hash from operator strings to the corresponding token types.
43
- OPERATORS = {
44
- '+' => :plus,
45
- '-' => :minus,
46
- '*' => :times,
47
- '/' => :div,
48
- '%' => :mod,
49
- '=' => :single_eq,
50
- ':' => :colon,
51
- '(' => :lparen,
52
- ')' => :rparen,
53
- ',' => :comma,
54
- 'and' => :and,
55
- 'or' => :or,
56
- 'not' => :not,
57
- '==' => :eq,
58
- '!=' => :neq,
59
- '>=' => :gte,
60
- '<=' => :lte,
61
- '>' => :gt,
62
- '<' => :lt,
63
- '#{' => :begin_interpolation,
64
- '}' => :end_interpolation,
65
- ';' => :semicolon,
66
- '{' => :lcurly,
67
- }
68
-
69
- OPERATORS_REVERSE = Haml::Util.map_hash(OPERATORS) {|k, v| [v, k]}
70
-
71
- TOKEN_NAMES = Haml::Util.map_hash(OPERATORS_REVERSE) {|k, v| [k, v.inspect]}.merge({
72
- :const => "variable (e.g. $foo)",
73
- :ident => "identifier (e.g. middle)",
74
- :bool => "boolean (e.g. true, false)",
75
- })
76
-
77
- # A list of operator strings ordered with longer names first
78
- # so that `>` and `<` don't clobber `>=` and `<=`.
79
- OP_NAMES = OPERATORS.keys.sort_by {|o| -o.size}
80
-
81
- # A sub-list of {OP_NAMES} that only includes operators
82
- # with identifier names.
83
- IDENT_OP_NAMES = OP_NAMES.select {|k, v| k =~ /^\w+/}
84
-
85
- # A hash of regular expressions that are used for tokenizing.
86
- REGULAR_EXPRESSIONS = {
87
- :whitespace => /\s+/,
88
- :comment => COMMENT,
89
- :single_line_comment => SINGLE_LINE_COMMENT,
90
- :variable => /([!\$])(#{IDENT})/,
91
- :ident => /(#{IDENT})(\()?/,
92
- :number => /(-)?(?:(\d*\.\d+)|(\d+))([a-zA-Z%]+)?/,
93
- :color => HEXCOLOR,
94
- :bool => /(true|false)\b/,
95
- :ident_op => %r{(#{Regexp.union(*IDENT_OP_NAMES.map{|s| Regexp.new(Regexp.escape(s) + "(?!#{NMCHAR}|\Z)")})})},
96
- :op => %r{(#{Regexp.union(*OP_NAMES)})},
97
- }
98
-
99
- class << self
100
- private
101
- def string_re(open, close)
102
- /#{open}((?:\\.|\#(?!\{)|[^#{close}\\#])*)(#{close}|#\{)/
103
- end
104
- end
105
-
106
- # A hash of regular expressions that are used for tokenizing strings.
107
- #
108
- # The key is a `[Symbol, Boolean]` pair.
109
- # The symbol represents which style of quotation to use,
110
- # while the boolean represents whether or not the string
111
- # is following an interpolated segment.
112
- STRING_REGULAR_EXPRESSIONS = {
113
- [:double, false] => string_re('"', '"'),
114
- [:single, false] => string_re("'", "'"),
115
- [:double, true] => string_re('', '"'),
116
- [:single, true] => string_re('', "'"),
117
- [:uri, false] => /url\(#{W}(#{URLCHAR}*?)(#{W}\)|#\{)/,
118
- [:uri, true] => /(#{URLCHAR}*?)(#{W}\)|#\{)/,
119
- }
120
-
121
- # @param str [String, StringScanner] The source text to lex
122
- # @param line [Fixnum] The line on which the SassScript appears.
123
- # Used for error reporting
124
- # @param offset [Fixnum] The number of characters in on which the SassScript appears.
125
- # Used for error reporting
126
- # @param options [{Symbol => Object}] An options hash;
127
- # see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
128
- def initialize(str, line, offset, options)
129
- @scanner = str.is_a?(StringScanner) ? str : StringScanner.new(str)
130
- @line = line
131
- @offset = offset
132
- @options = options
133
- @interpolation_stack = []
134
- @prev = nil
135
- end
136
-
137
- # Moves the lexer forward one token.
138
- #
139
- # @return [Token] The token that was moved past
140
- def next
141
- @tok ||= read_token
142
- @tok, tok = nil, @tok
143
- @prev = tok
144
- return tok
145
- end
146
-
147
- # Returns whether or not there's whitespace before the next token.
148
- #
149
- # @return [Boolean]
150
- def whitespace?(tok = @tok)
151
- if tok
152
- @scanner.string[0...tok.pos] =~ /\s\Z/
153
- else
154
- @scanner.string[@scanner.pos, 1] =~ /^\s/ ||
155
- @scanner.string[@scanner.pos - 1, 1] =~ /\s\Z/
156
- end
157
- end
158
-
159
- # Returns the next token without moving the lexer forward.
160
- #
161
- # @return [Token] The next token
162
- def peek
163
- @tok ||= read_token
164
- end
165
-
166
- # Rewinds the underlying StringScanner
167
- # to before the token returned by \{#peek}.
168
- def unpeek!
169
- @scanner.pos = @tok.pos if @tok
170
- end
171
-
172
- # @return [Boolean] Whether or not there's more source text to lex.
173
- def done?
174
- whitespace unless after_interpolation? && @interpolation_stack.last
175
- @scanner.eos? && @tok.nil?
176
- end
177
-
178
- # @return [Boolean] Whether or not the last token lexed was `:end_interpolation`.
179
- def after_interpolation?
180
- @prev && @prev.type == :end_interpolation
181
- end
182
-
183
- # Raise an error to the effect that `name` was expected in the input stream
184
- # and wasn't found.
185
- #
186
- # This calls \{#unpeek!} to rewind the scanner to immediately after
187
- # the last returned token.
188
- #
189
- # @param name [String] The name of the entity that was expected but not found
190
- # @raise [Sass::SyntaxError]
191
- def expected!(name)
192
- unpeek!
193
- Sass::SCSS::Parser.expected(@scanner, name, @line)
194
- end
195
-
196
- # Records all non-comment text the lexer consumes within the block
197
- # and returns it as a string.
198
- #
199
- # @yield A block in which text is recorded
200
- # @return [String]
201
- def str
202
- old_pos = @tok ? @tok.pos : @scanner.pos
203
- yield
204
- new_pos = @tok ? @tok.pos : @scanner.pos
205
- @scanner.string[old_pos...new_pos]
206
- end
207
-
208
- private
209
-
210
- def read_token
211
- return if done?
212
- return unless value = token
213
- type, val, size = value
214
- size ||= @scanner.matched_size
215
-
216
- val.line = @line if val.is_a?(Script::Node)
217
- Token.new(type, val, @line,
218
- current_position - size, @scanner.pos - size)
219
- end
220
-
221
- def whitespace
222
- nil while scan(REGULAR_EXPRESSIONS[:whitespace]) ||
223
- scan(REGULAR_EXPRESSIONS[:comment]) ||
224
- scan(REGULAR_EXPRESSIONS[:single_line_comment])
225
- end
226
-
227
- def token
228
- if after_interpolation? && (interp_type = @interpolation_stack.pop)
229
- return string(interp_type, true)
230
- end
231
-
232
- variable || string(:double, false) || string(:single, false) || number ||
233
- color || bool || string(:uri, false) || raw(UNICODERANGE) ||
234
- special_fun || ident_op || ident || op
235
- end
236
-
237
- def variable
238
- _variable(REGULAR_EXPRESSIONS[:variable])
239
- end
240
-
241
- def _variable(rx)
242
- line = @line
243
- offset = @offset
244
- return unless scan(rx)
245
- if @scanner[1] == '!' && @scanner[2] != 'important'
246
- Script.var_warning(@scanner[2], line, offset + 1, @options[:filename])
247
- end
248
-
249
- [:const, @scanner[2]]
250
- end
251
-
252
- def ident
253
- return unless scan(REGULAR_EXPRESSIONS[:ident])
254
- [@scanner[2] ? :funcall : :ident, @scanner[1]]
255
- end
256
-
257
- def string(re, open)
258
- return unless scan(STRING_REGULAR_EXPRESSIONS[[re, open]])
259
- if @scanner[2] == '#{' #'
260
- @scanner.pos -= 2 # Don't actually consume the #{
261
- @interpolation_stack << re
262
- end
263
- str =
264
- if re == :uri
265
- Script::String.new("#{'url(' unless open}#{@scanner[1]}#{')' unless @scanner[2] == '#{'}")
266
- else
267
- Script::String.new(@scanner[1].gsub(/\\(['"]|\#\{)/, '\1'), :string)
268
- end
269
- [:string, str]
270
- end
271
-
272
- def number
273
- return unless scan(REGULAR_EXPRESSIONS[:number])
274
- value = @scanner[2] ? @scanner[2].to_f : @scanner[3].to_i
275
- value = -value if @scanner[1]
276
- [:number, Script::Number.new(value, Array(@scanner[4]))]
277
- end
278
-
279
- def color
280
- return unless s = scan(REGULAR_EXPRESSIONS[:color])
281
- raise Sass::SyntaxError.new(<<MESSAGE.rstrip) unless s.size == 4 || s.size == 7
282
- Colors must have either three or six digits: '#{s}'
283
- MESSAGE
284
- value = s.scan(/^#(..?)(..?)(..?)$/).first.
285
- map {|num| num.ljust(2, num).to_i(16)}
286
- [:color, Script::Color.new(value)]
287
- end
288
-
289
- def bool
290
- return unless s = scan(REGULAR_EXPRESSIONS[:bool])
291
- [:bool, Script::Bool.new(s == 'true')]
292
- end
293
-
294
- def special_fun
295
- return unless str1 = scan(/((-[\w-]+-)?calc|expression|progid:[a-z\.]*)\(/i)
296
- str2, _ = Haml::Shared.balance(@scanner, ?(, ?), 1)
297
- c = str2.count("\n")
298
- old_line = @line
299
- old_offset = @offset
300
- @line += c
301
- @offset = (c == 0 ? @offset + str2.size : str2[/\n(.*)/, 1].size)
302
- [:special_fun,
303
- Haml::Util.merge_adjacent_strings(
304
- [str1] + Sass::Engine.parse_interp(str2, old_line, old_offset, @options)),
305
- str1.size + str2.size]
306
- end
307
-
308
- def ident_op
309
- return unless op = scan(REGULAR_EXPRESSIONS[:ident_op])
310
- [OPERATORS[op]]
311
- end
312
-
313
- def op
314
- return unless op = scan(REGULAR_EXPRESSIONS[:op])
315
- @interpolation_stack << nil if op == :begin_interpolation
316
- [OPERATORS[op]]
317
- end
318
-
319
- def raw(rx)
320
- return unless val = scan(rx)
321
- [:raw, val]
322
- end
323
-
324
- def scan(re)
325
- return unless str = @scanner.scan(re)
326
- c = str.count("\n")
327
- @line += c
328
- @offset = (c == 0 ? @offset + str.size : str[/\n(.*)/, 1].size)
329
- str
330
- end
331
-
332
- def current_position
333
- @offset + 1
334
- end
335
- end
336
- end
337
- end
@@ -1,236 +0,0 @@
1
- module Sass::Script
2
- # The abstract superclass for SassScript objects.
3
- #
4
- # Many of these methods, especially the ones that correspond to SassScript operations,
5
- # are designed to be overridden by subclasses which may change the semantics somewhat.
6
- # The operations listed here are just the defaults.
7
- class Literal < Node
8
- require 'sass/script/string'
9
- require 'sass/script/number'
10
- require 'sass/script/color'
11
- require 'sass/script/bool'
12
-
13
- # Returns the Ruby value of the literal.
14
- # The type of this value varies based on the subclass.
15
- #
16
- # @return [Object]
17
- attr_reader :value
18
-
19
- # Creates a new literal.
20
- #
21
- # @param value [Object] The object for \{#value}
22
- def initialize(value = nil)
23
- @value = value
24
- super()
25
- end
26
-
27
- # Returns an empty array.
28
- #
29
- # @return [Array<Node>] empty
30
- # @see Node#children
31
- def children
32
- []
33
- end
34
-
35
- # Returns the options hash for this node.
36
- #
37
- # @return [{Symbol => Object}]
38
- # @raise [Sass::SyntaxError] if the options hash hasn't been set.
39
- # This should only happen when the literal was created
40
- # outside of the parser and \{#to\_s} was called on it
41
- def options
42
- opts = super
43
- return opts if opts
44
- raise Sass::SyntaxError.new(<<MSG)
45
- The #options attribute is not set on this #{self.class}.
46
- This error is probably occurring because #to_s was called
47
- on this literal within a custom Sass function without first
48
- setting the #option attribute.
49
- MSG
50
- end
51
-
52
- # The SassScript `and` operation.
53
- #
54
- # @param other [Literal] The right-hand side of the operator
55
- # @return [Literal] The result of a logical and:
56
- # `other` if this literal isn't a false {Bool},
57
- # and this literal otherwise
58
- def and(other)
59
- to_bool ? other : self
60
- end
61
-
62
- # The SassScript `or` operation.
63
- #
64
- # @param other [Literal] The right-hand side of the operator
65
- # @return [Literal] The result of the logical or:
66
- # this literal if it isn't a false {Bool},
67
- # and `other` otherwise
68
- def or(other)
69
- to_bool ? self : other
70
- end
71
-
72
- # The SassScript `==` operation.
73
- # **Note that this returns a {Sass::Script::Bool} object,
74
- # not a Ruby boolean**.
75
- #
76
- # @param other [Literal] The right-hand side of the operator
77
- # @return [Bool] True if this literal is the same as the other,
78
- # false otherwise
79
- def eq(other)
80
- Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
81
- end
82
-
83
- # The SassScript `!=` operation.
84
- # **Note that this returns a {Sass::Script::Bool} object,
85
- # not a Ruby boolean**.
86
- #
87
- # @param other [Literal] The right-hand side of the operator
88
- # @return [Bool] False if this literal is the same as the other,
89
- # true otherwise
90
- def neq(other)
91
- Sass::Script::Bool.new(!eq(other).to_bool)
92
- end
93
-
94
- # The SassScript `==` operation.
95
- # **Note that this returns a {Sass::Script::Bool} object,
96
- # not a Ruby boolean**.
97
- #
98
- # @param other [Literal] The right-hand side of the operator
99
- # @return [Bool] True if this literal is the same as the other,
100
- # false otherwise
101
- def unary_not
102
- Sass::Script::Bool.new(!to_bool)
103
- end
104
-
105
- # The SassScript default operation (e.g. `$a $b`, `"foo" "bar"`).
106
- #
107
- # @param other [Literal] The right-hand side of the operator
108
- # @return [Script::String] A string containing both literals
109
- # separated by a space
110
- def concat(other)
111
- Sass::Script::String.new("#{self.to_s} #{other.to_s}")
112
- end
113
-
114
- # The SassScript `,` operation (e.g. `$a, $b`, `"foo", "bar"`).
115
- #
116
- # @param other [Literal] The right-hand side of the operator
117
- # @return [Script::String] A string containing both literals
118
- # separated by `", "`
119
- def comma(other)
120
- Sass::Script::String.new("#{self.to_s},#{' ' unless options[:style] == :compressed}#{other.to_s}")
121
- end
122
-
123
- # The SassScript `=` operation
124
- # (used for proprietary MS syntax like `alpha(opacity=20)`).
125
- #
126
- # @param other [Literal] The right-hand side of the operator
127
- # @return [Script::String] A string containing both literals
128
- # separated by `"="`
129
- def single_eq(other)
130
- Sass::Script::String.new("#{self.to_s}=#{other.to_s}")
131
- end
132
-
133
- # The SassScript `+` operation.
134
- #
135
- # @param other [Literal] The right-hand side of the operator
136
- # @return [Script::String] A string containing both literals
137
- # without any separation
138
- def plus(other)
139
- if other.is_a?(Sass::Script::String)
140
- return Sass::Script::String.new(self.to_s + other.value, other.type)
141
- end
142
- Sass::Script::String.new(self.to_s + other.to_s)
143
- end
144
-
145
- # The SassScript `-` operation.
146
- #
147
- # @param other [Literal] The right-hand side of the operator
148
- # @return [Script::String] A string containing both literals
149
- # separated by `"-"`
150
- def minus(other)
151
- Sass::Script::String.new("#{self.to_s}-#{other.to_s}")
152
- end
153
-
154
- # The SassScript `/` operation.
155
- #
156
- # @param other [Literal] The right-hand side of the operator
157
- # @return [Script::String] A string containing both literals
158
- # separated by `"/"`
159
- def div(other)
160
- Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
161
- end
162
-
163
- # The SassScript unary `+` operation (e.g. `+$a`).
164
- #
165
- # @param other [Literal] The right-hand side of the operator
166
- # @return [Script::String] A string containing the literal
167
- # preceded by `"+"`
168
- def unary_plus
169
- Sass::Script::String.new("+#{self.to_s}")
170
- end
171
-
172
- # The SassScript unary `-` operation (e.g. `-$a`).
173
- #
174
- # @param other [Literal] The right-hand side of the operator
175
- # @return [Script::String] A string containing the literal
176
- # preceded by `"-"`
177
- def unary_minus
178
- Sass::Script::String.new("-#{self.to_s}")
179
- end
180
-
181
- # The SassScript unary `/` operation (e.g. `/$a`).
182
- #
183
- # @param other [Literal] The right-hand side of the operator
184
- # @return [Script::String] A string containing the literal
185
- # preceded by `"/"`
186
- def unary_div
187
- Sass::Script::String.new("/#{self.to_s}")
188
- end
189
-
190
- # @return [String] A readable representation of the literal
191
- def inspect
192
- value.inspect
193
- end
194
-
195
- # @return [Boolean] `true` (the Ruby boolean value)
196
- def to_bool
197
- true
198
- end
199
-
200
- # Compares this object with another.
201
- #
202
- # @param other [Object] The object to compare with
203
- # @return [Boolean] Whether or not this literal is equivalent to `other`
204
- def ==(other)
205
- eq(other).to_bool
206
- end
207
-
208
- # @return [Fixnum] The integer value of this literal
209
- # @raise [Sass::SyntaxError] if this literal isn't an integer
210
- def to_i
211
- raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
212
- end
213
-
214
- # @raise [Sass::SyntaxError] if this literal isn't an integer
215
- def assert_int!; to_i; end
216
-
217
- # Returns the string representation of this literal
218
- # as it would be output to the CSS document.
219
- #
220
- # @return [String]
221
- def to_s(opts = {})
222
- raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.")
223
- end
224
- alias_method :to_sass, :to_s
225
-
226
- protected
227
-
228
- # Evaluates the literal.
229
- #
230
- # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
231
- # @return [Literal] This literal
232
- def _perform(environment)
233
- self
234
- end
235
- end
236
- end