haml-edge 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/EDGE_GEM_VERSION +1 -0
- data/FAQ +138 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +332 -0
- data/REVISION +1 -0
- data/Rakefile +226 -0
- data/VERSION +1 -0
- data/bin/css2sass +7 -0
- data/bin/haml +9 -0
- data/bin/html2haml +7 -0
- data/bin/sass +8 -0
- data/extra/edge_gem_watch.rb +13 -0
- data/extra/haml-mode.el +596 -0
- data/extra/sass-mode.el +200 -0
- data/init.rb +8 -0
- data/lib/haml/buffer.rb +255 -0
- data/lib/haml/engine.rb +268 -0
- data/lib/haml/error.rb +22 -0
- data/lib/haml/exec.rb +395 -0
- data/lib/haml/filters.rb +275 -0
- data/lib/haml/helpers/action_view_extensions.rb +45 -0
- data/lib/haml/helpers/action_view_mods.rb +181 -0
- data/lib/haml/helpers.rb +488 -0
- data/lib/haml/html.rb +222 -0
- data/lib/haml/precompiler.rb +904 -0
- data/lib/haml/shared.rb +45 -0
- data/lib/haml/template/patch.rb +58 -0
- data/lib/haml/template/plugin.rb +72 -0
- data/lib/haml/template.rb +42 -0
- data/lib/haml/util.rb +88 -0
- data/lib/haml/version.rb +47 -0
- data/lib/haml.rb +1044 -0
- data/lib/sass/css.rb +388 -0
- data/lib/sass/engine.rb +495 -0
- data/lib/sass/environment.rb +46 -0
- data/lib/sass/error.rb +35 -0
- data/lib/sass/plugin/merb.rb +56 -0
- data/lib/sass/plugin/rails.rb +24 -0
- data/lib/sass/plugin.rb +204 -0
- data/lib/sass/repl.rb +51 -0
- data/lib/sass/script/bool.rb +13 -0
- data/lib/sass/script/color.rb +97 -0
- data/lib/sass/script/funcall.rb +29 -0
- data/lib/sass/script/functions.rb +134 -0
- data/lib/sass/script/lexer.rb +148 -0
- data/lib/sass/script/literal.rb +82 -0
- data/lib/sass/script/number.rb +231 -0
- data/lib/sass/script/operation.rb +30 -0
- data/lib/sass/script/parser.rb +142 -0
- data/lib/sass/script/string.rb +9 -0
- data/lib/sass/script/unary_operation.rb +21 -0
- data/lib/sass/script/variable.rb +20 -0
- data/lib/sass/script.rb +38 -0
- data/lib/sass/tree/attr_node.rb +64 -0
- data/lib/sass/tree/comment_node.rb +30 -0
- data/lib/sass/tree/debug_node.rb +22 -0
- data/lib/sass/tree/directive_node.rb +50 -0
- data/lib/sass/tree/file_node.rb +27 -0
- data/lib/sass/tree/for_node.rb +29 -0
- data/lib/sass/tree/if_node.rb +27 -0
- data/lib/sass/tree/mixin_def_node.rb +18 -0
- data/lib/sass/tree/mixin_node.rb +35 -0
- data/lib/sass/tree/node.rb +99 -0
- data/lib/sass/tree/rule_node.rb +161 -0
- data/lib/sass/tree/variable_node.rb +24 -0
- data/lib/sass/tree/while_node.rb +21 -0
- data/lib/sass.rb +1062 -0
- data/rails/init.rb +1 -0
- data/test/benchmark.rb +99 -0
- data/test/haml/engine_test.rb +795 -0
- data/test/haml/helper_test.rb +228 -0
- data/test/haml/html2haml_test.rb +108 -0
- data/test/haml/markaby/standard.mab +52 -0
- data/test/haml/mocks/article.rb +6 -0
- data/test/haml/results/content_for_layout.xhtml +15 -0
- data/test/haml/results/eval_suppressed.xhtml +9 -0
- data/test/haml/results/filters.xhtml +62 -0
- data/test/haml/results/helpers.xhtml +93 -0
- data/test/haml/results/helpful.xhtml +10 -0
- data/test/haml/results/just_stuff.xhtml +68 -0
- data/test/haml/results/list.xhtml +12 -0
- data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
- data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
- data/test/haml/results/original_engine.xhtml +20 -0
- data/test/haml/results/partial_layout.xhtml +5 -0
- data/test/haml/results/partials.xhtml +21 -0
- data/test/haml/results/render_layout.xhtml +3 -0
- data/test/haml/results/silent_script.xhtml +74 -0
- data/test/haml/results/standard.xhtml +162 -0
- data/test/haml/results/tag_parsing.xhtml +23 -0
- data/test/haml/results/very_basic.xhtml +5 -0
- data/test/haml/results/whitespace_handling.xhtml +89 -0
- data/test/haml/rhtml/_av_partial_1.rhtml +12 -0
- data/test/haml/rhtml/_av_partial_2.rhtml +8 -0
- data/test/haml/rhtml/action_view.rhtml +62 -0
- data/test/haml/rhtml/standard.rhtml +54 -0
- data/test/haml/template_test.rb +204 -0
- data/test/haml/templates/_av_partial_1.haml +9 -0
- data/test/haml/templates/_av_partial_1_ugly.haml +9 -0
- data/test/haml/templates/_av_partial_2.haml +5 -0
- data/test/haml/templates/_av_partial_2_ugly.haml +5 -0
- data/test/haml/templates/_layout.erb +3 -0
- data/test/haml/templates/_layout_for_partial.haml +3 -0
- data/test/haml/templates/_partial.haml +8 -0
- data/test/haml/templates/_text_area.haml +3 -0
- data/test/haml/templates/action_view.haml +47 -0
- data/test/haml/templates/action_view_ugly.haml +47 -0
- data/test/haml/templates/breakage.haml +8 -0
- data/test/haml/templates/content_for_layout.haml +10 -0
- data/test/haml/templates/eval_suppressed.haml +11 -0
- data/test/haml/templates/filters.haml +66 -0
- data/test/haml/templates/helpers.haml +95 -0
- data/test/haml/templates/helpful.haml +11 -0
- data/test/haml/templates/just_stuff.haml +83 -0
- data/test/haml/templates/list.haml +12 -0
- data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
- data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
- data/test/haml/templates/original_engine.haml +17 -0
- data/test/haml/templates/partial_layout.haml +3 -0
- data/test/haml/templates/partialize.haml +1 -0
- data/test/haml/templates/partials.haml +12 -0
- data/test/haml/templates/render_layout.haml +2 -0
- data/test/haml/templates/silent_script.haml +40 -0
- data/test/haml/templates/standard.haml +42 -0
- data/test/haml/templates/standard_ugly.haml +42 -0
- data/test/haml/templates/tag_parsing.haml +21 -0
- data/test/haml/templates/very_basic.haml +4 -0
- data/test/haml/templates/whitespace_handling.haml +87 -0
- data/test/haml/util_test.rb +87 -0
- data/test/linked_rails.rb +12 -0
- data/test/sass/css2sass_test.rb +193 -0
- data/test/sass/engine_test.rb +709 -0
- data/test/sass/functions_test.rb +109 -0
- data/test/sass/more_results/more1.css +9 -0
- data/test/sass/more_results/more1_with_line_comments.css +26 -0
- data/test/sass/more_results/more_import.css +29 -0
- data/test/sass/more_templates/_more_partial.sass +2 -0
- data/test/sass/more_templates/more1.sass +23 -0
- data/test/sass/more_templates/more_import.sass +11 -0
- data/test/sass/plugin_test.rb +213 -0
- data/test/sass/results/alt.css +4 -0
- data/test/sass/results/basic.css +9 -0
- data/test/sass/results/compact.css +5 -0
- data/test/sass/results/complex.css +87 -0
- data/test/sass/results/compressed.css +1 -0
- data/test/sass/results/expanded.css +19 -0
- data/test/sass/results/import.css +29 -0
- data/test/sass/results/line_numbers.css +49 -0
- data/test/sass/results/mixins.css +95 -0
- data/test/sass/results/multiline.css +24 -0
- data/test/sass/results/nested.css +22 -0
- data/test/sass/results/parent_ref.css +13 -0
- data/test/sass/results/script.css +16 -0
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
- data/test/sass/results/subdir/subdir.css +3 -0
- data/test/sass/results/units.css +11 -0
- data/test/sass/script_test.rb +250 -0
- data/test/sass/templates/_partial.sass +2 -0
- data/test/sass/templates/alt.sass +16 -0
- data/test/sass/templates/basic.sass +23 -0
- data/test/sass/templates/bork.sass +2 -0
- data/test/sass/templates/bork2.sass +2 -0
- data/test/sass/templates/compact.sass +17 -0
- data/test/sass/templates/complex.sass +309 -0
- data/test/sass/templates/compressed.sass +15 -0
- data/test/sass/templates/expanded.sass +17 -0
- data/test/sass/templates/import.sass +11 -0
- data/test/sass/templates/importee.sass +19 -0
- data/test/sass/templates/line_numbers.sass +13 -0
- data/test/sass/templates/mixins.sass +76 -0
- data/test/sass/templates/multiline.sass +20 -0
- data/test/sass/templates/nested.sass +25 -0
- data/test/sass/templates/parent_ref.sass +25 -0
- data/test/sass/templates/script.sass +101 -0
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
- data/test/sass/templates/subdir/subdir.sass +6 -0
- data/test/sass/templates/units.sass +11 -0
- data/test/test_helper.rb +21 -0
- metadata +278 -0
data/extra/sass-mode.el
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
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: 1.0
|
|
8
|
+
;; Keywords: markup, language
|
|
9
|
+
|
|
10
|
+
;;; Commentary:
|
|
11
|
+
|
|
12
|
+
;; Because Sass's indentation schema is similar
|
|
13
|
+
;; to that of YAML and Python, many indentation-related
|
|
14
|
+
;; functions are similar to those in yaml-mode and python-mode.
|
|
15
|
+
|
|
16
|
+
;; To install, save this on your load path and add the following to
|
|
17
|
+
;; your .emacs file:
|
|
18
|
+
;;
|
|
19
|
+
;; (require 'sass-mode)
|
|
20
|
+
|
|
21
|
+
;;; Code:
|
|
22
|
+
|
|
23
|
+
(require 'haml-mode)
|
|
24
|
+
|
|
25
|
+
;; User definable variables
|
|
26
|
+
|
|
27
|
+
(defgroup sass nil
|
|
28
|
+
"Support for the Sass template language."
|
|
29
|
+
:group 'languages
|
|
30
|
+
:prefix "sass-")
|
|
31
|
+
|
|
32
|
+
(defcustom sass-mode-hook nil
|
|
33
|
+
"Hook run when entering Sass mode."
|
|
34
|
+
:type 'hook
|
|
35
|
+
:group 'sass)
|
|
36
|
+
|
|
37
|
+
(defcustom sass-indent-offset 2
|
|
38
|
+
"Amount of offset per level of indentation."
|
|
39
|
+
:type 'integer
|
|
40
|
+
:group 'sass)
|
|
41
|
+
|
|
42
|
+
(defvar sass-non-block-openers
|
|
43
|
+
'("^ *:[^ \t]+[ \t]+[^ \t]"
|
|
44
|
+
"^ *[^ \t:]+[ \t]*[=:][ \t]*[^ \t]")
|
|
45
|
+
"A list of regexps that match lines of Sass that couldn't have
|
|
46
|
+
text nested beneath them.")
|
|
47
|
+
|
|
48
|
+
;; Font lock
|
|
49
|
+
|
|
50
|
+
(defconst sass-selector-font-lock-keywords
|
|
51
|
+
'(;; Attribute selectors (e.g. p[foo=bar])
|
|
52
|
+
("\\[\\([^]=]+\\)" (1 font-lock-variable-name-face)
|
|
53
|
+
("[~|$^*]?=\\([^]=]+\\)" nil nil (1 font-lock-string-face)))
|
|
54
|
+
("&" 0 font-lock-constant-face)
|
|
55
|
+
("\\.\\w+" 0 font-lock-type-face)
|
|
56
|
+
("#\\w+" 0 font-lock-keyword-face)
|
|
57
|
+
;; Pseudo-selectors, optionally with arguments (e.g. :first, :nth-child(12))
|
|
58
|
+
("\\(::?\\w+\\)" (1 font-lock-function-name-face)
|
|
59
|
+
("(\\([^)]+\\))" nil nil (1 font-lock-string-face)))))
|
|
60
|
+
|
|
61
|
+
(defconst sass-script-font-lock-keywords
|
|
62
|
+
`(("\"\\([^\"\\\\]\\|\\\\.\\)*\"" 0 font-lock-string-face)
|
|
63
|
+
("!\\w+" 0 font-lock-variable-name-face)
|
|
64
|
+
("#[0-9a-fA-F]\\{0,6\\}" 0 font-lock-preprocessor-face)
|
|
65
|
+
(,(regexp-opt
|
|
66
|
+
'("true" "false" "black" "silver" "gray" "white" "maroon" "red"
|
|
67
|
+
"purple" "fuchsia" "green" "lime" "olive" "yellow" "navy"
|
|
68
|
+
"blue" "teal" "aqua"))
|
|
69
|
+
0 font-lock-constant-face)
|
|
70
|
+
(,(regexp-opt '("and" "or" "not")) 0 font-lock-keyword-face)))
|
|
71
|
+
|
|
72
|
+
(defconst sass-syntax-table
|
|
73
|
+
(let ((st (make-syntax-table)))
|
|
74
|
+
(modify-syntax-entry ?- "w" st)
|
|
75
|
+
st))
|
|
76
|
+
|
|
77
|
+
(defconst sass-script-syntax-table
|
|
78
|
+
(let ((st (make-syntax-table sass-syntax-table)))
|
|
79
|
+
(modify-syntax-entry ?- "." st)
|
|
80
|
+
st))
|
|
81
|
+
|
|
82
|
+
(defconst sass-font-lock-keywords
|
|
83
|
+
'((sass-highlight-line 1 nil nil t)))
|
|
84
|
+
|
|
85
|
+
(defconst sass-line-keywords
|
|
86
|
+
'(("@\\(\\w+\\)" 0 font-lock-keyword-face sass-highlight-directive)
|
|
87
|
+
("/[/*].*" 0 font-lock-comment-face)
|
|
88
|
+
("[=+]\\w+" 0 font-lock-function-name-face sass-highlight-script-after-match)
|
|
89
|
+
("!\\w+" 0 font-lock-variable-name-face sass-highlight-script-after-match)
|
|
90
|
+
(":\\w+" 0 font-lock-variable-name-face)
|
|
91
|
+
("\\w+\s*:" 0 font-lock-variable-name-face)
|
|
92
|
+
("\\(\\w+\\)\s*=" 1 font-lock-variable-name-face sass-highlight-script-after-match)
|
|
93
|
+
("\\(:\\w+\\)\s*=" 1 font-lock-variable-name-face sass-highlight-script-after-match)
|
|
94
|
+
(".*" sass-highlight-selector))
|
|
95
|
+
"A list of full-line Sass syntax to highlight,
|
|
96
|
+
used by `sass-highlight-line'.
|
|
97
|
+
|
|
98
|
+
Each item is either of the form (REGEXP SUBEXP FACE), (REGEXP FN),
|
|
99
|
+
or (REGEXP SUBEXP FACE FN). Each REGEXP is run successively on the
|
|
100
|
+
beginning of non-whitespace on the current line until one matches.
|
|
101
|
+
If it has SUBEXP and FACE, then SUBEXP is highlighted using FACE.
|
|
102
|
+
If it has FN, FN is run.")
|
|
103
|
+
|
|
104
|
+
(defun sass-highlight-line (limit)
|
|
105
|
+
"Highlight a single line using some Sass single-line syntax,
|
|
106
|
+
taken from `sass-line-keywords'."
|
|
107
|
+
(save-match-data
|
|
108
|
+
(when (re-search-forward "^ *\\(.+\\)$" limit t)
|
|
109
|
+
(goto-char (match-beginning 1))
|
|
110
|
+
(dolist (keyword sass-line-keywords)
|
|
111
|
+
(destructuring-bind (keyword subexp-or-fn &optional face fn) keyword
|
|
112
|
+
(when (looking-at keyword)
|
|
113
|
+
(if (integerp subexp-or-fn)
|
|
114
|
+
(put-text-property (match-beginning subexp-or-fn)
|
|
115
|
+
(match-end subexp-or-fn)
|
|
116
|
+
'face face)
|
|
117
|
+
(setq fn subexp-or-fn))
|
|
118
|
+
(when fn (funcall fn))
|
|
119
|
+
(end-of-line)
|
|
120
|
+
(return t)))))))
|
|
121
|
+
|
|
122
|
+
(defun sass-highlight-selector ()
|
|
123
|
+
"Highlight a CSS selector starting at `point'
|
|
124
|
+
and ending at `end-of-line'."
|
|
125
|
+
(let ((font-lock-keywords sass-selector-font-lock-keywords)
|
|
126
|
+
font-lock-multiline)
|
|
127
|
+
(font-lock-fontify-region
|
|
128
|
+
(point) (progn (end-of-line) (point))))
|
|
129
|
+
t)
|
|
130
|
+
|
|
131
|
+
(defun sass-highlight-script (beg end)
|
|
132
|
+
"Highlight a section of SassScript between BEG and END."
|
|
133
|
+
(save-match-data
|
|
134
|
+
(with-syntax-table sass-script-syntax-table
|
|
135
|
+
(let ((font-lock-keywords sass-script-font-lock-keywords)
|
|
136
|
+
font-lock-syntax-table
|
|
137
|
+
font-lock-extend-region-functions)
|
|
138
|
+
(font-lock-fontify-region beg end)))))
|
|
139
|
+
|
|
140
|
+
(defun sass-highlight-script-after-match ()
|
|
141
|
+
(end-of-line)
|
|
142
|
+
(sass-highlight-script (match-end 0) (point)))
|
|
143
|
+
|
|
144
|
+
(defun sass-highlight-directive ()
|
|
145
|
+
(goto-char (match-end 0))
|
|
146
|
+
(block nil
|
|
147
|
+
(case (intern (match-string 1))
|
|
148
|
+
(for
|
|
149
|
+
(unless (looking-at " +!\\w+") (return))
|
|
150
|
+
(put-text-property (match-beginning 0) (match-end 0)
|
|
151
|
+
'face font-lock-variable-name-face)
|
|
152
|
+
(goto-char (match-end 0))
|
|
153
|
+
(unless (looking-at " +from") (return))
|
|
154
|
+
(put-text-property (match-beginning 0) (match-end 0)
|
|
155
|
+
'face font-lock-keyword-face)
|
|
156
|
+
(goto-char (match-end 0))
|
|
157
|
+
(when (looking-at " +\\(.+?\\) +\\(to\\|through\\)")
|
|
158
|
+
(sass-highlight-script (match-beginning 1) (match-end 1))
|
|
159
|
+
(put-text-property (match-beginning 2) (match-end 2)
|
|
160
|
+
'face font-lock-keyword-face))
|
|
161
|
+
(sass-highlight-script-after-match))
|
|
162
|
+
|
|
163
|
+
(else
|
|
164
|
+
(unless (looking-at " +if") (return))
|
|
165
|
+
(put-text-property (match-beginning 0) (match-end 0)
|
|
166
|
+
'face font-lock-keyword-face)
|
|
167
|
+
(sass-highlight-script-after-match))
|
|
168
|
+
|
|
169
|
+
((if while debug) (sass-highlight-script-after-match)))))
|
|
170
|
+
|
|
171
|
+
;; Constants
|
|
172
|
+
|
|
173
|
+
;; Mode setup
|
|
174
|
+
|
|
175
|
+
;;;###autoload
|
|
176
|
+
(define-derived-mode sass-mode haml-mode "Sass"
|
|
177
|
+
"Major mode for editing Sass files."
|
|
178
|
+
(set-syntax-table sass-syntax-table)
|
|
179
|
+
(setq font-lock-extend-region-functions
|
|
180
|
+
'(font-lock-extend-region-wholelines font-lock-extend-region-multiline))
|
|
181
|
+
(setq font-lock-multiline nil)
|
|
182
|
+
(setq comment-start "/*")
|
|
183
|
+
(set (make-local-variable 'haml-indent-function) 'sass-indent-p)
|
|
184
|
+
(set (make-local-variable 'haml-indent-offset) sass-indent-offset)
|
|
185
|
+
(setq font-lock-defaults '(sass-font-lock-keywords t t)))
|
|
186
|
+
|
|
187
|
+
;; Indentation
|
|
188
|
+
|
|
189
|
+
(defun sass-indent-p ()
|
|
190
|
+
"Returns t if the current line can have lines nested beneath it."
|
|
191
|
+
(loop for opener in sass-non-block-openers
|
|
192
|
+
unless (looking-at opener) return t
|
|
193
|
+
return nil))
|
|
194
|
+
|
|
195
|
+
;;;###autoload
|
|
196
|
+
(add-to-list 'auto-mode-alist '("\\.sass$" . sass-mode))
|
|
197
|
+
|
|
198
|
+
;; Setup/Activation
|
|
199
|
+
(provide 'sass-mode)
|
|
200
|
+
;;; sass-mode.el ends here
|
data/init.rb
ADDED
data/lib/haml/buffer.rb
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
module Haml
|
|
2
|
+
# This class is used only internally. It holds the buffer of XHTML that
|
|
3
|
+
# is eventually output by Haml::Engine's to_html method. It's called
|
|
4
|
+
# from within the precompiled code, and helps reduce the amount of
|
|
5
|
+
# processing done within instance_eval'd code.
|
|
6
|
+
class Buffer
|
|
7
|
+
include Haml::Helpers
|
|
8
|
+
include Haml::Util
|
|
9
|
+
|
|
10
|
+
# The string that holds the compiled XHTML. This is aliased as
|
|
11
|
+
# _erbout for compatibility with ERB-specific code.
|
|
12
|
+
attr_accessor :buffer
|
|
13
|
+
|
|
14
|
+
# The options hash passed in from Haml::Engine.
|
|
15
|
+
attr_accessor :options
|
|
16
|
+
|
|
17
|
+
# The Buffer for the enclosing Haml document.
|
|
18
|
+
# This is set for partials and similar sorts of nested templates.
|
|
19
|
+
# It's nil at the top level (see #toplevel?).
|
|
20
|
+
attr_accessor :upper
|
|
21
|
+
|
|
22
|
+
# See #active?
|
|
23
|
+
attr_writer :active
|
|
24
|
+
|
|
25
|
+
# True if the format is XHTML
|
|
26
|
+
def xhtml?
|
|
27
|
+
not html?
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# True if the format is any flavor of HTML
|
|
31
|
+
def html?
|
|
32
|
+
html4? or html5?
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# True if the format is HTML4
|
|
36
|
+
def html4?
|
|
37
|
+
@options[:format] == :html4
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# True if the format is HTML5
|
|
41
|
+
def html5?
|
|
42
|
+
@options[:format] == :html5
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# True if this buffer is a top-level template,
|
|
46
|
+
# as opposed to a nested partial.
|
|
47
|
+
def toplevel?
|
|
48
|
+
upper.nil?
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# True if this buffer is currently being used to render a Haml template.
|
|
52
|
+
# However, this returns false if a subtemplate is being rendered,
|
|
53
|
+
# even if it's a subtemplate of this buffer's template.
|
|
54
|
+
def active?
|
|
55
|
+
@active
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Gets the current tabulation of the document.
|
|
59
|
+
def tabulation
|
|
60
|
+
@real_tabs + @tabulation
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Sets the current tabulation of the document.
|
|
64
|
+
def tabulation=(val)
|
|
65
|
+
val = val - @real_tabs
|
|
66
|
+
@tabulation = val > -1 ? val : 0
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Creates a new buffer.
|
|
70
|
+
def initialize(upper = nil, options = {})
|
|
71
|
+
@active = true
|
|
72
|
+
@upper = upper
|
|
73
|
+
@options = {
|
|
74
|
+
:attr_wrapper => "'",
|
|
75
|
+
:ugly => false,
|
|
76
|
+
:format => :xhtml
|
|
77
|
+
}.merge options
|
|
78
|
+
@buffer = ""
|
|
79
|
+
@tabulation = 0
|
|
80
|
+
|
|
81
|
+
# The number of tabs that Engine thinks we should have
|
|
82
|
+
# @real_tabs + @tabulation is the number of tabs actually output
|
|
83
|
+
@real_tabs = 0
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def push_text(text, tab_change, dont_tab_up)
|
|
87
|
+
if @tabulation > 0
|
|
88
|
+
# Have to push every line in by the extra user set tabulation.
|
|
89
|
+
# Don't push lines with just whitespace, though,
|
|
90
|
+
# because that screws up precompiled indentation.
|
|
91
|
+
text.gsub!(/^(?!\s+$)/m, tabs)
|
|
92
|
+
text.sub!(tabs, '') if dont_tab_up
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
@buffer << text
|
|
96
|
+
@real_tabs += tab_change
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def adjust_tabs(tab_change)
|
|
100
|
+
@real_tabs += tab_change
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
Haml::Util.def_static_method(self, :format_script, [:result],
|
|
104
|
+
:preserve_script, :in_tag, :preserve_tag, :escape_html,
|
|
105
|
+
:nuke_inner_whitespace, :interpolated, :ugly, <<RUBY)
|
|
106
|
+
<% unless ugly %>
|
|
107
|
+
# If we're interpolated,
|
|
108
|
+
# then the custom tabulation is handled in #push_text.
|
|
109
|
+
# The easiest way to avoid it here is to reset @tabulation.
|
|
110
|
+
<% if interpolated %>
|
|
111
|
+
old_tabulation = @tabulation
|
|
112
|
+
@tabulation = 0
|
|
113
|
+
<% end %>
|
|
114
|
+
|
|
115
|
+
tabulation = @real_tabs
|
|
116
|
+
result = result.to_s.<% if nuke_inner_whitespace %>strip<% else %>rstrip<% end %>
|
|
117
|
+
<% else %>
|
|
118
|
+
result = result.to_s<% if nuke_inner_whitespace %>.strip<% end %>
|
|
119
|
+
<% end %>
|
|
120
|
+
|
|
121
|
+
<% if escape_html %> result = html_escape(result) <% end %>
|
|
122
|
+
|
|
123
|
+
<% if preserve_tag %>
|
|
124
|
+
result = Haml::Helpers.preserve(result)
|
|
125
|
+
<% elsif preserve_script %>
|
|
126
|
+
result = Haml::Helpers.find_and_preserve(result, options[:preserve])
|
|
127
|
+
<% end %>
|
|
128
|
+
|
|
129
|
+
<% if ugly %>
|
|
130
|
+
return result
|
|
131
|
+
<% else %>
|
|
132
|
+
|
|
133
|
+
has_newline = result.include?("\\n")
|
|
134
|
+
<% if in_tag && !nuke_inner_whitespace %>
|
|
135
|
+
<% unless preserve_tag %> if !has_newline <% end %>
|
|
136
|
+
@real_tabs -= 1
|
|
137
|
+
<% if interpolated %> @tabulation = old_tabulation <% end %>
|
|
138
|
+
return result
|
|
139
|
+
<% unless preserve_tag %> end <% end %>
|
|
140
|
+
<% end %>
|
|
141
|
+
|
|
142
|
+
# Precompiled tabulation may be wrong
|
|
143
|
+
<% if !interpolated && !in_tag %>
|
|
144
|
+
result = tabs + result if @tabulation > 0
|
|
145
|
+
<% end %>
|
|
146
|
+
|
|
147
|
+
if has_newline
|
|
148
|
+
result = result.gsub "\\n", "\\n" + tabs(tabulation)
|
|
149
|
+
|
|
150
|
+
# Add tabulation if it wasn't precompiled
|
|
151
|
+
<% if in_tag && !nuke_inner_whitespace %> result = tabs(tabulation) + result <% end %>
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
<% if in_tag && !nuke_inner_whitespace %>
|
|
155
|
+
result = "\\n\#{result}\\n\#{tabs(tabulation-1)}"
|
|
156
|
+
@real_tabs -= 1
|
|
157
|
+
<% end %>
|
|
158
|
+
<% if interpolated %> @tabulation = old_tabulation <% end %>
|
|
159
|
+
result
|
|
160
|
+
<% end %>
|
|
161
|
+
RUBY
|
|
162
|
+
|
|
163
|
+
# Takes the various information about the opening tag for an
|
|
164
|
+
# element, formats it, and adds it to the buffer.
|
|
165
|
+
def open_tag(name, self_closing, try_one_line, preserve_tag, escape_html, class_id,
|
|
166
|
+
nuke_outer_whitespace, nuke_inner_whitespace, obj_ref, content, *attributes_hashes)
|
|
167
|
+
tabulation = @real_tabs
|
|
168
|
+
|
|
169
|
+
attributes = class_id
|
|
170
|
+
attributes_hashes.each do |old|
|
|
171
|
+
self.class.merge_attrs(attributes, to_hash(old.map {|k, v| [k.to_s, v]}))
|
|
172
|
+
end
|
|
173
|
+
self.class.merge_attrs(attributes, parse_object_ref(obj_ref)) if obj_ref
|
|
174
|
+
|
|
175
|
+
if self_closing && xhtml?
|
|
176
|
+
str = " />" + (nuke_outer_whitespace ? "" : "\n")
|
|
177
|
+
else
|
|
178
|
+
str = ">" + ((if self_closing && html?
|
|
179
|
+
nuke_outer_whitespace
|
|
180
|
+
else
|
|
181
|
+
try_one_line || preserve_tag || nuke_inner_whitespace
|
|
182
|
+
end) ? "" : "\n")
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
attributes = Precompiler.build_attributes(html?, @options[:attr_wrapper], attributes)
|
|
186
|
+
@buffer << "#{nuke_outer_whitespace || @options[:ugly] ? '' : tabs(tabulation)}<#{name}#{attributes}#{str}"
|
|
187
|
+
|
|
188
|
+
if content
|
|
189
|
+
@buffer << "#{content}</#{name}>" << (nuke_outer_whitespace ? "" : "\n")
|
|
190
|
+
return
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
@real_tabs += 1 unless self_closing || nuke_inner_whitespace
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def self.merge_attrs(to, from)
|
|
197
|
+
if to['id'] && from['id']
|
|
198
|
+
to['id'] << '_' << from.delete('id')
|
|
199
|
+
elsif to['id'] || from['id']
|
|
200
|
+
from['id'] ||= to['id']
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
if to['class'] && from['class']
|
|
204
|
+
# Make sure we don't duplicate class names
|
|
205
|
+
from['class'] = (from['class'].split(' ') | to['class'].split(' ')).join(' ')
|
|
206
|
+
elsif to['class'] || from['class']
|
|
207
|
+
from['class'] ||= to['class']
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
to.merge!(from)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
private
|
|
214
|
+
|
|
215
|
+
# Some of these methods are exposed as public class methods
|
|
216
|
+
# so they can be re-used in helpers.
|
|
217
|
+
|
|
218
|
+
@@tab_cache = {}
|
|
219
|
+
# Gets <tt>count</tt> tabs. Mostly for internal use.
|
|
220
|
+
def tabs(count = 0)
|
|
221
|
+
tabs = [count + @tabulation, 0].max
|
|
222
|
+
@@tab_cache[tabs] ||= ' ' * tabs
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# Takes an array of objects and uses the class and id of the first
|
|
226
|
+
# one to create an attributes hash.
|
|
227
|
+
# The second object, if present, is used as a prefix,
|
|
228
|
+
# just like you can do with dom_id() and dom_class() in Rails
|
|
229
|
+
def parse_object_ref(ref)
|
|
230
|
+
prefix = ref[1]
|
|
231
|
+
ref = ref[0]
|
|
232
|
+
# Let's make sure the value isn't nil. If it is, return the default Hash.
|
|
233
|
+
return {} if ref.nil?
|
|
234
|
+
class_name = underscore(ref.class)
|
|
235
|
+
id = "#{class_name}_#{ref.id || 'new'}"
|
|
236
|
+
if prefix
|
|
237
|
+
class_name = "#{ prefix }_#{ class_name}"
|
|
238
|
+
id = "#{ prefix }_#{ id }"
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
{'id' => id, 'class' => class_name}
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# Changes a word from camel case to underscores.
|
|
245
|
+
# Based on the method of the same name in Rails' Inflector,
|
|
246
|
+
# but copied here so it'll run properly without Rails.
|
|
247
|
+
def underscore(camel_cased_word)
|
|
248
|
+
camel_cased_word.to_s.gsub(/::/, '_').
|
|
249
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
|
250
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
|
251
|
+
tr("-", "_").
|
|
252
|
+
downcase
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|