Skip to content

Instantly share code, notes, and snippets.

View dcolthorp's full-sized avatar

Drew Colthorp dcolthorp

View GitHub Profile
def foo
puts "bar"
end
def capture(*args, &block)
ret = ""
captured = send("capture_#{@_template}", *args) do
ret = block.call
end
if captured.blank?
ret
else
captured
end
#================== config/dependencies.rb
dependency "merb-action-args", "0.9.9" # Provides support for querystring arguments to be passed in to controller actions
dependency "merb-assets", "0.9.9" # Provides link_to, asset_path, auto_link, image_tag methods (and lots more)
dependency "merb-cache", "0.9.9" # Provides your application with caching functions
dependency "merb-helpers", "0.9.9" # Provides the form, date/time, and other helpers
dependency "merb-mailer", "0.9.9" # Integrates mail support via Merb Mailer
dependency "merb-slices", "0.9.9" # Provides a mechanism for letting plugins provide controllers, views, etc. to your app
dependency "merb-auth", "0.9.9" # An authentication slice (Merb's equivalent to Rails' restful authentication)
dependency "dm-core", "0.9.5" # The datamapper ORM
require 'merb-core'
require 'merb-haml'
END {
require 'rbench'
expando = Expando.new
raise "haml's not fair" unless expando.efficient_haml == expando.naive_haml
raise "erb's not fair" unless expando.efficient_erb == expando.naive_erb
require 'merb-core'
require 'merb-haml'
END {
require 'rbench'
expando = Expando.new
raise "haml's not fair" unless expando.efficient_haml == expando.naive_haml
raise "erb's not fair" unless expando.efficient_erb == expando.naive_erb
# return an address in the adr microformat
def format_address address
expand_template(:haml, <<-END, :address => address)
.adr
.street-address= address.street_address
%span.locality= address.city
,
%span.region= address.state
%span.postal-code= address.zip
END
@dcolthorp
dcolthorp / gist:17553
Created October 17, 2008 22:41
prototype of efficient inline template expansion
# Prototype of a mechanism for efficient inline template compilation
# via call site caching.
require 'merb-core'
require 'merb-haml'
END {
require 'rbench'
expando = Expando.new
<dl class="realius" style="display:none">
<dt>content</dt>
<dd><a href="#">foo</a></dd>
<dt>user</dt>
<dd>
<dl>
<dt>id</dt>
<dd>123asdfa</dd>
<dl class="realius" style="display:none">
<dt>content</dt>
<dd><a href="#">foo</a></dd>
<dt>user</dt>
<dd>asdfkjdslkfjdslfkjsdlfjdsalfjsdalkfjdsaklfjdslf</dd>
<dt>listing</dt>
<dd>
<dl>
<a class="launch_realius" style="display: none"
listing_id="40366444"
street_address="123 foobar st."
lat="37.3"
lng="-121.9"
market="CLAMLS"
price="100000"
category="San Fran">Predict sales price</a>
<dl class="realius" style="display:none">