haml 2.0.7 → 2.0.8

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/Rakefile CHANGED
@@ -13,7 +13,11 @@ end
13
13
 
14
14
  # ----- Default: Testing ------
15
15
 
16
- task :default => :test
16
+ if ENV["RUN_CODE_RUN"] == "true"
17
+ task :default => :"test:rails_compatibility"
18
+ else
19
+ task :default => :test
20
+ end
17
21
 
18
22
  require 'rake/testtask'
19
23
 
@@ -148,3 +152,33 @@ END
148
152
  RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
149
153
  end
150
154
  rescue LoadError; end
155
+
156
+ # ----- Testing Multiple Rails Versions -----
157
+
158
+ rails_versions = [
159
+ "v2.3.0",
160
+ "v2.2.2",
161
+ "v2.1.2",
162
+ "v2.0.5"
163
+ ]
164
+
165
+ namespace :test do
166
+ desc "Test all supported versions of rails. This takes a while."
167
+ task :rails_compatibility do
168
+ `rm -rf test/rails`
169
+ puts "Checking out rails. Please wait."
170
+ `git clone git://github.com/rails/rails.git test/rails` rescue nil
171
+ begin
172
+ rails_versions.each do |version|
173
+ Dir.chdir "test/rails" do
174
+ `git checkout #{version}`
175
+ end
176
+ puts "Testing Rails #{version}"
177
+ Rake::Task['test'].reenable
178
+ Rake::Task['test'].execute
179
+ end
180
+ ensure
181
+ `rm -rf test/rails`
182
+ end
183
+ end
184
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.7
1
+ 2.0.8
@@ -0,0 +1,331 @@
1
+ ;;; haml-mode.el -- Major mode for editing Haml files
2
+ ;;; Written by Nathan Weizenbaum
3
+
4
+ ;;; Because Haml's indentation schema is similar
5
+ ;;; to that of YAML and Python, many indentation-related
6
+ ;;; functions are similar to those in yaml-mode and python-mode.
7
+
8
+ ;;; To install, save this somewhere and add the following to your .emacs file:
9
+ ;;;
10
+ ;;; (add-to-list 'load-path "/path/to/haml-mode.el")
11
+ ;;; (require 'haml-mode nil 't)
12
+ ;;; (add-to-list 'auto-mode-alist '("\\.haml$" . haml-mode))
13
+ ;;;
14
+
15
+ ;;; Code:
16
+
17
+ (eval-when-compile (require 'cl))
18
+
19
+ ;; User definable variables
20
+
21
+ (defgroup haml nil
22
+ "Support for the Haml template language."
23
+ :group 'languages
24
+ :prefix "haml-")
25
+
26
+ (defcustom haml-mode-hook nil
27
+ "Hook run when entering Haml mode."
28
+ :type 'hook
29
+ :group 'haml)
30
+
31
+ (defcustom haml-indent-offset 2
32
+ "Amount of offset per level of indentation."
33
+ :type 'integer
34
+ :group 'haml)
35
+
36
+ (defcustom haml-backspace-backdents-nesting t
37
+ "Non-nil to have `haml-electric-backspace' re-indent all code
38
+ nested beneath the backspaced line be re-indented along with the
39
+ line itself."
40
+ :type 'boolean
41
+ :group 'haml)
42
+
43
+ (defface haml-tab-face
44
+ '((((class color)) (:background "hotpink"))
45
+ (t (:reverse-video t)))
46
+ "Face to use for highlighting tabs in Haml files."
47
+ :group 'faces
48
+ :group 'haml)
49
+
50
+ (defvar haml-indent-function 'haml-indent-p
51
+ "This function should look at the current line and return true
52
+ if the next line could be nested within this line.")
53
+
54
+ (defvar haml-block-openers
55
+ `("^ *\\([%\\.#][^ \t]*\\)\\(\\[.*\\]\\)?\\({.*}\\)?\\(\\[.*\\]\\)?[ \t]*$"
56
+ "^ *[-=].*do[ \t]*\\(|.*|[ \t]*\\)?$"
57
+ ,(concat "^ *-[ \t]*\\("
58
+ (regexp-opt '("else" "elsif" "rescue" "ensure" "when"))
59
+ "\\)")
60
+ "^ */\\(\\[.*\\]\\)?[ \t]*$"
61
+ "^ *-#"
62
+ "^ *:")
63
+ "A list of regexps that match lines of Haml that could have
64
+ text nested beneath them.")
65
+
66
+ ;; Font lock
67
+
68
+ (defconst haml-font-lock-keywords
69
+ '(("^ *\\(\t\\)" 1 'haml-tab-face)
70
+ ("^!!!.*" 0 font-lock-constant-face)
71
+ ("\\('[^']*'\\)" 1 font-lock-string-face append)
72
+ ("\\(\"[^\"]*\"\\)" 1 font-lock-string-face append)
73
+ ("&?:\\w+" 0 font-lock-constant-face append)
74
+ ("@[a-z0-9_]+" 0 font-lock-variable-name-face append)
75
+ ("| *$" 0 font-lock-string-face)
76
+ ("^[ \t]*\\(/.*\\)$" 1 font-lock-comment-face append)
77
+ ("^ *\\(#[a-z0-9_]+\/?\\)" 1 font-lock-keyword-face)
78
+ ("^ *\\(\\.[a-z0-9_]+\/?\\)" 1 font-lock-type-face)
79
+ ("^ *\\(%[a-z0-9_]+\/?\\)" 1 font-lock-function-name-face)
80
+ ("^ *\\(#[a-z0-9_]+\/?\\)" (1 font-lock-keyword-face)
81
+ ("\\.[a-z0-9_]+" nil nil (0 font-lock-type-face)))
82
+ ("^ *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face)
83
+ ("\\.[a-z0-9_]+" nil nil (0 font-lock-type-face)))
84
+ ("^ *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face)
85
+ ("\\#[a-z0-9_]+" nil nil (0 font-lock-keyword-face)))
86
+ ("^ *\\(%[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face)
87
+ ("\\.[a-z0-9_]+" nil nil (0 font-lock-type-face)))
88
+ ("^ *\\(%[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face)
89
+ ("\\#[a-z0-9_]+" nil nil (0 font-lock-keyword-face)))
90
+ ("^ *\\([~=-] .*\\)" 1 font-lock-preprocessor-face prepend)
91
+ ("^ *[\\.#%a-z0-9_]+\\([~=-] .*\\)" 1 font-lock-preprocessor-face prepend)
92
+ ("^ *[\\.#%a-z0-9_]+\\({[^}]+}\\)" 1 font-lock-preprocessor-face prepend)
93
+ ("^ *[\\.#%a-z0-9_]+\\(\\[[^]]+\\]\\)" 1 font-lock-preprocessor-face prepend)))
94
+
95
+ ;; Mode setup
96
+
97
+ (defvar haml-mode-syntax-table
98
+ (let ((table (make-syntax-table)))
99
+ (modify-syntax-entry ?: "." table)
100
+ (modify-syntax-entry ?_ "w" table)
101
+ table)
102
+ "Syntax table in use in haml-mode buffers.")
103
+
104
+ (defvar haml-mode-map
105
+ (let ((map (make-sparse-keymap)))
106
+ (define-key map [backspace] 'haml-electric-backspace)
107
+ (define-key map "\C-?" 'haml-electric-backspace)
108
+ (define-key map "\C-\M-f" 'haml-forward-sexp)
109
+ (define-key map "\C-\M-b" 'haml-backward-sexp)
110
+ (define-key map "\C-\M-u" 'haml-up-list)
111
+ (define-key map "\C-\M-d" 'haml-down-list)
112
+ (define-key map "\C-C\C-k" 'haml-kill-line-and-indent)
113
+ map))
114
+
115
+ ;;;###autoload
116
+ (define-derived-mode haml-mode fundamental-mode "Haml"
117
+ "Major mode for editing Haml files.
118
+
119
+ \\{haml-mode-map}"
120
+ (set-syntax-table haml-mode-syntax-table)
121
+ (set (make-local-variable 'indent-line-function) 'haml-indent-line)
122
+ (set (make-local-variable 'indent-region-function) 'haml-indent-region)
123
+ (set (make-local-variable 'forward-sexp-function) 'haml-forward-sexp)
124
+ (setq indent-tabs-mode nil)
125
+ (setq font-lock-defaults '((haml-font-lock-keywords) nil t)))
126
+
127
+ ;; Navigation
128
+
129
+ (defun haml-forward-through-whitespace (&optional backward)
130
+ "Move the point forward at least one line, until it reaches
131
+ either the end of the buffer or a line with no whitespace.
132
+
133
+ If `backward' is non-nil, move the point backward instead."
134
+ (let ((arg (if backward -1 1))
135
+ (endp (if backward 'bobp 'eobp)))
136
+ (loop do (forward-line arg)
137
+ while (and (not (funcall endp))
138
+ (looking-at "^[ \t]*$")))))
139
+
140
+ (defun haml-at-indent-p ()
141
+ "Returns whether or not the point is at the first
142
+ non-whitespace character in a line or whitespace preceding that
143
+ character."
144
+ (let ((opoint (point)))
145
+ (save-excursion
146
+ (back-to-indentation)
147
+ (>= (point) opoint))))
148
+
149
+ (defun haml-forward-sexp (&optional arg)
150
+ "Move forward across one nested expression.
151
+ With `arg', do it that many times. Negative arg -N means move
152
+ backward across N balanced expressions.
153
+
154
+ A sexp in Haml is defined as a line of Haml code as well as any
155
+ lines nested beneath it."
156
+ (interactive "p")
157
+ (or arg (setq arg 1))
158
+ (if (and (< arg 0) (not (haml-at-indent-p)))
159
+ (back-to-indentation)
160
+ (while (/= arg 0)
161
+ (let ((indent (current-indentation)))
162
+ (loop do (haml-forward-through-whitespace (< arg 0))
163
+ while (and (not (eobp))
164
+ (not (bobp))
165
+ (> (current-indentation) indent)))
166
+ (back-to-indentation)
167
+ (setq arg (+ arg (if (> arg 0) -1 1)))))))
168
+
169
+ (defun haml-backward-sexp (&optional arg)
170
+ "Move backward across one nested expression.
171
+ With ARG, do it that many times. Negative arg -N means move
172
+ forward across N balanced expressions.
173
+
174
+ A sexp in Haml is defined as a line of Haml code as well as any
175
+ lines nested beneath it."
176
+ (interactive "p")
177
+ (haml-forward-sexp (if arg (- arg) -1)))
178
+
179
+ (defun haml-up-list (&optional arg)
180
+ "Move out of one level of nesting.
181
+ With ARG, do this that many times."
182
+ (interactive "p")
183
+ (or arg (setq arg 1))
184
+ (while (> arg 0)
185
+ (let ((indent (current-indentation)))
186
+ (loop do (haml-forward-through-whitespace t)
187
+ while (and (not (bobp))
188
+ (>= (current-indentation) indent)))
189
+ (setq arg (- arg 1))))
190
+ (back-to-indentation))
191
+
192
+ (defun haml-down-list (&optional arg)
193
+ "Move down one level of nesting.
194
+ With ARG, do this that many times."
195
+ (interactive "p")
196
+ (or arg (setq arg 1))
197
+ (while (> arg 0)
198
+ (let ((indent (current-indentation)))
199
+ (haml-forward-through-whitespace)
200
+ (when (<= (current-indentation) indent)
201
+ (haml-forward-through-whitespace t)
202
+ (back-to-indentation)
203
+ (error "Nothing is nested beneath this line"))
204
+ (setq arg (- arg 1))))
205
+ (back-to-indentation))
206
+
207
+ (defun haml-mark-sexp-but-not-next-line ()
208
+ "Marks the next Haml sexp, but puts the mark at the end of the
209
+ last line of the sexp rather than the first non-whitespace
210
+ character of the next line."
211
+ (mark-sexp)
212
+ (set-mark
213
+ (save-excursion
214
+ (goto-char (mark))
215
+ (forward-line -1)
216
+ (end-of-line)
217
+ (point))))
218
+
219
+ ;; Indentation and electric keys
220
+
221
+ (defun haml-indent-p ()
222
+ "Returns true if the current line can have lines nested beneath it."
223
+ (loop for opener in haml-block-openers
224
+ if (looking-at opener) return t
225
+ finally return nil))
226
+
227
+ (defun haml-compute-indentation ()
228
+ "Calculate the maximum sensible indentation for the current line."
229
+ (save-excursion
230
+ (beginning-of-line)
231
+ (if (bobp) 0
232
+ (haml-forward-through-whitespace t)
233
+ (+ (current-indentation)
234
+ (if (funcall haml-indent-function) haml-indent-offset
235
+ 0)))))
236
+
237
+ (defun haml-indent-region (start end)
238
+ "Indent each nonblank line in the region.
239
+ This is done by indenting the first line based on
240
+ `haml-compute-indentation' and preserving the relative
241
+ indentation of the rest of the region.
242
+
243
+ If this command is used multiple times in a row, it will cycle
244
+ between possible indentations."
245
+ (save-excursion
246
+ (goto-char end)
247
+ (setq end (point-marker))
248
+ (goto-char start)
249
+ (let (this-line-column current-column
250
+ (next-line-column
251
+ (if (and (equal last-command this-command) (/= (current-indentation) 0))
252
+ (* (/ (- (current-indentation) 1) haml-indent-offset) haml-indent-offset)
253
+ (haml-compute-indentation))))
254
+ (while (< (point) end)
255
+ (setq this-line-column next-line-column
256
+ current-column (current-indentation))
257
+ ;; Delete whitespace chars at beginning of line
258
+ (delete-horizontal-space)
259
+ (unless (eolp)
260
+ (setq next-line-column (save-excursion
261
+ (loop do (forward-line 1)
262
+ while (and (not (eobp)) (looking-at "^[ \t]*$")))
263
+ (+ this-line-column
264
+ (- (current-indentation) current-column))))
265
+ ;; Don't indent an empty line
266
+ (unless (eolp) (indent-to this-line-column)))
267
+ (forward-line 1)))
268
+ (move-marker end nil)))
269
+
270
+ (defun haml-indent-line ()
271
+ "Indent the current line.
272
+ The first time this command is used, the line will be indented to the
273
+ maximum sensible indentation. Each immediately subsequent usage will
274
+ back-dent the line by `haml-indent-offset' spaces. On reaching column
275
+ 0, it will cycle back to the maximum sensible indentation."
276
+ (interactive "*")
277
+ (let ((ci (current-indentation))
278
+ (cc (current-column))
279
+ (need (haml-compute-indentation)))
280
+ (save-excursion
281
+ (beginning-of-line)
282
+ (delete-horizontal-space)
283
+ (if (and (equal last-command this-command) (/= ci 0))
284
+ (indent-to (* (/ (- ci 1) haml-indent-offset) haml-indent-offset))
285
+ (indent-to need)))
286
+ (if (< (current-column) (current-indentation))
287
+ (forward-to-indentation 0))))
288
+
289
+ (defun haml-reindent-region-by (n)
290
+ "Add N spaces to the beginning of each line in the region.
291
+ If N is negative, will remove the spaces instead. Assumes all
292
+ lines in the region have indentation >= that of the first line."
293
+ (let ((ci (current-indentation)))
294
+ (save-excursion
295
+ (replace-regexp (concat "^" (make-string ci ? ))
296
+ (make-string (max 0 (+ ci n)) ? )
297
+ nil (point) (mark)))))
298
+
299
+ (defun haml-electric-backspace (arg)
300
+ "Delete characters or back-dent the current line.
301
+ If invoked following only whitespace on a line, will back-dent
302
+ the line and all nested lines to the immediately previous
303
+ multiple of `haml-indent-offset' spaces.
304
+
305
+ Set `haml-backspace-backdents-nesting' to nil to just back-dent
306
+ the current line."
307
+ (interactive "*p")
308
+ (if (or (/= (current-indentation) (current-column))
309
+ (bolp)
310
+ (looking-at "^[ \t]+$"))
311
+ (backward-delete-char arg)
312
+ (let ((ci (current-column)))
313
+ (beginning-of-line)
314
+ (if haml-backspace-backdents-nesting
315
+ (haml-mark-sexp-but-not-next-line)
316
+ (set-mark (save-excursion (end-of-line) (point))))
317
+ (haml-reindent-region-by (* (- arg) haml-indent-offset))
318
+ (back-to-indentation)
319
+ (pop-mark))))
320
+
321
+ (defun haml-kill-line-and-indent ()
322
+ "Kill the current line, and re-indent all lines nested beneath it."
323
+ (interactive)
324
+ (beginning-of-line)
325
+ (haml-mark-sexp-but-not-next-line)
326
+ (kill-line 1)
327
+ (haml-reindent-region-by (* -1 haml-indent-offset)))
328
+
329
+ ;; Setup/Activation
330
+
331
+ (provide 'haml-mode)
@@ -0,0 +1,89 @@
1
+ ;;; sass-mode.el -- Major mode for editing Sass files
2
+ ;;; Written by Nathan Weizenbaum
3
+
4
+ ;;; Because Sass's indentation schema is similar
5
+ ;;; to that of YAML and Python, many indentation-related
6
+ ;;; functions are similar to those in yaml-mode and python-mode.
7
+
8
+ ;;; To install, save this somewhere and add the following to your .emacs file:
9
+ ;;;
10
+ ;;; (add-to-list 'load-path "/path/to/sass-mode.el")
11
+ ;;; (require 'sass-mode nil 't)
12
+ ;;; (add-to-list 'auto-mode-alist '("\\.sass$" . sass-mode))
13
+ ;;;
14
+
15
+ ;;; Code:
16
+
17
+ (require 'haml-mode)
18
+
19
+ ;; User definable variables
20
+
21
+ (defgroup sass nil
22
+ "Support for the Sass template language."
23
+ :group 'languages
24
+ :prefix "sass-")
25
+
26
+ (defcustom sass-mode-hook nil
27
+ "Hook run when entering Sass mode."
28
+ :type 'hook
29
+ :group 'sass)
30
+
31
+ (defcustom sass-indent-offset 2
32
+ "Amount of offset per level of indentation."
33
+ :type 'integer
34
+ :group 'sass)
35
+
36
+ (defvar sass-non-block-openers
37
+ '("^ *:[^ \t]+[ \t]+[^ \t]"
38
+ "^ *[^ \t:]+[ \t]*[=:][ \t]*[^ \t]")
39
+ "A list of regexps that match lines of Sass that couldn't have
40
+ text nested beneath them.")
41
+
42
+ ;; Font lock
43
+
44
+ (defconst sass-font-lock-keywords
45
+ '(("^ *\\(\t\\)" 1 'haml-tab-face)
46
+ ("^@.*" 0 font-lock-constant-face)
47
+ ("\\(\'[^']*'\\)" 1 font-lock-string-face append)
48
+ ("\\(\"[^\"]*\"\\)" 1 font-lock-string-face append)
49
+ ("\\(#[0-9a-fA-F]\\{3\\}\\{1,2\\}\\>\\)" 1 font-lock-string-face append)
50
+ ("\\(:[A-Za-z-]+\\|[A-Za-z-]+:\\)" 0 font-lock-constant-face append)
51
+ ("![a-z0-9_-]+" 0 font-lock-variable-name-face append)
52
+ ("^ *\\(/[/*].*\\)$" 1 font-lock-comment-face append)
53
+ ("\\(?:^\\|,\\) *\\(#[a-z0-9_-]+\/?\\)" 1 font-lock-keyword-face)
54
+ ("\\(?:^\\|,\\) *\\(\\.[a-z0-9_-]+\/?\\)" 1 font-lock-type-face)
55
+ ("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" 1 font-lock-function-name-face)
56
+ ("\\([=]\\)" 0 font-lock-preprocessor-face prepend)
57
+ ("\\(?:^\\|,\\) *\\(#[a-z0-9_]+\/?\\)" (1 font-lock-keyword-face)
58
+ ("\\.[a-z0-9_-]+" nil nil (0 font-lock-type-face)))
59
+ ("\\(?:^\\|,\\) *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face)
60
+ ("\\.[a-z0-9_-]+" nil nil (0 font-lock-type-face)))
61
+ ("\\(?:^\\|,\\) *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face)
62
+ ("\\#[a-z0-9_-]+" nil nil (0 font-lock-keyword-face)))
63
+ ("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face)
64
+ ("\\.[a-z0-9_-]+" nil nil (0 font-lock-type-face)))
65
+ ("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face)
66
+ ("\\#[a-z0-9_-]+" nil nil (0 font-lock-keyword-face)))))
67
+
68
+ ;; Constants
69
+
70
+ ;; Mode setup
71
+
72
+ ;;;###autoload
73
+ (define-derived-mode sass-mode haml-mode "Sass"
74
+ "Major mode for editing Sass files."
75
+ (set (make-local-variable 'haml-indent-function) 'sass-indent-p)
76
+ (set (make-local-variable 'haml-indent-offset) sass-indent-offset)
77
+ (setq font-lock-defaults '(sass-font-lock-keywords nil t)))
78
+
79
+ ;; Indentation
80
+
81
+ (defun sass-indent-p ()
82
+ "Returns true if the current line can have lines nested beneath it."
83
+ (loop for opener in sass-non-block-openers
84
+ unless (looking-at opener) return t
85
+ return nil))
86
+
87
+ ;; Setup/Activation
88
+
89
+ (provide 'sass-mode)
@@ -1,6 +1,8 @@
1
1
  dir = File.dirname(__FILE__)
2
2
  $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
3
3
 
4
+ require 'haml/version'
5
+
4
6
  # = Haml (XHTML Abstraction Markup Language)
5
7
  #
6
8
  # Haml is a markup language
@@ -994,52 +996,11 @@ $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
994
996
  # See also Whitespace Preservation, above.
995
997
  #
996
998
  module Haml
997
- # Returns a hash representing the version of Haml.
998
- # The :major, :minor, and :teeny keys have their respective numbers.
999
- # The :string key contains a human-readable string representation of the version.
1000
- # If Haml is checked out from Git,
1001
- # the :rev key will have the revision hash.
1002
- def self.version
1003
- return @@version if defined?(@@version)
1004
-
1005
- numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
1006
- @@version = {
1007
- :major => numbers[0],
1008
- :minor => numbers[1],
1009
- :teeny => numbers[2]
1010
- }
1011
- @@version[:string] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')
1012
-
1013
- if File.exists?(scope('REVISION'))
1014
- rev = File.read(scope('REVISION')).strip
1015
- rev = nil if rev !~ /^([a-f0-9]+|\(.*\))$/
1016
- end
1017
-
1018
- if rev.nil? && File.exists?(scope('.git/HEAD'))
1019
- rev = File.read(scope('.git/HEAD')).strip
1020
- if rev =~ /^ref: (.*)$/
1021
- rev = File.read(scope(".git/#{$1}")).strip
1022
- end
1023
- end
1024
999
 
1025
- if rev
1026
- @@version[:rev] = rev
1027
- unless rev[0] == ?(
1028
- @@version[:string] << "."
1029
- @@version[:string] << rev[0...7]
1030
- end
1031
- end
1032
-
1033
- @@version
1034
- end
1035
-
1036
- # Returns the path of file relative to the Haml root.
1037
- def self.scope(file) # :nodoc:
1038
- File.join(File.dirname(__FILE__), '..', file)
1039
- end
1000
+ extend Haml::Version
1040
1001
 
1041
1002
  # A string representing the version of Haml.
1042
- # A more fine-grained representation is generated by Haml.version.
1003
+ # A more fine-grained representation is available from Haml.version.
1043
1004
  VERSION = version[:string] unless defined?(Haml::VERSION)
1044
1005
 
1045
1006
  # This method is called by init.rb,
@@ -42,8 +42,8 @@ module Haml
42
42
  # SyntaxErrors have weird line reporting
43
43
  # when there's trailing whitespace,
44
44
  # which there is for Haml documents.
45
- return exception.message.scan(/:(\d+)/)[0] if exception.is_a?(::SyntaxError)
46
- exception.backtrace[0].scan(/:(\d+)/)[0]
45
+ return exception.message.scan(/:(\d+)/).first.first if exception.is_a?(::SyntaxError)
46
+ exception.backtrace[0].scan(/:(\d+)/).first.first
47
47
  end
48
48
 
49
49
  private
@@ -225,7 +225,8 @@ END
225
225
 
226
226
  def compile(precompiler, text)
227
227
  return if precompiler.options[:suppress_eval]
228
- src = ::ERB.new(text).src.sub(/^_erbout = '';/, "").gsub("\n", ';')
228
+ src = ::ERB.new(text).src.sub(/^#coding:.*?\n/, '').
229
+ sub(/^_erbout = '';/, "").gsub("\n", ';')
229
230
  precompiler.send(:push_silent, src)
230
231
  end
231
232
  end
@@ -269,10 +269,9 @@ module Haml
269
269
  min_tabs = min_tabs > tabs ? tabs : min_tabs
270
270
  end
271
271
 
272
- result = captured.map do |line|
272
+ captured.map do |line|
273
273
  line[min_tabs..-1]
274
- end
275
- result.to_s
274
+ end.join
276
275
  end
277
276
  end
278
277
 
@@ -79,7 +79,7 @@ module Haml
79
79
  class ::Hpricot::Doc
80
80
  def to_haml(tabs = 0)
81
81
  output = ''
82
- children.each { |child| output += child.to_haml(0) }
82
+ children.each { |child| output += child.to_haml(0) } if children
83
83
  output
84
84
  end
85
85
  end
@@ -148,13 +148,9 @@ module Haml
148
148
  output += haml_attributes if attributes.length > 0
149
149
  end
150
150
 
151
- output += "\n"
152
-
153
- self.children.each do |child|
154
- output += child.to_haml(tabs + 1)
151
+ (self.children || []).inject(output + "\n") do |output, child|
152
+ output + child.to_haml(tabs + 1)
155
153
  end
156
-
157
- output
158
154
  end
159
155
 
160
156
  private
@@ -11,5 +11,13 @@ module Haml
11
11
  def has?(attr, klass, method)
12
12
  klass.send("#{attr}s").include?(ruby1_8? ? method.to_s : method.to_sym)
13
13
  end
14
+
15
+ def each_char(str, &block)
16
+ if ruby1_8?
17
+ str.each_byte(&block)
18
+ else
19
+ str.each_char(&block)
20
+ end
21
+ end
14
22
  end
15
23
  end
@@ -0,0 +1,47 @@
1
+ module Haml
2
+ module Version
3
+ # Returns a hash representing the version of Haml.
4
+ # The :major, :minor, and :teeny keys have their respective numbers.
5
+ # The :string key contains a human-readable string representation of the version.
6
+ # If Haml is checked out from Git,
7
+ # the :rev key will have the revision hash.
8
+ def version
9
+ return @@version if defined?(@@version)
10
+
11
+ numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
12
+ @@version = {
13
+ :major => numbers[0],
14
+ :minor => numbers[1],
15
+ :teeny => numbers[2]
16
+ }
17
+ @@version[:string] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')
18
+
19
+ if File.exists?(scope('REVISION'))
20
+ rev = File.read(scope('REVISION')).strip
21
+ rev = nil if rev !~ /^([a-f0-9]+|\(.*\))$/
22
+ end
23
+
24
+ if (rev.nil? || rev == '(unknown)') && File.exists?(scope('.git/HEAD'))
25
+ rev = File.read(scope('.git/HEAD')).strip
26
+ if rev =~ /^ref: (.*)$/
27
+ rev = File.read(scope(".git/#{$1}")).strip
28
+ end
29
+ end
30
+
31
+ if rev
32
+ @@version[:rev] = rev
33
+ unless rev[0] == ?(
34
+ @@version[:string] << "."
35
+ @@version[:string] << rev[0...7]
36
+ end
37
+ end
38
+
39
+ @@version
40
+ end
41
+
42
+ # Returns the path of file relative to the Haml root.
43
+ def scope(file) # :nodoc:
44
+ File.expand_path File.join(File.dirname(__FILE__), '..', '..', file)
45
+ end
46
+ end
47
+ end
@@ -1,6 +1,8 @@
1
1
  dir = File.dirname(__FILE__)
2
2
  $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
3
3
 
4
+ require 'haml/version'
5
+
4
6
  # = Sass (Syntactically Awesome StyleSheets)
5
7
  #
6
8
  # Sass is a meta-language on top of CSS
@@ -857,7 +859,14 @@ $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
857
859
  # This defaults to the working directory and, in Rails or Merb,
858
860
  # whatever <tt>:template_location</tt> is.
859
861
  #
860
- module Sass; end
862
+ module Sass
863
+ extend Haml::Version
864
+
865
+ # A string representing the version of Sass.
866
+ # A more fine-grained representation is available from Sass.version.
867
+ VERSION = version[:string] unless defined?(Sass::VERSION)
868
+
869
+ end
861
870
 
862
871
  require 'sass/engine'
863
872
  require 'sass/plugin' if defined?(Merb::Plugins)
@@ -40,6 +40,8 @@ module Sass
40
40
  SECOND_ORDER = [:plus, :minus]
41
41
 
42
42
  class << self
43
+ include Haml::Util
44
+
43
45
  def parse(value, constants, line)
44
46
  begin
45
47
  operationalize(parenthesize(tokenize(value)), constants).to_s
@@ -68,7 +70,7 @@ module Sass
68
70
  ''
69
71
  end
70
72
 
71
- value.each_byte do |byte|
73
+ each_char(value) do |byte|
72
74
  unless escaped
73
75
  if byte == ESCAPE_CHAR
74
76
  escaped = true
@@ -492,7 +492,7 @@ HAML
492
492
  def test_compile_error
493
493
  render("a\nb\n- fee)\nc")
494
494
  rescue Exception => e
495
- assert_match(/^compile error\n\(test_compile_error\):3: syntax error/i, e.message)
495
+ assert_match(/\(test_compile_error\):3: syntax error/i, e.message)
496
496
  else
497
497
  assert(false,
498
498
  '"a\nb\n- fee)\nc" doesn\'t produce an exception!')
@@ -9,7 +9,6 @@ class ActionView::Base
9
9
  end
10
10
 
11
11
  class HelperTest < Test::Unit::TestCase
12
- include Haml::Helpers
13
12
  Post = Struct.new('Post', :body)
14
13
 
15
14
  def setup
@@ -28,14 +27,14 @@ class HelperTest < Test::Unit::TestCase
28
27
  end
29
28
 
30
29
  def test_flatten
31
- assert_equal("FooBar", flatten("FooBar"))
30
+ assert_equal("FooBar", Haml::Helpers.flatten("FooBar"))
32
31
 
33
- assert_equal("FooBar", flatten("Foo\rBar"))
32
+ assert_equal("FooBar", Haml::Helpers.flatten("Foo\rBar"))
34
33
 
35
- assert_equal("Foo&#x000A;Bar", flatten("Foo\nBar"))
34
+ assert_equal("Foo&#x000A;Bar", Haml::Helpers.flatten("Foo\nBar"))
36
35
 
37
36
  assert_equal("Hello&#x000A;World!&#x000A;YOU ARE FLAT?&#x000A;OMGZ!",
38
- flatten("Hello\nWorld!\nYOU ARE \rFLAT?\n\rOMGZ!"))
37
+ Haml::Helpers.flatten("Hello\nWorld!\nYOU ARE \rFLAT?\n\rOMGZ!"))
39
38
  end
40
39
 
41
40
  def test_list_of_should_render_correctly
@@ -52,11 +52,6 @@ This
52
52
 
53
53
  </ul>
54
54
  <div class='res'>178</div>
55
- <ul>
56
- <li>Foo</li>
57
- <li>Bar</li>
58
- <li>BAZ!</li>
59
- </ul>
60
55
  Text!
61
56
  Hello, World!
62
57
  How are you doing today?
@@ -31,7 +31,7 @@
31
31
  <li>f</li>
32
32
  </ul>
33
33
  <div class='of_divs_with_underscore' id='combo'>with this text</div>
34
- hello
34
+ foo
35
35
  <div class='footer'>
36
36
  <strong class='shout'>
37
37
  This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid.
@@ -36,7 +36,10 @@
36
36
  </div>
37
37
  <div class='foo'>
38
38
  13
39
- <textarea>&#x000A;a</textarea><textarea>&#x000A;b</textarea><textarea>&#x000A;c</textarea>
39
+ <textarea>
40
+ a
41
+ </textarea>
42
+ <textarea>&#x000A;a</textarea>
40
43
  </div>
41
44
  <div id='whitespace_test'>
42
45
  <div class='text_area_test_area'>
@@ -23,7 +23,7 @@
23
23
  "multiline " +
24
24
  "tags! " +
25
25
  "A pipe (|) even!" %>
26
- <%= [1, 2, 3].collect { |n| "PipesIgnored|" } %>
26
+ <%= [1, 2, 3].collect { |n| "PipesIgnored|" }.join %>
27
27
  <%= [1, 2, 3].collect { |n|
28
28
  n.to_s
29
29
  }.join("|") %>
@@ -41,8 +41,8 @@
41
41
  <li><%= a %>
42
42
  <% end %>
43
43
  <div class='of_divs_with_underscore' id='combo'><%= @should_eval = "with this text" %></div>
44
- <%= [ 104, 101, 108, 108, 111 ].map do |byte|
45
- byte.chr
44
+ <%= "foo".each_line do |line|
45
+ nil
46
46
  end %>
47
47
  <div class='footer'>
48
48
  <strong class='shout'>
@@ -20,7 +20,18 @@ module Haml::Helpers
20
20
  end
21
21
  end
22
22
 
23
+ class Egocentic
24
+ def method_missing(*args)
25
+ self
26
+ end
27
+ end
28
+
23
29
  class DummyController
30
+ attr_accessor :logger
31
+ def initialize
32
+ @logger = Egocentic.new
33
+ end
34
+
24
35
  def self.controller_path
25
36
  ''
26
37
  end
@@ -36,31 +47,36 @@ class TemplateTest < Test::Unit::TestCase
36
47
  TEMPLATES << 'partial_layout' unless ActionPack::VERSION::MAJOR < 2
37
48
 
38
49
  def setup
50
+ @base = create_base
51
+
52
+ # filters template uses :sass
53
+ Sass::Plugin.options.update(:line_comments => true, :style => :compact)
54
+ end
55
+
56
+ def create_base
39
57
  vars = { 'article' => Article.new, 'foo' => 'value one' }
40
58
 
41
59
  unless Haml::Util.has?(:instance_method, ActionView::Base, :finder)
42
- @base = ActionView::Base.new(TEMPLATE_PATH, vars)
60
+ base = ActionView::Base.new(TEMPLATE_PATH, vars)
43
61
  else
44
62
  # Rails 2.1.0
45
- @base = ActionView::Base.new([], vars)
46
- @base.finder.append_view_path(TEMPLATE_PATH)
63
+ base = ActionView::Base.new([], vars)
64
+ base.finder.append_view_path(TEMPLATE_PATH)
47
65
  end
48
66
 
49
- if Haml::Util.has?(:private_method, @base, :evaluate_assigns)
50
- @base.send(:evaluate_assigns)
67
+ if Haml::Util.has?(:private_method, base, :evaluate_assigns)
68
+ base.send(:evaluate_assigns)
51
69
  else
52
70
  # Rails 2.2
53
- @base.send(:_evaluate_assigns_and_ivars)
71
+ base.send(:_evaluate_assigns_and_ivars)
54
72
  end
55
73
 
56
74
  # This is used by form_for.
57
75
  # It's usually provided by ActionController::Base.
58
- def @base.protect_against_forgery?; false; end
59
-
60
- # filters template uses :sass
61
- Sass::Plugin.options.update(:line_comments => true, :style => :compact)
62
-
63
- @base.controller = DummyController.new
76
+ def base.protect_against_forgery?; false; end
77
+
78
+ base.controller = DummyController.new
79
+ base
64
80
  end
65
81
 
66
82
  def render(text)
@@ -148,7 +164,9 @@ class TemplateTest < Test::Unit::TestCase
148
164
  def test_haml_options
149
165
  Haml::Template.options = { :suppress_eval => true }
150
166
  assert_equal({ :suppress_eval => true }, Haml::Template.options)
167
+ old_base, @base = @base, create_base
151
168
  assert_renders_correctly("eval_suppressed")
169
+ @base = old_base
152
170
  Haml::Template.options = {}
153
171
  end
154
172
 
@@ -53,11 +53,6 @@
53
53
 
54
54
  .res= res
55
55
 
56
- :markdown
57
- * Foo
58
- * Bar
59
- * BAZ!
60
-
61
56
  = "Text!"
62
57
 
63
58
  - var = "Hello"
@@ -19,7 +19,7 @@
19
19
  "multiline " + |
20
20
  "tags! " + |
21
21
  "A pipe (|) even!" |
22
- = [1, 2, 3].collect { |n| "PipesIgnored|" }
22
+ = [1, 2, 3].collect { |n| "PipesIgnored|" }.join
23
23
  = [1, 2, 3].collect { |n| |
24
24
  n.to_s |
25
25
  }.join("|") |
@@ -36,7 +36,7 @@
36
36
  - ('a'..'f').each do |a|
37
37
  %li= a
38
38
  #combo.of_divs_with_underscore= @should_eval = "with this text"
39
- = [ 104, 101, 108, 108, 111 ].map do |byte|
40
- - byte.chr
39
+ = "foo".each_line do |line|
40
+ - nil
41
41
  .footer
42
42
  %strong.shout= "This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid. \nSo, I'm just making it *really* long. God, I hope this works"
@@ -19,7 +19,7 @@
19
19
  "multiline " + |
20
20
  "tags! " + |
21
21
  "A pipe (|) even!" |
22
- = [1, 2, 3].collect { |n| "PipesIgnored|" }
22
+ = [1, 2, 3].collect { |n| "PipesIgnored|" }.join
23
23
  = [1, 2, 3].collect { |n| |
24
24
  n.to_s |
25
25
  }.join("|") |
@@ -36,7 +36,7 @@
36
36
  - ('a'..'f').each do |a|
37
37
  %li= a
38
38
  #combo.of_divs_with_underscore= @should_eval = "with this text"
39
- = [ 104, 101, 108, 108, 111 ].map do |byte|
40
- - byte.chr
39
+ = "foo".each_line do |line|
40
+ - nil
41
41
  .footer
42
42
  %strong.shout= "This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid. \nSo, I'm just making it *really* long. God, I hope this works"
@@ -12,8 +12,8 @@
12
12
  %p~ "foo\nbar"
13
13
  .foo
14
14
  ~ 13
15
- ~ ['a', 'b', 'c'].map do |a|
16
- - "<textarea>\n#{a}\n</textarea>"
15
+ ~ "<textarea>\na\n</textarea>".each_line do |l|
16
+ - haml_concat l.strip
17
17
  #whitespace_test
18
18
  = test_partial "text_area", :value => "Oneline"
19
19
  = test_partial "text_area", :value => "Two\nlines"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-01-22 00:00:00 -08:00
13
+ date: 2009-02-13 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -61,6 +61,7 @@ files:
61
61
  - lib/haml/error.rb
62
62
  - lib/haml/template.rb
63
63
  - lib/haml/engine.rb
64
+ - lib/haml/version.rb
64
65
  - lib/haml/template
65
66
  - lib/haml/template/patch.rb
66
67
  - lib/haml/template/plugin.rb
@@ -184,6 +185,8 @@ files:
184
185
  - test/haml/engine_test.rb
185
186
  - test/test_helper.rb
186
187
  - test/rails
188
+ - extra/haml-mode.el
189
+ - extra/sass-mode.el
187
190
  - Rakefile
188
191
  - init.rb
189
192
  - FAQ