haml 4.0.0 → 5.0.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.
- checksums.yaml +7 -0
- data/.yardopts +1 -1
- data/CHANGELOG.md +117 -5
- data/FAQ.md +7 -17
- data/MIT-LICENSE +1 -1
- data/README.md +85 -42
- data/REFERENCE.md +181 -86
- data/Rakefile +47 -51
- data/lib/haml/attribute_builder.rb +163 -0
- data/lib/haml/attribute_compiler.rb +215 -0
- data/lib/haml/attribute_parser.rb +144 -0
- data/lib/haml/buffer.rb +38 -128
- data/lib/haml/compiler.rb +88 -295
- data/lib/haml/engine.rb +25 -41
- data/lib/haml/error.rb +3 -0
- data/lib/haml/escapable.rb +49 -0
- data/lib/haml/exec.rb +33 -19
- data/lib/haml/filters.rb +20 -24
- data/lib/haml/generator.rb +41 -0
- data/lib/haml/helpers/action_view_extensions.rb +3 -2
- data/lib/haml/helpers/action_view_mods.rb +44 -66
- data/lib/haml/helpers/action_view_xss_mods.rb +1 -0
- data/lib/haml/helpers/safe_erubi_template.rb +27 -0
- data/lib/haml/helpers/safe_erubis_template.rb +16 -4
- data/lib/haml/helpers/xss_mods.rb +18 -12
- data/lib/haml/helpers.rb +122 -58
- data/lib/haml/options.rb +39 -46
- data/lib/haml/parser.rb +278 -217
- data/lib/haml/{template/plugin.rb → plugin.rb} +8 -15
- data/lib/haml/railtie.rb +21 -11
- data/lib/haml/sass_rails_filter.rb +17 -4
- data/lib/haml/template/options.rb +12 -2
- data/lib/haml/template.rb +12 -6
- data/lib/haml/temple_engine.rb +120 -0
- data/lib/haml/temple_line_counter.rb +29 -0
- data/lib/haml/util.rb +80 -199
- data/lib/haml/version.rb +2 -1
- data/lib/haml.rb +2 -1
- data/test/attribute_parser_test.rb +101 -0
- data/test/engine_test.rb +306 -176
- data/test/filters_test.rb +32 -19
- data/test/gemfiles/Gemfile.rails-4.0.x +11 -0
- data/test/gemfiles/Gemfile.rails-4.0.x.lock +87 -0
- data/test/gemfiles/Gemfile.rails-4.1.x +5 -0
- data/test/gemfiles/Gemfile.rails-4.2.x +5 -0
- data/test/gemfiles/Gemfile.rails-5.0.x +4 -0
- data/test/helper_test.rb +282 -96
- data/test/options_test.rb +22 -0
- data/test/parser_test.rb +71 -4
- data/test/results/bemit.xhtml +4 -0
- data/test/results/eval_suppressed.xhtml +4 -4
- data/test/results/helpers.xhtml +43 -41
- data/test/results/helpful.xhtml +6 -3
- data/test/results/just_stuff.xhtml +21 -20
- data/test/results/list.xhtml +9 -9
- data/test/results/nuke_inner_whitespace.xhtml +22 -22
- data/test/results/nuke_outer_whitespace.xhtml +84 -92
- data/test/results/original_engine.xhtml +17 -17
- data/test/results/partial_layout.xhtml +4 -3
- data/test/results/partial_layout_erb.xhtml +4 -3
- data/test/results/partials.xhtml +11 -10
- data/test/results/silent_script.xhtml +63 -63
- data/test/results/standard.xhtml +156 -159
- data/test/results/tag_parsing.xhtml +19 -19
- data/test/results/very_basic.xhtml +2 -2
- data/test/results/whitespace_handling.xhtml +56 -50
- data/test/template_test.rb +44 -53
- data/test/template_test_helper.rb +38 -0
- data/test/templates/_text_area_helper.html.haml +4 -0
- data/test/templates/bemit.haml +3 -0
- data/test/templates/just_stuff.haml +1 -0
- data/test/templates/partial_layout_erb.erb +1 -1
- data/test/templates/standard_ugly.haml +1 -0
- data/test/templates/with_bom.haml +1 -0
- data/test/temple_line_counter_test.rb +40 -0
- data/test/test_helper.rb +26 -12
- data/test/util_test.rb +6 -47
- metadata +88 -106
- data/lib/haml/helpers/rails_323_textarea_fix.rb +0 -24
- data/test/gemfiles/Gemfile.rails-3.0.x +0 -5
- data/test/gemfiles/Gemfile.rails-3.1.x +0 -6
- data/test/gemfiles/Gemfile.rails-3.2.x +0 -5
- data/test/gemfiles/Gemfile.rails-master +0 -4
- data/test/templates/_av_partial_1_ugly.haml +0 -9
- data/test/templates/_av_partial_2_ugly.haml +0 -5
- data/test/templates/action_view_ugly.haml +0 -47
- data/test/templates/standard_ugly.haml +0 -43
    
        data/REFERENCE.md
    CHANGED
    
    | @@ -121,7 +121,7 @@ see {Haml::Options}. | |
| 121 121 |  | 
| 122 122 | 
             
            ### Encodings
         | 
| 123 123 |  | 
| 124 | 
            -
             | 
| 124 | 
            +
            Haml supports the same sorts of
         | 
| 125 125 | 
             
            encoding-declaration comments that Ruby does. Although both Ruby and Haml
         | 
