haml 4.0.7 → 5.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +18 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +54 -0
  5. data/.yardopts +1 -1
  6. data/CHANGELOG.md +96 -4
  7. data/FAQ.md +4 -14
  8. data/Gemfile +19 -0
  9. data/MIT-LICENSE +1 -1
  10. data/README.md +80 -42
  11. data/REFERENCE.md +116 -64
  12. data/Rakefile +46 -54
  13. data/TODO +24 -0
  14. data/benchmark.rb +66 -0
  15. data/haml.gemspec +38 -0
  16. data/lib/haml/.gitattributes +1 -0
  17. data/lib/haml/attribute_builder.rb +163 -0
  18. data/lib/haml/attribute_compiler.rb +223 -0
  19. data/lib/haml/attribute_parser.rb +148 -0
  20. data/lib/haml/buffer.rb +22 -132
  21. data/lib/haml/compiler.rb +89 -298
  22. data/lib/haml/engine.rb +25 -41
  23. data/lib/haml/error.rb +3 -0
  24. data/lib/haml/escapable.rb +49 -0
  25. data/lib/haml/exec.rb +38 -19
  26. data/lib/haml/filters.rb +18 -24
  27. data/lib/haml/generator.rb +41 -0
  28. data/lib/haml/helpers/action_view_extensions.rb +3 -2
  29. data/lib/haml/helpers/action_view_mods.rb +42 -60
  30. data/lib/haml/helpers/action_view_xss_mods.rb +1 -0
  31. data/lib/haml/helpers/safe_erubi_template.rb +19 -0
  32. data/lib/haml/helpers/safe_erubis_template.rb +4 -1
  33. data/lib/haml/helpers/xss_mods.rb +18 -12
  34. data/lib/haml/helpers.rb +132 -89
  35. data/lib/haml/options.rb +41 -47
  36. data/lib/haml/parser.rb +278 -216
  37. data/lib/haml/{template/plugin.rb → plugin.rb} +8 -15
  38. data/lib/haml/railtie.rb +38 -12
  39. data/lib/haml/sass_rails_filter.rb +17 -4
  40. data/lib/haml/template/options.rb +12 -2
  41. data/lib/haml/template.rb +12 -6
  42. data/lib/haml/temple_engine.rb +121 -0
  43. data/lib/haml/temple_line_counter.rb +29 -0
  44. data/lib/haml/util.rb +80 -199
  45. data/lib/haml/version.rb +2 -1
  46. data/lib/haml.rb +1 -0
  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 +50 -111
  51. data/test/engine_test.rb +0 -2013
  52. data/test/erb/_av_partial_1.erb +0 -12
  53. data/test/erb/_av_partial_2.erb +0 -8
  54. data/test/erb/action_view.erb +0 -62
  55. data/test/erb/standard.erb +0 -55
  56. data/test/filters_test.rb +0 -254
  57. data/test/gemfiles/Gemfile.rails-3.0.x +0 -5
  58. data/test/gemfiles/Gemfile.rails-3.1.x +0 -6
  59. data/test/gemfiles/Gemfile.rails-3.2.x +0 -5
  60. data/test/gemfiles/Gemfile.rails-4.0.x +0 -5
  61. data/test/haml-spec/LICENSE +0 -14
  62. data/test/haml-spec/README.md +0 -106
  63. data/test/haml-spec/lua_haml_spec.lua +0 -38
  64. data/test/haml-spec/perl_haml_test.pl +0 -81
  65. data/test/haml-spec/ruby_haml_test.rb +0 -23
  66. data/test/haml-spec/tests.json +0 -660
  67. data/test/helper_test.rb +0 -583
  68. data/test/markaby/standard.mab +0 -52
  69. data/test/mocks/article.rb +0 -6
  70. data/test/parser_test.rb +0 -105
  71. data/test/results/content_for_layout.xhtml +0 -12
  72. data/test/results/eval_suppressed.xhtml +0 -9
  73. data/test/results/helpers.xhtml +0 -70
  74. data/test/results/helpful.xhtml +0 -10
  75. data/test/results/just_stuff.xhtml +0 -70
  76. data/test/results/list.xhtml +0 -12
  77. data/test/results/nuke_inner_whitespace.xhtml +0 -40
  78. data/test/results/nuke_outer_whitespace.xhtml +0 -148
  79. data/test/results/original_engine.xhtml +0 -20
  80. data/test/results/partial_layout.xhtml +0 -5
  81. data/test/results/partial_layout_erb.xhtml +0 -5
  82. data/test/results/partials.xhtml +0 -21
  83. data/test/results/render_layout.xhtml +0 -3
  84. data/test/results/silent_script.xhtml +0 -74
  85. data/test/results/standard.xhtml +0 -162
  86. data/test/results/tag_parsing.xhtml +0 -23
  87. data/test/results/very_basic.xhtml +0 -5
  88. data/test/results/whitespace_handling.xhtml +0 -90
  89. data/test/template_test.rb +0 -354
  90. data/test/templates/_av_partial_1.haml +0 -9
  91. data/test/templates/_av_partial_1_ugly.haml +0 -9
  92. data/test/templates/_av_partial_2.haml +0 -5
  93. data/test/templates/_av_partial_2_ugly.haml +0 -5
  94. data/test/templates/_layout.erb +0 -3
  95. data/test/templates/_layout_for_partial.haml +0 -3
  96. data/test/templates/_partial.haml +0 -8
  97. data/test/templates/_text_area.haml +0 -3
  98. data/test/templates/_text_area_helper.html.haml +0 -4
  99. data/test/templates/action_view.haml +0 -47
  100. data/test/templates/action_view_ugly.haml +0 -47
  101. data/test/templates/breakage.haml +0 -8
  102. data/test/templates/content_for_layout.haml +0 -8
  103. data/test/templates/eval_suppressed.haml +0 -11
  104. data/test/templates/helpers.haml +0 -55
  105. data/test/templates/helpful.haml +0 -11
  106. data/test/templates/just_stuff.haml +0 -85
  107. data/test/templates/list.haml +0 -12
  108. data/test/templates/nuke_inner_whitespace.haml +0 -32
  109. data/test/templates/nuke_outer_whitespace.haml +0 -144
  110. data/test/templates/original_engine.haml +0 -17
  111. data/test/templates/partial_layout.haml +0 -3
  112. data/test/templates/partial_layout_erb.erb +0 -4
  113. data/test/templates/partialize.haml +0 -1
  114. data/test/templates/partials.haml +0 -12
  115. data/test/templates/render_layout.haml +0 -2
  116. data/test/templates/silent_script.haml +0 -45
  117. data/test/templates/standard.haml +0 -43
  118. data/test/templates/standard_ugly.haml +0 -43
  119. data/test/templates/tag_parsing.haml +0 -21
  120. data/test/templates/very_basic.haml +0 -4
  121. data/test/templates/whitespace_handling.haml +0 -87
  122. data/test/test_helper.rb +0 -81
  123. data/test/util_test.rb +0 -63
