haml 1.8.0 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. data/FAQ +138 -0
  2. data/MIT-LICENSE +1 -1
  3. data/{README → README.rdoc} +66 -3
  4. data/REVISION +1 -0
  5. data/Rakefile +115 -147
  6. data/VERSION +1 -1
  7. data/bin/css2sass +0 -0
  8. data/bin/haml +2 -1
  9. data/bin/html2haml +0 -0
  10. data/bin/sass +0 -0
  11. data/init.rb +6 -1
  12. data/lib/haml/buffer.rb +122 -64
  13. data/lib/haml/engine.rb +77 -46
  14. data/lib/haml/error.rb +15 -6
  15. data/lib/haml/exec.rb +61 -10
  16. data/lib/haml/filters.rb +229 -74
  17. data/lib/haml/helpers/action_view_extensions.rb +1 -1
  18. data/lib/haml/helpers/action_view_mods.rb +109 -24
  19. data/lib/haml/helpers.rb +137 -76
  20. data/lib/haml/html.rb +8 -8
  21. data/lib/haml/precompiler.rb +280 -153
  22. data/lib/haml/template/patch.rb +10 -3
  23. data/lib/haml/template/plugin.rb +61 -10
  24. data/lib/haml/template.rb +14 -9
  25. data/lib/haml.rb +483 -214
  26. data/lib/sass/constant/color.rb +13 -13
  27. data/lib/sass/constant/literal.rb +8 -7
  28. data/lib/sass/constant/nil.rb +9 -0
  29. data/lib/sass/constant/number.rb +10 -10
  30. data/lib/sass/constant/operation.rb +4 -4
  31. data/lib/sass/constant/string.rb +3 -3
  32. data/lib/sass/constant.rb +46 -77
  33. data/lib/sass/css.rb +130 -56
  34. data/lib/sass/engine.rb +131 -43
  35. data/lib/sass/plugin/merb.rb +48 -12
  36. data/lib/sass/plugin/rails.rb +10 -4
  37. data/lib/sass/plugin.rb +33 -10
  38. data/lib/sass/tree/attr_node.rb +5 -5
  39. data/lib/sass/tree/directive_node.rb +2 -7
  40. data/lib/sass/tree/node.rb +1 -12
  41. data/lib/sass/tree/rule_node.rb +39 -31
  42. data/lib/sass/tree/value_node.rb +1 -1
  43. data/lib/sass.rb +194 -19
  44. data/rails/init.rb +1 -0
  45. data/test/benchmark.rb +67 -80
  46. data/test/haml/engine_test.rb +368 -152
  47. data/test/haml/helper_test.rb +68 -16
  48. data/test/haml/html2haml_test.rb +3 -4
  49. data/test/haml/results/content_for_layout.xhtml +1 -2
  50. data/test/haml/results/eval_suppressed.xhtml +2 -4
  51. data/test/haml/results/filters.xhtml +38 -30
  52. data/test/haml/results/helpers.xhtml +4 -8
  53. data/test/haml/results/just_stuff.xhtml +8 -7
  54. data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
  55. data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
  56. data/test/haml/results/original_engine.xhtml +3 -7
  57. data/test/haml/results/partials.xhtml +1 -0
  58. data/test/haml/results/tag_parsing.xhtml +1 -6
  59. data/test/haml/results/very_basic.xhtml +2 -4
  60. data/test/haml/results/whitespace_handling.xhtml +13 -21
  61. data/test/haml/template_test.rb +42 -57
  62. data/test/haml/templates/_partial.haml +1 -0
  63. data/test/haml/templates/filters.haml +39 -21
  64. data/test/haml/templates/helpers.haml +10 -10
  65. data/test/haml/templates/just_stuff.haml +8 -3
  66. data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
  67. data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
  68. data/test/haml/templates/partials.haml +1 -1
  69. data/test/haml/templates/tag_parsing.haml +0 -3
  70. data/test/haml/templates/whitespace_handling.haml +10 -10
  71. data/test/sass/engine_test.rb +97 -39
  72. data/test/sass/plugin_test.rb +4 -7
  73. data/test/sass/results/constants.css +2 -0
  74. data/test/sass/results/import.css +2 -2
  75. data/test/sass/results/mixins.css +95 -0
  76. data/test/sass/results/multiline.css +24 -0
  77. data/test/sass/templates/constants.sass +3 -0
  78. data/test/sass/templates/import.sass +4 -1
  79. data/test/sass/templates/importee.sass +4 -0
  80. data/test/sass/templates/mixins.sass +76 -0
  81. data/test/sass/templates/multiline.sass +20 -0
  82. data/test/test_helper.rb +18 -0
  83. metadata +70 -53
  84. data/lib/haml/helpers/action_view_mods.rb.rej +0 -30
  85. data/lib/haml/util.rb +0 -18
  86. data/lib/sass/constant.rb.rej +0 -42
  87. data/test/haml/runner.rb +0 -16
  88. data/test/profile.rb +0 -65
  89. data/test/sass/engine_test.rb.rej +0 -18
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].
data/MIT-LICENSE CHANGED
@@ -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/REVISION ADDED
@@ -0,0 +1 @@
1
+ (release)
data/Rakefile CHANGED
@@ -1,182 +1,150 @@
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
+ test_files = FileList['test/**/*_test.rb']
23
+ test_files.exclude('test/rails/*')
24
+ t.test_files = test_files
25
+ t.verbose = true
26
+ end
27
+ Rake::Task[:test].send(:add_comment, <<END)
28
+ To run with an alternate version of Rails, make test/rails a symlink to that version.
29
+ END
41
30
 
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
31
+ # ----- Packaging -----
48
32
 
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']
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
33
+ require 'rake/gempackagetask'
34
+ load 'haml.gemspec'
89
35
 