| 126 126 | 
             
            support several different styles, the easiest it just to add `-# coding:
         | 
| 127 127 | 
             
            encoding-name` at the beginning of the Haml template (it must come before all
         | 
| @@ -130,8 +130,8 @@ encoding. | |
| 130 130 |  | 
| 131 131 | 
             
            By default, the HTML generated by Haml has the same encoding as the Haml
         | 
| 132 132 | 
             
            template. However, if `Encoding.default_internal` is set, Haml will attempt to
         | 
| 133 | 
            -
            use that instead. In addition, the  | 
| 134 | 
            -
            used to specify an output encoding manually.
         | 
| 133 | 
            +
            use that instead. In addition, the {Haml::Options#encoding `:encoding` option}
         | 
| 134 | 
            +
            can be used to specify an output encoding manually.
         | 
| 135 135 |  | 
| 136 136 | 
             
            Note that, like Ruby, Haml does not support templates encoded in UTF-16 or
         | 
| 137 137 | 
             
            UTF-32, since these encodings are not compatible with ASCII. It is possible to
         | 
| @@ -186,7 +186,6 @@ is compiled to: | |
| 186 186 |  | 
| 187 187 | 
             
            ## HTML Elements
         | 
| 188 188 |  | 
| 189 | 
            -
             | 
| 190 189 | 
             
            ### Element Name: `%`
         | 
| 191 190 |  | 
| 192 191 | 
             
            The percent character is placed at the beginning of a line. It's followed
         | 
| @@ -234,8 +233,7 @@ is compiled to: | |
| 234 233 |  | 
| 235 234 | 
             
                <script src='javascripts/script_9' type='text/javascript'></script>
         | 
| 236 235 |  | 
| 237 | 
            -
            #### `:class` and `:id` Attributes
         | 
| 238 | 
            -
            {#class-and-id-attributes}
         | 
| 236 | 
            +
            #### `:class` and `:id` Attributes {#class-and-id-attributes}
         | 
| 239 237 |  | 
| 240 238 | 
             
            The `:class` and `:id` attributes can also be specified as a Ruby array whose
         | 
| 241 239 | 
             
            elements will be joined together. A `:class` array is joined with `" "` and an
         | 
| @@ -307,7 +305,7 @@ hash-style attributes: | |
| 307 305 |  | 
| 308 306 | 
             
            #### Ruby 1.9-style Hashes
         | 
| 309 307 |  | 
| 310 | 
            -
             | 
| 308 | 
            +
            Haml also supports Ruby's new hash syntax:
         | 
| 311 309 |  | 
| 312 310 | 
             
                %a{title: @title, href: href} Stuff
         | 
| 313 311 |  | 
| @@ -330,7 +328,7 @@ This is compiled to: | |
| 330 328 | 
             
                </html>
         | 
| 331 329 |  | 
| 332 330 | 
             
            You can use as many such attribute methods as you want by separating them with
         | 
| 333 | 
            -
            commas, like a Ruby argument list. All the hashes will  | 
| 331 | 
            +
            commas, like a Ruby argument list. All the hashes will be merged together, from
         | 
| 334 332 | 
             
            left to right. For example, if you defined
         | 
| 335 333 |  | 
| 336 334 | 
             
                def hash1
         | 
| @@ -390,27 +388,49 @@ or using `true` and `false`: | |
| 390 388 |  | 
| 391 389 | 
             
                %input(selected=true)
         | 
| 392 390 |  | 
| 393 | 
            -
             | 
| 391 | 
            +
            <!-- The title to the next section (Prefixed Attributes) has changed. This
         | 
| 392 | 
            +
            <a> tag is so old links to here still work. -->
         | 
| 393 | 
            +
            <a id="html5_custom_data_attributes" style="border:0;"></a>
         | 
| 394 | 
            +
             | 
| 395 | 
            +
            #### Prefixed Attributes
         | 
| 394 396 |  | 
| 395 | 
            -
            HTML5 allows for adding | 
| 396 | 
            -
            attributes](http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#embedding-custom-non-visible-data)
         | 
| 397 | 
            -
            to elements using attribute names beginning with `data-`.  | 
| 398 | 
            -
             | 
| 399 | 
            -
             | 
| 400 | 
            -
             | 
| 397 | 
            +
            HTML5 allows for adding
         | 
| 398 | 
            +
            [custom non-visible data attributes](http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
         | 
| 399 | 
            +
            to elements using attribute names beginning with `data-`. The
         | 
| 400 | 
            +
            [Accessible Rich Internet Applications](http://www.w3.org/WAI/intro/aria)
         | 
| 401 | 
            +
            specification makes use of attributes beginning with `aria-`. There are also
         | 
| 402 | 
            +
            frameworks that use non-standard attributes with a common prefix.
         | 
| 401 403 |  | 
| 402 | 
            -
             | 
| 404 | 
            +
            Haml can help generate collections of attributes that share a prefix like
         | 
| 405 | 
            +
            these. Any entry in an attribute hash that has a Hash as its value is expanded
         | 
| 406 | 
            +
            into a series of attributes, one for each key/value pair in the hash, with the
         | 
| 407 | 
            +
            attribute name formed by joining the “parent” key name to the key name with a
         | 
| 408 | 
            +
            hyphen.
         | 
| 409 | 
            +
             | 
| 410 | 
            +
            For example:
         | 
| 411 | 
            +
             | 
| 412 | 
            +
                %a{:href=>"/posts", :data => {:author_id => 123, :category => 7}} Posts By Author
         | 
| 403 413 |  | 
| 404 414 | 
             
            will render as:
         | 
| 405 415 |  | 
| 406 | 
            -
                <a data-author-id='123' href='/posts'>Posts By Author</a>
         | 
| 416 | 
            +
                <a data-author-id='123' data-category='7' href='/posts'>Posts By Author</a>
         | 
| 407 417 |  | 
| 408 418 | 
             
            Notice that the underscore in `author_id` was replaced by a hyphen. If you wish
         | 
| 409 | 
            -
            to suppress this behavior, you can set Haml's | 
| 410 | 
            -
             | 
| 411 | 
            -
            rendered as:
         | 
| 419 | 
            +
            to suppress this behavior, you can set Haml's
         | 
| 420 | 
            +
            {Haml::Options#hyphenate_data_attrs `:hyphenate_data_attrs` option} to `false`,
         | 
| 421 | 
            +
            and the output will be rendered as:
         | 
| 422 | 
            +
             | 
| 423 | 
            +
                <a data-author_id='123' data-category='7' href='/posts'>Posts By Author</a>
         | 
| 424 | 
            +
             | 
| 425 | 
            +
            This expansion of hashes is recursive – any value of the child hash that is
         | 
| 426 | 
            +
            itself a hash will create an attribute for each entry, with the attribute name
         | 
| 427 | 
            +
            prefixed with all ancestor keys. For example:
         | 
| 412 428 |  | 
| 413 | 
            -
                 | 
| 429 | 
            +
                .book-info{:data => {:book => {:id => 123, :genre => 'programming'}, :category => 7}}
         | 
| 430 | 
            +
             | 
| 431 | 
            +
            will render as:
         | 
| 432 | 
            +
             | 
| 433 | 
            +
                <div class='book-info' data-book-genre='programming' data-book-id='123' data-category='7'></div>
         | 
| 414 434 |  | 
| 415 435 | 
             
            ### Class and ID: `.` and `#`
         | 
| 416 436 |  | 
| @@ -492,31 +512,33 @@ and is compiled to: | |
| 492 512 | 
             
                  </div>
         | 
| 493 513 | 
             
                </div>
         | 
| 494 514 |  | 
| 495 | 
            -
            ###  | 
| 515 | 
            +
            ### Empty (void) Tags: `/`
         | 
| 496 516 |  | 
| 497 517 | 
             
            The forward slash character, when placed at the end of a tag definition, causes
         | 
| 498 | 
            -
             | 
| 518 | 
            +
            Haml to treat it as being an empty (or void) element. Depending on the format,
         | 
| 519 | 
            +
            the tag will be rendered either without a closing tag (`:html4` or `:html5`), or
         | 
| 520 | 
            +
            as a self-closing tag (`:xhtml`).
         | 
| 521 | 
            +
             | 
| 522 | 
            +
            Taking the following as an example:
         | 
| 499 523 |  | 
| 500 524 | 
             
                %br/
         | 
| 501 525 | 
             
                %meta{'http-equiv' => 'Content-Type', :content => 'text/html'}/
         | 
| 502 526 |  | 
| 503 | 
            -
            is compiled to:
         | 
| 504 | 
            -
             | 
| 505 | 
            -
                <br />
         | 
| 506 | 
            -
                <meta http-equiv='Content-Type' content='text/html' />
         | 
| 507 | 
            -
             | 
| 508 | 
            -
            Some tags are automatically closed, as long as they have no content. `meta`,
         | 
| 509 | 
            -
            `img`, `link`, `script`, `br`, and `hr` tags are closed by default. This list
         | 
| 510 | 
            -
            can be customized by setting the [`:autoclose`](#autoclose-option) option. For
         | 
| 511 | 
            -
            example:
         | 
| 527 | 
            +
            When the format is `:html4` or `:html5` this is compiled to:
         | 
| 512 528 |  | 
| 513 | 
            -
                 | 
| 514 | 
            -
                 | 
| 529 | 
            +
                <br>
         | 
| 530 | 
            +
                <meta content='text/html' http-equiv='Content-Type'>
         | 
| 515 531 |  | 
| 516 | 
            -
            is  | 
| 532 | 
            +
            and when the format is `:xhtml` it is compiled to:
         | 
| 517 533 |  | 
| 518 534 | 
             
                <br />
         | 
| 519 | 
            -
                <meta http-equiv='Content-Type'  | 
| 535 | 
            +
                <meta content='text/html' http-equiv='Content-Type' />
         | 
| 536 | 
            +
             | 
| 537 | 
            +
            Some tags are automatically treated as being empty, as long as they have no
         | 
| 538 | 
            +
            content in the Haml source. `meta`, `img`, `link`, `br`, `hr`, `input`,
         | 
| 539 | 
            +
            `area`, `param`, `col` and `base` tags are treated as empty by default. This
         | 
| 540 | 
            +
            list can be customized by setting the {Haml::Options#autoclose `:autoclose`}
         | 
| 541 | 
            +
            option.
         | 
| 520 542 |  | 
| 521 543 | 
             
            ### Whitespace Removal: `>` and `<`
         | 
| 522 544 |  | 
| @@ -621,6 +643,12 @@ is compiled to: | |
| 621 643 | 
             
                  Hello!
         | 
| 622 644 | 
             
                </div>
         | 
| 623 645 |  | 
| 646 | 
            +
            The `:class` attribute may be used in conjunction with an object
         | 
| 647 | 
            +
            reference.  The compiled element will have the union of all classes.
         | 
| 648 | 
            +
             | 
| 649 | 
            +
                - user = User.find(1)
         | 
| 650 | 
            +
                %p[user]{:class => 'alpha bravo'}
         | 
| 651 | 
            +
                <p id="user_1" class="alpha bravo user"></p>
         | 
| 624 652 |  | 
| 625 653 | 
             
            ## Doctype: `!!!`
         | 
| 626 654 |  | 
| @@ -651,7 +679,7 @@ is compiled to: | |
| 651 679 | 
             
                </html>
         | 
| 652 680 |  | 
| 653 681 | 
             
            You can also specify the specific doctype after the `!!!` When the
         | 
| 654 | 
            -
             | 
| 682 | 
            +
            {Haml::Options#format `:format`} is set to `:xhtml`. The following doctypes are
         | 
| 655 683 | 
             
            supported:
         | 
| 656 684 |  | 
| 657 685 | 
             
            `!!!`
         | 
| @@ -686,7 +714,7 @@ supported: | |
| 686 714 | 
             
            : XHTML+RDFa 1.0<br/>
         | 
| 687 715 | 
             
             `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">`
         | 
| 688 716 |  | 
| 689 | 
            -
            When the  | 
| 717 | 
            +
            When the {Haml::Options#format `:format`} option is set to `:html4`, the following
         | 
| 690 718 | 
             
            doctypes are supported:
         | 
| 691 719 |  | 
| 692 720 | 
             
            `!!!`
         | 
| @@ -701,7 +729,7 @@ doctypes are supported: | |
| 701 729 | 
             
            : HTML 4.01 Frameset<br/>
         | 
| 702 730 | 
             
             `<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">`
         | 
| 703 731 |  | 
| 704 | 
            -
            When the  | 
| 732 | 
            +
            When the {Haml::Options#format `:format`} option is set to `:html5`,
         | 
| 705 733 | 
             
            `!!!` is always `<!DOCTYPE html>`.
         | 
| 706 734 |  | 
| 707 735 | 
             
            If you're not using the UTF-8 character set for your document, you can specify
         | 
| @@ -772,6 +800,21 @@ is compiled to: | |
| 772 800 | 
             
                  </a>
         | 
| 773 801 | 
             
                <![endif]-->
         | 
| 774 802 |  | 
| 803 | 
            +
            To generate “downlevel-revealed” conditional comments, where the content is
         | 
| 804 | 
            +
            hidden from IE but not other browsers,  add a `!` before the brackets: `/![]`.
         | 
| 805 | 
            +
            Haml will produce valid HTML when generating this kind of conditional comment.
         | 
| 806 | 
            +
             | 
| 807 | 
            +
            For example:
         | 
| 808 | 
            +
             | 
| 809 | 
            +
                /![if !IE]
         | 
| 810 | 
            +
                  You are not using Internet Explorer, or are using version 10+.
         | 
| 811 | 
            +
             | 
| 812 | 
            +
            is compiled to:
         | 
| 813 | 
            +
             | 
| 814 | 
            +
                <!--[if !IE]><!-->
         | 
| 815 | 
            +
                  You are not using Internet Explorer, or are using version 10+.
         | 
| 816 | 
            +
                <!--<![endif]-->
         | 
| 817 | 
            +
             | 
| 775 818 | 
             
            ### Haml Comments: `-#`
         | 
| 776 819 |  | 
| 777 820 | 
             
            The hyphen followed immediately by the pound sign signifies a silent comment.
         | 
| @@ -821,7 +864,7 @@ is compiled to: | |
| 821 864 | 
             
                  yo
         | 
| 822 865 | 
             
                </p>
         | 
| 823 866 |  | 
| 824 | 
            -
            If the  | 
| 867 | 
            +
            If the {Haml::Options#escape_html `:escape_html`} option is set, `=` will sanitize
         | 
| 825 868 | 
             
            any HTML-sensitive characters generated by the script. For example:
         | 
| 826 869 |  | 
| 827 870 | 
             
                = '<script>alert("I\'m evil!");</script>'
         | 
| @@ -941,7 +984,7 @@ Ruby string interpolation. For example, | |
| 941 984 |  | 
| 942 985 | 
             
            is the same as
         | 
| 943 986 |  | 
| 944 | 
            -
                %p= "This is  | 
| 987 | 
            +
                %p= "This is #{h quality} cake!"
         | 
| 945 988 |  | 
| 946 989 | 
             
            and might compile to:
         | 
| 947 990 |  | 
| @@ -978,6 +1021,21 @@ might compile to: | |
| 978 1021 | 
             
                  //]]>
         | 
| 979 1022 | 
             
                </script>
         | 
| 980 1023 |  | 
| 1024 | 
            +
            #### Gotchas
         | 
| 1025 | 
            +
             | 
| 1026 | 
            +
            Haml uses an overly simplistic regular expression to identify string
         | 
| 1027 | 
            +
            interpolation rather than a full-blown Ruby parser. This is fast and works for
         | 
| 1028 | 
            +
            most code but you may have errors with code like the following:
         | 
| 1029 | 
            +
             | 
| 1030 | 
            +
                %span #{'{'}
         | 
| 1031 | 
            +
             | 
| 1032 | 
            +
            This code will generate a syntax error, complaining about unbalanced brackets.
         | 
| 1033 | 
            +
            In cases like this, the recommended workaround is output the code as a Ruby
         | 
| 1034 | 
            +
            string to force Haml to parse the code with Ruby.
         | 
| 1035 | 
            +
             | 
| 1036 | 
            +
                %span= "#{'{'}"
         | 
| 1037 | 
            +
             | 
| 1038 | 
            +
             | 
| 981 1039 | 
             
            ### Escaping HTML: `&=` {#escaping_html}
         | 
| 982 1040 |  | 
| 983 1041 | 
             
            An ampersand followed by one or two equals characters evaluates Ruby code just
         | 
| @@ -1080,54 +1138,53 @@ more info. | |
| 1080 1138 |  | 
| 1081 1139 | 
             
            Haml comes with the following filters defined:
         | 
| 1082 1140 |  | 
| 1083 | 
            -
            {#cdata-filter}
         | 
| 1084 | 
            -
             | 
| 1141 | 
            +
            ### `:cdata` {#cdata-filter}
         | 
| 1142 | 
            +
             | 
| 1085 1143 | 
             
            Surrounds the filtered text with CDATA tags.
         | 
| 1086 1144 |  | 
| 1087 | 
            -
            {#coffee-filter}
         | 
| 1088 | 
            -
             | 
| 1089 | 
            -
            Compiles the filtered text to Javascript using  | 
| 1145 | 
            +
            ### `:coffee` {#coffee-filter}
         | 
| 1146 | 
            +
             | 
| 1147 | 
            +
            Compiles the filtered text to Javascript using Coffeescript. You can also
         | 
| 1090 1148 | 
             
            reference this filter as `:coffeescript`. This filter is implemented using
         | 
| 1091 1149 | 
             
            Tilt.
         | 
| 1092 1150 |  | 
| 1093 | 
            -
            {#css-filter}
         | 
| 1094 | 
            -
             | 
| 1151 | 
            +
            ### `:css` {#css-filter}
         | 
| 1152 | 
            +
             | 
| 1095 1153 | 
             
            Surrounds the filtered text with `<style>` and (optionally) CDATA tags. Useful
         | 
| 1096 1154 | 
             
            for including inline CSS. Use the {Haml::Options#cdata `:cdata` option} to
         | 
| 1097 1155 | 
             
            control when CDATA tags are added.
         | 
| 1098 1156 |  | 
| 1099 | 
            -
            {#erb-filter}
         | 
| 1100 | 
            -
             | 
| 1101 | 
            -
            Parses the filtered text with  | 
| 1102 | 
            -
             | 
| 1103 | 
            -
            code is evaluated in the same context as the Haml template. This filter is
         | 
| 1157 | 
            +
            ### `:erb` {#erb-filter}
         | 
| 1158 | 
            +
             | 
| 1159 | 
            +
            Parses the filtered text with ERB, like an RHTML template. Not available if the
         | 
| 1160 | 
            +
            {Haml::Options#suppress_eval `:suppress_eval`} option is set to true. Embedded
         | 
| 1161 | 
            +
            Ruby code is evaluated in the same context as the Haml template. This filter is
         | 
| 1104 1162 | 
             
            implemented using Tilt.
         | 
| 1105 1163 |  | 
| 1106 | 
            -
            {#escaped-filter}
         | 
| 1107 | 
            -
             | 
| 1164 | 
            +
            ### `:escaped` {#escaped-filter}
         | 
| 1165 | 
            +
             | 
| 1108 1166 | 
             
            Works the same as plain, but HTML-escapes the text
         | 
| 1109 1167 | 
             
            before placing it in the document.
         | 
| 1110 1168 |  | 
| 1111 | 
            -
            {#javascript-filter}
         | 
| 1112 | 
            -
             | 
| 1169 | 
            +
            ### `:javascript` {#javascript-filter}
         | 
| 1170 | 
            +
             | 
| 1113 1171 | 
             
            Surrounds the filtered text with `<script>` and (optionally) CDATA tags.
         | 
| 1114 1172 | 
             
            Useful for including inline Javascript. Use the {Haml::Options#cdata `:cdata`
         | 
| 1115 1173 | 
             
            option} to control when CDATA tags are added.
         | 
| 1116 1174 |  | 
| 1117 | 
            -
            {#less-filter}
         | 
| 1118 | 
            -
             | 
| 1175 | 
            +
            ### `:less` {#less-filter}
         | 
| 1176 | 
            +
             | 
| 1119 1177 | 
             
            Parses the filtered text with [Less](http://lesscss.org/) to produce CSS output.
         | 
| 1120 1178 | 
             
            This filter is implemented using Tilt.
         | 
| 1121 1179 |  | 
| 1180 | 
            +
            ### `:markdown` {#markdown-filter}
         | 
| 1122 1181 |  | 
| 1123 | 
            -
            {#markdown-filter}
         | 
| 1124 | 
            -
            ### `:markdown`
         | 
| 1125 1182 | 
             
            Parses the filtered text with
         | 
| 1126 1183 | 
             
            [Markdown](http://daringfireball.net/projects/markdown). This filter is
         | 
| 1127 1184 | 
             
            implemented using Tilt.
         | 
| 1128 1185 |  | 
| 1129 | 
            -
            {#maruku-filter}
         | 
| 1130 | 
            -
             | 
| 1186 | 
            +
            ### `:maruku` {#maruku-filter}
         | 
| 1187 | 
            +
             | 
| 1131 1188 | 
             
            Parses the filtered text with [Maruku](https://github.com/nex3/maruku), which
         | 
| 1132 1189 | 
             
            has some non-standard extensions to Markdown.
         | 
| 1133 1190 |  | 
| @@ -1136,38 +1193,39 @@ contrib](https://github.com/haml/haml-contrib) but is loaded automatically for | |
| 1136 1193 | 
             
            historical reasons. In future versions of Haml it will likely not be loaded by
         | 
| 1137 1194 | 
             
            default. This filter is implemented using Tilt.
         | 
| 1138 1195 |  | 
| 1139 | 
            -
            {#plain-filter}
         | 
| 1140 | 
            -
             | 
| 1196 | 
            +
            ### `:plain` {#plain-filter}
         | 
| 1197 | 
            +
             | 
| 1141 1198 | 
             
            Does not parse the filtered text. This is useful for large blocks of text
         | 
| 1142 1199 | 
             
            without HTML tags, when you don't want lines starting with `.` or `-` to be
         | 
| 1143 1200 | 
             
            parsed.
         | 
| 1144 1201 |  | 
| 1145 | 
            -
            {#preserve-filter}
         | 
| 1146 | 
            -
             | 
| 1202 | 
            +
            ### `:preserve` {#preserve-filter}
         | 
| 1203 | 
            +
             | 
| 1147 1204 | 
             
            Inserts the filtered text into the template with whitespace preserved.
         | 
| 1148 1205 | 
             
            `preserve`d blocks of text aren't indented, and newlines are replaced with the
         | 
| 1149 1206 | 
             
            HTML escape code for newlines, to preserve nice-looking output. See also
         | 
| 1150 1207 | 
             
            [Whitespace Preservation](#whitespace_preservation).
         | 
| 1151 1208 |  | 
| 1152 | 
            -
            {#ruby-filter}
         | 
| 1153 | 
            -
             | 
| 1154 | 
            -
            Parses the filtered text with the normal Ruby interpreter.  | 
| 1155 | 
            -
             | 
| 1156 | 
            -
            the  | 
| 1157 | 
            -
            code is evaluated in the same context as the Haml | 
| 1209 | 
            +
            ### `:ruby` {#ruby-filter}
         | 
| 1210 | 
            +
             | 
| 1211 | 
            +
            Parses the filtered text with the normal Ruby interpreter. Creates an `IO`
         | 
| 1212 | 
            +
            object named `haml_io`, anything written to it is output into the Haml document.
         | 
| 1213 | 
            +
            Not available if the {Haml::Options#suppress_eval `:suppress_eval`} option is
         | 
| 1214 | 
            +
            set to true. The Ruby code is evaluated in the same context as the Haml
         | 
| 1215 | 
            +
            template.
         | 
| 1216 | 
            +
             | 
| 1217 | 
            +
            ### `:sass` {#sass-filter}
         | 
| 1158 1218 |  | 
| 1159 | 
            -
            {#sass-filter}
         | 
| 1160 | 
            -
            ### `:sass`
         | 
| 1161 1219 | 
             
            Parses the filtered text with [Sass](http://sass-lang.com/) to produce CSS
         | 
| 1162 1220 | 
             
            output. This filter is implemented using Tilt.
         | 
| 1163 1221 |  | 
| 1164 | 
            -
            {#scss-filter}
         | 
| 1165 | 
            -
             | 
| 1222 | 
            +
            ### `:scss` {#scss-filter}
         | 
| 1223 | 
            +
             | 
| 1166 1224 | 
             
            Parses the filtered text with Sass like the `:sass` filter, but uses the newer
         | 
| 1167 1225 | 
             
            SCSS syntax to produce CSS output. This filter is implemented using Tilt.
         | 
| 1168 1226 |  | 
| 1169 | 
            -
            {#textile-filter}
         | 
| 1170 | 
            -
             | 
| 1227 | 
            +
            ### `:textile` {#textile-filter}
         | 
| 1228 | 
            +
             | 
| 1171 1229 | 
             
            Parses the filtered text with [Textile](http://www.textism.com/tools/textile).
         | 
| 1172 1230 | 
             
            Only works if [RedCloth](http://redcloth.org) is installed.
         | 
| 1173 1231 |  | 
| @@ -1180,6 +1238,42 @@ default. This filter is implemented using Tilt. | |
| 1180 1238 |  | 
| 1181 1239 | 
             
            You can also define your own filters. See {Haml::Filters} for details.
         | 
| 1182 1240 |  | 
| 1241 | 
            +
            ## Helper Methods {#helper-methods}
         | 
| 1242 | 
            +
             | 
| 1243 | 
            +
            Sometimes you need to manipulate whitespace in a more precise fashion than what
         | 
| 1244 | 
            +
            the whitespace removal methods allow. There are a few helper methods that are
         | 
| 1245 | 
            +
            useful when dealing with inline content. All these methods take a Haml block to
         | 
| 1246 | 
            +
            modify.
         | 
| 1247 | 
            +
             | 
| 1248 | 
            +
            ### surround {#surround}
         | 
| 1249 | 
            +
             | 
| 1250 | 
            +
            Surrounds a Haml block with text. Expects 1 or 2 string arguments used to
         | 
| 1251 | 
            +
            surround the Haml block. If a second argument is not provided, the first
         | 
| 1252 | 
            +
            argument is used as the second.
         | 
| 1253 | 
            +
             | 
| 1254 | 
            +
                = surround "(", ")" do
         | 
| 1255 | 
            +
                  = link_to "learn more", "#"
         | 
| 1256 | 
            +
             | 
| 1257 | 
            +
            ### precede {#precede}
         | 
| 1258 | 
            +
             | 
| 1259 | 
            +
            Prepends a Haml block with text. Expects 1 argument.
         | 
| 1260 | 
            +
             | 
| 1261 | 
            +
                = precede "*" do
         | 
| 1262 | 
            +
                  %span Required
         | 
| 1263 | 
            +
             | 
| 1264 | 
            +
            ### succeed {#succeed}
         | 
| 1265 | 
            +
             | 
| 1266 | 
            +
            Appends a Haml block with text. Expects 1 argument.
         | 
| 1267 | 
            +
             | 
| 1268 | 
            +
                Begin by
         | 
| 1269 | 
            +
                = succeed "," do
         | 
| 1270 | 
            +
                  = link_to "filling out your profile", "#"
         | 
| 1271 | 
            +
                = succeed "," do
         | 
| 1272 | 
            +
                  = link_to "adding a bio", "#"
         | 
| 1273 | 
            +
                and
         | 
| 1274 | 
            +
                = succeed "." do
         | 
| 1275 | 
            +
                  = link_to "inviting friends", "#"
         | 
| 1276 | 
            +
             | 
| 1183 1277 | 
             
            ## Multiline: `|` {#multiline}
         | 
| 1184 1278 |  | 
| 1185 1279 | 
             
            The pipe character designates a multiline string.
         | 
| @@ -1231,14 +1325,15 @@ Sometimes you don't want Haml to indent all your text. | |
| 1231 1325 | 
             
            For example, tags like `pre` and `textarea` are whitespace-sensitive;
         | 
| 1232 1326 | 
             
            indenting the text makes them render wrong.
         | 
| 1233 1327 |  | 
| 1234 | 
            -
            Haml deals with this by "preserving" newlines before they're put into the | 
| 1235 | 
            -
            converting them to the HTML whitespace escape code, `
`.
         | 
| 1236 | 
            -
             | 
| 1328 | 
            +
            Haml deals with this by "preserving" newlines before they're put into the
         | 
| 1329 | 
            +
            document -- converting them to the HTML whitespace escape code, `
`. Then
         | 
| 1330 | 
            +
            Haml won't try to re-format the indentation.
         | 
| 1237 1331 |  | 
| 1238 | 
            -
            Literal `textarea` and `pre` tags automatically preserve content given through | 
| 1239 | 
            -
            Dynamically-generated `textarea`s and `pre`s can't be preserved | 
| 1240 | 
            -
            and so should be passed through | 
| 1241 | 
            -
            which has the | 
| 1332 | 
            +
            Literal `textarea` and `pre` tags automatically preserve content given through
         | 
| 1333 | 
            +
            `=`. Dynamically-generated `textarea`s and `pre`s can't be preserved
         | 
| 1334 | 
            +
            automatically, and so should be passed through
         | 
| 1335 | 
            +
            {Haml::Helpers#find\_and\_preserve} or the [`~` command](#tilde), which has the
         | 
| 1336 | 
            +
            same effect.
         | 
| 1242 1337 |  | 
| 1243 1338 | 
             
            Blocks of literal text can be preserved using the [`:preserve` filter](#preserve-filter).
         | 
| 1244 1339 |  | 
    
        data/Rakefile
    CHANGED
    
    | @@ -1,41 +1,38 @@ | |
| 1 1 | 
             
            require "rake/clean"
         | 
| 2 2 | 
             
            require "rake/testtask"
         | 
| 3 | 
            -
            require " | 
| 3 | 
            +
            require "bundler/gem_tasks"
         | 
| 4 4 |  | 
| 5 5 | 
             
            task :default => :test
         | 
| 6 6 |  | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
               | 
| 11 | 
            -
               | 
| 12 | 
            -
             | 
| 13 | 
            -
               | 
| 7 | 
            +
            # FIXME: Redefining :test task to run test/options_test.rb in isolated process since it depends on whether Rails is loaded or not.
         | 
| 8 | 
            +
            # Remove this task when we finished changing escape_html option to be true by default.
         | 
| 9 | 
            +
            isolated_test = Rake::TestTask.new do |t|
         | 
| 10 | 
            +
              t.libs << 'test'
         | 
| 11 | 
            +
              t.test_files = %w[test/options_test.rb]
         | 
| 12 | 
            +
              t.warning = true
         | 
| 13 | 
            +
              t.verbose = true
         | 
| 14 | 
            +
            end
         | 
| 15 | 
            +
            Rake::TestTask.new do |t|
         | 
| 16 | 
            +
              t.libs << 'test'
         | 
| 17 | 
            +
              t.test_files = Dir['test/*_test.rb'] + Dir['test/haml-spec/*_test.rb'] - isolated_test.file_list
         | 
| 18 | 
            +
              t.warning = true
         | 
| 19 | 
            +
              t.verbose = true
         | 
| 14 20 | 
             
            end
         | 
| 15 21 |  | 
| 16 | 
            -
             | 
| 22 | 
            +
            CLEAN.replace %w(pkg doc coverage .yardoc test/haml vendor)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            desc "Benchmark Haml against ERB. TIMES=n sets the number of runs, default is 1000."
         | 
| 17 25 | 
             
            task :benchmark do
         | 
| 18 26 | 
             
              sh "ruby benchmark.rb #{ENV['TIMES']}"
         | 
| 19 27 | 
             
            end
         | 
| 20 28 |  | 
| 21 | 
            -
            Rake::TestTask.new do |t|
         | 
| 22 | 
            -
              t.libs << 'lib' << 'test'
         | 
| 23 | 
            -
              t.test_files = Dir["test/**/*_test.rb"]
         | 
| 24 | 
            -
              t.verbose = true
         | 
| 25 | 
            -
            end
         | 
| 26 | 
            -
             | 
| 27 29 | 
             
            task :set_coverage_env do
         | 
| 28 30 | 
             
              ENV["COVERAGE"] = "true"
         | 
| 29 31 | 
             
            end
         | 
| 30 32 |  | 
| 31 | 
            -
            desc "Run Simplecov | 
| 33 | 
            +
            desc "Run Simplecov"
         | 
| 32 34 | 
             
            task :coverage => [:set_coverage_env, :test]
         | 
| 33 35 |  | 
| 34 | 
            -
            gemspec = File.expand_path("../haml.gemspec", __FILE__)
         | 
| 35 | 
            -
            if File.exist? gemspec
         | 
| 36 | 
            -
              Gem::PackageTask.new(eval(File.read(gemspec))) { |pkg| }
         | 
| 37 | 
            -
            end
         | 
| 38 | 
            -
             | 
| 39 36 | 
             
            task :submodules do
         | 
| 40 37 | 
             
              if File.exist?(File.dirname(__FILE__) + "/.git")
         | 
| 41 38 | 
             
                sh %{git submodule sync}
         | 
| @@ -43,31 +40,32 @@ task :submodules do | |
| 43 40 | 
             
              end
         | 
| 44 41 | 
             
            end
         | 
| 45 42 |  | 
| 46 | 
            -
             | 
| 47 | 
            -
               | 
| 48 | 
            -
                require ' | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
                task :undocumented do
         | 
| 54 | 
            -
                  command = 'yard --list --query '
         | 
| 55 | 
            -
                  command << '"object.docstring.blank? && '
         | 
| 56 | 
            -
                  command << '!(object.type == :method && object.is_alias?)"'
         | 
| 57 | 
            -
                  sh command
         | 
| 43 | 
            +
            namespace :doc do
         | 
| 44 | 
            +
              task :sass do
         | 
| 45 | 
            +
                require 'sass'
         | 
| 46 | 
            +
                Dir["yard/default/**/*.sass"].each do |sass|
         | 
| 47 | 
            +
                  File.open(sass.gsub(/sass$/, 'css'), 'w') do |f|
         | 
| 48 | 
            +
                    f.write(Sass::Engine.new(File.read(sass)).render)
         | 
| 49 | 
            +
                  end
         | 
| 58 50 | 
             
                end
         | 
| 59 51 | 
             
              end
         | 
| 60 52 |  | 
| 61 | 
            -
              desc " | 
| 62 | 
            -
              task | 
| 53 | 
            +
              desc "List all undocumented methods and classes."
         | 
| 54 | 
            +
              task :undocumented do
         | 
| 55 | 
            +
                command = 'yard --list --query '
         | 
| 56 | 
            +
                command << '"object.docstring.blank? && '
         | 
| 57 | 
            +
                command << '!(object.type == :method && object.is_alias?)"'
         | 
| 58 | 
            +
                sh command
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
            end
         | 
| 63 61 |  | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 62 | 
            +
            desc "Generate documentation"
         | 
| 63 | 
            +
            task(:doc => 'doc:sass') {sh "yard"}
         | 
| 66 64 |  | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 65 | 
            +
            desc "Generate documentation incrementally"
         | 
| 66 | 
            +
            task(:redoc) {sh "yard -c"}
         | 
| 69 67 |  | 
| 70 | 
            -
             | 
| 68 | 
            +
            desc <<END
         | 
| 71 69 | 
             
            Profile Haml.
         | 
| 72 70 | 
             
              TIMES=n sets the number of runs. Defaults to 1000.
         | 
| 73 71 | 
             
              FILE=str sets the file to profile. Defaults to 'standard'
         | 
| @@ -76,15 +74,14 @@ Profile Haml. | |
| 76 74 | 
             
            END
         | 
| 77 75 | 
             
            task :profile do
         | 
| 78 76 | 
             
              times  = (ENV['TIMES'] || '1000').to_i
         | 
| 79 | 
            -
              file   = ENV['FILE']
         | 
| 77 | 
            +
              file   = ENV['FILE'] || 'test/templates/standard.haml'
         | 
| 80 78 |  | 
| 81 79 | 
             
              require 'bundler/setup'
         | 
| 82 80 | 
             
              require 'ruby-prof'
         | 
| 83 81 | 
             
              require 'haml'
         | 
| 84 | 
            -
             | 
| 85 | 
            -
              file = File.read(File.expand_path("../test/templates/#{file || 'standard'}.haml", __FILE__))
         | 
| 82 | 
            +
              file = File.read(File.expand_path("../#{file}", __FILE__))
         | 
| 86 83 | 
             
              obj = Object.new
         | 
| 87 | 
            -
              Haml::Engine.new(file | 
| 84 | 
            +
              Haml::Engine.new(file).def_method(obj, :render)
         | 
| 88 85 | 
             
              result = RubyProf.profile { times.times { obj.render } }
         | 
| 89 86 |  | 
| 90 87 | 
             
              RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
         | 
| @@ -94,19 +91,18 @@ def gemfiles | |
| 94 91 | 
             
              @gemfiles ||= begin
         | 
| 95 92 | 
             
                Dir[File.dirname(__FILE__) + '/test/gemfiles/Gemfile.*'].
         | 
| 96 93 | 
             
                  reject {|f| f =~ /\.lock$/}.
         | 
| 97 | 
            -
                  reject {|f| RUBY_VERSION < '1.9.3' && f =~ / | 
| 94 | 
            +
                  reject {|f| RUBY_VERSION < '1.9.3' && f =~ /Gemfile.rails-(\d+).\d+.x/ && $1.to_i > 3}
         | 
| 98 95 | 
             
              end
         | 
| 99 96 | 
             
            end
         | 
| 100 97 |  | 
| 101 98 | 
             
            def with_each_gemfile
         | 
| 102 | 
            -
              old_env = ENV['BUNDLE_GEMFILE']
         | 
| 103 99 | 
             
              gemfiles.each do |gemfile|
         | 
| 104 | 
            -
                 | 
| 105 | 
            -
             | 
| 106 | 
            -
             | 
| 100 | 
            +
                Bundler.with_clean_env do
         | 
| 101 | 
            +
                  puts "Using gemfile: #{gemfile}"
         | 
| 102 | 
            +
                  ENV['BUNDLE_GEMFILE'] = gemfile
         | 
| 103 | 
            +
                  yield
         | 
| 104 | 
            +
                end
         | 
| 107 105 | 
             
              end
         | 
| 108 | 
            -
            ensure
         | 
| 109 | 
            -
              ENV['BUNDLE_GEMFILE'] = old_env
         | 
| 110 106 | 
             
            end
         | 
| 111 107 |  | 
| 112 108 | 
             
            namespace :test do
         |