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

View file

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