90
- Rake::GemPackageTask.new(spec) do |pkg|
91
- pkg.need_zip = true
36
+ Rake::GemPackageTask.new(HAML_GEMSPEC) do |pkg|
37
+ if Rake.application.top_level_tasks.include?('release')
92
38
  pkg.need_tar_gz = true
93
39
  pkg.need_tar_bz2 = true
40
+ pkg.need_zip = true
94
41
  end
42
+ end
95
43
 
96
- task :install => [:package] do
97
- sh %{gem install --no-ri pkg/haml-#{File.read('VERSION').strip}}
98
- end
44
+ task :revision_file do
45
+ require 'lib/haml'
99
46
 
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}
47
+ if Haml.version[:rev] && !Rake.application.top_level_tasks.include?('release')
48
+ File.open('REVISION', 'w') { |f| f.puts Haml.version[:rev] }
49
+ elsif Rake.application.top_level_tasks.include?('release')
50
+ File.open('REVISION', 'w') { |f| f.puts "(release)" }
51
+ else
52
+ File.open('REVISION', 'w') { |f| f.puts "(unknown)" }
108
53
  end
54
+ end
55
+ Rake::Task[:package].prerequisites.insert(0, :revision_file)
56
+
57
+ # We also need to get rid of this file after packaging.
58
+ at_exit { File.delete('REVISION') rescue nil }
109
59
 
110
- # ----- Documentation -----
60
+ desc "Install Haml as a gem."
61
+ task :install => [:package] do
62
+ sudo = RUBY_PLATFORM =~ /win32/ ? '' : 'sudo'
63
+ sh %{#{sudo} gem install --no-ri pkg/haml-#{File.read('VERSION').strip}}
64
+ end
65
+
66
+ desc "Release a new Haml package to Rubyforge. Requires the NAME and VERSION flags."
67
+ task :release => [:package] do
68
+ name, version = ENV['NAME'], ENV['VERSION']
69
+ raise "Must supply NAME and VERSION for release task." unless name && version
70
+ sh %{rubyforge login}
71
+ sh %{rubyforge add_release haml haml "#{name} (v#{version})" pkg/haml-#{version}.gem}
72
+ sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.gz}
73
+ sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.bz2}
74
+ sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.zip}
75
+ end
76
+
77
+ # ----- Documentation -----
111
78
 
79
+ begin
80
+ require 'hanna/rdoctask'
81
+ rescue LoadError
112
82
  require 'rake/rdoctask'
