mack-haml 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/lib/gems.rb +13 -0
  2. data/lib/gems/haml-2.0.4/VERSION +1 -0
  3. data/lib/gems/haml-2.0.4/bin/css2sass +7 -0
  4. data/lib/gems/haml-2.0.4/bin/haml +9 -0
  5. data/lib/gems/haml-2.0.4/bin/html2haml +7 -0
  6. data/lib/gems/haml-2.0.4/bin/sass +8 -0
  7. data/lib/gems/haml-2.0.4/lib/haml.rb +1040 -0
  8. data/lib/gems/haml-2.0.4/lib/haml/buffer.rb +239 -0
  9. data/lib/gems/haml-2.0.4/lib/haml/engine.rb +265 -0
  10. data/lib/gems/haml-2.0.4/lib/haml/error.rb +22 -0
  11. data/lib/gems/haml-2.0.4/lib/haml/exec.rb +364 -0
  12. data/lib/gems/haml-2.0.4/lib/haml/filters.rb +275 -0
  13. data/lib/gems/haml-2.0.4/lib/haml/helpers.rb +453 -0
  14. data/lib/gems/haml-2.0.4/lib/haml/helpers/action_view_extensions.rb +45 -0
  15. data/lib/gems/haml-2.0.4/lib/haml/helpers/action_view_mods.rb +179 -0
  16. data/lib/gems/haml-2.0.4/lib/haml/html.rb +227 -0
  17. data/lib/gems/haml-2.0.4/lib/haml/precompiler.rb +805 -0
  18. data/lib/gems/haml-2.0.4/lib/haml/template.rb +51 -0
  19. data/lib/gems/haml-2.0.4/lib/haml/template/patch.rb +58 -0
  20. data/lib/gems/haml-2.0.4/lib/haml/template/plugin.rb +72 -0
  21. data/lib/gems/haml-2.0.4/lib/sass.rb +863 -0
  22. data/lib/gems/haml-2.0.4/lib/sass/constant.rb +214 -0
  23. data/lib/gems/haml-2.0.4/lib/sass/constant/color.rb +101 -0
  24. data/lib/gems/haml-2.0.4/lib/sass/constant/literal.rb +54 -0
  25. data/lib/gems/haml-2.0.4/lib/sass/constant/nil.rb +9 -0
  26. data/lib/gems/haml-2.0.4/lib/sass/constant/number.rb +87 -0
  27. data/lib/gems/haml-2.0.4/lib/sass/constant/operation.rb +30 -0
  28. data/lib/gems/haml-2.0.4/lib/sass/constant/string.rb +22 -0
  29. data/lib/gems/haml-2.0.4/lib/sass/css.rb +394 -0
  30. data/lib/gems/haml-2.0.4/lib/sass/engine.rb +466 -0
  31. data/lib/gems/haml-2.0.4/lib/sass/error.rb +35 -0
  32. data/lib/gems/haml-2.0.4/lib/sass/plugin.rb +169 -0
  33. data/lib/gems/haml-2.0.4/lib/sass/plugin/merb.rb +56 -0
  34. data/lib/gems/haml-2.0.4/lib/sass/plugin/rails.rb +24 -0
  35. data/lib/gems/haml-2.0.4/lib/sass/tree/attr_node.rb +53 -0
  36. data/lib/gems/haml-2.0.4/lib/sass/tree/comment_node.rb +20 -0
  37. data/lib/gems/haml-2.0.4/lib/sass/tree/directive_node.rb +46 -0
  38. data/lib/gems/haml-2.0.4/lib/sass/tree/node.rb +42 -0
  39. data/lib/gems/haml-2.0.4/lib/sass/tree/rule_node.rb +89 -0
  40. data/lib/gems/haml-2.0.4/lib/sass/tree/value_node.rb +16 -0
  41. data/lib/gems/haml-2.0.4/rails/init.rb +1 -0
  42. data/lib/mack-haml.rb +1 -0
  43. metadata +65 -16
