From 2dbec48c61419e4f803e5b35472e0309a696a613 Mon Sep 17 00:00:00 2001 From: tdreyno Date: Fri, 18 Sep 2009 09:59:07 -0700 Subject: [PATCH] support alternative ext --- bin/mm-build | 21 ++++++++++++++------- lib/middleman.rb | 21 ++++++++++++++++----- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/bin/mm-build b/bin/mm-build index bb8bf9b2..dce06cc0 100755 --- a/bin/mm-build +++ b/bin/mm-build @@ -26,15 +26,22 @@ module Generators end if (args[0] === args[1]) - newext = case File.extname(args.first) - when '.haml', '.erb', '.mab', '.maruku' - '.html' - when '.sass' - '.css' + file_name_parts = File.basename(args.first).split('.') + + if file_name_parts.length > 2 + # static ext embedded in filename + newext = "" else - File.extname(args.first) + # use defaults + newext = case file_name_parts.last + when 'haml', 'erb', 'mab', 'maruku' + '.html' + when 'sass' + '.css' + end end - args[1] = args[0].gsub(File.extname(args.first), newext).gsub('views/', '') + + args[1] = args[0].gsub(".#{file_name_parts.last}", newext).gsub('views/', '') end super(name, *args, &block) diff --git a/lib/middleman.rb b/lib/middleman.rb index 326e9187..6f2f8aaf 100644 --- a/lib/middleman.rb +++ b/lib/middleman.rb @@ -14,7 +14,7 @@ class Middleman < Sinatra::Base set :static, true set :root, Dir.pwd set :environment, defined?(MIDDLEMAN_BUILDER) ? :build : :development - + set :default_ext, 'html' set :supported_formats, %w(haml erb builder) helpers Sinatra::ContentFor @@ -82,15 +82,20 @@ class Middleman < Sinatra::Base # All other files get /(.*)/ do |path| - path << "index.html" if path.match(%r{/$}) + path << "index.#{options.default_ext}" if path.match(%r{/$}) path.gsub!(%r{^/}, '') - path.gsub!(File.extname(path), '') + path_without_ext = path.gsub(File.extname(path), '') result = nil begin options.supported_formats.detect do |renderer| - next false if !File.exists?(File.join(options.views, "#{path}.#{renderer}")) - result = send(renderer.to_sym, path.to_sym) + if File.exists?(File.join(options.views, "#{path}.#{renderer}")) + result = send(renderer.to_sym, path.to_sym) + elsif File.exists?(File.join(options.views, "#{path_without_ext}.#{renderer}")) + result = send(renderer.to_sym, path_without_ext.to_sym) + else + false + end end rescue Haml::Error => e result = "Haml Error: #{e}" @@ -99,4 +104,10 @@ class Middleman < Sinatra::Base result || pass end + + + get %r{/(.*\.xml)} do |path| + content_type 'text/xml', :charset => 'utf-8' + haml(path.to_sym, :layout => false) + end end \ No newline at end of file