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

@ -22,7 +22,7 @@ module Generators
if (args[0] === args[1])
newext = case File.extname(args.first)
when '.haml', '.mab', '.maruku'
when '.haml', '.erb', '.mab', '.maruku'
'.html'
when '.sass'
'.css'
@ -48,7 +48,7 @@ module Generators
file(action.downcase.gsub(/[^a-z0-9]+/, '_').to_sym, action, action.gsub('public/', ''))
end
glob! "views", %w(haml sass mab maruku)
glob! "views", %w(haml sass erb builder mab maruku)
end
add :build, Builder

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