From 5cc9470ae91679577b44e82de1a78bc38c9ba9a7 Mon Sep 17 00:00:00 2001 From: tdreyno Date: Tue, 28 Jul 2009 13:44:56 -0700 Subject: [PATCH] generalize renderers --- bin/mm-build | 4 ++-- lib/middleman.rb | 31 ++++++++++++++++--------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/bin/mm-build b/bin/mm-build index 606b9211..7236c06a 100755 --- a/bin/mm-build +++ b/bin/mm-build @@ -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 diff --git a/lib/middleman.rb b/lib/middleman.rb index dce63b66..c26a351b 100644 --- a/lib/middleman.rb +++ b/lib/middleman.rb @@ -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 \ No newline at end of file