haml 4.0.6 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +19 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +72 -0
  5. data/.yardopts +2 -3
  6. data/CHANGELOG.md +138 -4
  7. data/FAQ.md +4 -14
  8. data/Gemfile +16 -0
  9. data/MIT-LICENSE +2 -2
  10. data/README.md +79 -42
  11. data/REFERENCE.md +142 -67
  12. data/Rakefile +44 -63
  13. data/TODO +24 -0
  14. data/benchmark.rb +70 -0
  15. data/haml.gemspec +45 -0
  16. data/lib/haml.rb +2 -0
  17. data/lib/haml/.gitattributes +1 -0
  18. data/lib/haml/attribute_builder.rb +164 -0
  19. data/lib/haml/attribute_compiler.rb +235 -0
  20. data/lib/haml/attribute_parser.rb +150 -0
  21. data/lib/haml/buffer.rb +29 -136
  22. data/lib/haml/compiler.rb +110 -320
  23. data/lib/haml/engine.rb +34 -41
  24. data/lib/haml/error.rb +28 -24
  25. data/lib/haml/escapable.rb +77 -0
  26. data/lib/haml/exec.rb +38 -20
  27. data/lib/haml/filters.rb +22 -27
  28. data/lib/haml/generator.rb +42 -0
  29. data/lib/haml/helpers.rb +134 -89
  30. data/lib/haml/helpers/action_view_extensions.rb +4 -2
  31. data/lib/haml/helpers/action_view_mods.rb +45 -60
  32. data/lib/haml/helpers/action_view_xss_mods.rb +2 -0
  33. data/lib/haml/helpers/safe_erubi_template.rb +20 -0
  34. data/lib/haml/helpers/safe_erubis_template.rb +5 -1
  35. data/lib/haml/helpers/xss_mods.rb +23 -13
  36. data/lib/haml/options.rb +63 -69
  37. data/lib/haml/parser.rb +292 -228
  38. data/lib/haml/plugin.rb +37 -0
  39. data/lib/haml/railtie.rb +38 -12
  40. data/lib/haml/sass_rails_filter.rb +18 -4
  41. data/lib/haml/template.rb +13 -6
  42. data/lib/haml/template/options.rb +13 -2
  43. data/lib/haml/temple_engine.rb +123 -0
  44. data/lib/haml/temple_line_counter.rb +30 -0
  45. data/lib/haml/util.rb +83 -202
  46. data/lib/haml/version.rb +3 -1
  47. data/yard/default/.gitignore +1 -0
  48. data/yard/default/fulldoc/html/css/common.sass +15 -0
  49. data/yard/default/layout/html/footer.erb +12 -0
  50. metadata +73 -108
  51. data/lib/haml/template/plugin.rb +0 -41
  52. data/test/engine_test.rb +0 -2013
  53. data/test/erb/_av_partial_1.erb +0 -12
  54. data/test/erb/_av_partial_2.erb +0 -8
  55. data/test/erb/action_view.erb +0 -62
  56. data/test/erb/standard.erb +0 -55
  57. data/test/filters_test.rb +0 -254
  58. data/test/gemfiles/Gemfile.rails-3.0.x +0 -5
  59. data/test/gemfiles/Gemfile.rails-3.1.x +0 -6
  60. data/test/gemfiles/Gemfile.rails-3.2.x +0 -5
  61. data/test/gemfiles/Gemfile.rails-4.0.x +0 -5
  62. data/test/helper_test.rb +0 -583
  63. data/test/markaby/standard.mab +0 -52
  64. data/test/mocks/article.rb +0 -6
  65. data/test/parser_test.rb +0 -105
  66. data/test/results/content_for_layout.xhtml +0 -12
  67. data/test/results/eval_suppressed.xhtml +0 -9
  68. data/test/results/helpers.xhtml +0 -70
  69. data/test/results/helpful.xhtml +0 -10
  70. data/test/results/just_stuff.xhtml +0 -70
  71. data/test/results/list.xhtml +0 -12
  72. data/test/results/nuke_inner_whitespace.xhtml +0 -40
  73. data/test/results/nuke_outer_whitespace.xhtml +0 -148
  74. data/test/results/original_engine.xhtml +0 -20
  75. data/test/results/partial_layout.xhtml +0 -5
  76. data/test/results/partial_layout_erb.xhtml +0 -5
  77. data/test/results/partials.xhtml +0 -21
  78. data/test/results/render_layout.xhtml +0 -3
  79. data/test/results/silent_script.xhtml +0 -74
  80. data/test/results/standard.xhtml +0 -162
  81. data/test/results/tag_parsing.xhtml +0 -23
  82. data/test/results/very_basic.xhtml +0 -5
  83. data/test/results/whitespace_handling.xhtml +0 -90
  84. data/test/template_test.rb +0 -354
  85. data/test/templates/_av_partial_1.haml +0 -9
  86. data/test/templates/_av_partial_1_ugly.haml +0 -9
  87. data/test/templates/_av_partial_2.haml +0 -5
  88. data/test/templates/_av_partial_2_ugly.haml +0 -5
  89. data/test/templates/_layout.erb +0 -3
  90. data/test/templates/_layout_for_partial.haml +0 -3
  91. data/test/templates/_partial.haml +0 -8
  92. data/test/templates/_text_area.haml +0 -3
  93. data/test/templates/_text_area_helper.html.haml +0 -4
  94. data/test/templates/action_view.haml +0 -47
  95. data/test/templates/action_view_ugly.haml +0 -47
  96. data/test/templates/breakage.haml +0 -8
  97. data/test/templates/content_for_layout.haml +0 -8
  98. data/test/templates/eval_suppressed.haml +0 -11
  99. data/test/templates/helpers.haml +0 -55
  100. data/test/templates/helpful.haml +0 -11
  101. data/test/templates/just_stuff.haml +0 -85
  102. data/test/templates/list.haml +0 -12
  103. data/test/templates/nuke_inner_whitespace.haml +0 -32
  104. data/test/templates/nuke_outer_whitespace.haml +0 -144
  105. data/test/templates/original_engine.haml +0 -17
  106. data/test/templates/partial_layout.haml +0 -3
  107. data/test/templates/partial_layout_erb.erb +0 -4
  108. data/test/templates/partialize.haml +0 -1
  109. data/test/templates/partials.haml +0 -12
  110. data/test/templates/render_layout.haml +0 -2
  111. data/test/templates/silent_script.haml +0 -45
  112. data/test/templates/standard.haml +0 -43
  113. data/test/templates/standard_ugly.haml +0 -43
  114. data/test/templates/tag_parsing.haml +0 -21
  115. data/test/templates/very_basic.haml +0 -4
  116. data/test/templates/whitespace_handling.haml +0 -87
  117. data/test/test_helper.rb +0 -81
  118. data/test/util_test.rb +0 -63