83
+ end
113
84
 
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
85
+ Rake::RDocTask.new do |rdoc|
86
+ rdoc.title = 'Haml/Sass'
87
+ rdoc.options << '--line-numbers' << '--inline-source'
88
+ rdoc.rdoc_files.include(*FileList.new('*') do |list|
89
+ list.exclude(/(^|[^.a-z])[a-z]+/)
90
+ list.exclude('TODO')
91
+ end.to_a)
92
+ rdoc.rdoc_files.include('lib/**/*.rb')
93
+ rdoc.rdoc_files.exclude('TODO')
94
+ rdoc.rdoc_files.exclude('lib/haml/buffer.rb')
95
+ rdoc.rdoc_files.exclude('lib/sass/tree/*')
96
+ rdoc.rdoc_dir = 'rdoc'
97
+ rdoc.main = 'README.rdoc'
98
+ end
123
99
 
124
- Rake::RDocTask.new do |rdoc|
125
- rdoc_task.call(rdoc)
126
- rdoc.rdoc_dir = 'rdoc'
127
- end
100
+ # ----- Coverage -----
128
101
 
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
102
+ begin
103
+ require 'rcov/rcovtask'
140
104
 
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
105
+ Rcov::RcovTask.new do |t|
106
+ t.test_files = FileList['test/**/*_test.rb']
107
+ t.rcov_opts << '-x' << '"^\/"'
108
+ if ENV['NON_NATIVE']
109
+ t.rcov_opts << "--no-rcovrt"
152
110
  end
111
+ t.verbose = true
153
112
  end
113
+ rescue LoadError; end
154
114
 
155
- # ----- Profiling -----
115
+ # ----- Profiling -----
156
116
 
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
117
+ begin
118
+ require 'ruby-prof'
119
+
120
+ desc <<END
121
+ Run a profile of haml.
122
+ ENGINE=str sets the engine to be profiled. Defaults to Haml.
123
+ TIMES=n sets the number of runs. Defaults to 1000.
124
+ FILE=str sets the file to profile.
125
+ Defaults to 'standard' for Haml and 'complex' for Sass.
126
+ OUTPUT=str sets the ruby-prof output format.
127
+ Can be Flat, CallInfo, or Graph. Defaults to Flat. Defaults to Flat.
128
+ END
164
129
  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
130
+ engine = (ENV['ENGINE'] || 'haml').downcase
131
+ times = (ENV['TIMES'] || '1000').to_i
132
+ file = ENV['FILE']
133
+
134
+ if engine == 'sass'
135
+ require 'lib/sass'
136
+
137
+ file = File.read("#{File.dirname(__FILE__)}/test/sass/templates/#{file || 'complex'}.sass")
138
+ result = RubyProf.profile { times.times { Sass::Engine.new(file).render } }
139
+ else
140
+ require 'lib/haml'
141
+
142
+ file = File.read("#{File.dirname(__FILE__)}/test/haml/templates/#{file || 'standard'}.haml")
143
+ obj = Object.new
144
+ Haml::Engine.new(file).def_method(obj, :render)
145
+ result = RubyProf.profile { times.times { obj.render } }
146
+ end
181
147
 
182
- end
148
+ RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
149
+ end
150
+ rescue LoadError; end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.0
1
+ 2.0.3
data/bin/css2sass CHANGED
File without changes
data/bin/haml CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # The command line Haml parser.
3
3
 
4
- require File.dirname(__FILE__) + '/../lib/haml'
4
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
+ require 'haml'
5
6
  require 'haml/exec'
6
7
 
7
8
  opts = Haml::Exec::Haml.new(ARGV)
data/bin/html2haml CHANGED
File without changes
data/bin/sass CHANGED
File without changes
data/init.rb CHANGED
@@ -1,2 +1,7 @@
1
- require 'haml'
1
+ begin
2
+ require File.join(File.dirname(__FILE__), 'lib', 'haml') # From here
3
+ rescue LoadError
4
+ require 'haml' # From gem
5
+ end
6
+
2
7
  Haml.init_rails(binding)