data/lib/gems.rb ADDED
@@ -0,0 +1,13 @@
1
+ path = File.expand_path(File.join(File.dirname(__FILE__), 'gems'))
2
+ Gem.set_paths(path)
3
+
4
+ Dir.glob(File.join(path, '*')).each do |p|
5
+ full_gem_name = File.basename(p)
6
+ version = full_gem_name.match(/([\d\.?]+)/).to_s
7
+ gem_name = full_gem_name.gsub("-#{version}", '')
8
+ $:.unshift(File.join(p, 'lib'))
9
+ begin
10
+ gem gem_name, "~> #{version}"
11
+ rescue Gem::LoadError
12
+ end
13
+ end
@@ -0,0 +1 @@
1
+ 2.0.4
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/haml'
4
+ require 'haml/exec'
5
+
6
+ opts = Haml::Exec::CSS2Sass.new(ARGV)
7
+ opts.parse!
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # The command line Haml parser.
3
+
4
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
+ require 'haml'
6
+ require 'haml/exec'
7
+
8
+ opts = Haml::Exec::Haml.new(ARGV)
9
+ opts.parse!
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/haml'
4
+ require 'haml/exec'
5
+
6
+ opts = Haml::Exec::HTML2Haml.new(ARGV)
7
+ opts.parse!
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # The command line Sass parser.
3
+
4
+ require File.dirname(__FILE__) + '/../lib/haml'
5
+ require 'haml/exec'
6
+
7
+ opts = Haml::Exec::Sass.new(ARGV)
8
+ opts.parse!
@@ -0,0 +1,1040 @@
1
+ dir = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
3
+
4
+ # = Haml (XHTML Abstraction Markup Language)
5
+ #
6
+ # Haml is a markup language
7
+ # that's used to cleanly and simply describe the XHTML of any web document,
8
+ # without the use of inline code.
9
+ # Haml functions as a replacement
10
+ # for inline page templating systems such as PHP, ERB, and ASP.
11
+ # However, Haml avoids the need for explicitly coding XHTML into the template,
12
+ # because it is actually an abstract description of the XHTML,
13
+ # with some code to generate dynamic content.
14
+ #
15
+ # == Features
16
+ #
17
+ # * Whitespace active
18
+ # * Well-formatted markup
19
+ # * DRY
20
+ # * Follows CSS conventions
21
+ # * Integrates Ruby code
22
+ # * Implements Rails templates with the .haml extension
23
+ #
24
+ # == Using Haml
25
+ #
26
+ # Haml can be used in three ways:
27
+ # as a plugin for Ruby on Rails,
28
+ # as a standalone Ruby module,
29
+ # and as a command-line tool.
30
+ # The first step for all of these is to install the Haml gem:
31
+ #
32
+ # gem install haml
33
+ #
34
+ # To enable it as a Rails plugin,
35
+ # then run
36
+ #
37
+ # haml --rails path/to/rails/app
38
+ #
39
+ # Once it's installed, all view files with the ".html.haml" extension
40
+ # will be compiled using Haml.
41
+ #
42
+ # To run Haml from the commandline, just use
43
+ #
44
+ # haml input.haml output.html
45
+ #
46
+ # Use <tt>haml --help</tt> for full documentation.
47
+ #
48
+ # You can access instance variables in Haml templates
49
+ # the same way you do in ERb templates.
50
+ # Helper methods are also available in Haml templates.
51
+ # For example (this example uses Rails, but the principle for Merb is the same):
52
+ #
53
+ # # file: app/controllers/movies_controller.rb
54
+ #
55
+ # class MoviesController < ApplicationController
56
+ # def index
57
+ # @title = "Teen Wolf"
58
+ # end
59
+ # end
60
+ #
61
+ # -# file: app/views/movies/index.haml
62
+ #
63
+ # #content
64
+ # .title
65
+ # %h1= @title
66
+ # = link_to 'Home', home_url
67
+ #
68
+ # may be compiled to:
69
+ #
70
+ # <div id='content'>
71
+ # <div class='title'>
72
+ # <h1>Teen Wolf</h1>
73
+ # <a href='/'>Home</a>
74
+ # </div>
75
+ # </div>
76
+ #
77
+ # === Ruby Module
78
+ #
79
+ # Haml can also be used completely separately from Rails and ActionView.
80
+ # To do this, install the gem with RubyGems:
81
+ #
82
+ # gem install haml
83
+ #
84
+ # You can then use it by including the "haml" gem in Ruby code,
85
+ # and using Haml::Engine like so:
86
+ #
87
+ # engine = Haml::Engine.new("%p Haml code!")
88
+ # engine.render #=> "<p>Haml code!</p>\n"
89
+ #
90
+ # == Characters with meaning to Haml
91
+ #
92
+ # Various characters, when placed at a certain point in a line,
93
+ # instruct Haml to render different types of things.
94
+ #
95
+ # === XHTML Tags
96
+ #
97
+ # These characters render XHTML tags.
98
+ #
99
+ # ==== %
100
+ #
101
+ #
102
+ # The percent character is placed at the beginning of a line.
103
+ # It's followed immediately by the name of an element,
104
+ # then optionally by modifiers (see below), a space,
105
+ # and text to be rendered inside the element.
106
+ # It creates an element in the form of <tt><element></element></tt>.
107
+ # For example:
108
+ #
109
+ # %one
110
+ # %two
111
+ # %three Hey there
112
+ #
113
+ # is compiled to:
114
+ #
115
+ # <one>
116
+ # <two>
117
+ # <three>Hey there</three>
118
+ # </two>
119
+ # </one>
120
+ #
121
+ # Any string is a valid element name;
122
+ # Haml will automatically generate opening and closing tags for any element.
123
+ #
124
+ # ==== {}
125
+ #
126
+ # Brackets represent a Ruby hash
127
+ # that is used for specifying the attributes of an element.
128
+ # It is literally evaluated as a Ruby hash,
129
+ # so logic will work in it and local variables may be used.
130
+ # Quote characters within the attribute
131
+ # will be replaced by appropriate escape sequences.
132
+ # The hash is placed after the tag is defined.
133
+ # For example:
134
+ #
135
+ # %head{ :name => "doc_head" }
136
+ # %script{ 'type' => "text/" + "javascript",
137
+ # :src => "javascripts/script_#{2 + 7}" }
138
+ #
139
+ # is compiled to:
140
+ #
141
+ # <head name='doc_head'>
142
+ # <script src='javascripts/script_9' type='text/javascript'>
143
+ # </script>
144
+ # </head>
145
+ #
146
+ # ===== Attribute Methods
147
+ #
148
+ # A Ruby method call that returns a hash
149
+ # can be substituted for the hash contents.
150
+ # For example, Haml::Helpers defines the following method:
151
+ #
152
+ # def html_attrs(lang = 'en-US')
153
+ # {:xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang' => lang, :lang => lang}
154
+ # end
155
+ #
156
+ # This can then be used in Haml, like so:
157
+ #
158
+ # %html{html_attrs('fr-fr')}
159
+ #
160
+ # This is compiled to:
161
+ #
162
+ # <html lang='fr-fr' xml:lang='fr-fr' xmlns='http://www.w3.org/1999/xhtml'>
163
+ # </html>
164
+ #
165
+ # You can use as many such attribute methods as you want
166
+ # by separating them with commas,
167
+ # like a Ruby argument list.
168
+ # All the hashes will me merged together, from left to right.
169
+ # For example, if you defined
170
+ #
171
+ # def hash1
172
+ # {:bread => 'white', :filling => 'peanut butter and jelly'}
173
+ # end
174
+ #
175
+ # def hash2
176
+ # {:bread => 'whole wheat'}
177
+ # end
178
+ #
179
+ # then
180
+ #
181
+ # %sandwich{hash1, hash2, :delicious => true}/
182
+ #
183
+ # would compile to:
184
+ #
185
+ # <sandwich bread='whole wheat' delicious='true' filling='peanut butter and jelly' />
186
+ #
187
+ # Note that the Haml attributes list has the same syntax as a Ruby method call.
188
+ # This means that any attribute methods must come before the hash literal.
189
+ #
190
+ # ===== Boolean Attributes
191
+ #
192
+ # Some attributes, such as "checked" for <tt>input</tt> tags or "selected" for <tt>option</tt> tags,
193
+ # are "boolean" in the sense that their values don't matter -
194
+ # it only matters whether or not they're present.
195
+ # In HTML (but not XHTML), these attributes can be written as
196
+ #
197
+ # <input selected>
198
+ #
199
+ # To do this in Haml, just assign a Ruby true value to the attribute:
200
+ #
201
+ # %input{:selected => true}
202
+ #
203
+ # In XHTML, the only valid value for these attributes is the name of the attribute.
204
+ # Thus this will render in XHTML as
205
+ #
206
+ # <input selected='selected'>
207
+ #
208
+ # To set these attributes to false, simply assign them to a Ruby false value.
209
+ # In both XHTML and HTML
210
+ #
211
+ # %input{:selected => false}
212
+ #
213
+ # will just render as
214
+ #
215
+ # <input>
216
+ #
217
+ # ==== []
218
+ #
219
+ # Square brackets follow a tag definition and contain a Ruby object
220
+ # that is used to set the class and id of that tag.
221
+ # The class is set to the object's class
222
+ # (transformed to use underlines rather than camel case)
223
+ # and the id is set to the object's class, followed by its id.
224
+ # Because the id of an object is normally an obscure implementation detail,
225
+ # this is most useful for elements that represent instances of Models.
226
+ # Additionally, the second argument (if present) will be used as a prefix for
227
+ # both the id and class attributes.
228
+ # For example:
229
+ #
230
+ # # file: app/controllers/users_controller.rb
231
+ #
232
+ # def show
233
+ # @user = CrazyUser.find(15)
234
+ # end
235
+ #
236
+ # -# file: app/views/users/show.haml
237
+ #
238
+ # %div[@user, :greeting]
239
+ # %bar[290]/
240
+ # Hello!
241
+ #
242
+ # is compiled to:
243
+ #
244
+ # <div class='greeting_crazy_user' id='greeting_crazy_user_15'>
245
+ # <bar class='fixnum' id='fixnum_581' />
246
+ # Hello!
247
+ # </div>
248
+ #
249
+ # ==== /
250
+ #
251
+ # The forward slash character, when placed at the end of a tag definition,
252
+ # causes the tag to be self-closed.
253
+ # For example:
254
+ #
255
+ # %br/
256
+ # %meta{'http-equiv' => 'Content-Type', :content => 'text/html'}/
257
+ #
258
+ # is compiled to:
259
+ #
260
+ # <br />
261
+ # <meta http-equiv='Content-Type' content='text/html' />
262
+ #
263
+ # Some tags are automatically closed, as long as they have no content.
264
+ # +meta+, +img+, +link+, +script+, +br+, and +hr+ tags are closed by default.
265
+ # This list can be customized by setting the <tt>:autoclose</tt> option (see below).
266
+ # For example:
267
+ #
268
+ # %br
269
+ # %meta{'http-equiv' => 'Content-Type', :content => 'text/html'}
270
+ #
271
+ # is also compiled to:
272
+ #
273
+ # <br />
274
+ # <meta http-equiv='Content-Type' content='text/html' />
275
+ #
276
+ # ==== . and #
277
+ #
278
+ # The period and pound sign are borrowed from CSS.
279
+ # They are used as shortcuts to specify the <tt>class</tt>
280
+ # and <tt>id</tt> attributes of an element, respectively.
281
+ # Multiple class names can be specified in a similar way to CSS,
282
+ # by chaining the class names together with periods.
283
+ # They are placed immediately after the tag and before an attributes hash.
284
+ # For example:
285
+ #
286
+ # %div#things
287
+ # %span#rice Chicken Fried
288
+ # %p.beans{ :food => 'true' } The magical fruit
289
+ # %h1.class.otherclass#id La La La
290
+ #
291
+ # is compiled to:
292
+ #
293
+ # <div id='things'>
294
+ # <span id='rice'>Chicken Fried</span>
295
+ # <p class='beans' food='true'>The magical fruit</p>
296
+ # <h1 class='class otherclass' id='id'>La La La</h1>
297
+ # </div>
298
+ #
299
+ # And,
300
+ #
301
+ # #content
302
+ # .articles
303
+ # .article.title
304
+ # Doogie Howser Comes Out
305
+ # .article.date
306
+ # 2006-11-05
307
+ # .article.entry
308
+ # Neil Patrick Harris would like to dispel any rumors that he is straight
309
+ #
310
+ # is compiled to:
311
+ #
312
+ # <div id='content'>
313
+ # <div class='articles'>
314
+ # <div class='article title'>Doogie Howser Comes Out</div>
315
+ # <div class='article date'>2006-11-05</div>
316
+ # <div class='article entry'>
317
+ # Neil Patrick Harris would like to dispel any rumors that he is straight
318
+ # </div>
319
+ # </div>
320
+ # </div>
321
+ #
322
+ # ==== Implicit Div Elements
323
+ #
324
+ # Because the div element is used so often, it is the default element.
325
+ # If you only define a class and/or id using the <tt>.</tt> or <tt>#</tt> syntax,
326
+ # a div element is automatically used.
327
+ # For example:
328
+ #
329
+ # #collection
330
+ # .item
331
+ # .description What a cool item!
332
+ #
333
+ # is the same as:
334
+ #
335
+ # %div{:id => collection}
336
+ # %div{:class => 'item'}
337
+ # %div{:class => 'description'} What a cool item!
338
+ #
339
+ # and is compiled to:
340
+ #
341
+ # <div id='collection'>
342
+ # <div class='item'>
343
+ # <div class='description'>What a cool item!</div>
344
+ # </div>
345
+ # </div>
346
+ #
347
+ # ==== > and <
348
+ #
349
+ # <tt>></tt> and <tt><</tt> give you more control over the whitespace near a tag.
350
+ # <tt>></tt> will remove all whitespace surrounding a tag,
351
+ # while <tt><</tt> will remove all whitespace immediately within a tag.
352
+ # You can think of them as alligators eating the whitespace:
353
+ # <tt>></tt> faces out of the tag and eats the whitespace on the outside,
354
+ # and <tt><</tt> faces into the tag and eats the whitespace on the inside.
355
+ # They're placed at the end of a tag definition,
356
+ # after class, id, and attribute declarations
357
+ # but before <tt>/</tt> or <tt>=</tt>.
358
+ # For example:
359
+ #
360
+ # %blockquote<
361
+ # %div
362
+ # Foo!
363
+ #
364
+ # is compiled to:
365
+ #
366
+ # <blockquote><div>
367
+ # Foo!
368
+ # </div></blockquote>
369
+ #
370
+ # And:
371
+ #
372
+ # %img
373
+ # %img>
374
+ # %img
375
+ #
376
+ # is compiled to:
377
+ #
378
+ # <img /><img /><img />
379
+ #
380
+ # And:
381
+ #
382
+ # %p<= "Foo\nBar"
383
+ #
384
+ # is compiled to:
385
+ #
386
+ # <p>Foo
387
+ # Bar</p>
388
+ #
389
+ # And finally:
390
+ #
391
+ # %img
392
+ # %pre><
393
+ # foo
394
+ # bar
395
+ # %img
396
+ #
397
+ # is compiled to:
398
+ #
399
+ # <img /><pre>foo
400
+ # bar</pre><img />
401
+ #
402
+ # ==== =
403
+ #
404
+ # <tt>=</tt> is placed at the end of a tag definition,
405
+ # after class, id, and attribute declarations.
406
+ # It's just a shortcut for inserting Ruby code into an element.
407
+ # It works the same as <tt>=</tt> without a tag:
408
+ # it inserts the result of the Ruby code into the template.
409
+ # However, if the result is short enough,
410
+ # it is displayed entirely on one line.
411
+ # For example:
412
+ #
413
+ # %p= "hello"
414
+ #
415
+ # is not quite the same as:
416
+ #
417
+ # %p
418
+ # = "hello"
419
+ #
420
+ # It's compiled to:
421
+ #
422
+ # <p>hello</p>
423
+ #
424
+ # ==== ~
425
+ #
426
+ # ~ works just like =, except that it runs Haml::Helpers#find_and_preserve on its input.
427
+ # For example,
428
+ #
429
+ # ~ "Foo\n<pre>Bar\nBaz</pre>"
430
+ #
431
+ # is the same as:
432
+ #
433
+ # = find_and_preserve("Foo\n<pre>Bar\nBaz</pre>")
434
+ #
435
+ # and is compiled to:
436
+ #
437
+ # Foo
438
+ # <pre>Bar&#x000A;Baz</pre>
439
+ #
440
+ # See also Whitespace Preservation, below.
441
+ #
442
+ # === XHTML Helpers
443
+ #
444
+ # ==== No Special Character
445
+ #
446
+ # If no special character appears at the beginning of a line,
447
+ # the line is rendered as plain text.
448
+ # For example:
449
+ #
450
+ # %gee
451
+ # %whiz
452
+ # Wow this is cool!
453
+ #
454
+ # is compiled to:
455
+ #
456
+ # <gee>
457
+ # <whiz>
458
+ # Wow this is cool!
459
+ # </whiz>
460
+ # </gee>
461
+ #
462
+ # ==== !!!
463
+ #
464
+ # When describing XHTML documents with Haml,
465
+ # you can have a document type or XML prolog generated automatically
466
+ # by including the characters <tt>!!!</tt>.
467
+ # For example:
468
+ #
469
+ # !!! XML
470
+ # !!!
471
+ # %html
472
+ # %head
473
+ # %title Myspace
474
+ # %body
475
+ # %h1 I am the international space station
476
+ # %p Sign my guestbook
477
+ #
478
+ # is compiled to:
479
+ #
480
+ # <?xml version='1.0' encoding='utf-8' ?>
481
+ # <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
482
+ # <html>
483
+ # <head>
484
+ # <title>Myspace</title>
485
+ # </head>
486
+ # <body>
487
+ # <h1>I am the international space station</h1>
488
+ # <p>Sign my guestbook</p>
489
+ # </body>
490
+ # </html>
491
+ #
492
+ # You can also specify the version and type of XHTML after the <tt>!!!</tt>.
493
+ # XHTML 1.0 Strict, Transitional, and Frameset and XHTML 1.1 are supported.
494
+ # The default version is 1.0 and the default type is Transitional.
495
+ # For example:
496
+ #
497
+ # !!! 1.1
498
+ #
499
+ # is compiled to:
500
+ #
501
+ # <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
502
+ #
503
+ # and
504
+ #
505
+ # !!! Strict
506
+ #
507
+ # is compiled to:
508
+ #
509
+ # <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
510
+ #
511
+ # If you're not using the UTF-8 character set for your document,
512
+ # you can specify which encoding should appear
513
+ # in the XML prolog in a similar way.
514
+ # For example:
515
+ #
516
+ # !!! XML iso-8859-1
517
+ #
518
+ # is compiled to:
519
+ #
520
+ # <?xml version='1.0' encoding='iso-8859-1' ?>
521
+ #
522
+ # ==== /
523
+ #
524
+ # The forward slash character, when placed at the beginning of a line,
525
+ # wraps all text after it in an HTML comment.
526
+ # For example:
527
+ #
528
+ # %peanutbutterjelly
529
+ # / This is the peanutbutterjelly element
530
+ # I like sandwiches!
531
+ #
532
+ # is compiled to:
533
+ #
534
+ # <peanutbutterjelly>
535
+ # <!-- This is the peanutbutterjelly element -->
536
+ # I like sandwiches!
537
+ # </peanutbutterjelly>
538
+ #
539
+ # The forward slash can also wrap indented sections of code. For example:
540
+ #
541
+ # /
542
+ # %p This doesn't render...
543
+ # %div
544
+ # %h1 Because it's commented out!
545
+ #
546
+ # is compiled to:
547
+ #
548
+ # <!--
549
+ # <p>This doesn't render...</p>
550
+ # <div>
551
+ # <h1>Because it's commented out!</h1>
552
+ # </div>
553
+ # -->
554
+ #
555
+ # You can also use Internet Explorer conditional comments
556
+ # (about)[http://www.quirksmode.org/css/condcom.html]
557
+ # by enclosing the condition in square brackets after the <tt>/</tt>.
558
+ # For example:
559
+ #
560
+ # /[if IE]
561
+ # %a{ :href => 'http://www.mozilla.com/en-US/firefox/' }
562
+ # %h1 Get Firefox
563
+ #
564
+ # is compiled to:
565
+ #
566
+ # <!--[if IE]>
567
+ # <a href='http://www.mozilla.com/en-US/firefox/'>
568
+ # <h1>Get Firefox</h1>
569
+ # </a>
570
+ # <![endif]-->
571
+ #
572
+ # ==== \
573
+ #
574
+ # The backslash character escapes the first character of a line,
575
+ # allowing use of otherwise interpreted characters as plain text.
576
+ # For example:
577
+ #
578
+ # %title
579
+ # = @title
580
+ # \- MySite
581
+ #
582
+ # is compiled to:
583
+ #
584
+ # <title>
585
+ # MyPage
586
+ # - MySite
587
+ # </title>
588
+ #
589
+ # ==== |
590
+ #
591
+ # The pipe character designates a multiline string.
592
+ # It's placed at the end of a line
593
+ # and means that all following lines that end with <tt>|</tt>
594
+ # will be evaluated as though they were on the same line.
595
+ # For example:
596
+ #
597
+ # %whoo
598
+ # %hoo I think this might get |
599
+ # pretty long so I should |
600
+ # probably make it |
601
+ # multiline so it doesn't |
602
+ # look awful. |
603
+ # %p This is short.
604
+ #
605
+ # is compiled to:
606
+ #
607
+ # <whoo>
608
+ # <hoo>
609
+ # I think this might get pretty long so I should probably make it multiline so it doesn't look awful.
610
+ # </hoo>
611
+ # <p>This is short</p>
612
+ # </whoo>
613
+ #
614
+ # ==== :
615
+ #
616
+ # The colon character designates a filter.
617
+ # This allows you to pass an indented block of text as input
618
+ # to another filtering program and add the result to the output of Haml.
619
+ # The syntax is simply a colon followed by the name of the filter.
620
+ # For example,
621
+ #
622
+ # %p
623
+ # :markdown
624
+ # Textile
625
+ # =======
626
+ #
627
+ # Hello, *World*
628
+ #
629
+ # is compiled to
630
+ #
631
+ # <p>
632
+ # <h1>Textile</h1>
633
+ #
634
+ # <p>Hello, <em>World</em></p>
635
+ # </p>
636
+ #
637
+ # Filters can have Ruby code interpolated, like with ==.
638
+ # For example,
639
+ #
640
+ # - flavor = "raspberry"
641
+ # #content
642
+ # :textile
643
+ # I *really* prefer _#{h flavor}_ jam.
644
+ #
645
+ # is compiled to
646
+ #
647
+ # <div id='content'>
648
+ # <p>I <strong>really</strong> prefer <em>raspberry</em> jam.</p>
649
+ # </div>
650
+ #
651
+ # Haml has the following filters defined:
652
+ #
653
+ # [plain] Does not parse the filtered text.
654
+ # This is useful for large blocks of text without HTML tags,
655
+ # when you don't want lines starting with <tt>.</tt> or <tt>-</tt>
656
+ # to be parsed.
657
+ #
658
+ # [javascript] Surrounds the filtered text with <script> and CDATA tags.
659
+ # Useful for including inline Javascript.
660
+ #
661
+ # [escaped] Works the same as plain, but HTML-escapes the text
662
+ # before placing it in the document.
663
+ #
664
+ # [ruby] Parses the filtered text with the normal Ruby interpreter.
665
+ # All output sent to <tt>$stdout</tt>, like with +puts+,
666
+ # is output into the Haml document.
667
+ # Not available if the <tt>suppress_eval</tt> option is set to true.
668
+ # The Ruby code is evaluated in the same context as the Haml template.
669
+ #
670
+ # [preserve] Inserts the filtered text into the template with whitespace preserved.
671
+ # <tt>preserve</tt>d blocks of text aren't indented,
672
+ # and newlines are replaced with the HTML escape code for newlines,
673
+ # to preserve nice-looking output.
674
+ # See also Whitespace Preservation, below.
675
+ #
676
+ # [erb] Parses the filtered text with ERB, like an RHTML template.
677
+ # Not available if the <tt>suppress_eval</tt> option is set to true.
678
+ # Embedded Ruby code is evaluated in the same context as the Haml template.
679
+ #
680
+ # [sass] Parses the filtered text with Sass to produce CSS output.
681
+ #
682
+ # [textile] Parses the filtered text with Textile (http://www.textism.com/tools/textile).
683
+ # Only works if RedCloth is installed.
684
+ #
685
+ # [markdown] Parses the filtered text with Markdown (http://daringfireball.net/projects/markdown).
686
+ # Only works if RDiscount, RPeg-Markdown, Maruku, or BlueCloth are installed.
687
+ #
688
+ # [maruku] Parses the filtered text with Maruku, which has some non-standard extensions to Markdown.
689
+ #
690
+ # You can also define your own filters (see Haml::Filters).
691
+ #
692
+ # === Ruby evaluators
693
+ #
694
+ # ==== =
695
+ #
696
+ # The equals character is followed by Ruby code,
697
+ # which is evaluated and the output inserted into the document as plain text.
698
+ # For example:
699
+ #
700
+ # %p
701
+ # = ['hi', 'there', 'reader!'].join " "
702
+ # = "yo"
703
+ #
704
+ # is compiled to:
705
+ #
706
+ # <p>
707
+ # hi there reader!
708
+ # yo
709
+ # </p>
710
+ #
711
+ # If the <tt>:escape_html</tt> option is set, <tt>=</tt> will sanitize any
712
+ # HTML-sensitive characters generated by the script. For example:
713
+ #
714
+ # = '<script>alert("I\'m evil!");</script>'
715
+ #
716
+ # would be compiled to
717
+ #
718
+ # &lt;script&gt;alert(&quot;I'm evil!&quot;);&lt;/script&gt;
719
+ #
720
+ # ==== -
721
+ #
722
+ # The hyphen character makes the text following it into "silent script":
723
+ # Ruby script that is evaluated, but not output.
724
+ #
725
+ # <b>It is not recommended that you use this widely;
726
+ # almost all processing code and logic should be restricted
727
+ # to the Controller, the Helper, or partials.</b>
728
+ #
729
+ # For example:
730
+ #
731
+ # - foo = "hello"
732
+ # - foo << " there"
733
+ # - foo << " you!"
734
+ # %p= foo
735
+ #
736
+ # is compiled to:
737
+ #
738
+ # <p>
739
+ # hello there you!
740
+ # </p>
741
+ #
742
+ # ==== ==
743
+ #
744
+ # Two equals characters interpolates Ruby code into plain text,
745
+ # similarly to Ruby string interpolation.
746
+ # For example,
747
+ #
748
+ # %p== This is #{h quality} cake!
749
+ #
750
+ # is the same as
751
+ #
752
+ # %p= "This is #{h quality} cake!"
753
+ #
754
+ # and might compile to
755
+ #
756
+ # <p>This is scrumptious cake!</p>
757
+ #
758
+ # Backslashes can be used to escape "#{" strings,
759
+ # but they don't act as escapes anywhere else in the string.
760
+ # For example:
761
+ #
762
+ # %p
763
+ # == \\ Look at \\#{h word} lack of backslash: \#{foo}
764
+ #
765
+ # might compile to
766
+ #
767
+ # <p>
768
+ # \\ Look at \yon lack of backslash: #{foo}
769
+ # </p>
770
+ #
771
+ # ==== &=
772
+ #
773
+ # An ampersand followed by one or two equals characters
774
+ # evaluates Ruby code just like the equals without the ampersand,
775
+ # but sanitizes any HTML-sensitive characters in the result of the code.
776
+ # For example:
777
+ #
778
+ # &= "I like cheese & crackers"
779
+ #
780
+ # compiles to
781
+ #
782
+ # I like cheese &amp; crackers
783
+ #
784
+ # If the <tt>:escape_html</tt> option is set,
785
+ # &= behaves identically to =.
786
+ #
787
+ # ==== !=
788
+ #
789
+ # An exclamation mark followed by one or two equals characters
790
+ # evaluates Ruby code just like the equals would,
791
+ # but never sanitizes the HTML.
792
+ #
793
+ # By default, the single equals doesn't sanitize HTML either.
794
+ # However, if the <tt>:escape_html</tt> option is set, = will sanitize the HTML, but != still won't.
795
+ # For example, if <tt>:escape_html</tt> is set:
796
+ #
797
+ # = "I feel <strong>!"
798
+ # != "I feel <strong>!"
799
+ #
800
+ # compiles to
801
+ #
802
+ # I feel &lt;strong&gt;!
803
+ # I feel <strong>!
804
+ #
805
+ # ===== Blocks
806
+ #
807
+ # Ruby blocks, like XHTML tags, don't need to be explicitly closed in Haml.
808
+ # Rather, they're automatically closed, based on indentation.
809
+ # A block begins whenever the indentation is increased
810
+ # after a silent script command.
811
+ # It ends when the indentation decreases
812
+ # (as long as it's not an +else+ clause or something similar).
813
+ # For example:
814
+ #
815
+ # - (42...47).each do |i|
816
+ # %p= i
817
+ # %p See, I can count!
818
+ #
819
+ # is compiled to:
820
+ #
821
+ # <p>
822
+ # 42
823
+ # </p>
824
+ # <p>
825
+ # 43
826
+ # </p>
827
+ # <p>
828
+ # 44
829
+ # </p>
830
+ # <p>
831
+ # 45
832
+ # </p>
833
+ # <p>
834
+ # 46
835
+ # </p>
836
+ #
837
+ # Another example:
838
+ #
839
+ # %p
840
+ # - case 2
841
+ # - when 1
842
+ # = "1!"
843
+ # - when 2
844
+ # = "2?"
845
+ # - when 3
846
+ # = "3."
847
+ #
848
+ # is compiled to:
849
+ #
850
+ # <p>
851
+ # 2?
852
+ # </p>
853
+ #
854
+ # ==== -#
855
+ #
856
+ # The hyphen followed immediately by the pound sign
857
+ # signifies a silent comment.
858
+ # Any text following this isn't rendered in the resulting document
859
+ # at all.
860
+ #
861
+ # For example:
862
+ #
863
+ # %p foo
864
+ # -# This is a comment
865
+ # %p bar
866
+ #
867
+ # is compiled to:
868
+ #
869
+ # <p>foo</p>
870
+ # <p>bar</p>
871
+ #
872
+ # You can also nest text beneath a silent comment.
873
+ # None of this text will be rendered.
874
+ # For example:
875
+ #
876
+ # %p foo
877
+ # -#
878
+ # This won't be displayed
879
+ # Nor will this
880
+ # %p bar
881
+ #
882
+ # is compiled to:
883
+ #
884
+ # <p>foo</p>
885
+ # <p>bar</p>
886
+ #
887
+ # == Other Useful Things
888
+ #
889
+ # === Whitespace Preservation
890
+ #
891
+ # Sometimes you don't want Haml to indent all your text.
892
+ # For example, tags like +pre+ and +textarea+ are whitespace-sensitive;
893
+ # indenting the text makes them render wrong.
894
+ #
895
+ # Haml deals with this by "preserving" newlines before they're put into the document --
896
+ # converting them to the XHTML whitespace escape code, <tt>&#x000A;</tt>.
897
+ # Then Haml won't try to re-format the indentation.
898
+ #
899
+ # Literal +textarea+ and +pre+ tags automatically preserve their content.
900
+ # Dynamically can't be caught automatically,
901
+ # and so should be passed through Haml::Helpers#find_and_preserve or the <tt>~</tt> command,
902
+ # which has the same effect (see above).
903
+ #
904
+ # Blocks of literal text can be preserved using the :preserve filter (see above).
905
+ #
906
+ # === Helpers
907
+ #
908
+ # Haml offers a bunch of helpers that are useful
909
+ # for doing stuff like preserving whitespace,
910
+ # creating nicely indented output for user-defined helpers,
911
+ # and other useful things.
912
+ # The helpers are all documented in the Haml::Helpers and Haml::Helpers::ActionViewExtensions modules.
913
+ #
914
+ # === Haml Options
915
+ #
916
+ # Options can be set by setting the <tt>Haml::Template.options</tt> hash
917
+ # in <tt>environment.rb</tt> in Rails...
918
+ #
919
+ # Haml::Template.options[:format] = :html5
920
+ #
921
+ # ...or by setting the <tt>Merb::Plugin.config[:haml]</tt> hash in <tt>init.rb</tt> in Merb...
922
+ #
923
+ # Merb::Plugin.config[:haml][:format] = :html5
924
+ #
925
+ # ...or by passing an options hash to Haml::Engine.new.
926
+ # Available options are:
927
+ #
928
+ # [<tt>:format</tt>] Determines the output format. The default is :xhtml.
929
+ # Other options are :html4 and :html5, which are
930
+ # identical to :xhtml except there are no self-closing tags,
931
+ # XML prolog is ignored and correct DOCTYPEs are generated.
932
+ #
933
+ # [<tt>:escape_html</tt>] Sets whether or not to escape HTML-sensitive characters in script.
934
+ # If this is true, = behaves like &=;
935
+ # otherwise, it behaves like !=.
936
+ # Note that if this is set, != should be used for yielding to subtemplates
937
+ # and rendering partials.
938
+ # Defaults to false.
939
+ #
940
+ # [<tt>:suppress_eval</tt>] Whether or not attribute hashes and Ruby scripts
941
+ # designated by <tt>=</tt> or <tt>~</tt> should be
942
+ # evaluated. If this is true, said scripts are
943
+ # rendered as empty strings. Defaults to false.
944
+ #
945
+ # [<tt>:attr_wrapper</tt>] The character that should wrap element attributes.
946
+ # This defaults to <tt>'</tt> (an apostrophe). Characters
947
+ # of this type within the attributes will be escaped
948
+ # (e.g. by replacing them with <tt>&apos;</tt>) if
949
+ # the character is an apostrophe or a quotation mark.
950
+ #
951
+ # [<tt>:filename</tt>] The name of the Haml file being parsed.
952
+ # This is only used as information when exceptions are raised.
953
+ # This is automatically assigned when working through ActionView,
954
+ # so it's really only useful for the user to assign
955
+ # when dealing with Haml programatically.
956
+ #
957
+ # [<tt>:line</tt>] The line offset of the Haml template being parsed.
958
+ # This is useful for inline templates,
959
+ # similar to the last argument to Kernel#eval.
960
+ #
961
+ # [<tt>:autoclose</tt>] A list of tag names that should be automatically self-closed
962
+ # if they have no content.
963
+ # Defaults to <tt>['meta', 'img', 'link', 'br', 'hr', 'input', 'area', 'param', 'col', 'base']</tt>.
964
+ #
965
+ # [<tt>:preserve</tt>] A list of tag names that should automatically have their newlines preserved
966
+ # using the Haml::Helpers#preserve helper.
967
+ # This means that any content given on the same line as the tag will be preserved.
968
+ # For example:
969
+ #
970
+ # %textarea= "Foo\nBar"
971
+ #
972
+ # compiles to:
973
+ #
974
+ # <textarea>Foo&&#x000A;Bar</textarea>
975
+ #
976
+ # Defaults to <tt>['textarea', 'pre']</tt>.
977
+ #
978
+ # See also Whitespace Preservation, above.
979
+ #
980
+ module Haml
981
+ # Returns a hash representing the version of Haml.
982
+ # The :major, :minor, and :teeny keys have their respective numbers.
983
+ # The :string key contains a human-readable string representation of the version.
984
+ # If Haml is checked out from Git,
985
+ # the :rev key will have the revision hash.
986
+ def self.version
987
+ return @@version if defined?(@@version)
988
+
989
+ numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
990
+ @@version = {
991
+ :major => numbers[0],
992
+ :minor => numbers[1],
993
+ :teeny => numbers[2]
994
+ }
995
+ @@version[:string] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')
996
+
997
+ if File.exists?(scope('REVISION'))
998
+ rev = File.read(scope('REVISION')).strip
999
+ rev = nil if rev !~ /^([a-f0-9]+|\(.*\))$/
1000
+ end
1001
+
1002
+ if rev.nil? && File.exists?(scope('.git/HEAD'))
1003
+ rev = File.read(scope('.git/HEAD')).strip
1004
+ if rev =~ /^ref: (.*)$/
1005
+ rev = File.read(scope(".git/#{$1}")).strip
1006
+ end
1007
+ end
1008
+
1009
+ if rev
1010
+ @@version[:rev] = rev
1011
+ unless rev[0] == ?(
1012
+ @@version[:string] << "."
1013
+ @@version[:string] << rev[0...7]
1014
+ end
1015
+ end
1016
+
1017
+ @@version
1018
+ end
1019
+
1020
+ # Returns the path of file relative to the Haml root.
1021
+ def self.scope(file) # :nodoc:
1022
+ File.join(File.dirname(__FILE__), '..', file)
1023
+ end
1024
+
1025
+ # A string representing the version of Haml.
1026
+ # A more fine-grained representation is generated by Haml.version.
1027
+ VERSION = version[:string] unless defined?(Haml::VERSION)
1028
+
1029
+ # This method is called by init.rb,
1030
+ # which is run by Rails on startup.
1031
+ # We use it rather than putting stuff straight into init.rb
1032
+ # so we can change the initialization behavior
1033
+ # without modifying the file itself.
1034
+ def self.init_rails(binding)
1035
+ # No &method here for Rails 2.1 compatibility
1036
+ %w[haml/template sass sass/plugin].each {|f| require f}
1037
+ end
1038
+ end
1039
+
1040
+ require 'haml/engine'