haml 1.8.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of haml might be problematic. Click here for more details.

Files changed (77) hide show
  1. data/FAQ +138 -0
  2. data/MIT-LICENSE +1 -1
  3. data/{README → README.rdoc} +66 -3
  4. data/Rakefile +111 -147
  5. data/VERSION +1 -1
  6. data/bin/css2sass +0 -0
  7. data/bin/haml +0 -0
  8. data/bin/html2haml +0 -0
  9. data/bin/sass +0 -0
  10. data/init.rb +6 -1
  11. data/lib/haml.rb +464 -201
  12. data/lib/haml/buffer.rb +117 -63
  13. data/lib/haml/engine.rb +63 -44
  14. data/lib/haml/error.rb +16 -6
  15. data/lib/haml/exec.rb +37 -7
  16. data/lib/haml/filters.rb +213 -68
  17. data/lib/haml/helpers.rb +95 -60
  18. data/lib/haml/helpers/action_view_extensions.rb +1 -1
  19. data/lib/haml/helpers/action_view_mods.rb +54 -6
  20. data/lib/haml/html.rb +6 -6
  21. data/lib/haml/precompiler.rb +254 -133
  22. data/lib/haml/template.rb +3 -6
  23. data/lib/haml/template/patch.rb +9 -2
  24. data/lib/haml/template/plugin.rb +52 -23
  25. data/lib/sass.rb +157 -12
  26. data/lib/sass/constant.rb +22 -22
  27. data/lib/sass/constant/color.rb +13 -13
  28. data/lib/sass/constant/literal.rb +7 -7
  29. data/lib/sass/constant/number.rb +9 -9
  30. data/lib/sass/constant/operation.rb +4 -4
  31. data/lib/sass/constant/string.rb +3 -3
  32. data/lib/sass/css.rb +104 -31
  33. data/lib/sass/engine.rb +120 -39
  34. data/lib/sass/error.rb +1 -1
  35. data/lib/sass/plugin.rb +14 -3
  36. data/lib/sass/plugin/merb.rb +6 -2
  37. data/lib/sass/tree/attr_node.rb +5 -5
  38. data/lib/sass/tree/directive_node.rb +2 -7
  39. data/lib/sass/tree/node.rb +1 -12
  40. data/lib/sass/tree/rule_node.rb +39 -31
  41. data/lib/sass/tree/value_node.rb +1 -1
  42. data/test/benchmark.rb +67 -80
  43. data/test/haml/engine_test.rb +284 -84
  44. data/test/haml/helper_test.rb +51 -15
  45. data/test/haml/results/content_for_layout.xhtml +1 -2
  46. data/test/haml/results/eval_suppressed.xhtml +2 -4
  47. data/test/haml/results/filters.xhtml +44 -15
  48. data/test/haml/results/helpers.xhtml +2 -3
  49. data/test/haml/results/just_stuff.xhtml +2 -6
  50. data/test/haml/results/nuke_inner_whitespace.xhtml +34 -0
  51. data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
  52. data/test/haml/results/original_engine.xhtml +3 -7
  53. data/test/haml/results/partials.xhtml +1 -0
  54. data/test/haml/results/tag_parsing.xhtml +1 -6
  55. data/test/haml/results/very_basic.xhtml +2 -4
  56. data/test/haml/results/whitespace_handling.xhtml +13 -21
  57. data/test/haml/template_test.rb +8 -15
  58. data/test/haml/templates/_partial.haml +1 -0
  59. data/test/haml/templates/filters.haml +48 -7
  60. data/test/haml/templates/just_stuff.haml +1 -2
  61. data/test/haml/templates/nuke_inner_whitespace.haml +26 -0
  62. data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
  63. data/test/haml/templates/tag_parsing.haml +0 -3
  64. data/test/haml/test_helper.rb +15 -0
  65. data/test/sass/engine_test.rb +80 -34
  66. data/test/sass/plugin_test.rb +1 -1
  67. data/test/sass/results/import.css +2 -2
  68. data/test/sass/results/mixins.css +95 -0
  69. data/test/sass/results/multiline.css +24 -0
  70. data/test/sass/templates/import.sass +4 -1
  71. data/test/sass/templates/importee.sass +4 -0
  72. data/test/sass/templates/mixins.sass +76 -0
  73. data/test/sass/templates/multiline.sass +20 -0
  74. metadata +65 -51
  75. data/lib/haml/util.rb +0 -18
  76. data/test/haml/runner.rb +0 -16
  77. data/test/profile.rb +0 -65
