haml 4.0.6 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +19 -0
- data/.gitmodules +3 -0
- data/.travis.yml +72 -0
- data/.yardopts +2 -3
- data/CHANGELOG.md +138 -4
- data/FAQ.md +4 -14
- data/Gemfile +16 -0
- data/MIT-LICENSE +2 -2
- data/README.md +79 -42
- data/REFERENCE.md +142 -67
- data/Rakefile +44 -63
- data/TODO +24 -0
- data/benchmark.rb +70 -0
- data/haml.gemspec +45 -0
- data/lib/haml.rb +2 -0
- data/lib/haml/.gitattributes +1 -0
- data/lib/haml/attribute_builder.rb +164 -0
- data/lib/haml/attribute_compiler.rb +235 -0
- data/lib/haml/attribute_parser.rb +150 -0
- data/lib/haml/buffer.rb +29 -136
- data/lib/haml/compiler.rb +110 -320
- data/lib/haml/engine.rb +34 -41
- data/lib/haml/error.rb +28 -24
- data/lib/haml/escapable.rb +77 -0
- data/lib/haml/exec.rb +38 -20
- data/lib/haml/filters.rb +22 -27
- data/lib/haml/generator.rb +42 -0
- data/lib/haml/helpers.rb +134 -89
- data/lib/haml/helpers/action_view_extensions.rb +4 -2
- data/lib/haml/helpers/action_view_mods.rb +45 -60
- data/lib/haml/helpers/action_view_xss_mods.rb +2 -0
- data/lib/haml/helpers/safe_erubi_template.rb +20 -0
- data/lib/haml/helpers/safe_erubis_template.rb +5 -1
- data/lib/haml/helpers/xss_mods.rb +23 -13
- data/lib/haml/options.rb +63 -69
- data/lib/haml/parser.rb +292 -228
- data/lib/haml/plugin.rb +37 -0
- data/lib/haml/railtie.rb +38 -12
- data/lib/haml/sass_rails_filter.rb +18 -4
- data/lib/haml/template.rb +13 -6
- data/lib/haml/template/options.rb +13 -2
- data/lib/haml/temple_engine.rb +123 -0
- data/lib/haml/temple_line_counter.rb +30 -0
- data/lib/haml/util.rb +83 -202
- data/lib/haml/version.rb +3 -1
- data/yard/default/.gitignore +1 -0
- data/yard/default/fulldoc/html/css/common.sass +15 -0
- data/yard/default/layout/html/footer.erb +12 -0
- metadata +73 -108
- data/lib/haml/template/plugin.rb +0 -41
- data/test/engine_test.rb +0 -2013
- data/test/erb/_av_partial_1.erb +0 -12
- data/test/erb/_av_partial_2.erb +0 -8
- data/test/erb/action_view.erb +0 -62
- data/test/erb/standard.erb +0 -55
- data/test/filters_test.rb +0 -254
- 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-4.0.x +0 -5
- data/test/helper_test.rb +0 -583
- data/test/markaby/standard.mab +0 -52
- data/test/mocks/article.rb +0 -6
- data/test/parser_test.rb +0 -105
- data/test/results/content_for_layout.xhtml +0 -12
- data/test/results/eval_suppressed.xhtml +0 -9
- data/test/results/helpers.xhtml +0 -70
- data/test/results/helpful.xhtml +0 -10
- data/test/results/just_stuff.xhtml +0 -70
- data/test/results/list.xhtml +0 -12
- data/test/results/nuke_inner_whitespace.xhtml +0 -40
- data/test/results/nuke_outer_whitespace.xhtml +0 -148
- data/test/results/original_engine.xhtml +0 -20
- data/test/results/partial_layout.xhtml +0 -5
- data/test/results/partial_layout_erb.xhtml +0 -5
- data/test/results/partials.xhtml +0 -21
- data/test/results/render_layout.xhtml +0 -3
- data/test/results/silent_script.xhtml +0 -74
- data/test/results/standard.xhtml +0 -162
- data/test/results/tag_parsing.xhtml +0 -23
- data/test/results/very_basic.xhtml +0 -5
- data/test/results/whitespace_handling.xhtml +0 -90
- data/test/template_test.rb +0 -354
- data/test/templates/_av_partial_1.haml +0 -9
- data/test/templates/_av_partial_1_ugly.haml +0 -9
- data/test/templates/_av_partial_2.haml +0 -5
- data/test/templates/_av_partial_2_ugly.haml +0 -5
- data/test/templates/_layout.erb +0 -3
- data/test/templates/_layout_for_partial.haml +0 -3
- data/test/templates/_partial.haml +0 -8
- data/test/templates/_text_area.haml +0 -3
- data/test/templates/_text_area_helper.html.haml +0 -4
- data/test/templates/action_view.haml +0 -47
- data/test/templates/action_view_ugly.haml +0 -47
- data/test/templates/breakage.haml +0 -8
- data/test/templates/content_for_layout.haml +0 -8
- data/test/templates/eval_suppressed.haml +0 -11
- data/test/templates/helpers.haml +0 -55
- data/test/templates/helpful.haml +0 -11
- data/test/templates/just_stuff.haml +0 -85
- data/test/templates/list.haml +0 -12
- data/test/templates/nuke_inner_whitespace.haml +0 -32
- data/test/templates/nuke_outer_whitespace.haml +0 -144
- data/test/templates/original_engine.haml +0 -17
- data/test/templates/partial_layout.haml +0 -3
- data/test/templates/partial_layout_erb.erb +0 -4
- data/test/templates/partialize.haml +0 -1
- data/test/templates/partials.haml +0 -12
- data/test/templates/render_layout.haml +0 -2
- data/test/templates/silent_script.haml +0 -45
- data/test/templates/standard.haml +0 -43
- data/test/templates/standard_ugly.haml +0 -43
- data/test/templates/tag_parsing.haml +0 -21
- data/test/templates/very_basic.haml +0 -4
- data/test/templates/whitespace_handling.haml +0 -87
- data/test/test_helper.rb +0 -81
- data/test/util_test.rb +0 -63
data/REFERENCE.md
CHANGED
@@ -115,13 +115,18 @@ Haml::Options.defaults:
|
|
115
115
|
|
116
116
|
Haml::Options.defaults[:format] = :html5
|
117
117
|
|
118
|
+
In sinatra specifically, you can set them in global config with:
|
119
|
+
```ruby
|
120
|
+
set :haml, { escape_html: true }
|
121
|
+
```
|
122
|
+
|
118
123
|
Finally, you can also set them by passing an options hash to
|
119
124
|
{Haml::Engine#initialize}. For the complete list of available options, please
|
120
125
|
see {Haml::Options}.
|
121
126
|
|
122
127
|
### Encodings
|
123
128
|
|
124
|
-
|
129
|
+
Haml supports the same sorts of
|
125
130
|
encoding-declaration comments that Ruby does. Although both Ruby and Haml
|
126
131
|
support several different styles, the easiest it just to add `-# coding:
|
127
132
|
encoding-name` at the beginning of the Haml template (it must come before all
|
@@ -233,8 +238,7 @@ is compiled to:
|
|
233
238
|
|
234
239
|
<script src='javascripts/script_9' type='text/javascript'></script>
|
235
240
|
|
236
|
-
#### `:class` and `:id` Attributes
|
237
|
-
{#class-and-id-attributes}
|
241
|
+
#### `:class` and `:id` Attributes {#class-and-id-attributes}
|
238
242
|
|
239
243
|
The `:class` and `:id` attributes can also be specified as a Ruby array whose
|
240
244
|
elements will be joined together. A `:class` array is joined with `" "` and an
|
@@ -306,7 +310,7 @@ hash-style attributes:
|
|
306
310
|
|
307
311
|
#### Ruby 1.9-style Hashes
|
308
312
|
|
309
|
-
|
313
|
+
Haml also supports Ruby's new hash syntax:
|
310
314
|
|
311
315
|
%a{title: @title, href: href} Stuff
|
312
316
|
|
@@ -329,7 +333,7 @@ This is compiled to:
|
|
329
333
|
</html>
|
330
334
|
|
331
335
|
You can use as many such attribute methods as you want by separating them with
|
332
|
-
commas, like a Ruby argument list. All the hashes will
|
336
|
+
commas, like a Ruby argument list. All the hashes will be merged together, from
|
333
337
|
left to right. For example, if you defined
|
334
338
|
|
335
339
|
def hash1
|
@@ -389,27 +393,49 @@ or using `true` and `false`:
|
|
389
393
|
|
390
394
|
%input(selected=true)
|
391
395
|
|
392
|
-
|
396
|
+
<!-- The title to the next section (Prefixed Attributes) has changed. This
|
397
|
+
<a> tag is so old links to here still work. -->
|
398
|
+
<a id="html5_custom_data_attributes" style="border:0;"></a>
|
399
|
+
|
400
|
+
#### Prefixed Attributes
|
393
401
|
|
394
|
-
HTML5 allows for adding
|
395
|
-
attributes](http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#embedding-custom-non-visible-data)
|
396
|
-
to elements using attribute names beginning with `data-`.
|
397
|
-
|
398
|
-
|
399
|
-
|
402
|
+
HTML5 allows for adding
|
403
|
+
[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)
|
404
|
+
to elements using attribute names beginning with `data-`. The
|
405
|
+
[Accessible Rich Internet Applications](http://www.w3.org/WAI/intro/aria)
|
406
|
+
specification makes use of attributes beginning with `aria-`. There are also
|
407
|
+
frameworks that use non-standard attributes with a common prefix.
|
400
408
|
|
401
|
-
|
409
|
+
Haml can help generate collections of attributes that share a prefix like
|
410
|
+
these. Any entry in an attribute hash that has a Hash as its value is expanded
|
411
|
+
into a series of attributes, one for each key/value pair in the hash, with the
|
412
|
+
attribute name formed by joining the “parent” key name to the key name with a
|
413
|
+
hyphen.
|
414
|
+
|
415
|
+
For example:
|
416
|
+
|
417
|
+
%a{:href=>"/posts", :data => {:author_id => 123, :category => 7}} Posts By Author
|
402
418
|
|
403
419
|
will render as:
|
404
420
|
|
405
|
-
<a data-author-id='123' href='/posts'>Posts By Author</a>
|
421
|
+
<a data-author-id='123' data-category='7' href='/posts'>Posts By Author</a>
|
406
422
|
|
407
423
|
Notice that the underscore in `author_id` was replaced by a hyphen. If you wish
|
408
424
|
to suppress this behavior, you can set Haml's
|
409
425
|
{Haml::Options#hyphenate_data_attrs `:hyphenate_data_attrs` option} to `false`,
|
410
426
|
and the output will be rendered as:
|
411
427
|
|
412
|
-
<a data-author_id='123' href='/posts'>Posts By Author</a>
|
428
|
+
<a data-author_id='123' data-category='7' href='/posts'>Posts By Author</a>
|
429
|
+
|
430
|
+
This expansion of hashes is recursive – any value of the child hash that is
|
431
|
+
itself a hash will create an attribute for each entry, with the attribute name
|
432
|
+
prefixed with all ancestor keys. For example:
|
433
|
+
|
434
|
+
.book-info{:data => {:book => {:id => 123, :genre => 'programming'}, :category => 7}}
|
435
|
+
|
436
|
+
will render as:
|
437
|
+
|
438
|
+
<div class='book-info' data-book-genre='programming' data-book-id='123' data-category='7'></div>
|
413
439
|
|
414
440
|
### Class and ID: `.` and `#`
|
415
441
|
|
@@ -491,28 +517,46 @@ and is compiled to:
|
|
491
517
|
</div>
|
492
518
|
</div>
|
493
519
|
|
520
|
+
#### Class Name Merging and Ordering
|
521
|
+
|
522
|
+
Class names are ordered in the following way:
|
523
|
+
|
524
|
+
1) Tag identifiers in order (aka, ".alert.me" => "alert me")
|
525
|
+
2) Classes appearing in HTML-style attributes
|
526
|
+
3) Classes appearing in Hash-style attributes
|
527
|
+
|
528
|
+
For instance, this is a complicated and unintuitive test case illustrating the ordering
|
529
|
+
|
530
|
+
.foo.moo{:class => ['bar', 'alpha']}(class='baz')
|
531
|
+
|
532
|
+
The resulting HTML would be as follows:
|
533
|
+
|
534
|
+
<div class='foo moo baz bar alpha'></div>
|
535
|
+
|
536
|
+
*Versions of Haml prior to 5.0 would alphabetically sort class names.*
|
537
|
+
|
494
538
|
### Empty (void) Tags: `/`
|
495
539
|
|
496
540
|
The forward slash character, when placed at the end of a tag definition, causes
|
497
541
|
Haml to treat it as being an empty (or void) element. Depending on the format,
|
498
542
|
the tag will be rendered either without a closing tag (`:html4` or `:html5`), or
|
499
|
-
as a self-closing tag (`:xhtml`).
|
543
|
+
as a self-closing tag (`:xhtml`).
|
544
|
+
|
545
|
+
Taking the following as an example:
|
500
546
|
|
501
547
|
%br/
|
502
548
|
%meta{'http-equiv' => 'Content-Type', :content => 'text/html'}/
|
503
549
|
|
504
|
-
is compiled to:
|
550
|
+
When the format is `:html4` or `:html5` this is compiled to:
|
505
551
|
|
506
552
|
<br>
|
507
553
|
<meta content='text/html' http-equiv='Content-Type'>
|
508
554
|
|
509
|
-
when the format is `:
|
555
|
+
and when the format is `:xhtml` it is compiled to:
|
510
556
|
|
511
557
|
<br />
|
512
558
|
<meta content='text/html' http-equiv='Content-Type' />
|
513
559
|
|
514
|
-
when the format is `:xhtml`.
|
515
|
-
|
516
560
|
Some tags are automatically treated as being empty, as long as they have no
|
517
561
|
content in the Haml source. `meta`, `img`, `link`, `br`, `hr`, `input`,
|
518
562
|
`area`, `param`, `col` and `base` tags are treated as empty by default. This
|
@@ -779,6 +823,21 @@ is compiled to:
|
|
779
823
|
</a>
|
780
824
|
<![endif]-->
|
781
825
|
|
826
|
+
To generate “downlevel-revealed” conditional comments, where the content is
|
827
|
+
hidden from IE but not other browsers, add a `!` before the brackets: `/![]`.
|
828
|
+
Haml will produce valid HTML when generating this kind of conditional comment.
|
829
|
+
|
830
|
+
For example:
|
831
|
+
|
832
|
+
/![if !IE]
|
833
|
+
You are not using Internet Explorer, or are using version 10+.
|
834
|
+
|
835
|
+
is compiled to:
|
836
|
+
|
837
|
+
<!--[if !IE]><!-->
|
838
|
+
You are not using Internet Explorer, or are using version 10+.
|
839
|
+
<!--<![endif]-->
|
840
|
+
|
782
841
|
### Haml Comments: `-#`
|
783
842
|
|
784
843
|
The hyphen followed immediately by the pound sign signifies a silent comment.
|
@@ -812,7 +871,7 @@ is compiled to:
|
|
812
871
|
|
813
872
|
## Ruby Evaluation
|
814
873
|
|
815
|
-
### Inserting Ruby: `=`
|
874
|
+
### Inserting Ruby: `=` {#inserting_ruby}
|
816
875
|
|
817
876
|
The equals character is followed by Ruby code. This code is evaluated and the
|
818
877
|
output is inserted into the document. For example:
|
@@ -985,6 +1044,21 @@ might compile to:
|
|
985
1044
|
//]]>
|
986
1045
|
</script>
|
987
1046
|
|
1047
|
+
#### Gotchas
|
1048
|
+
|
1049
|
+
Haml uses an overly simplistic regular expression to identify string
|
1050
|
+
interpolation rather than a full-blown Ruby parser. This is fast and works for
|
1051
|
+
most code but you may have errors with code like the following:
|
1052
|
+
|
1053
|
+
%span #{'{'}
|
1054
|
+
|
1055
|
+
This code will generate a syntax error, complaining about unbalanced brackets.
|
1056
|
+
In cases like this, the recommended workaround is output the code as a Ruby
|
1057
|
+
string to force Haml to parse the code with Ruby.
|
1058
|
+
|
1059
|
+
%span= "#{'{'}"
|
1060
|
+
|
1061
|
+
|
988
1062
|
### Escaping HTML: `&=` {#escaping_html}
|
989
1063
|
|
990
1064
|
An ampersand followed by one or two equals characters evaluates Ruby code just
|
@@ -1069,8 +1143,8 @@ is compiled to
|
|
1069
1143
|
<p>I <strong>really</strong> prefer <em>raspberry</em> jam.</p>
|
1070
1144
|
</div>
|
1071
1145
|
|
1072
|
-
|
1073
|
-
|
1146
|
+
Note that `#{}` interpolation within filters is HTML-escaped if you specify true to
|
1147
|
+
{Haml::Options#escape_filter_interpolations `:escape_filter_interpolations`} option.
|
1074
1148
|
|
1075
1149
|
The functionality of some filters such as Markdown can be provided by many
|
1076
1150
|
different libraries. Usually you don't have to worry about this - you can just
|
@@ -1087,53 +1161,53 @@ more info.
|
|
1087
1161
|
|
1088
1162
|
Haml comes with the following filters defined:
|
1089
1163
|
|
1090
|
-
{#cdata-filter}
|
1091
|
-
|
1164
|
+
### `:cdata` {#cdata-filter}
|
1165
|
+
|
1092
1166
|
Surrounds the filtered text with CDATA tags.
|
1093
1167
|
|
1094
|
-
{#coffee-filter}
|
1095
|
-
|
1096
|
-
Compiles the filtered text to
|
1097
|
-
reference this filter as `:coffeescript`. This filter is
|
1098
|
-
Tilt.
|
1168
|
+
### `:coffee` {#coffee-filter}
|
1169
|
+
|
1170
|
+
Compiles the filtered text to JavaScript in `<script>` tag using CoffeeScript.
|
1171
|
+
You can also reference this filter as `:coffeescript`. This filter is
|
1172
|
+
implemented using Tilt.
|
1173
|
+
|
1174
|
+
### `:css` {#css-filter}
|
1099
1175
|
|
1100
|
-
{#css-filter}
|
1101
|
-
### `:css`
|
1102
1176
|
Surrounds the filtered text with `<style>` and (optionally) CDATA tags. Useful
|
1103
1177
|
for including inline CSS. Use the {Haml::Options#cdata `:cdata` option} to
|
1104
1178
|
control when CDATA tags are added.
|
1105
1179
|
|
1106
|
-
{#erb-filter}
|
1107
|
-
|
1108
|
-
Parses the filtered text with
|
1180
|
+
### `:erb` {#erb-filter}
|
1181
|
+
|
1182
|
+
Parses the filtered text with ERB, like an RHTML template. Not available if the
|
1109
1183
|
{Haml::Options#suppress_eval `:suppress_eval`} option is set to true. Embedded
|
1110
1184
|
Ruby code is evaluated in the same context as the Haml template. This filter is
|
1111
1185
|
implemented using Tilt.
|
1112
1186
|
|
1113
|
-
{#escaped-filter}
|
1114
|
-
|
1187
|
+
### `:escaped` {#escaped-filter}
|
1188
|
+
|
1115
1189
|
Works the same as plain, but HTML-escapes the text
|
1116
1190
|
before placing it in the document.
|
1117
1191
|
|
1118
|
-
{#javascript-filter}
|
1119
|
-
|
1192
|
+
### `:javascript` {#javascript-filter}
|
1193
|
+
|
1120
1194
|
Surrounds the filtered text with `<script>` and (optionally) CDATA tags.
|
1121
1195
|
Useful for including inline Javascript. Use the {Haml::Options#cdata `:cdata`
|
1122
1196
|
option} to control when CDATA tags are added.
|
1123
1197
|
|
1124
|
-
{#less-filter}
|
1125
|
-
|
1126
|
-
Parses the filtered text with [Less](http://lesscss.org/) to produce CSS output.
|
1198
|
+
### `:less` {#less-filter}
|
1199
|
+
|
1200
|
+
Parses the filtered text with [Less](http://lesscss.org/) to produce CSS output in `<style>` tag.
|
1127
1201
|
This filter is implemented using Tilt.
|
1128
1202
|
|
1129
|
-
{#markdown-filter}
|
1130
|
-
|
1203
|
+
### `:markdown` {#markdown-filter}
|
1204
|
+
|
1131
1205
|
Parses the filtered text with
|
1132
1206
|
[Markdown](http://daringfireball.net/projects/markdown). This filter is
|
1133
1207
|
implemented using Tilt.
|
1134
1208
|
|
1135
|
-
{#maruku-filter}
|
1136
|
-
|
1209
|
+
### `:maruku` {#maruku-filter}
|
1210
|
+
|
1137
1211
|
Parses the filtered text with [Maruku](https://github.com/nex3/maruku), which
|
1138
1212
|
has some non-standard extensions to Markdown.
|
1139
1213
|
|
@@ -1142,39 +1216,40 @@ contrib](https://github.com/haml/haml-contrib) but is loaded automatically for
|
|
1142
1216
|
historical reasons. In future versions of Haml it will likely not be loaded by
|
1143
1217
|
default. This filter is implemented using Tilt.
|
1144
1218
|
|
1145
|
-
{#plain-filter}
|
1146
|
-
|
1219
|
+
### `:plain` {#plain-filter}
|
1220
|
+
|
1147
1221
|
Does not parse the filtered text. This is useful for large blocks of text
|
1148
1222
|
without HTML tags, when you don't want lines starting with `.` or `-` to be
|
1149
1223
|
parsed.
|
1150
1224
|
|
1151
|
-
{#preserve-filter}
|
1152
|
-
|
1225
|
+
### `:preserve` {#preserve-filter}
|
1226
|
+
|
1153
1227
|
Inserts the filtered text into the template with whitespace preserved.
|
1154
1228
|
`preserve`d blocks of text aren't indented, and newlines are replaced with the
|
1155
1229
|
HTML escape code for newlines, to preserve nice-looking output. See also
|
1156
1230
|
[Whitespace Preservation](#whitespace_preservation).
|
1157
1231
|
|
1158
|
-
{#ruby-filter}
|
1159
|
-
|
1232
|
+
### `:ruby` {#ruby-filter}
|
1233
|
+
|
1160
1234
|
Parses the filtered text with the normal Ruby interpreter. Creates an `IO`
|
1161
1235
|
object named `haml_io`, anything written to it is output into the Haml document.
|
1162
1236
|
Not available if the {Haml::Options#suppress_eval `:suppress_eval`} option is
|
1163
1237
|
set to true. The Ruby code is evaluated in the same context as the Haml
|
1164
1238
|
template.
|
1165
1239
|
|
1166
|
-
{#sass-filter}
|
1167
|
-
|
1240
|
+
### `:sass` {#sass-filter}
|
1241
|
+
|
1168
1242
|
Parses the filtered text with [Sass](http://sass-lang.com/) to produce CSS
|
1169
|
-
output. This filter is implemented using Tilt.
|
1243
|
+
output in `<style>` tag. This filter is implemented using Tilt.
|
1244
|
+
|
1245
|
+
### `:scss` {#scss-filter}
|
1170
1246
|
|
1171
|
-
{#scss-filter}
|
1172
|
-
### `:scss`
|
1173
1247
|
Parses the filtered text with Sass like the `:sass` filter, but uses the newer
|
1174
|
-
SCSS syntax to produce CSS output. This filter is implemented
|
1248
|
+
SCSS syntax to produce CSS output in `<style>` tag. This filter is implemented
|
1249
|
+
using Tilt.
|
1250
|
+
|
1251
|
+
### `:textile` {#textile-filter}
|
1175
1252
|
|
1176
|
-
{#textile-filter}
|
1177
|
-
### `:textile`
|
1178
1253
|
Parses the filtered text with [Textile](http://www.textism.com/tools/textile).
|
1179
1254
|
Only works if [RedCloth](http://redcloth.org) is installed.
|
1180
1255
|
|
@@ -1194,8 +1269,8 @@ the whitespace removal methods allow. There are a few helper methods that are
|
|
1194
1269
|
useful when dealing with inline content. All these methods take a Haml block to
|
1195
1270
|
modify.
|
1196
1271
|
|
1197
|
-
{#surround}
|
1198
|
-
|
1272
|
+
### surround {#surround}
|
1273
|
+
|
1199
1274
|
Surrounds a Haml block with text. Expects 1 or 2 string arguments used to
|
1200
1275
|
surround the Haml block. If a second argument is not provided, the first
|
1201
1276
|
argument is used as the second.
|
@@ -1203,15 +1278,15 @@ argument is used as the second.
|
|
1203
1278
|
= surround "(", ")" do
|
1204
1279
|
= link_to "learn more", "#"
|
1205
1280
|
|
1206
|
-
{#precede}
|
1207
|
-
|
1281
|
+
### precede {#precede}
|
1282
|
+
|
1208
1283
|
Prepends a Haml block with text. Expects 1 argument.
|
1209
1284
|
|
1210
1285
|
= precede "*" do
|
1211
1286
|
%span Required
|
1212
1287
|
|
1213
|
-
{#succeed}
|
1214
|
-
|
1288
|
+
### succeed {#succeed}
|
1289
|
+
|
1215
1290
|
Appends a Haml block with text. Expects 1 argument.
|
1216
1291
|
|
1217
1292
|
Begin by
|
@@ -1266,7 +1341,7 @@ that just need a lot of template information.
|
|
1266
1341
|
So data structures and functions that require lots of arguments
|
1267
1342
|
can be wrapped over multiple lines,
|
1268
1343
|
as long as each line but the last ends in a comma
|
1269
|
-
(see [Inserting Ruby](#
|
1344
|
+
(see [Inserting Ruby](#inserting_ruby)).
|
1270
1345
|
|
1271
1346
|
## Whitespace Preservation
|
1272
1347
|
|
data/Rakefile
CHANGED
@@ -1,43 +1,29 @@
|
|
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
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
desc "Benchmark Haml against ERb. TIMES=n sets the number of runs, default is 1000."
|
17
|
-
task :benchmark do
|
18
|
-
sh "ruby benchmark.rb #{ENV['TIMES']}"
|
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
|
19
14
|
end
|
20
|
-
|
21
15
|
Rake::TestTask.new do |t|
|
22
|
-
t.libs << '
|
23
|
-
|
24
|
-
|
25
|
-
files = Dir["test/*_test.rb"]
|
26
|
-
files.concat(Dir['test/haml-spec/*_test.rb'])
|
27
|
-
t.test_files = files
|
16
|
+
t.libs << 'test'
|
17
|
+
t.test_files = Dir['test/*_test.rb'] + Dir['test/haml-spec/*_test.rb'] + Dir['test/cases/*_test.rb'] - isolated_test.file_list
|
18
|
+
t.warning = true
|
28
19
|
t.verbose = true
|
29
20
|
end
|
30
21
|
|
31
|
-
|
32
|
-
ENV["COVERAGE"] = "true"
|
33
|
-
end
|
34
|
-
|
35
|
-
desc "Run Simplecov (only works on 1.9)"
|
36
|
-
task :coverage => [:set_coverage_env, :test]
|
22
|
+
CLEAN.replace %w(pkg doc coverage .yardoc test/haml vendor)
|
37
23
|
|
38
|
-
|
39
|
-
|
40
|
-
|
24
|
+
desc "Benchmark Haml against ERB. TIMES=n sets the number of runs, default is 1000."
|
25
|
+
task :benchmark do
|
26
|
+
sh "ruby benchmark.rb #{ENV['TIMES']}"
|
41
27
|
end
|
42
28
|
|
43
29
|
task :submodules do
|
@@ -47,31 +33,32 @@ task :submodules do
|
|
47
33
|
end
|
48
34
|
end
|
49
35
|
|
50
|
-
|
51
|
-
|
52
|
-
require '
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
task :undocumented do
|
58
|
-
command = 'yard --list --query '
|
59
|
-
command << '"object.docstring.blank? && '
|
60
|
-
command << '!(object.type == :method && object.is_alias?)"'
|
61
|
-
sh command
|
36
|
+
namespace :doc do
|
37
|
+
task :sass do
|
38
|
+
require 'sass'
|
39
|
+
Dir["yard/default/**/*.sass"].each do |sass|
|
40
|
+
File.open(sass.gsub(/sass$/, 'css'), 'w') do |f|
|
41
|
+
f.write(Sass::Engine.new(File.read(sass)).render)
|
42
|
+
end
|
62
43
|
end
|
63
44
|
end
|
64
45
|
|
65
|
-
desc "
|
66
|
-
task
|
46
|
+
desc "List all undocumented methods and classes."
|
47
|
+
task :undocumented do
|
48
|
+
command = 'yard --list --query '
|
49
|
+
command << '"object.docstring.blank? && '
|
50
|
+
command << '!(object.type == :method && object.is_alias?)"'
|
51
|
+
sh command
|
52
|
+
end
|
53
|
+
end
|
67
54
|
|
68
|
-
|
69
|
-
|
55
|
+
desc "Generate documentation"
|
56
|
+
task(:doc => 'doc:sass') {sh "yard"}
|
70
57
|
|
71
|
-
|
72
|
-
|
58
|
+
desc "Generate documentation incrementally"
|
59
|
+
task(:redoc) {sh "yard -c"}
|
73
60
|
|
74
|
-
|
61
|
+
desc <<END
|
75
62
|
Profile Haml.
|
76
63
|
TIMES=n sets the number of runs. Defaults to 1000.
|
77
64
|
FILE=str sets the file to profile. Defaults to 'standard'
|
@@ -80,37 +67,31 @@ Profile Haml.
|
|
80
67
|
END
|
81
68
|
task :profile do
|
82
69
|
times = (ENV['TIMES'] || '1000').to_i
|
83
|
-
file = ENV['FILE']
|
70
|
+
file = ENV['FILE'] || 'test/templates/standard.haml'
|
84
71
|
|
85
72
|
require 'bundler/setup'
|
86
73
|
require 'ruby-prof'
|
87
74
|
require 'haml'
|
88
|
-
|
89
|
-
file = File.read(File.expand_path("../test/templates/#{file || 'standard'}.haml", __FILE__))
|
75
|
+
file = File.read(File.expand_path("../#{file}", __FILE__))
|
90
76
|
obj = Object.new
|
91
|
-
Haml::Engine.new(file
|
77
|
+
Haml::Engine.new(file).def_method(obj, :render)
|
92
78
|
result = RubyProf.profile { times.times { obj.render } }
|
93
79
|
|
94
80
|
RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
|
95
81
|
end
|
96
82
|
|
97
83
|
def gemfiles
|
98
|
-
@gemfiles ||=
|
99
|
-
Dir[File.dirname(__FILE__) + '/test/gemfiles/Gemfile.*'].
|
100
|
-
reject {|f| f =~ /\.lock$/}.
|
101
|
-
reject {|f| RUBY_VERSION < '1.9.3' && f =~ /Gemfile.rails-(\d+).\d+.x/ && $1.to_i > 3}
|
102
|
-
end
|
84
|
+
@gemfiles ||= Dir[File.dirname(__FILE__) + '/test/gemfiles/Gemfile.*'].reject {|f| f =~ /\.lock$/}
|
103
85
|
end
|
104
86
|
|
105
87
|
def with_each_gemfile
|
106
|
-
old_env = ENV['BUNDLE_GEMFILE']
|
107
88
|
gemfiles.each do |gemfile|
|
108
|
-
|
109
|
-
|
110
|
-
|
89
|
+
Bundler.with_clean_env do
|
90
|
+
puts "Using gemfile: #{gemfile}"
|
91
|
+
ENV['BUNDLE_GEMFILE'] = gemfile
|
92
|
+
yield
|
93
|
+
end
|
111
94
|
end
|
112
|
-
ensure
|
113
|
-
ENV['BUNDLE_GEMFILE'] = old_env
|
114
95
|
end
|
115
96
|
|
116
97
|
namespace :test do
|