Created
March 22, 2011 23:37
-
-
Save jfairbairn/882338 to your computer and use it in GitHub Desktop.
Using haml-js in Ruby. See comments for what/why. You'll need to get haml.js and copy it to your clone directory to make this work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'benchmark' | |
require 'rubygems' | |
gem 'therubyracer' | |
gem 'haml' | |
gem 'tilt' | |
require 'v8' | |
require 'haml' | |
require 'tilt' | |
class HamlJs | |
def initialize | |
@cxt = V8::Context.new | |
@cxt.eval(File.read('haml.js')) | |
end | |
def template(code) | |
@cxt['code'] = code | |
@cxt.eval('Haml(code)') | |
end | |
end | |
hj=HamlJs.new.template(File.read('foo.haml')) | |
hr=Haml::Engine.new(File.read('foo.haml'), :ugly=>true) | |
ht=Tilt.new('foo.haml', :ugly=>true) | |
locals = {'name'=>'hello'} | |
Benchmark.bm(18) do |bm| | |
bm.report('haml js from ruby:') { 100000.times { hj.call(locals) }} | |
bm.report('haml rb:') { 100000.times { hr.render(self, locals) }} | |
bm.report('tilt/haml rb:') { 100000.times { ht.render(self, locals) }} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!