data/FAQ ADDED
@@ -0,0 +1,138 @@
1
+ = Frequently Asked Questions
2
+
3
+ == Haml
4
+
5
+ === How do I put a punctuation mark after an element, like "<tt>I like <strong>cake</strong>!</tt>"?
6
+
7
+ Expressing the structure of a document
8
+ and expressing inline formatting are two very different problems.
9
+ Haml is mostly designed for structure,
10
+ so the best way to deal with formatting is to leave it to other languages
11
+ that are designed for it.
12
+ You could use Textile:
13
+
14
+ %p
15
+ :textile
16
+ I like *cake*!
17
+
18
+ or Markdown:
19
+
20
+ %p
21
+ :markdown
22
+ I like **cake**!
23
+
24
+ or plain old XHTML:
25
+
26
+ %p I like <strong>cake</strong>!
27
+
28
+ If you're inserting something that's generated by a helper, like a link,
29
+ then it's even easier:
30
+
31
+ %p== I like #{link_to 'chocolate', 'http://franschocolates.com'}!
32
+
33
+ === How do I stop Haml from indenting the contents of my +pre+ and +textarea+ tags?
34
+
35
+ Because Haml automatically indents the HTML source code,
36
+ the contents of whitespace-sensitive tags like +pre+ and +textarea+
37
+ can get screwed up.
38
+ The solution is to replace the newlines inside these tags
39
+ with HTML newline entities (<tt>&#x000A;</tt>),
40
+ which Haml does using the Haml::Helpers#preserve and Haml::Helpers#find_and_preserve helpers.
41
+
42
+ Normally, Haml will do this for you automatically
43
+ when you're using a tag that needs it
44
+ (this can be customized using the <tt>:preserve</tt> option;
45
+ see the Options section of the {Haml reference}(../classes/Haml.html)).
46
+ For example,
47
+
48
+ %p
49
+ %textarea= "Foo\nBar"
50
+
51
+ will be compiled to
52
+
53
+ <p>
54
+ <textarea>Foo&#x000A;Bar</textarea>
55
+ </p>
56
+
57
+ However, if a helper is generating the tag,
58
+ Haml can't detect that and so you'll have to call +find_and_preserve+ yourself.
59
+ You can also use <tt>~</tt>, which is the same as <tt>=</tt>
60
+ except that it automatically runs +find_and_preserve+ on its input.
61
+ For example:
62
+
63
+ %p= find_and_preserve "<textarea>Foo\nBar</textarea>"
64
+
65
+ is the same as
66
+
67
+ %p~ "<textarea>Foo\nBar</textarea>"
68
+
69
+ and renders
70
+
71
+ <p><textarea>Foo&#x000A;Bar</textarea></p>
72
+
73
+ === How do I make my long lines of Ruby code look nicer in my Haml document?
74
+
75
+ Put them in a helper or your model.
76
+
77
+ Haml purposefully makes it annoying to put lots of Ruby code into your templates,
78
+ because lots of code doesn't belong in the view.
79
+ If you take that huge +link_to_remote+ call
80
+ and move it to a +update_sidebar_link+ helper,
81
+ it'll make your view both easier to read and more semantic.
82
+
83
+ If you absolutely must put lots of code in your template,
84
+ Haml offers a somewhat awkward multiline-continuation tool.
85
+ Put a <tt>|</tt> (pipe character) at the end of each line you want to be merged into one
86
+ (including the last line!).
87
+ For example:
88
+
89
+ %p= @this.is(way.too.much). |
90
+ code("and I should"). |
91
+ really_move.it.into( |
92
+ :a => @helper) |
93
+
94
+ === I have Haml installed. Why is Rails (only looking for <tt>.html.erb</tt> files | rendering Haml files as plain text | rendering Haml files as blank pages)?
95
+
96
+ There are several reasons these things might be happening.
97
+ First of all, make sure vendor/plugins/haml really exists
98
+ and has an init.rb file in there.
99
+ Then try restarting Mongrel or WEBrick or whatever you might be using.
100
+
101
+ Finally, if none of these work,
102
+ chances are you've got some localization plugin like Globalize installed.
103
+ Such plugins often don't play nicely with Haml.
104
+ Luckily, there's usually an easy fix.
105
+ For Globalize, just edit globalize/lib/globalize/rails/action_view.rb
106
+ and change
107
+
108
+ @@re_extension = /\.(rjs|rhtml|rxml)$/
109
+
110
+ to
111
+
112
+ @@re_extension = /\.(rjs|rhtml|rxml|erb|builder|haml)$/
113
+
114
+ For other plugins, a little searching will probably turn up a way to fix them as well.
115
+
116
+ == Sass
117
+
118
+ === Can I use a variable from my controller in my Sass file?
119
+
120
+ No. Sass files aren't views.
121
+ They're compiled once into static CSS files,
122
+ then left along until they're changed and need to be compiled again.
123
+ Not only don't you want to be running a full request cycle
124
+ every time someone requests a stylesheet,
125
+ but it's not a great idea to put much logic in there anyway
126
+ due to how browsers handle them.
127
+
128
+ If you really need some sort of dynamic CSS,
129
+ the best thing to do is put only the snippet you need to dynamically set
130
+ in the +head+ of your HTML document.
131
+
132
+ == You still haven't answered my question!
133
+
134
+ Sorry! Try looking at the Haml or Sass references,
135
+ in the doucmentation for the haml and Sass modules, respectively.
136
+ If you can't find an answer there,
137
+ feel free to ask in #haml on irc.freenode.net
138
+ or send an email to the {mailing list}[http://groups.google.com/group/haml?hl=en].
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2007 Hampton Catlin
1
+ Copyright (c) 2006-2008 Hampton Catlin
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -67,7 +67,7 @@ a tag without a name defaults to a div. So
67
67
  becomes
68
68
 
69
69
  <div id='foo'>Hello!</div>
70
-
70
+
71
71
  Haml uses indentation
72
72
  to bring the individual elements to represent the HTML structure.
73
73
  A tag's children are indented two spaces more than the parent tag.
@@ -228,15 +228,78 @@ becomes:
228
228
  background-color: #79d645;
229
229
  width: 15em; }
230
230
 
231
+ Taking the idea of constants a bit further are mixins.
232
+ These let you group whole swathes of CSS attributes into a single
233
+ directive and then include those anywhere you want:
234
+
235
+ =blue-border
236
+ :border
237
+ :color blue
238
+ :width 2px
239
+ :style dotted
240
+
241
+ .comment
242
+ +blue-border
243
+ :padding 2px
244
+ :margin 10px 0
245
+
246
+ .reply
247
+ +blue-border
248
+
249
+ becomes:
250
+
251
+ .comment {
252
+ border-color: blue;
253
+ border-width: 2px;
254
+ border-style: dotted;
255
+ padding: 2px;
256
+ margin: 10px 0;
257
+ }
258
+
259
+ .reply {
260
+ border-color: blue;
261
+ border-width: 2px;
262
+ border-style: dotted;
263
+ }
264
+
231
265
  A comprehensive list of features is in
232
266
  the documentation for the Sass module.
233
267
 
268
+ == Executables
269
+
270
+ The Haml gem includes several executables that are useful
271
+ for dealing with Haml and Sass from the command line.
272
+
273
+ === +haml+
274
+
275
+ The +haml+ executable transforms a source Haml file into HTML.
276
+ See <tt>haml --help</tt> for further information and options.
277
+
278
+ === +sass+
279
+
280
+ The +sass+ executable transforms a source Sass file into CSS.
281
+ See <tt>sass --help</tt> for further information and options.
282
+
283
+ === <tt>html2haml</tt>
284
+
285
+ The <tt>html2haml</tt> executable attempts to transform HTML,
286
+ optionally with ERB markup, into Haml code.
287
+ Since HTML is so variable, this transformation is not always perfect;
288
+ it's a good idea to have a human check the output of this tool.
289
+ See <tt>html2haml --help</tt> for further information and options.
290
+
291
+ === <tt>css2sass</tt>
292
+
293
+ The <tt>css2sass</tt> executable attempts to transform CSS into Sass code.
294
+ This transformation attempts to use Sass nesting where possible.
295
+ See <tt>css2sass --help</tt> for further information and options.
296
+
234
297
  == Authors
235
298
 
236
299
  Haml and Sass are designed by Hampton Catlin (hcatlin) and he is the author
237
300
  of the original implementation. However, Hampton doesn't even know his way
238
- around the code anymore and mostly just concentrates on the language issues.
239
- Hampton lives in Toronto, Ontario (though he's an American by birth) and
301
+ around the code anymore and mostly just concentrates on the language issues.
302
+ Hampton lives in Toronto, Ontario (though he's an American by birth) and
240
303
  is a partner at Unspace Interactive.
241
304
 
242
305
  Nathan Weizenbaum is the primary maintainer and architect of the "modern" Ruby
data/Rakefile CHANGED
@@ -1,182 +1,146 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- volatile_requires = ['rcov/rcovtask']
5
- not_loaded = []
6
- volatile_requires.each do |file|
7
- begin
8
- require file
9
- rescue LoadError
10
- not_loaded.push file
11
- end
12
- end
13
-
14
4
  # ----- Benchmarking -----
15
5
 
16
- temp_desc = <<END
6
+ desc <<END
17
7
  Benchmark haml against ERb.
18
- TIMES=n sets the number of runs. Defaults to 100.
8
+ TIMES=n sets the number of runs. Defaults to 1000.
19
9
  END
20
-
21
- desc temp_desc.chomp
22
10
  task :benchmark do
23
- require 'test/benchmark'
24
-
25
- puts "Running benchmarks #{ENV['TIMES']} times..." if ENV['TIMES']
26
- times = ENV['TIMES'].to_i if ENV['TIMES']
27
- Haml.benchmark(times || 100)
28
- puts '-'*51
11
+ sh "ruby test/benchmark.rb #{ENV['TIMES']}"
29
12
  end
30
13
 
31
- # Benchmarking gets screwed up if some other tasks have been
32
- # initialized.
33
- unless ARGV[0] == 'benchmark'
14
+ # ----- Default: Testing ------
34
15
 
35
- # ----- Default: Testing ------
16
+ task :default => :test
36
17
 
37
- desc 'Default: run unit tests.'
38
- task :default => :test
18
+ require 'rake/testtask'
39
19
 
40
- require 'rake/testtask'
20
+ Rake::TestTask.new do |t|
21
+ t.libs << 'lib'
22
+ t.pattern = 'test/**/*_test.rb'
23
+ t.verbose = true
24
+ end
25
+ Rake::Task[:test].send(:add_comment, <<END)
26
+ To run with an alternate version of Rails, make test/rails a symlink to that version.
27
+ END
41
28
 
42
- desc 'Test the Haml plugin'
43
- Rake::TestTask.new(:test) do |t|
44
- t.libs << 'lib'
45
- t.pattern = 'test/**/*_test.rb'
46
- t.verbose = true
47
- end
29
+ # ----- Packaging -----
48
30
 
49
- # ----- Packaging -----
50
-
51
- require 'rake/gempackagetask'
52
-
53
- spec = Gem::Specification.new do |spec|
54
- spec.name = 'haml'
55
- spec.summary = "An elegant, structured XHTML/XML templating engine.\nComes with Sass, a similar CSS templating engine."
56
- spec.version = File.read('VERSION').strip
57
- spec.author = 'Hampton Catlin'
58
- spec.email = 'haml@googlegroups.com'
59
- spec.description = <<-END
60
- Haml (HTML Abstraction Markup Language) is a layer on top of XHTML or XML
61
- that's designed to express the structure of XHTML or XML documents
62
- in a non-repetitive, elegant, easy way,
63
- using indentation rather than closing tags
64
- and allowing Ruby to be embedded with ease.
65
- It was originally envisioned as a plugin for Ruby on Rails,
66
- but it can function as a stand-alone templating engine.
67
- END
68
- #'
69
-
70
- readmes = FileList.new('*') do |list|
71
- list.exclude(/[a-z]/)
72
- list.exclude('TODO')
73
- end.to_a
74
- spec.executables = ['haml', 'html2haml', 'sass', 'css2sass']
75
- spec.files = FileList['lib/**/*', 'bin/*', 'test/**/*', 'Rakefile', 'init.rb'].to_a + readmes
76
- spec.autorequire = ['haml', 'sass']
77
- spec.homepage = 'http://haml.hamptoncatlin.com/'
78
- spec.has_rdoc = true
79
- spec.extra_rdoc_files = readmes
80
- spec.rdoc_options += [
81
- '--title', 'Haml',
82
- '--main', 'README',
83
- '--exclude', 'lib/haml/buffer.rb',
84
- '--line-numbers',
85
- '--inline-source'
86
- ]
87
- spec.test_files = FileList['test/**/*_test.rb'].to_a
88
- end
31
+ require 'rake/gempackagetask'
32
+ load 'haml.gemspec'
89
33
 
90
- Rake::GemPackageTask.new(spec) do |pkg|
91
- pkg.need_zip = true
34
+ Rake::GemPackageTask.new(HAML_GEMSPEC) do |pkg|
35
+ if Rake.application.top_level_tasks.include?('release')
92
36
  pkg.need_tar_gz = true
93
37
  pkg.need_tar_bz2 = true
38
+ pkg.need_zip = true
94
39
  end
40
+ end
95
41
 
96
- task :install => [:package] do
97
- sh %{gem install --no-ri pkg/haml-#{File.read('VERSION').strip}}
98
- end
42
+ task :revision_file do
43
+ require 'lib/haml'
99
44
 
100
- task :release => [:package] do
101
- name, version = ENV['NAME'], ENV['VERSION']
102
- raise "Must supply NAME and VERSION for release task." unless name && version
103
- sh %{rubyforge login}
104
- sh %{rubyforge add_release haml haml "#{name} (v#{version})" pkg/haml-#{version}.gem}
105
- sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.gz}
106
- sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.bz2}
107
- sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.zip}
45
+ if Haml.version[:rev] && !Rake.application.top_level_tasks.include?('release')
46
+ File.open('REVISION', 'w') { |f| f.puts Haml.version[:rev] }
47
+ elsif Rake.application.top_level_tasks.include?('release')
48
+ File.open('REVISION', 'w') { |f| f.puts "(release)" }
49
+ else
50
+ File.open('REVISION', 'w') { |f| f.puts "(unknown)" }
108
51
  end
52
+ end
53
+ Rake::Task[:package].prerequisites.insert(0, :revision_file)
54
+
55
+ # We also need to get rid of this file after packaging.
56
+ Rake::Task[:package].enhance { File.delete('REVISION') if File.exists?('REVISION') }
109
57
 
110
- # ----- Documentation -----
58
+ task :install => [:package] do
59
+ sudo = RUBY_PLATFORM =~ /win32/ ? '' : 'sudo'
60
+ sh %{#{sudo} gem install --no-ri pkg/haml-#{File.read('VERSION').strip}}
61
+ end
62
+
63
+ task :release => [:package] do
64
+ name, version = ENV['NAME'], ENV['VERSION']
65
+ raise "Must supply NAME and VERSION for release task." unless name && version
66
+ sh %{rubyforge login}
67
+ sh %{rubyforge add_release haml haml "#{name} (v#{version})" pkg/haml-#{version}.gem}
68
+ sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.gz}
69
+ sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.bz2}
70
+ sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.zip}
71
+ end
72
+
73
+ # ----- Documentation -----
111
74
 
75
+ begin
76
+ require 'hanna/rdoctask'
77
+ rescue LoadError
112
78
  require 'rake/rdoctask'
79
+ end
113
80
 
114
- rdoc_task = Proc.new do |rdoc|
115
- rdoc.title = 'Haml/Sass'
116
- rdoc.options << '--line-numbers' << '--inline-source'
117
- rdoc.rdoc_files.include('README')
118
- rdoc.rdoc_files.include('lib/**/*.rb')
119
- rdoc.rdoc_files.exclude('lib/haml/buffer.rb')
120
- rdoc.rdoc_files.exclude('lib/haml/util.rb')
121
- rdoc.rdoc_files.exclude('lib/sass/tree/*')
122
- end
81
+ Rake::RDocTask.new do |rdoc|
82
+ rdoc.title = 'Haml/Sass'
83
+ rdoc.options << '--line-numbers' << '--inline-source'
84
+ rdoc.rdoc_files.include(*FileList.new('*') do |list|
85
+ list.exclude(/(^|[^.a-z])[a-z]+/)
86
+ list.exclude('TODO')
87
+ end.to_a)
88
+ rdoc.rdoc_files.include('lib/**/*.rb')
89
+ rdoc.rdoc_files.exclude('TODO')
90
+ rdoc.rdoc_files.exclude('lib/haml/buffer.rb')
91
+ rdoc.rdoc_files.exclude('lib/sass/tree/*')
92
+ rdoc.rdoc_dir = 'rdoc'
93
+ rdoc.main = 'README.rdoc'
94
+ end
123
95
 
124
- Rake::RDocTask.new do |rdoc|
125
- rdoc_task.call(rdoc)
126
- rdoc.rdoc_dir = 'rdoc'
127
- end
96
+ # ----- Coverage -----
128
97
 
129
- Rake::RDocTask.new(:rdoc_devel) do |rdoc|
130
- rdoc_task.call(rdoc)
131
- rdoc.rdoc_dir = 'rdoc_devel'
132
- rdoc.options << '--all'
133
- rdoc.rdoc_files.include('test/*.rb')
134
-
135
- # Get rid of exclusion rules
136
- rdoc.rdoc_files = Rake::FileList.new(*rdoc.rdoc_files.to_a)
137
- rdoc.rdoc_files.include('lib/haml/buffer.rb')
138
- rdoc.rdoc_files.include('lib/sass/tree/*')
139
- end
98
+ begin
99
+ require 'rcov/rcovtask'
140
100
 
141
- # ----- Coverage -----
142
-
143
- unless not_loaded.include? 'rcov/rcovtask'
144
- Rcov::RcovTask.new do |t|
145
- t.libs << "test"
146
- t.test_files = FileList['test/**/*_test.rb']
147
- t.rcov_opts << '-x' << '"^\/"'
148
- if ENV['NON_NATIVE']
149
- t.rcov_opts << "--no-rcovrt"
150
- end
151
- t.verbose = true
101
+ Rcov::RcovTask.new do |t|
102
+ t.test_files = FileList['test/**/*_test.rb']
103
+ t.rcov_opts << '-x' << '"^\/"'
104
+ if ENV['NON_NATIVE']
105
+ t.rcov_opts << "--no-rcovrt"
152
106
  end
107
+ t.verbose = true
153
108
  end
109
+ rescue LoadError; end
154
110
 
155
- # ----- Profiling -----
111
+ # ----- Profiling -----
156
112
 
157
- temp_desc = <<-END
158
- Run a profile of haml.
159
- ENGINE=str sets the engine to be profiled (Haml or Sass).
160
- TIMES=n sets the number of runs. Defaults to 100.
161
- FILE=n sets the file to profile. Defaults to 'standard'.
162
- END
163
- desc temp_desc.chomp
113
+ begin
114
+ require 'ruby-prof'
115
+
116
+ desc <<END
117
+ Run a profile of haml.
118
+ ENGINE=str sets the engine to be profiled. Defaults to Haml.
119
+ TIMES=n sets the number of runs. Defaults to 1000.
120
+ FILE=str sets the file to profile.
121
+ Defaults to 'standard' for Haml and 'complex' for Sass.
122
+ OUTPUT=str sets the ruby-prof output format.
123
+ Can be Flat, CallInfo, or Graph. Defaults to Flat. Defaults to Flat.
124
+ END
164
125
  task :profile do
165
- require 'test/profile'
166
-
167
- engine = ENV['ENGINE'] && ENV['ENGINE'].downcase == 'sass' ? Sass : Haml
168
-
169
- puts '-'*51, "Profiling #{engine}", '-'*51
170
-
171
- args = []
172
- args.push ENV['TIMES'].to_i if ENV['TIMES']
173
- args.push ENV['FILE'] if ENV['FILE']
174
-
175
- profiler = engine::Profiler.new
176
- res = profiler.profile(*args)
177
- puts res
178
-
179
- puts '-'*51
180
- end
126
+ engine = (ENV['ENGINE'] || 'haml').downcase
127
+ times = (ENV['TIMES'] || '1000').to_i
128
+ file = ENV['FILE']
129
+
130
+ if engine == 'sass'
131
+ require 'lib/sass'
132
+
133
+ file = File.read("#{File.dirname(__FILE__)}/test/sass/templates/#{file || 'complex'}.sass")
134
+ result = RubyProf.profile { times.times { Sass::Engine.new(file).render } }
135
+ else
136
+ require 'lib/haml'
137
+
138
+ file = File.read("#{File.dirname(__FILE__)}/test/haml/templates/#{file || 'standard'}.haml")
139
+ obj = Object.new
140
+ Haml::Engine.new(file).def_method(obj, :render)
141
+ result = RubyProf.profile { times.times { obj.render } }
142
+ end
181
143
 
182
- end
144
+ RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
145
+ end
146
+ rescue LoadError; end