@@ -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
- When using Ruby 1.9 or later, Haml supports the same sorts of
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
- On Ruby 1.9, Haml also supports Ruby's new hash syntax:
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 me merged together, from
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
- #### HTML5 Custom Data Attributes
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 [custom non-visible data
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-`. Custom data attributes
397
- can be used in Haml by using the key `:data` with a Hash value in an attribute
398
- hash. Each of the key/value pairs in the Hash will be transformed into a custom
399
- data attribute. For example:
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
- %a{:href=>"/posts", :data => {:author_id => 123}} Posts By Author
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`). For example:
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 `:html4` or `:html5`, and to
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
- Currently, filters ignore the {Haml::Options#escape_html `:escape_html`} option.
1073
- This means that `#{}` interpolation within filters is never HTML-escaped.
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
- ### `:cdata`
1164
+ ### `:cdata` {#cdata-filter}
1165
+
1092
1166
  Surrounds the filtered text with CDATA tags.
1093
1167
 
1094
- {#coffee-filter}
1095
- ### `:coffee`
1096
- Compiles the filtered text to Javascript using Cofeescript. You can also
1097
- reference this filter as `:coffeescript`. This filter is implemented using
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
- ### `:erb`
1108
- Parses the filtered text with ERb, like an RHTML template. Not available if the
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
- ### `:escaped`
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
- ### `:javascript`
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
- ### `:less`
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
- ### `:markdown`
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
- ### `:maruku`
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
- ### `:plain`
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
- ### `:preserve`
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
- ### `:ruby`
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
- ### `:sass`
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 using Tilt.
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
- ### surround
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
- ### precede
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
- ### succeed
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](#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 "rubygems/package_task"
3
+ require "bundler/gem_tasks"
4
4
 
5
5
  task :default => :test
6
6
 
7
- CLEAN.replace %w(pkg doc coverage .yardoc test/haml vendor)
8
-
9
- def silence_warnings
10
- the_real_stderr, $stderr = $stderr, StringIO.new
11
- yield
12
- ensure
13
- $stderr = the_real_stderr
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 << 'lib' << 'test'
23
- # haml-spec tests are explicitly added after other tests so they don't
24
- # interfere with the Haml loading process which can cause test failures
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
- task :set_coverage_env do
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
- gemspec = File.expand_path("../haml.gemspec", __FILE__)
39
- if File.exist? gemspec
40
- Gem::PackageTask.new(eval(File.read(gemspec))) { |pkg| }
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
- begin
51
- silence_warnings do
52
- require 'yard'
53
- end
54
-
55
- namespace :doc do
56
- desc "List all undocumented methods and classes."
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 "Generate documentation"
66
- task(:doc) {sh "yard"}
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
- desc "Generate documentation incrementally"
69
- task(:redoc) {sh "yard -c"}
55
+ desc "Generate documentation"
56
+ task(:doc => 'doc:sass') {sh "yard"}
70
57
 
71
- rescue LoadError
72
- end
58
+ desc "Generate documentation incrementally"
59
+ task(:redoc) {sh "yard -c"}
73
60
 
74
- desc <<END
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, :ugly => true).def_method(obj, :render)
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 ||= begin
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
- puts "Using gemfile: #{gemfile}"
109
- ENV['BUNDLE_GEMFILE'] = gemfile
110
- yield
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