honkster-haml 2.1.0

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