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.
- data/.yardopts +1 -1
- data/CONTRIBUTING +0 -1
- data/EDGE_GEM_VERSION +1 -0
- data/MIT-LICENSE +1 -1
- data/README.md +10 -175
- data/Rakefile +56 -84
- data/VERSION +1 -1
- data/VERSION_NAME +1 -1
- data/init.rb +1 -1
- data/lib/haml.rb +14 -12
- data/lib/haml/engine.rb +1 -1
- data/lib/haml/exec.rb +19 -316
- data/lib/haml/helpers/action_view_extensions.rb +1 -1
- data/lib/haml/html.rb +69 -76
- data/lib/haml/precompiler.rb +34 -41
- data/lib/haml/railtie.rb +4 -6
- data/lib/haml/template/plugin.rb +6 -16
- data/lib/haml/util.rb +91 -107
- data/lib/haml/version.rb +7 -0
- data/test/benchmark.rb +2 -9
- data/test/haml/engine_test.rb +195 -92
- data/test/haml/html2haml/erb_tests.rb +0 -14
- data/test/haml/util_test.rb +32 -0
- data/test/test_helper.rb +0 -39
- metadata +96 -324
- data/bin/css2sass +0 -13
- data/bin/sass +0 -8
- data/bin/sass-convert +0 -7
- data/extra/haml-mode.el +0 -753
- data/extra/sass-mode.el +0 -207
- data/lib/haml/util/subset_map.rb +0 -101
- data/lib/sass.rb +0 -29
- data/lib/sass/callbacks.rb +0 -52
- data/lib/sass/css.rb +0 -294
- data/lib/sass/engine.rb +0 -720
- data/lib/sass/environment.rb +0 -143
- data/lib/sass/error.rb +0 -198
- data/lib/sass/files.rb +0 -160
- data/lib/sass/less.rb +0 -382
- data/lib/sass/plugin.rb +0 -279
- data/lib/sass/plugin/configuration.rb +0 -221
- data/lib/sass/plugin/generic.rb +0 -15
- data/lib/sass/plugin/merb.rb +0 -37
- data/lib/sass/plugin/rack.rb +0 -47
- data/lib/sass/plugin/rails.rb +0 -32
- data/lib/sass/plugin/staleness_checker.rb +0 -123
- data/lib/sass/repl.rb +0 -58
- data/lib/sass/script.rb +0 -63
- data/lib/sass/script/bool.rb +0 -18
- data/lib/sass/script/color.rb +0 -491
- data/lib/sass/script/css_lexer.rb +0 -29
- data/lib/sass/script/css_parser.rb +0 -31
- data/lib/sass/script/funcall.rb +0 -77
- data/lib/sass/script/functions.rb +0 -861
- data/lib/sass/script/interpolation.rb +0 -70
- data/lib/sass/script/lexer.rb +0 -337
- data/lib/sass/script/literal.rb +0 -236
- data/lib/sass/script/node.rb +0 -112
- data/lib/sass/script/number.rb +0 -423
- data/lib/sass/script/operation.rb +0 -95
- data/lib/sass/script/parser.rb +0 -401
- data/lib/sass/script/string.rb +0 -67
- data/lib/sass/script/string_interpolation.rb +0 -93
- data/lib/sass/script/unary_operation.rb +0 -57
- data/lib/sass/script/variable.rb +0 -48
- data/lib/sass/scss.rb +0 -17
- data/lib/sass/scss/css_parser.rb +0 -46
- data/lib/sass/scss/parser.rb +0 -855
- data/lib/sass/scss/rx.rb +0 -126
- data/lib/sass/scss/sass_parser.rb +0 -11
- data/lib/sass/scss/script_lexer.rb +0 -15
- data/lib/sass/scss/script_parser.rb +0 -25
- data/lib/sass/scss/static_parser.rb +0 -40
- data/lib/sass/selector.rb +0 -361
- data/lib/sass/selector/abstract_sequence.rb +0 -62
- data/lib/sass/selector/comma_sequence.rb +0 -82
- data/lib/sass/selector/sequence.rb +0 -237
- data/lib/sass/selector/simple.rb +0 -113
- data/lib/sass/selector/simple_sequence.rb +0 -136
- data/lib/sass/tree/charset_node.rb +0 -37
- data/lib/sass/tree/comment_node.rb +0 -128
- data/lib/sass/tree/debug_node.rb +0 -36
- data/lib/sass/tree/directive_node.rb +0 -75
- data/lib/sass/tree/extend_node.rb +0 -65
- data/lib/sass/tree/for_node.rb +0 -55
- data/lib/sass/tree/if_node.rb +0 -69
- data/lib/sass/tree/import_node.rb +0 -102
- data/lib/sass/tree/mixin_def_node.rb +0 -48
- data/lib/sass/tree/mixin_node.rb +0 -111
- data/lib/sass/tree/node.rb +0 -464
- data/lib/sass/tree/prop_node.rb +0 -220
- data/lib/sass/tree/root_node.rb +0 -163
- data/lib/sass/tree/rule_node.rb +0 -261
- data/lib/sass/tree/variable_node.rb +0 -39
- data/lib/sass/tree/warn_node.rb +0 -42
- data/lib/sass/tree/while_node.rb +0 -36
- data/test/haml/util/subset_map_test.rb +0 -91
- data/test/sass/callbacks_test.rb +0 -61
- data/test/sass/conversion_test.rb +0 -1218
- data/test/sass/css2sass_test.rb +0 -364
- data/test/sass/data/hsl-rgb.txt +0 -319
- data/test/sass/engine_test.rb +0 -2267
- data/test/sass/extend_test.rb +0 -1348
- data/test/sass/functions_test.rb +0 -556
- data/test/sass/less_conversion_test.rb +0 -653
- data/test/sass/more_results/more1.css +0 -9
- data/test/sass/more_results/more1_with_line_comments.css +0 -26
- data/test/sass/more_results/more_import.css +0 -29
- data/test/sass/more_templates/_more_partial.sass +0 -2
- data/test/sass/more_templates/more1.sass +0 -23
- data/test/sass/more_templates/more_import.sass +0 -11
- data/test/sass/plugin_test.rb +0 -433
- data/test/sass/results/alt.css +0 -4
- data/test/sass/results/basic.css +0 -9
- data/test/sass/results/compact.css +0 -5
- data/test/sass/results/complex.css +0 -86
- data/test/sass/results/compressed.css +0 -1
- data/test/sass/results/expanded.css +0 -19
- data/test/sass/results/import.css +0 -31
- data/test/sass/results/import_charset.css +0 -4
- data/test/sass/results/import_charset_1_8.css +0 -4
- data/test/sass/results/import_charset_ibm866.css +0 -4
- data/test/sass/results/line_numbers.css +0 -49
- data/test/sass/results/mixins.css +0 -95
- data/test/sass/results/multiline.css +0 -24
- data/test/sass/results/nested.css +0 -22
- data/test/sass/results/options.css +0 -1
- data/test/sass/results/parent_ref.css +0 -13
- data/test/sass/results/script.css +0 -16
- data/test/sass/results/scss_import.css +0 -31
- data/test/sass/results/scss_importee.css +0 -2
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +0 -1
- data/test/sass/results/subdir/subdir.css +0 -3
- data/test/sass/results/units.css +0 -11
- data/test/sass/results/warn.css +0 -0
- data/test/sass/results/warn_imported.css +0 -0
- data/test/sass/script_conversion_test.rb +0 -314
- data/test/sass/script_test.rb +0 -470
- data/test/sass/scss/css_test.rb +0 -916
- data/test/sass/scss/rx_test.rb +0 -156
- data/test/sass/scss/scss_test.rb +0 -1122
- data/test/sass/scss/test_helper.rb +0 -37
- data/test/sass/templates/_imported_charset_ibm866.sass +0 -4
- data/test/sass/templates/_imported_charset_utf8.sass +0 -4
- data/test/sass/templates/_partial.sass +0 -2
- data/test/sass/templates/alt.sass +0 -16
- data/test/sass/templates/basic.sass +0 -23
- data/test/sass/templates/bork1.sass +0 -2
- data/test/sass/templates/bork2.sass +0 -2
- data/test/sass/templates/bork3.sass +0 -2
- data/test/sass/templates/bork4.sass +0 -2
- data/test/sass/templates/compact.sass +0 -17
- data/test/sass/templates/complex.sass +0 -305
- data/test/sass/templates/compressed.sass +0 -15
- data/test/sass/templates/expanded.sass +0 -17
- data/test/sass/templates/import.sass +0 -12
- data/test/sass/templates/import_charset.sass +0 -7
- data/test/sass/templates/import_charset_1_8.sass +0 -4
- data/test/sass/templates/import_charset_ibm866.sass +0 -9
- data/test/sass/templates/importee.less +0 -2
- data/test/sass/templates/importee.sass +0 -19
- data/test/sass/templates/line_numbers.sass +0 -13
- data/test/sass/templates/mixin_bork.sass +0 -5
- data/test/sass/templates/mixins.sass +0 -76
- data/test/sass/templates/multiline.sass +0 -20
- data/test/sass/templates/nested.sass +0 -25
- data/test/sass/templates/nested_bork1.sass +0 -2
- data/test/sass/templates/nested_bork2.sass +0 -2
- data/test/sass/templates/nested_bork3.sass +0 -2
- data/test/sass/templates/nested_bork4.sass +0 -2
- data/test/sass/templates/nested_mixin_bork.sass +0 -6
- data/test/sass/templates/options.sass +0 -2
- data/test/sass/templates/parent_ref.sass +0 -25
- data/test/sass/templates/script.sass +0 -101
- data/test/sass/templates/scss_import.scss +0 -11
- data/test/sass/templates/scss_importee.scss +0 -1
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +0 -2
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +0 -3
- data/test/sass/templates/subdir/subdir.sass +0 -6
- data/test/sass/templates/units.sass +0 -11
- data/test/sass/templates/warn.sass +0 -3
- data/test/sass/templates/warn_imported.sass +0 -4
- data/vendor/fssm/LICENSE +0 -20
- data/vendor/fssm/README.markdown +0 -55
- data/vendor/fssm/Rakefile +0 -59
- data/vendor/fssm/VERSION.yml +0 -5
- data/vendor/fssm/example.rb +0 -9
- data/vendor/fssm/fssm.gemspec +0 -77
- data/vendor/fssm/lib/fssm.rb +0 -33
- data/vendor/fssm/lib/fssm/backends/fsevents.rb +0 -36
- data/vendor/fssm/lib/fssm/backends/inotify.rb +0 -26
- data/vendor/fssm/lib/fssm/backends/polling.rb +0 -25
- data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +0 -131
- data/vendor/fssm/lib/fssm/monitor.rb +0 -26
- data/vendor/fssm/lib/fssm/path.rb +0 -91
- data/vendor/fssm/lib/fssm/pathname.rb +0 -502
- data/vendor/fssm/lib/fssm/state/directory.rb +0 -57
- data/vendor/fssm/lib/fssm/state/file.rb +0 -24
- data/vendor/fssm/lib/fssm/support.rb +0 -63
- data/vendor/fssm/lib/fssm/tree.rb +0 -176
- data/vendor/fssm/profile/prof-cache.rb +0 -40
- data/vendor/fssm/profile/prof-fssm-pathname.html +0 -1231
- data/vendor/fssm/profile/prof-pathname.rb +0 -68
- data/vendor/fssm/profile/prof-plain-pathname.html +0 -988
- data/vendor/fssm/profile/prof.html +0 -2379
- data/vendor/fssm/spec/path_spec.rb +0 -75
- data/vendor/fssm/spec/root/duck/quack.txt +0 -0
- data/vendor/fssm/spec/root/file.css +0 -0
- data/vendor/fssm/spec/root/file.rb +0 -0
- data/vendor/fssm/spec/root/file.yml +0 -0
- data/vendor/fssm/spec/root/moo/cow.txt +0 -0
- data/vendor/fssm/spec/spec_helper.rb +0 -14
data/extra/sass-mode.el
DELETED
@@ -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
|
data/lib/haml/util/subset_map.rb
DELETED
@@ -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
|
data/lib/sass.rb
DELETED
@@ -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)
|
data/lib/sass/callbacks.rb
DELETED
@@ -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
|
data/lib/sass/css.rb
DELETED
@@ -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
|