haml-edge 2.1.30 → 2.1.32

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/lib/haml.rb CHANGED
@@ -3,1041 +3,16 @@ $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
3
3
 
4
4
  require 'haml/version'
5
5
 
6
- # # Haml (XHTML Abstraction Markup Language)
6
+ # The module that contains everything Haml-related:
7
7
  #
8
- # Haml is a markup language
9
- # that's used to cleanly and simply describe the XHTML of any web document,
10
- # without the use of inline code.
11
- # Haml functions as a replacement
12
- # for inline page templating systems such as PHP, ERB, and ASP.
13
- # However, Haml avoids the need for explicitly coding XHTML into the template,
14
- # because it is actually an abstract description of the XHTML,
15
- # with some code to generate dynamic content.
16
- #
17
- # ## Features
18
- #
19
- # * Whitespace active
20
- # * Well-formatted markup
21
- # * DRY
22
- # * Follows CSS conventions
23
- # * Integrates Ruby code
24
- # * Implements Rails templates with the .haml extension
25
- #
26
- # ## Using Haml
27
- #
28
- # Haml can be used in three ways:
29
- # as a plugin for Ruby on Rails,
30
- # as a standalone Ruby module,
31
- # and as a command-line tool.
32
- # The first step for all of these is to install the Haml gem:
33
- #
34
- # gem install haml
35
- #
36
- # To enable it as a Rails plugin,
37
- # then run
38
- #
39
- # haml --rails path/to/rails/app
40
- #
41
- # Once it's installed, all view files with the `".html.haml"` extension
42
- # will be compiled using Haml.
43
- #
44
- # To run Haml from the command line, just use
45
- #
46
- # haml input.haml output.html
47
- #
48
- # Use `haml --help` for full documentation.
49
- #
50
- # You can access instance variables in Haml templates
51
- # the same way you do in ERB templates.
52
- # Helper methods are also available in Haml templates.
53
- # For example (this example uses Rails, but the principle for Merb is the same):
54
- #
55
- # # file: app/controllers/movies_controller.rb
56
- #
57
- # class MoviesController < ApplicationController
58
- # def index
59
- # @title = "Teen Wolf"
60
- # end
61
- # end
62
- #
63
- # -# file: app/views/movies/index.haml
64
- #
65
- # #content
66
- # .title
67
- # %h1= @title
68
- # = link_to 'Home', home_url
69
- #
70
- # may be compiled to:
71
- #
72
- # <div id='content'>
73
- # <div class='title'>
74
- # <h1>Teen Wolf</h1>
75
- # <a href='/'>Home</a>
76
- # </div>
77
- # </div>
78
- #
79
- # ### Ruby Module
80
- #
81
- # Haml can also be used completely separately from Rails and ActionView.
82
- # To do this, install the gem with RubyGems:
83
- #
84
- # gem install haml
85
- #
86
- # You can then use it by including the "haml" gem in Ruby code,
87
- # and using {Haml::Engine} like so:
88
- #
89
- # engine = Haml::Engine.new("%p Haml code!")
90
- # engine.render #=> "<p>Haml code!</p>\n"
91
- #
92
- # ## Characters with meaning to Haml
93
- #
94
- # Various characters, when placed at a certain point in a line,
95
- # instruct Haml to render different types of things.
96
- #
97
- # ### XHTML Tags
98
- #
99
- # These characters render XHTML tags.
100
- #
101
- # #### %
102
- #
103
- # The percent character is placed at the beginning of a line.
104
- # It's followed immediately by the name of an element,
105
- # then optionally by modifiers (see below), a space,
106
- # and text to be rendered inside the element.
107
- # It creates an element in the form of `<element></element>`.
108
- # For example:
109
- #
110
- # %one
111
- # %two
112
- # %three Hey there
113
- #
114
- # is compiled to:
115
- #
116
- # <one>
117
- # <two>
118
- # <three>Hey there</three>
119
- # </two>
120
- # </one>
121
- #
122
- # Any string is a valid element name;
123
- # Haml will automatically generate opening and closing tags for any element.
124
- #
125
- # #### {}
126
- #
127
- # Brackets represent a Ruby hash
128
- # that is used for specifying the attributes of an element.
129
- # It is literally evaluated as a Ruby hash,
130
- # so logic will work in it and local variables may be used.
131
- # Quote characters within the attribute
132
- # will be replaced by appropriate escape sequences.
133
- # The hash is placed after the tag is defined.
134
- # For example:
135
- #
136
- # %html{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en", :lang => "en"}
137
- #
138
- # is compiled to:
139
- #
140
- # <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'></html>
141
- #
142
- # Attribute hashes can also be stretched out over multiple lines
143
- # to accomidate many attributes.
144
- # However, newlines may only be placed immediately after commas.
145
- # For example:
146
- #
147
- # %script{:type => "text/javascript",
148
- # :src => "javascripts/script_#{2 + 7}"}
149
- #
150
- # is compiled to:
151
- #
152
- # <script src='javascripts/script_9' type='text/javascript'></script>
153
- #
154
- # ##### Attribute Methods
155
- #
156
- # A Ruby method call that returns a hash
157
- # can be substituted for the hash contents.
158
- # For example, {Haml::Helpers} defines the following method:
159
- #
160
- # def html_attrs(lang = 'en-US')
161
- # {:xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang' => lang, :lang => lang}
162
- # end
163
- #
164
- # This can then be used in Haml, like so:
165
- #
166
- # %html{html_attrs('fr-fr')}
167
- #
168
- # This is compiled to:
169
- #
170
- # <html lang='fr-fr' xml:lang='fr-fr' xmlns='http://www.w3.org/1999/xhtml'>
171
- # </html>
172
- #
173
- # You can use as many such attribute methods as you want
174
- # by separating them with commas,
175
- # like a Ruby argument list.
176
- # All the hashes will me merged together, from left to right.
177
- # For example, if you defined
178
- #
179
- # def hash1
180
- # {:bread => 'white', :filling => 'peanut butter and jelly'}
181
- # end
182
- #
183
- # def hash2
184
- # {:bread => 'whole wheat'}
185
- # end
186
- #
187
- # then
188
- #
189
- # %sandwich{hash1, hash2, :delicious => true}/
190
- #
191
- # would compile to:
192
- #
193
- # <sandwich bread='whole wheat' delicious='true' filling='peanut butter and jelly' />
194
- #
195
- # Note that the Haml attributes list has the same syntax as a Ruby method call.
196
- # This means that any attribute methods must come before the hash literal.
197
- #
198
- # ##### Boolean Attributes
199
- #
200
- # Some attributes, such as "checked" for `input` tags or "selected" for `option` tags,
201
- # are "boolean" in the sense that their values don't matter -
202
- # it only matters whether or not they're present.
203
- # In HTML (but not XHTML), these attributes can be written as
204
- #
205
- # <input selected>
206
- #
207
- # To do this in Haml, just assign a Ruby true value to the attribute:
208
- #
209
- # %input{:selected => true}
210
- #
211
- # In XHTML, the only valid value for these attributes is the name of the attribute.
212
- # Thus this will render in XHTML as
213
- #
214
- # <input selected='selected'>
215
- #
216
- # To set these attributes to false, simply assign them to a Ruby false value.
217
- # In both XHTML and HTML
218
- #
219
- # %input{:selected => false}
220
- #
221
- # will just render as
222
- #
223
- # <input>
224
- #
225
- # #### . and `#`
226
- #
227
- # The period and pound sign are borrowed from CSS.
228
- # They are used as shortcuts to specify the `class`
229
- # and `id` attributes of an element, respectively.
230
- # Multiple class names can be specified in a similar way to CSS,
231
- # by chaining the class names together with periods.
232
- # They are placed immediately after the tag and before an attributes hash.
233
- # For example:
234
- #
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
- #
240
- # is compiled to:
241
- #
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
- #
248
- # And,
249
- #
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
256
- #
257
- # is compiled to:
258
- #
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>
266
- # </div>
267
- # </div>
268
- #
269
- # #### Implicit Div Elements
270
- #
271
- # Because the div element is used so often, it is the default element.
272
- # If you only define a class and/or id using the `.` or `#` syntax,
273
- # a div element is automatically used.
274
- # For example:
275
- #
276
- # #collection
277
- # .item
278
- # .description What a cool item!
279
- #
280
- # is the same as:
281
- #
282
- # %div{:id => collection}
283
- # %div{:class => 'item'}
284
- # %div{:class => 'description'} What a cool item!
285
- #
286
- # and is compiled to:
287
- #
288
- # <div id='collection'>
289
- # <div class='item'>
290
- # <div class='description'>What a cool item!</div>
291
- # </div>
292
- # </div>
293
- #
294
- # #### /
295
- #
296
- # The forward slash character, when placed at the end of a tag definition,
297
- # causes the tag to be self-closed.
298
- # For example:
299
- #
300
- # %br/
301
- # %meta{'http-equiv' => 'Content-Type', :content => 'text/html'}/
302
- #
303
- # is compiled to:
304
- #
305
- # <br />
306
- # <meta http-equiv='Content-Type' content='text/html' />
307
- #
308
- # Some tags are automatically closed, as long as they have no content.
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).
311
- # For example:
312
- #
313
- # %br
314
- # %meta{'http-equiv' => 'Content-Type', :content => 'text/html'}
315
- #
316
- # is also compiled to:
317
- #
318
- # <br />
319
- # <meta http-equiv='Content-Type' content='text/html' />
320
- #
321
- # #### \[]
322
- #
323
- # Square brackets follow a tag definition and contain a Ruby object
324
- # that is used to set the class and id of that tag.
325
- # The class is set to the object's class
326
- # (transformed to use underlines rather than camel case)
327
- # and the id is set to the object's class, followed by its id.
328
- # Because the id of an object is normally an obscure implementation detail,
329
- # this is most useful for elements that represent instances of Models.
330
- # Additionally, the second argument (if present) will be used as a prefix for
331
- # both the id and class attributes.
332
- # For example:
333
- #
334
- # # file: app/controllers/users_controller.rb
335
- #
336
- # def show
337
- # @user = CrazyUser.find(15)
338
- # end
339
- #
340
- # -# file: app/views/users/show.haml
341
- #
342
- # %div[@user, :greeting]
343
- # %bar[290]/
344
- # Hello!
345
- #
346
- # is compiled to:
347
- #
348
- # <div class='greeting_crazy_user' id='greeting_crazy_user_15'>
349
- # <bar class='fixnum' id='fixnum_581' />
350
- # Hello!
351
- # </div>
352
- #
353
- # #### > and <
354
- #
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.
358
- # You can think of them as alligators eating the whitespace:
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.
361
- # They're placed at the end of a tag definition,
362
- # after class, id, and attribute declarations
363
- # but before `/` or `=`.
364
- # For example:
365
- #
366
- # %blockquote<
367
- # %div
368
- # Foo!
369
- #
370
- # is compiled to:
371
- #
372
- # <blockquote><div>
373
- # Foo!
374
- # </div></blockquote>
375
- #
376
- # And:
377
- #
378
- # %img
379
- # %img>
380
- # %img
381
- #
382
- # is compiled to:
383
- #
384
- # <img /><img /><img />
385
- #
386
- # And:
387
- #
388
- # %p<= "Foo\nBar"
389
- #
390
- # is compiled to:
391
- #
392
- # <p>Foo
393
- # Bar</p>
394
- #
395
- # And finally:
396
- #
397
- # %img
398
- # %pre><
399
- # foo
400
- # bar
401
- # %img
402
- #
403
- # is compiled to:
404
- #
405
- # <img /><pre>foo
406
- # bar</pre><img />
407
- #
408
- # #### =
409
- #
410
- # `=` is placed at the end of a tag definition,
411
- # after class, id, and attribute declarations.
412
- # It's just a shortcut for inserting Ruby code into an element.
413
- # It works the same as `=` without a tag:
414
- # it inserts the result of the Ruby code into the template.
415
- # However, if the result is short enough,
416
- # it is displayed entirely on one line.
417
- # For example:
418
- #
419
- # %p= "hello"
420
- #
421
- # is not quite the same as:
422
- #
423
- # %p
424
- # = "hello"
425
- #
426
- # It's compiled to:
427
- #
428
- # <p>hello</p>
429
- #
430
- # #### `#{}`
431
- #
432
- # Ruby code can also be interpolated within plain text using `#{}`,
433
- # similarly to Ruby string interpolation.
434
- # For example,
435
- #
436
- # %p This is #{h quality} cake!
437
- #
438
- # is the same as
439
- #
440
- # %p= "This is the #{h quality} cake!"
441
- #
442
- # and might compile to
443
- #
444
- # <p>This is scrumptious cake!</p>
445
- #
446
- # Backslashes can be used to escape `#{` strings,
447
- # but they don't act as escapes anywhere else in the string.
448
- # For example:
449
- #
450
- # %p
451
- # Look at \\#{h word} lack of backslash: \#{foo}
452
- # And yon presence thereof: \{foo}
453
- #
454
- # might compile to
455
- #
456
- # <p>
457
- # Look at \yon lack of backslash: #{foo}
458
- # And yon presence thereof: \{foo}
459
- # </p>
460
- #
461
- # {#tilde}
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](#whitespace_preservation).
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 `!!!`.
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 `!!!`.
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](http://www.quirksmode.org/css/condcom.html)
610
- # by enclosing the condition in square brackets after the `/`.
611
- # For example:
612
- #
613
- # /[if IE]
614
- # %a{ :href => 'http://www.mozilla.com/en-US/firefox/' }
615
- # %h1 Get Firefox
616
- #
617
- # is compiled to:
618
- #
619
- # <!--[if IE]>
620
- # <a href='http://www.mozilla.com/en-US/firefox/'>
621
- # <h1>Get Firefox</h1>
622
- # </a>
623
- # <![endif]-->
624
- #
625
- # #### \
626
- #
627
- # The backslash character escapes the first character of a line,
628
- # allowing use of otherwise interpreted characters as plain text.
629
- # For example:
630
- #
631
- # %title
632
- # = @title
633
- # \- MySite
634
- #
635
- # is compiled to:
636
- #
637
- # <title>
638
- # MyPage
639
- # - MySite
640
- # </title>
641
- #
642
- # #### |
643
- #
644
- # The pipe character designates a multiline string.
645
- # It's placed at the end of a line (after some whitespace)
646
- # and means that all following lines that end with `|`
647
- # will be evaluated as though they were on the same line.
648
- # For example:
649
- #
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
- #
658
- # is compiled to:
659
- #
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
- #
667
- # #### :
668
- #
669
- # The colon character designates a filter.
670
- # This allows you to pass an indented block of text as input
671
- # to another filtering program and add the result to the output of Haml.
672
- # The syntax is simply a colon followed by the name of the filter.
673
- # For example,
674
- #
675
- # %p
676
- # :markdown
677
- # Textile
678
- # =======
679
- #
680
- # Hello, *World*
681
- #
682
- # is compiled to
683
- #
684
- # <p>
685
- # <h1>Textile</h1>
686
- #
687
- # <p>Hello, <em>World</em></p>
688
- # </p>
689
- #
690
- # Filters can have Ruby code interpolated with `#{}`.
691
- # For example,
692
- #
693
- # - flavor = "raspberry"
694
- # #content
695
- # :textile
696
- # I *really* prefer _#{h flavor}_ jam.
697
- #
698
- # is compiled to
699
- #
700
- # <div id='content'>
701
- # <p>I <strong>really</strong> prefer <em>raspberry</em> jam.</p>
702
- # </div>
703
- #
704
- # Haml has the following filters defined:
705
- #
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
- #
711
- # {#javascript-filter} javascript
712
- # : Surrounds the filtered text with `<script>` and CDATA tags.
713
- # Useful for including inline Javascript.
714
- #
715
- # {#cdata-filter} cdata
716
- # : Surrounds the filtered text with CDATA tags.
717
- #
718
- # {#escaped-filter} escaped
719
- # : Works the same as plain, but HTML-escapes the text
720
- # before placing it in the document.
721
- #
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.
728
- #
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).
735
- #
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.
740
- #
741
- # {#sass-filter} sass
742
- # : Parses the filtered text with Sass to produce CSS output.
743
- #
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.
747
- #
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.
754
- #
755
- # {#maruku-filter} maruku
756
- # : Parses the filtered text with [Maruku](http://maruku.rubyforge.org),
757
- # which has some non-standard extensions to Markdown.
758
- #
759
- # You can also define your own filters (see {Haml::Filters}).
760
- #
761
- # ### Ruby evaluators
762
- #
763
- # #### =
764
- #
765
- # The equals character is followed by Ruby code,
766
- # which is evaluated and the output inserted into the document as plain text.
767
- # For example:
768
- #
769
- # %p
770
- # = ['hi', 'there', 'reader!'].join " "
771
- # = "yo"
772
- #
773
- # is compiled to:
774
- #
775
- # <p>
776
- # hi there reader!
777
- # yo
778
- # </p>
779
- #
780
- # If the [`:escape_html`](#escape_html-option) option is set, `=` will sanitize any
781
- # HTML-sensitive characters generated by the script. For example:
782
- #
783
- # = '<script>alert("I\'m evil!");</script>'
784
- #
785
- # would be compiled to
786
- #
787
- # &lt;script&gt;alert(&quot;I'm evil!&quot;);&lt;/script&gt;
788
- #
789
- # #### -
790
- #
791
- # The hyphen character makes the text following it into "silent script":
792
- # Ruby script that is evaluated, but not output.
793
- #
794
- # **It is not recommended that you use this widely;
795
- # almost all processing code and logic should be restricted
796
- # to the Controller, the Helper, or partials.**
797
- #
798
- # For example:
799
- #
800
- # - foo = "hello"
801
- # - foo << " there"
802
- # - foo << " you!"
803
- # %p= foo
804
- #
805
- # is compiled to:
806
- #
807
- # <p>
808
- # hello there you!
809
- # </p>
810
- #
811
- # #### &=
812
- #
813
- # An ampersand followed by one or two equals characters
814
- # evaluates Ruby code just like the equals without the ampersand,
815
- # but sanitizes any HTML-sensitive characters in the result of the code.
816
- # For example:
817
- #
818
- # &= "I like cheese & crackers"
819
- #
820
- # compiles to
821
- #
822
- # I like cheese &amp; crackers
823
- #
824
- # If the [`:escape_html`](#escape_html-option) option is set,
825
- # `&=` behaves identically to `=`.
826
- #
827
- # `&` can also be used on its own so that `#{}` interpolation is escaped.
828
- # For example,
829
- #
830
- # & I like #{"cheese & crackers"}
831
- #
832
- # compiles to
833
- #
834
- # I like cheese &amp; crackers
835
- #
836
- # #### !=
837
- #
838
- # An exclamation mark followed by one or two equals characters
839
- # evaluates Ruby code just like the equals would,
840
- # but never sanitizes the HTML.
841
- #
842
- # By default, the single equals doesn't sanitize HTML either.
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:
846
- #
847
- # = "I feel <strong>!"
848
- # != "I feel <strong>!"
849
- #
850
- # compiles to
851
- #
852
- # I feel &lt;strong&gt;!
853
- # I feel <strong>!
854
- #
855
- # `!` can also be used on its own so that `#{}` interpolation is unescaped.
856
- # For example,
857
- #
858
- # ! I feel #{"<strong>"}!
859
- #
860
- # compiles to
861
- #
862
- # I feel <strong>!
863
- #
864
- # ##### Blocks
865
- #
866
- # Ruby blocks, like XHTML tags, don't need to be explicitly closed in Haml.
867
- # Rather, they're automatically closed, based on indentation.
868
- # A block begins whenever the indentation is increased
869
- # after a silent script command.
870
- # It ends when the indentation decreases
871
- # (as long as it's not an `else` clause or something similar).
872
- # For example:
873
- #
874
- # - (42...47).each do |i|
875
- # %p= i
876
- # %p See, I can count!
877
- #
878
- # is compiled to:
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>
895
- #
896
- # Another example:
897
- #
898
- # %p
899
- # - case 2
900
- # - when 1
901
- # = "1!"
902
- # - when 2
903
- # = "2?"
904
- # - when 3
905
- # = "3."
906
- #
907
- # is compiled to:
908
- #
909
- # <p>
910
- # 2?
911
- # </p>
912
- #
913
- # #### -#
914
- #
915
- # The hyphen followed immediately by the pound sign
916
- # signifies a silent comment.
917
- # Any text following this isn't rendered in the resulting document
918
- # at all.
919
- #
920
- # For example:
921
- #
922
- # %p foo
923
- # -# This is a comment
924
- # %p bar
925
- #
926
- # is compiled to:
927
- #
928
- # <p>foo</p>
929
- # <p>bar</p>
930
- #
931
- # You can also nest text beneath a silent comment.
932
- # None of this text will be rendered.
933
- # For example:
934
- #
935
- # %p foo
936
- # -#
937
- # This won't be displayed
938
- # Nor will this
939
- # %p bar
940
- #
941
- # is compiled to:
942
- #
943
- # <p>foo</p>
944
- # <p>bar</p>
945
- #
946
- # ## Other Useful Things
947
- #
948
- # ### Whitespace Preservation
949
- #
950
- # Sometimes you don't want Haml to indent all your text.
951
- # For example, tags like `pre` and `textarea` are whitespace-sensitive;
952
- # indenting the text makes them render wrong.
953
- #
954
- # Haml deals with this by "preserving" newlines before they're put into the document --
955
- # converting them to the XHTML whitespace escape code, `&#x000A;`.
956
- # Then Haml won't try to re-format the indentation.
957
- #
958
- # Literal `textarea` and `pre` tags automatically preserve their content.
959
- # Dynamically can't be caught automatically,
960
- # and so should be passed through {Haml::Helpers#find\_and\_preserve} or the [`~` command](#tilde),
961
- # which has the same effect.
962
- #
963
- # Blocks of literal text can be preserved using the [`:preserve` filter](#preserve-filter).
964
- #
965
- # ### Helpers
966
- #
967
- # Haml offers a bunch of helpers that are useful
968
- # for doing stuff like preserving whitespace,
969
- # creating nicely indented output for user-defined helpers,
970
- # and other useful things.
971
- # The helpers are all documented in the {Haml::Helpers} and {Haml::Helpers::ActionViewExtensions} modules.
972
- #
973
- # ### Haml Options
974
- #
975
- # Options can be set by setting the {Haml::Template.options} hash
976
- # in `environment.rb` in Rails...
977
- #
978
- # Haml::Template.options[:format] = :html5
979
- #
980
- # ...or by setting the `Merb::Plugin.config[:haml]` hash in `init.rb` in Merb...
981
- #
982
- # Merb::Plugin.config[:haml][:format] = :html5
983
- #
984
- # ...or by passing an options hash to {Haml::Engine#initialize}.
985
- # Available options are:
986
- #
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 `&apos;`) 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&#x000A;Bar</textarea>`.
1036
- # Defaults to `['textarea', 'pre']`.
1037
- # See also [Whitespace Preservation](#whitespace_preservation).
8
+ # * {Haml::Engine} is the class used to render Haml within Ruby code.
9
+ # * {Haml::Helpers} contains Ruby helpers available within Haml templates.
10
+ # * {Haml::Template} interfaces with web frameworks (Rails in particular).
11
+ # * {Haml::Error} is raised when Haml encounters an error.
12
+ # * {Haml::HTML} handles conversion of HTML to Haml.
1038
13
  #
14
+ # Also see the {file:HAML_REFERENCE.md full Haml reference}.
1039
15
  module Haml
1040
-
1041
16
  extend Haml::Version
1042
17
 
1043
18
  # A string representing the version of Haml.