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