data/REFERENCE.md CHANGED
@@ -121,7 +121,7 @@ see {Haml::Options}.
121
121
 
122
122
  ### Encodings
123
123
 
124
- When using Ruby 1.9 or later, Haml supports the same sorts of
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
@@ -233,8 +233,7 @@ is compiled to:
233
233
 
234
234
  <script src='javascripts/script_9' type='text/javascript'></script>
235
235
 
236
- #### `:class` and `:id` Attributes
237
- {#class-and-id-attributes}
236
+ #### `:class` and `:id` Attributes {#class-and-id-attributes}
238
237
 
239
238
  The `:class` and `:id` attributes can also be specified as a Ruby array whose
240
239
  elements will be joined together. A `:class` array is joined with `" "` and an
@@ -306,7 +305,7 @@ hash-style attributes:
306
305
 
307
306
  #### Ruby 1.9-style Hashes
308
307
 
309
- On Ruby 1.9, Haml also supports Ruby's new hash syntax:
308
+ Haml also supports Ruby's new hash syntax:
310
309
 
311
310
  %a{title: @title, href: href} Stuff
312
311
 
@@ -389,27 +388,49 @@ or using `true` and `false`:
389
388
 
390
389
  %input(selected=true)
391
390
 
392
- #### HTML5 Custom Data Attributes
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>
393
394
 
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:
395
+ #### Prefixed Attributes
400
396
 
401
- %a{:href=>"/posts", :data => {:author_id => 123}} Posts By Author
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.
403
+
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
402
413
 
403
414
  will render as:
404
415
 
405
- <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>
406
417
 
407
418
  Notice that the underscore in `author_id` was replaced by a hyphen. If you wish
408
419
  to suppress this behavior, you can set Haml's
409
420
  {Haml::Options#hyphenate_data_attrs `:hyphenate_data_attrs` option} to `false`,
410
421
  and the output will be rendered as:
411
422
 
412
- <a data-author_id='123' href='/posts'>Posts By Author</a>
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:
428
+
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>
413
434
 
414
435
  ### Class and ID: `.` and `#`
415
436
 
@@ -496,23 +517,23 @@ and is compiled to:
496
517
  The forward slash character, when placed at the end of a tag definition, causes
497
518
  Haml to treat it as being an empty (or void) element. Depending on the format,
498
519
  the tag will be rendered either without a closing tag (`:html4` or `:html5`), or
499
- as a self-closing tag (`:xhtml`). For example:
520
+ as a self-closing tag (`:xhtml`).
521
+
522
+ Taking the following as an example:
500
523
 
501
524
  %br/
502
525
  %meta{'http-equiv' => 'Content-Type', :content => 'text/html'}/
503
526
 
504
- is compiled to:
527
+ When the format is `:html4` or `:html5` this is compiled to:
505
528
 
506
529
  <br>
507
530
  <meta content='text/html' http-equiv='Content-Type'>
508
531
 
509
- when the format is `:html4` or `:html5`, and to
532
+ and when the format is `:xhtml` it is compiled to:
510
533
 
511
534
  <br />
512
535
  <meta content='text/html' http-equiv='Content-Type' />
513
536
 
514
- when the format is `:xhtml`.
515
-
516
537
  Some tags are automatically treated as being empty, as long as they have no
517
538
  content in the Haml source. `meta`, `img`, `link`, `br`, `hr`, `input`,
518
539
  `area`, `param`, `col` and `base` tags are treated as empty by default. This
@@ -779,6 +800,21 @@ is compiled to:
779
800
  </a>
780
801
  <![endif]-->
781
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
+
782
818
  ### Haml Comments: `-#`
783
819
 
784
820
  The hyphen followed immediately by the pound sign signifies a silent comment.
@@ -985,6 +1021,21 @@ might compile to:
985
1021
  //]]>
986
1022
  </script>
987
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
+
988
1039
  ### Escaping HTML: `&=` {#escaping_html}
989
1040
 
990
1041
  An ampersand followed by one or two equals characters evaluates Ruby code just
@@ -1069,8 +1120,8 @@ is compiled to
1069
1120
  <p>I <strong>really</strong> prefer <em>raspberry</em> jam.</p>
1070
1121
  </div>
1071
1122
 
1072
- Currently, filters ignore the {Haml::Options#escape_html `:escape_html`} option.
1073
- This means that `#{}` interpolation within filters is never HTML-escaped.
1123
+ Note that `#{}` interpolation within filters is HTML-escaped if you specify
1124
+ {Haml::Options#escape_html `:escape_html`} option.
1074
1125
 
1075
1126
  The functionality of some filters such as Markdown can be provided by many
1076
1127
  different libraries. Usually you don't have to worry about this - you can just
@@ -1087,53 +1138,53 @@ more info.
1087
1138
 
1088
1139
  Haml comes with the following filters defined:
1089
1140
 
1090
- {#cdata-filter}
1091
- ### `:cdata`
1141
+ ### `:cdata` {#cdata-filter}
1142
+
1092
1143
  Surrounds the filtered text with CDATA tags.
1093
1144
 
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.
1145
+ ### `:coffee` {#coffee-filter}
1146
+
1147
+ Compiles the filtered text to JavaScript in `<script>` tag using CoffeeScript.
1148
+ You can also reference this filter as `:coffeescript`. This filter is
1149
+ implemented using Tilt.
1150
+
1151
+ ### `:css` {#css-filter}
1099
1152
 
1100
- {#css-filter}
1101
- ### `:css`
1102
1153
  Surrounds the filtered text with `<style>` and (optionally) CDATA tags. Useful
1103
1154
  for including inline CSS. Use the {Haml::Options#cdata `:cdata` option} to
1104
1155
  control when CDATA tags are added.
1105
1156
 
1106
- {#erb-filter}
1107
- ### `:erb`
1108
- Parses the filtered text with ERb, like an RHTML template. Not available if the
1157
+ ### `:erb` {#erb-filter}
1158
+
1159
+ Parses the filtered text with ERB, like an RHTML template. Not available if the
1109
1160
  {Haml::Options#suppress_eval `:suppress_eval`} option is set to true. Embedded
1110
1161
  Ruby code is evaluated in the same context as the Haml template. This filter is
1111
1162
  implemented using Tilt.
1112
1163
 
1113
- {#escaped-filter}
1114
- ### `:escaped`
1164
+ ### `:escaped` {#escaped-filter}
1165
+
1115
1166
  Works the same as plain, but HTML-escapes the text
1116
1167
  before placing it in the document.
1117
1168
 
1118
- {#javascript-filter}
1119
- ### `:javascript`
1169
+ ### `:javascript` {#javascript-filter}
1170
+
1120
1171
  Surrounds the filtered text with `<script>` and (optionally) CDATA tags.
1121
1172
  Useful for including inline Javascript. Use the {Haml::Options#cdata `:cdata`
1122
1173
  option} to control when CDATA tags are added.
1123
1174
 
1124
- {#less-filter}
1125
- ### `:less`
1126
- Parses the filtered text with [Less](http://lesscss.org/) to produce CSS output.
1175
+ ### `:less` {#less-filter}
1176
+
1177
+ Parses the filtered text with [Less](http://lesscss.org/) to produce CSS output in `<style>` tag.
1127
1178
  This filter is implemented using Tilt.
1128
1179
 
1129
- {#markdown-filter}
1130
- ### `:markdown`
1180
+ ### `:markdown` {#markdown-filter}
1181
+
1131
1182
  Parses the filtered text with
1132
1183
  [Markdown](http://daringfireball.net/projects/markdown). This filter is
1133
1184
  implemented using Tilt.
1134
1185
 
1135
- {#maruku-filter}
1136
- ### `:maruku`
1186
+ ### `:maruku` {#maruku-filter}
1187
+
1137
1188
  Parses the filtered text with [Maruku](https://github.com/nex3/maruku), which
1138
1189
  has some non-standard extensions to Markdown.
1139
1190
 
@@ -1142,39 +1193,40 @@ contrib](https://github.com/haml/haml-contrib) but is loaded automatically for
1142
1193
  historical reasons. In future versions of Haml it will likely not be loaded by
1143
1194
  default. This filter is implemented using Tilt.
1144
1195
 
1145
- {#plain-filter}
1146
- ### `:plain`
1196
+ ### `:plain` {#plain-filter}
1197
+
1147
1198
  Does not parse the filtered text. This is useful for large blocks of text
1148
1199
  without HTML tags, when you don't want lines starting with `.` or `-` to be
1149
1200
  parsed.
1150
1201
 
1151
- {#preserve-filter}
1152
- ### `:preserve`
1202
+ ### `:preserve` {#preserve-filter}
1203
+
1153
1204
  Inserts the filtered text into the template with whitespace preserved.
1154
1205
  `preserve`d blocks of text aren't indented, and newlines are replaced with the
1155
1206
  HTML escape code for newlines, to preserve nice-looking output. See also
1156
1207
  [Whitespace Preservation](#whitespace_preservation).
1157
1208
 
1158
- {#ruby-filter}
1159
- ### `:ruby`
1209
+ ### `:ruby` {#ruby-filter}
1210
+
1160
1211
  Parses the filtered text with the normal Ruby interpreter. Creates an `IO`
1161
1212
  object named `haml_io`, anything written to it is output into the Haml document.
1162
1213
  Not available if the {Haml::Options#suppress_eval `:suppress_eval`} option is
1163
1214
  set to true. The Ruby code is evaluated in the same context as the Haml
1164
1215
  template.
1165
1216
 
1166
- {#sass-filter}
1167
- ### `:sass`
1217
+ ### `:sass` {#sass-filter}
1218
+
1168
1219
  Parses the filtered text with [Sass](http://sass-lang.com/) to produce CSS
1169
- output. This filter is implemented using Tilt.
1220
+ output in `<style>` tag. This filter is implemented using Tilt.
1221
+
1222
+ ### `:scss` {#scss-filter}
1170
1223
 
1171
- {#scss-filter}
1172
- ### `:scss`
1173
1224
  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.
1225
+ SCSS syntax to produce CSS output in `<style>` tag. This filter is implemented
1226
+ using Tilt.
1227
+
1228
+ ### `:textile` {#textile-filter}
1175
1229
 
1176
- {#textile-filter}
1177
- ### `:textile`
1178
1230
  Parses the filtered text with [Textile](http://www.textism.com/tools/textile).
1179
1231
  Only works if [RedCloth](http://redcloth.org) is installed.
1180
1232
 
@@ -1194,8 +1246,8 @@ the whitespace removal methods allow. There are a few helper methods that are
1194
1246
  useful when dealing with inline content. All these methods take a Haml block to
1195
1247
  modify.
1196
1248
 
1197
- {#surround}
1198
- ### surround
1249
+ ### surround {#surround}
1250
+
1199
1251
  Surrounds a Haml block with text. Expects 1 or 2 string arguments used to
1200
1252
  surround the Haml block. If a second argument is not provided, the first
1201
1253
  argument is used as the second.
@@ -1203,15 +1255,15 @@ argument is used as the second.
1203
1255
  = surround "(", ")" do
1204
1256
  = link_to "learn more", "#"
1205
1257
 
1206
- {#precede}
1207
- ### precede
1258
+ ### precede {#precede}
1259
+
1208
1260
  Prepends a Haml block with text. Expects 1 argument.
1209
1261
 
1210
1262
  = precede "*" do
1211
1263
  %span Required
1212
1264
 
1213
- {#succeed}
1214
- ### succeed
1265
+ ### succeed {#succeed}
1266
+
1215
1267
  Appends a Haml block with text. Expects 1 argument.
1216
1268
 
1217
1269
  Begin by
data/Rakefile CHANGED
@@ -1,45 +1,38 @@
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
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
- desc "Benchmark Haml against ERb. TIMES=n sets the number of runs, default is 1000."
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
- # 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
28
- t.verbose = true
29
- end
30
-
31
29
  task :set_coverage_env do
32
30
  ENV["COVERAGE"] = "true"
33
31
  end
34
32
 
35
- desc "Run Simplecov (only works on 1.9)"
33
+ desc "Run Simplecov"
36
34
  task :coverage => [:set_coverage_env, :test]
37
35
 
38
- gemspec = File.expand_path("../haml.gemspec", __FILE__)
39
- if File.exist? gemspec
40
- Gem::PackageTask.new(eval(File.read(gemspec))) { |pkg| }
41
- end
42
-
43
36
  task :submodules do
44
37
  if File.exist?(File.dirname(__FILE__) + "/.git")
45
38
  sh %{git submodule sync}
@@ -47,31 +40,32 @@ task :submodules do
47
40
  end
48
41
  end
49
42
 
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
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
62
50
  end
63
51
  end
64
52
 
65
- desc "Generate documentation"
66
- task(:doc) {sh "yard"}
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
67
61
 
68
- desc "Generate documentation incrementally"
69
- task(:redoc) {sh "yard -c"}
62
+ desc "Generate documentation"
63
+ task(:doc => 'doc:sass') {sh "yard"}
70
64
 
71
- rescue LoadError
72
- end
65
+ desc "Generate documentation incrementally"
66
+ task(:redoc) {sh "yard -c"}
73
67
 
74
- desc <<END
68
+ desc <<END
75
69
  Profile Haml.
76
70
  TIMES=n sets the number of runs. Defaults to 1000.
77
71
  FILE=str sets the file to profile. Defaults to 'standard'
@@ -80,15 +74,14 @@ Profile Haml.
80
74
  END
81
75
  task :profile do
82
76
  times = (ENV['TIMES'] || '1000').to_i
83
- file = ENV['FILE']
77
+ file = ENV['FILE'] || 'test/templates/standard.haml'
84
78
 
85
79
  require 'bundler/setup'
86
80
  require 'ruby-prof'
87
81
  require 'haml'
88
-
89
- file = File.read(File.expand_path("../test/templates/#{file || 'standard'}.haml", __FILE__))
82
+ file = File.read(File.expand_path("../#{file}", __FILE__))
90
83
  obj = Object.new
91
- Haml::Engine.new(file, :ugly => true).def_method(obj, :render)
84
+ Haml::Engine.new(file).def_method(obj, :render)
92
85
  result = RubyProf.profile { times.times { obj.render } }
93
86
 
94
87
  RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
@@ -103,14 +96,13 @@ def gemfiles
103
96
  end
104
97
 
105
98
  def with_each_gemfile
106
- old_env = ENV['BUNDLE_GEMFILE']
107
99
  gemfiles.each do |gemfile|
108
- puts "Using gemfile: #{gemfile}"
109
- ENV['BUNDLE_GEMFILE'] = gemfile
110
- yield
100
+ Bundler.with_clean_env do
101
+ puts "Using gemfile: #{gemfile}"
102
+ ENV['BUNDLE_GEMFILE'] = gemfile
103
+ yield
104
+ end
111
105
  end
112
- ensure
113
- ENV['BUNDLE_GEMFILE'] = old_env
114
106
  end
115
107
 
116
108
  namespace :test do
data/TODO ADDED
@@ -0,0 +1,24 @@
1
+ # -*- mode: org -*-
2
+ #+STARTUP: nofold
3
+
4
+ * Documentation
5
+ Redo tutorial?
6
+ Using helpers
7
+ haml_concat and haml_tag in particular
8
+ Syntax highlighting?
9
+
10
+ * Code
11
+ Keep track of error offsets everywhere
12
+ Use this to show error location in messages
13
+ ** Haml
14
+ Support finer-grained HTML-escaping in filters
15
+ Speed
16
+ Make tags with dynamic attributes pre-render as much as possible
17
+ Including the attribute name where doable
18
+ :html improvements
19
+ Ignore closing tags where we can
20
+ http://code.google.com/speed/articles/optimizing-html.html
21
+ Requires Haml parsing refactor
22
+ Don't quote attributes that don't require it
23
+ http://www.w3.org/TR/REC-html40/intro/sgmltut.html#h-3.2.2
24
+ http://www.w3.org/TR/html5/syntax.html#attributes
data/benchmark.rb ADDED
@@ -0,0 +1,66 @@
1
+ require "bundler/setup"
2
+ require "haml"
3
+ require "rbench"
4
+
5
+ times = (ARGV.first || 1000).to_i
6
+
7
+ if times == 0 # Invalid parameter
8
+ puts <<END
9
+ ruby #$0 [times=1000]
10
+ Benchmark Haml against various other templating languages.
11
+ END
12
+ exit 1
13
+ end
14
+
15
+ %w[erb erubis rails active_support action_controller
16
+ action_view action_pack haml/template rbench].each {|dep| require(dep)}
17
+
18
+ def view
19
+ base = ActionView::Base.new
20
+ base.view_paths << File.join(File.dirname(__FILE__), '/test')
21
+ base
22
+ end
23
+
24
+ def render(view, file)
25
+ view.render :file => file
26
+ end
27
+
28
+ RBench.run(times) do
29
+ column :haml, :title => "Haml"
30
+ column :erb, :title => "ERB"
31
+ column :erubis, :title => "Erubis"
32
+
33
+ template_name = 'standard'
34
+ haml_template = File.read("#{File.dirname(__FILE__)}/test/templates/#{template_name}.haml")
35
+ erb_template = File.read("#{File.dirname(__FILE__)}/test/erb/#{template_name}.erb")
36
+
37
+ report "Cached" do
38
+ obj = Object.new
39
+
40
+ Haml::Engine.new(haml_template).def_method(obj, :haml)
41
+ Erubis::Eruby.new(erb_template).def_method(obj, :erubis)
42
+ obj.instance_eval("def erb; #{ERB.new(erb_template, nil, '-').src}; end")
43
+
44
+ haml { obj.haml }
45
+ erb { obj.erb }
46
+ erubis { obj.erubis }
47
+ end
48
+
49
+ report "ActionView" do
50
+ # To cache the template
51
+ render view, 'templates/standard'
52
+ render view, 'erb/standard'
53
+
54
+ haml { render view, 'templates/standard' }
55
+ erb { render view, 'erb/standard' }
56
+ end
57
+
58
+ report "ActionView with deep partials" do
59
+ # To cache the template
60
+ render view, 'templates/action_view'
61
+ render view, 'erb/action_view'
62
+
63
+ haml { render view, 'templates/action_view' }
64
+ erb { render view, 'erb/action_view' }
65
+ end
66
+ end
data/haml.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ ($LOAD_PATH << File.expand_path("../lib", __FILE__)).uniq!
2
+ require "haml/version"
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'haml'
6
+ spec.summary = "An elegant, structured (X)HTML/XML templating engine."
7
+ spec.version = Haml::VERSION
8
+ spec.authors = ['Natalie Weizenbaum', 'Hampton Catlin', 'Norman Clarke', 'Akira Matsuda']
9
+ spec.email = ['haml@googlegroups.com', 'norman@njclarke.com']
10
+
11
+ readmes = Dir['*'].reject{ |x| x =~ /(^|[^.a-z])[a-z]+/ || x == "TODO" }
12
+ spec.executables = ['haml']
13
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
14
+ f.match(%r{\Atest/})
15
+ end
16
+ spec.homepage = 'http://haml.info/'
17
+ spec.has_rdoc = false
18
+ spec.license = "MIT"
19
+
20
+ spec.required_ruby_version = '>= 2.0.0'
21
+
22
+ spec.add_dependency 'temple', '>= 0.8.0'
23
+ spec.add_dependency 'tilt'
24
+
25
+ spec.add_development_dependency 'rails', '>= 4.0.0'
26
+ spec.add_development_dependency 'rbench'
27
+ spec.add_development_dependency 'minitest', '>= 4.0'
28
+ spec.add_development_dependency 'nokogiri'
29
+
30
+ spec.description = <<-END
31
+ Haml (HTML Abstraction Markup Language) is a layer on top of HTML or XML that's
32
+ designed to express the structure of documents in a non-repetitive, elegant, and
33
+ easy way by using indentation rather than closing tags and allowing Ruby to be
34
+ embedded with ease. It was originally envisioned as a plugin for Ruby on Rails,
35
+ but it can function as a stand-alone templating engine.
36
+ END
37
+
38
+ end
@@ -0,0 +1 @@
1
+ version.rb merge=ours