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,207 +0,0 @@
1
- ;;; sass-mode.el --- Major mode for editing Sass files
2
-
3
- ;; Copyright (c) 2007, 2008 Nathan Weizenbaum
4
-
5
- ;; Author: Nathan Weizenbaum
6
- ;; URL: http://github.com/nex3/haml/tree/master
7
- ;; Version: 3.0.19
8
- ;; Created: 2007-03-15
9
- ;; By: Nathan Weizenbaum
10
- ;; Keywords: markup, language, css
11
- ;; Package-Requires: ((haml-mode "3.0.14"))
12
-
13
- ;;; Commentary:
14
-
15
- ;; Because Sass's indentation schema is similar
16
- ;; to that of YAML and Python, many indentation-related
17
- ;; functions are similar to those in yaml-mode and python-mode.
18
-
19
- ;; To install, save this on your load path and add the following to
20
- ;; your .emacs file:
21
- ;;
22
- ;; (require 'sass-mode)
23
-
24
- ;;; Code:
25
-
26
- (require 'haml-mode)
27
-
28
- ;; User definable variables
29
-
30
- (defgroup sass nil
31
- "Support for the Sass template language."
32
- :group 'languages
33
- :prefix "sass-")
34
-
35
- (defcustom sass-mode-hook nil
36
- "Hook run when entering Sass mode."
37
- :type 'hook
38
- :group 'sass)
39
-
40
- (defcustom sass-indent-offset 2
41
- "Amount of offset per level of indentation."
42
- :type 'integer
43
- :group 'sass)
44
-
45
- (defvar sass-non-block-openers
46
- '("^.*,$" ;; Continued selectors
47
- "^ *@\\(extend\\|debug\\|warn\\|include\\|import\\)" ;; Single-line mixins
48
- "^ *[$!]" ;; Variables
49
- )
50
- "A list of regexps that match lines of Sass that couldn't have
51
- text nested beneath them.")
52
-
53
- ;; Font lock
54
-
55
- (defconst sass-selector-font-lock-keywords
56
- '(;; Attribute selectors (e.g. p[foo=bar])
57
- ("\\[\\([^]=]+\\)" (1 font-lock-variable-name-face)
58
- ("[~|$^*]?=\\([^]=]+\\)" nil nil (1 font-lock-string-face)))
59
- ("&" 0 font-lock-constant-face)
60
- ("\\.\\w+" 0 font-lock-type-face)
61
- ("#\\w+" 0 font-lock-keyword-face)
62
- ;; Pseudo-selectors, optionally with arguments (e.g. :first, :nth-child(12))
63
- ("\\(::?\\w+\\)" (1 font-lock-function-name-face)
64
- ("(\\([^)]+\\))" nil nil (1 font-lock-string-face)))))
65
-
66
- (defconst sass-script-font-lock-keywords
67
- `(("\"\\([^\"\\\\]\\|\\\\.\\)*\"" 0 font-lock-string-face)
68
- ("!\\(\\w\\|_\\)+" 0 font-lock-variable-name-face)
69
- ("#[0-9a-fA-F]\\{0,6\\}" 0 font-lock-preprocessor-face)
70
- (,(regexp-opt
71
- '("true" "false" "black" "silver" "gray" "white" "maroon" "red"
72
- "purple" "fuchsia" "green" "lime" "olive" "yellow" "navy"
73
- "blue" "teal" "aqua"))
74
- 0 font-lock-constant-face)
75
- (,(regexp-opt '("and" "or" "not")) 0 font-lock-keyword-face)))
76
-
77
- (defconst sass-syntax-table
78
- (let ((st (make-syntax-table)))
79
- (modify-syntax-entry ?- "w" st)
80
- (modify-syntax-entry ?_ "w" st)
81
- st))
82
-
83
- (defconst sass-script-syntax-table
84
- (let ((st (make-syntax-table sass-syntax-table)))
85
- (modify-syntax-entry ?- "." st)
86
- st))
87
-
88
- (defconst sass-font-lock-keywords
89
- '((sass-highlight-line 1 nil nil t)))
90
-
91
- (defconst sass-line-keywords
92
- '(("@\\(\\w+\\)" 0 font-lock-keyword-face sass-highlight-directive)
93
- ("/[/*].*" 0 font-lock-comment-face)
94
- ("[=+]\\w+" 0 font-lock-function-name-face sass-highlight-script-after-match)
95
- ("!\\w+" 0 font-lock-variable-name-face sass-highlight-script-after-match)
96
- (":\\w+" 0 font-lock-variable-name-face)
97
- ("\\w+\s*:" 0 font-lock-variable-name-face)
98
- ("\\(\\w+\\)\s*=" 1 font-lock-variable-name-face sass-highlight-script-after-match)
99
- ("\\(:\\w+\\)\s*=" 1 font-lock-variable-name-face sass-highlight-script-after-match)
100
- (".*" sass-highlight-selector))
101
- "A list of full-line Sass syntax to highlight, used by `sass-highlight-line'.
102
-
103
- Each item is either of the form (REGEXP SUBEXP FACE), (REGEXP FN),
104
- or (REGEXP SUBEXP FACE FN). Each REGEXP is run successively on the
105
- beginning of non-whitespace on the current line until one matches.
106
- If it has SUBEXP and FACE, then SUBEXP is highlighted using FACE.
107
- If it has FN, FN is run.")
108
-
109
- (defun sass-highlight-line (limit)
110
- "Highlight a single line using some Sass single-line syntax.
111
- This syntax is taken from `sass-line-keywords'.
112
- LIMIT is the limit of the search."
113
- (save-match-data
114
- (when (re-search-forward "^ *\\(.+\\)$" limit t)
115
- (goto-char (match-beginning 1))
116
- (dolist (keyword sass-line-keywords)
117
- (destructuring-bind (keyword subexp-or-fn &optional face fn) keyword
118
- (when (looking-at keyword)
119
- (if (integerp subexp-or-fn)
120
- (put-text-property (match-beginning subexp-or-fn)
121
- (match-end subexp-or-fn)
122
- 'face face)
123
- (setq fn subexp-or-fn))
124
- (when fn (funcall fn))
125
- (end-of-line)
126
- (return t)))))))
127
-
128
- (defun sass-highlight-selector ()
129
- "Highlight a CSS selector starting at `point' and ending at `end-of-line'."
130
- (let ((font-lock-keywords sass-selector-font-lock-keywords)
131
- font-lock-multiline)
132
- (font-lock-fontify-region
133
- (point) (progn (end-of-line) (point))))
134
- t)
135
-
136
- (defun sass-highlight-script (beg end)
137
- "Highlight a section of SassScript between BEG and END."
138
- (save-match-data
139
- (with-syntax-table sass-script-syntax-table
140
- (let ((font-lock-keywords sass-script-font-lock-keywords)
141
- font-lock-syntax-table
142
- font-lock-extend-region-functions)
143
- (font-lock-fontify-region beg end)))))
144
-
145
- (defun sass-highlight-script-after-match ()
146
- "Highlight a section of SassScript after the last match."
147
- (end-of-line)
148
- (sass-highlight-script (match-end 0) (point)))
149
-
150
- (defun sass-highlight-directive ()
151
- "Highlight a Sass directive."
152
- (goto-char (match-end 0))
153
- (block nil
154
- (case (intern (match-string 1))
155
- (for
156
- (unless (looking-at " +!\\w+") (return))
157
- (put-text-property (match-beginning 0) (match-end 0)
158
- 'face font-lock-variable-name-face)
159
- (goto-char (match-end 0))
160
- (unless (looking-at " +from") (return))
161
- (put-text-property (match-beginning 0) (match-end 0)
162
- 'face font-lock-keyword-face)
163
- (goto-char (match-end 0))
164
- (when (looking-at " +\\(.+?\\) +\\(to\\|through\\)")
165
- (sass-highlight-script (match-beginning 1) (match-end 1))
166
- (put-text-property (match-beginning 2) (match-end 2)
167
- 'face font-lock-keyword-face))
168
- (sass-highlight-script-after-match))
169
-
170
- (else
171
- (unless (looking-at " +if") (return))
172
- (put-text-property (match-beginning 0) (match-end 0)
173
- 'face font-lock-keyword-face)
174
- (sass-highlight-script-after-match))
175
-
176
- ((if while debug) (sass-highlight-script-after-match)))))
177
-
178
- ;; Constants
179
-
180
- ;; Mode setup
181
-
182
- ;;;###autoload
183
- (define-derived-mode sass-mode haml-mode "Sass"
184
- "Major mode for editing Sass files."
185
- (set-syntax-table sass-syntax-table)
186
- (setq font-lock-extend-region-functions
187
- '(font-lock-extend-region-wholelines font-lock-extend-region-multiline))
188
- (setq font-lock-multiline nil)
189
- (setq comment-start "/*")
190
- (set (make-local-variable 'haml-indent-function) 'sass-indent-p)
191
- (set (make-local-variable 'haml-indent-offset) sass-indent-offset)
192
- (setq font-lock-defaults '(sass-font-lock-keywords t t)))
193
-
194
- ;; Indentation
195
-
196
- (defun sass-indent-p ()
197
- "Return non-nil if the current line can have lines nested beneath it."
198
- (loop for opener in sass-non-block-openers
199
- if (looking-at opener) return nil
200
- finally return t))
201
-
202
- ;;;###autoload
203
- (add-to-list 'auto-mode-alist '("\\.sass$" . sass-mode))
204
-
205
- ;; Setup/Activation
206
- (provide 'sass-mode)
207
- ;;; sass-mode.el ends here
@@ -1,101 +0,0 @@
1
- require 'set'
2
-
3
- module Haml
4
- module Util
5
- # A map from sets to values.
6
- # A value is \{#\[]= set} by providing a set (the "set-set") and a value,
7
- # which is then recorded as corresponding to that set.
8
- # Values are \{#\[] accessed} by providing a set (the "get-set")
9
- # and returning all values that correspond to set-sets
10
- # that are subsets of the get-set.
11
- #
12
- # SubsetMap preserves the order of values as they're inserted.
13
- #
14
- # @example
15
- # ssm = SubsetMap.new
16
- # ssm[Set[1, 2]] = "Foo"
17
- # ssm[Set[2, 3]] = "Bar"
18
- # ssm[Set[1, 2, 3]] = "Baz"
19
- #
20
- # ssm[Set[1, 2, 3]] #=> ["Foo", "Bar", "Baz"]
21
- class SubsetMap
22
- # Creates a new, empty SubsetMap.
23
- def initialize
24
- @hash = {}
25
- @vals = []
26
- end
27
-
28
- # Whether or not this SubsetMap has any key-value pairs.
29
- #
30
- # @return [Boolean]
31
- def empty?
32
- @hash.empty?
33
- end
34
-
35
- # Associates a value with a set.
36
- # When `set` or any of its supersets is accessed,
37
- # `value` will be among the values returned.
38
- #
39
- # Note that if the same `set` is passed to this method multiple times,
40
- # all given `value`s will be associated with that `set`.
41
- #
42
- # This runs in `O(n)` time, where `n` is the size of `set`.
43
- #
44
- # @param set [#to_set] The set to use as the map key. May not be empty.
45
- # @param value [Object] The value to associate with `set`.
46
- # @raise [ArgumentError] If `set` is empty.
47
- def []=(set, value)
48
- raise ArgumentError.new("SubsetMap keys may not be empty.") if set.empty?
49
-
50
- index = @vals.size
51
- @vals << value
52
- set.each do |k|
53
- @hash[k] ||= []
54
- @hash[k] << [set, set.to_set, index]
55
- end
56
- end
57
-
58
- # Returns all values associated with subsets of `set`.
59
- #
60
- # In the worst case, this runs in `O(m*max(n, log m))` time,
61
- # where `n` is the size of `set`
62
- # and `m` is the number of assocations in the map.
63
- # However, unless many keys in the map overlap with `set`,
64
- # `m` will typically be much smaller.
65
- #
66
- # @param set [Set] The set to use as the map key.
67
- # @return [Array<(Object, #to_set)>] An array of pairs,
68
- # where the first value is the value associated with a subset of `set`,
69
- # and the second value is that subset of `set`
70
- # (or whatever `#to_set` object was used to set the value)
71
- # This array is in insertion order.
72
- # @see #[]
73
- def get(set)
74
- res = set.map do |k|
75
- next unless subsets = @hash[k]
76
- subsets.map do |subenum, subset, index|
77
- next unless subset.subset?(set)
78
- [index, subenum]
79
- end
80
- end
81
- res = Haml::Util.flatten(res, 1)
82
- res.compact!
83
- res.uniq!
84
- res.sort!
85
- res.map! {|i, s| [@vals[i], s]}
86
- return res
87
- end
88
-
89
- # Same as \{#get}, but doesn't return the subsets of the argument
90
- # for which values were found.
91
- #
92
- # @param set [Set] The set to use as the map key.
93
- # @return [Array] The array of all values
94
- # associated with subsets of `set`, in insertion order.
95
- # @see #get
96
- def [](set)
97
- get(set).map {|v, _| v}
98
- end
99
- end
100
- end
101
- end
@@ -1,29 +0,0 @@
1
- dir = File.dirname(__FILE__)
2
- $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
3
-
4
- require 'haml/version'
5
-
6
- # The module that contains everything Sass-related:
7
- #
8
- # * {Sass::Engine} is the class used to render Sass/SCSS within Ruby code.
9
- # * {Sass::Plugin} is interfaces with web frameworks (Rails and Merb in particular).
10
- # * {Sass::SyntaxError} is raised when Sass encounters an error.
11
- # * {Sass::CSS} handles conversion of CSS to Sass.
12
- #
13
- # Also see the {file:SASS_REFERENCE.md full Sass reference}.
14
- module Sass
15
- extend Haml::Version
16
-
17
- # A string representing the version of Sass.
18
- # A more fine-grained representation is available from {Haml::Version#version Sass.version}.
19
- # @api public
20
- VERSION = version[:string] unless defined?(Sass::VERSION)
21
- end
22
-
23
- require 'haml/util'
24
-
25
- dir = Haml::Util.scope("vendor/fssm/lib")
26
- $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
27
-
28
- require 'sass/engine'
29
- require 'sass/plugin' if defined?(Merb::Plugins)
@@ -1,52 +0,0 @@
1
- module Sass
2
- # A lightweight infrastructure for defining and running callbacks.
3
- # Callbacks are defined using \{#define\_callback\} at the class level,
4
- # and called using `run_#{name}` at the instance level.
5
- #
6
- # Clients can add callbacks by calling the generated `on_#{name}` method,
7
- # and passing in a block that's run when the callback is activated.
8
- #
9
- # @example Define a callback
10
- # class Munger
11
- # extend Sass::Callbacks
12
- # define_callback :string_munged
13
- #
14
- # def munge(str)
15
- # res = str.gsub(/[a-z]/, '\1\1')
16
- # run_string_munged str, res
17
- # res
18
- # end
19
- # end
20
- #
21
- # @example Use a callback
22
- # m = Munger.new
23
- # m.on_string_munged {|str, res| puts "#{str} was munged into #{res}!"}
24
- # m.munge "bar" #=> bar was munged into bbaarr!
25
- module Callbacks
26
- protected
27
-
28
- # Define a callback with the given name.
29
- # This will define an `on_#{name}` method
30
- # that registers a block,
31
- # and a `run_#{name}` method that runs that block
32
- # (optionall with some arguments).
33
- #
34
- # @param name [Symbol] The name of the callback
35
- # @return [void]
36
- def define_callback(name)
37
- class_eval <<RUBY
38
- def on_#{name}(&block)
39
- @_sass_callbacks ||= {}
40
- (@_sass_callbacks[#{name.inspect}] ||= []) << block
41
- end
42
-
43
- def run_#{name}(*args)
44
- return unless @_sass_callbacks
45
- return unless @_sass_callbacks[#{name.inspect}]
46
- @_sass_callbacks[#{name.inspect}].each {|c| c[*args]}
47
- end
48
- private :run_#{name}
49
- RUBY
50
- end
51
- end
52
- end
@@ -1,294 +0,0 @@
1
- require File.dirname(__FILE__) + '/../sass'
2
- require 'sass/tree/node'
3
- require 'sass/scss/css_parser'
4
- require 'strscan'
5
-
6
- module Sass
7
- # This class converts CSS documents into Sass or SCSS templates.
8
- # It works by parsing the CSS document into a {Sass::Tree} structure,
9
- # and then applying various transformations to the structure
10
- # to produce more concise and idiomatic Sass/SCSS.
11
- #
12
- # Example usage:
13
- #
14
- # Sass::CSS.new("p { color: blue }").render(:sass) #=> "p\n color: blue"
15
- # Sass::CSS.new("p { color: blue }").render(:scss) #=> "p {\n color: blue; }"
16
- class CSS
17
- # @param template [String] The CSS stylesheet.
18
- # This stylesheet can be encoded using any encoding
19
- # that can be converted to Unicode.
20
- # If the stylesheet contains an `@charset` declaration,
21
- # that overrides the Ruby encoding
22
- # (see {file:SASS_REFERENCE.md#encodings the encoding documentation})
23
- # @option options :old [Boolean] (false)
24
- # Whether or not to output old property syntax
25
- # (`:color blue` as opposed to `color: blue`).
26
- # This is only meaningful when generating Sass code,
27
- # rather than SCSS.
28
- def initialize(template, options = {})
29
- if template.is_a? IO
30
- template = template.read
31
- end
32
-
33
- @options = options.dup
34
- # Backwards compatibility
35
- @options[:old] = true if @options[:alternate] == false
36
- @template = template
37
- end
38
-
39
- # Converts the CSS template into Sass or SCSS code.
40
- #
41
- # @param fmt [Symbol] `:sass` or `:scss`, designating the format to return.
42
- # @return [String] The resulting Sass or SCSS code
43
- # @raise [Sass::SyntaxError] if there's an error parsing the CSS template
44
- def render(fmt = :sass)
45
- check_encoding!
46
- build_tree.send("to_#{fmt}", @options).strip + "\n"
47
- rescue Sass::SyntaxError => err
48
- err.modify_backtrace(:filename => @options[:filename] || '(css)')
49
- raise err
50
- end
51
-
52
- # Returns the original encoding of the document,
53
- # or `nil` under Ruby 1.8.
54
- #
55
- # @return [Encoding, nil]
56
- # @raise [Encoding::UndefinedConversionError] if the source encoding
57
- # cannot be converted to UTF-8
58
- # @raise [ArgumentError] if the document uses an unknown encoding with `@charset`
59
- def source_encoding
60
- check_encoding!
61
- @original_encoding
62
- end
63
-
64
- private
65
-
66
- def check_encoding!
67
- return if @checked_encoding
68
- @checked_encoding = true
69
- @template, @original_encoding = Haml::Util.check_sass_encoding(@template) do |msg, line|
70
- raise Sass::SyntaxError.new(msg, :line => line)
71
- end
72
- end
73
-
74
- # Parses the CSS template and applies various transformations
75
- #
76
- # @return [Tree::Node] The root node of the parsed tree
77
- def build_tree
78
- root = Sass::SCSS::CssParser.new(@template).parse
79
- expand_commas root
80
- parent_ref_rules root
81
- remove_parent_refs root
82
- flatten_rules root
83
- fold_commas root
84
- root
85
- end
86
-
87
- # Transform
88
- #
89
- # foo, bar, baz
90
- # color: blue
91
- #
92
- # into
93
- #
94
- # foo
95
- # color: blue
96
- # bar
97
- # color: blue
98
- # baz
99
- # color: blue
100
- #
101
- # @param root [Tree::Node] The parent node
102
- def expand_commas(root)
103
- root.children.map! do |child|
104
- unless child.is_a?(Tree::RuleNode) && child.rule.first.include?(',')
105
- expand_commas(child) if child.is_a?(Tree::DirectiveNode)
106
- next child
107
- end
108
- child.rule.first.split(',').map do |rule|
109
- node = Tree::RuleNode.new([rule.strip])
110
- node.children = child.children
111
- node
112
- end
113
- end
114
- root.children.flatten!
115
- end
116
-
117
- # Make rules use parent refs so that
118
- #
119
- # foo
120
- # color: green
121
- # foo.bar
122
- # color: blue
123
- #
124
- # becomes
125
- #
126
- # foo
127
- # color: green
128
- # &.bar
129
- # color: blue
130
- #
131
- # This has the side effect of nesting rules,
132
- # so that
133
- #
134
- # foo
135
- # color: green
136
- # foo bar
137
- # color: red
138
- # foo baz
139
- # color: blue
140
- #
141
- # becomes
142
- #
143
- # foo
144
- # color: green
145
- # & bar
146
- # color: red
147
- # & baz
148
- # color: blue
149
- #
150
- # @param root [Tree::Node] The parent node
151
- def parent_ref_rules(root)
152
- current_rule = nil
153
- root.children.map! do |child|
154
- unless child.is_a?(Tree::RuleNode)
155
- parent_ref_rules(child) if child.is_a?(Tree::DirectiveNode)
156
- next child
157
- end
158
-
159
- first, rest = child.rule.first.scan(/\A(&?(?: .|[^ ])[^.#: \[]*)([.#: \[].*)?\Z/m).first
160
-
161
- if current_rule.nil? || current_rule.rule.first != first
162
- current_rule = Tree::RuleNode.new([first])
163
- end
164
-
165
- if rest
166
- child.rule = ["&" + rest]
167
- current_rule << child
168
- else
169
- current_rule.children += child.children
170
- end
171
-
172
- current_rule
173
- end
174
- root.children.compact!
175
- root.children.uniq!
176
-
177
- root.children.each { |v| parent_ref_rules(v) }
178
- end
179
-
180
- # Remove useless parent refs so that
181
- #
182
- # foo
183
- # & bar
184
- # color: blue
185
- #
186
- # becomes
187
- #
188
- # foo
189
- # bar
190
- # color: blue
191
- #
192
- # @param root [Tree::Node] The parent node
193
- def remove_parent_refs(root)
194
- root.children.each do |child|
195
- case child
196
- when Tree::RuleNode
197
- child.rule.first.gsub! /^& +/, ''
198
- remove_parent_refs child
199
- when Tree::DirectiveNode
200
- remove_parent_refs child
201
- end
202
- end
203
- end
204
-
205
- # Flatten rules so that
206
- #
207
- # foo
208
- # bar
209
- # color: red
210
- #
211
- # becomes
212
- #
213
- # foo bar
214
- # color: red
215
- #
216
- # and
217
- #
218
- # foo
219
- # &.bar
220
- # color: blue
221
- #
222
- # becomes
223
- #
224
- # foo.bar
225
- # color: blue
226
- #
227
- # @param root [Tree::Node] The parent node
228
- def flatten_rules(root)
229
- root.children.each do |child|
230
- case child
231
- when Tree::RuleNode
232
- flatten_rule(child)
233
- when Tree::DirectiveNode
234
- flatten_rules(child)
235
- end
236
- end
237
- end
238
-
239
- # Flattens a single rule
240
- #
241
- # @param rule [Tree::RuleNode] The candidate for flattening
242
- # @see #flatten_rules
243
- def flatten_rule(rule)
244
- while rule.children.size == 1 && rule.children.first.is_a?(Tree::RuleNode)
245
- child = rule.children.first
246
-
247
- if child.rule.first[0] == ?&
248
- rule.rule = [child.rule.first.gsub(/^&/, rule.rule.first)]
249
- else
250
- rule.rule = ["#{rule.rule.first} #{child.rule.first}"]
251
- end
252
-
253
- rule.children = child.children
254
- end
255
-
256
- flatten_rules(rule)
257
- end
258
-
259
- # Transform
260
- #
261
- # foo
262
- # bar
263
- # color: blue
264
- # baz
265
- # color: blue
266
- #
267
- # into
268
- #
269
- # foo
270
- # bar, baz
271
- # color: blue
272
- #
273
- # @param rule [Tree::RuleNode] The candidate for flattening
274
- def fold_commas(root)
275
- prev_rule = nil
276
- root.children.map! do |child|
277
- unless child.is_a?(Tree::RuleNode)
278
- fold_commas(child) if child.is_a?(Tree::DirectiveNode)
279
- next child
280
- end
281
-
282
- if prev_rule && prev_rule.children == child.children
283
- prev_rule.rule.first << ", #{child.rule.first}"
284
- next nil
285
- end
286
-
287
- fold_commas(child)
288
- prev_rule = child
289
- child
290
- end
291
- root.children.compact!
292
- end
293
- end
294
- end