generalize renderers

This commit is contained in:
tdreyno 2009-07-28 13:44:56 -07:00
parent 4a6eb26d58
commit 5cc9470ae9
2 changed files with 18 additions and 17 deletions

View file

@ -45,27 +45,28 @@ class Middleman < Sinatra::Base
config.http_images_path = "/images/"
end
end
get /(.*)/ do |path|
path << "index.html" if path.match(%r{/$})
path.gsub!(%r{^/}, '')
template = path.gsub(File.extname(path), '').to_sym
if path.match /.html$/
if File.exists? File.join(options.views, "#{template}.haml")
haml(template)
elsif File.exists? File.join(options.views, "#{template}.maruku")
maruku(template)
elsif File.exists? File.join(options.views, "#{template}.mab")
markaby(template)
result = nil
%w(haml erb builder maruku mab sass).each do |renderer|
next if !File.exists?(File.join(options.views, "#{template}.#{renderer}"))
renderer = "markaby" if renderer == "mab"
result = if renderer == "sass"
content_type 'text/css', :charset => 'utf-8'
sass(template, Compass.sass_engine_options)
else
pass
send(renderer.to_sym, template)
end
elsif path.match /.css$/
content_type 'text/css', :charset => 'utf-8'
sass(template, Compass.sass_engine_options)
else
pass
break
end
result || pass
end
end