support alternative ext
This commit is contained in:
parent
9e01c6c80f
commit
2dbec48c61
2 changed files with 30 additions and 12 deletions
21
bin/mm-build
21
bin/mm-build
|
@ -26,15 +26,22 @@ module Generators
|
||||||
end
|
end
|
||||||
|
|
||||||
if (args[0] === args[1])
|
if (args[0] === args[1])
|
||||||
newext = case File.extname(args.first)
|
file_name_parts = File.basename(args.first).split('.')
|
||||||
when '.haml', '.erb', '.mab', '.maruku'
|
|
||||||
'.html'
|
if file_name_parts.length > 2
|
||||||
when '.sass'
|
# static ext embedded in filename
|
||||||
'.css'
|
newext = ""
|
||||||
else
|
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/', '')
|
end
|
||||||
|
|
||||||
|
args[1] = args[0].gsub(".#{file_name_parts.last}", newext).gsub('views/', '')
|
||||||
end
|
end
|
||||||
|
|
||||||
super(name, *args, &block)
|
super(name, *args, &block)
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Middleman < Sinatra::Base
|
||||||
set :static, true
|
set :static, true
|
||||||
set :root, Dir.pwd
|
set :root, Dir.pwd
|
||||||
set :environment, defined?(MIDDLEMAN_BUILDER) ? :build : :development
|
set :environment, defined?(MIDDLEMAN_BUILDER) ? :build : :development
|
||||||
|
set :default_ext, 'html'
|
||||||
set :supported_formats, %w(haml erb builder)
|
set :supported_formats, %w(haml erb builder)
|
||||||
|
|
||||||
helpers Sinatra::ContentFor
|
helpers Sinatra::ContentFor
|
||||||
|
@ -82,15 +82,20 @@ class Middleman < Sinatra::Base
|
||||||
|
|
||||||
# All other files
|
# All other files
|
||||||
get /(.*)/ do |path|
|
get /(.*)/ do |path|
|
||||||
path << "index.html" if path.match(%r{/$})
|
path << "index.#{options.default_ext}" if path.match(%r{/$})
|
||||||
path.gsub!(%r{^/}, '')
|
path.gsub!(%r{^/}, '')
|
||||||
path.gsub!(File.extname(path), '')
|
path_without_ext = path.gsub(File.extname(path), '')
|
||||||
|
|
||||||
result = nil
|
result = nil
|
||||||
begin
|
begin
|
||||||
options.supported_formats.detect do |renderer|
|
options.supported_formats.detect do |renderer|
|
||||||
next false if !File.exists?(File.join(options.views, "#{path}.#{renderer}"))
|
if File.exists?(File.join(options.views, "#{path}.#{renderer}"))
|
||||||
result = send(renderer.to_sym, path.to_sym)
|
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
|
end
|
||||||
rescue Haml::Error => e
|
rescue Haml::Error => e
|
||||||
result = "Haml Error: #{e}"
|
result = "Haml Error: #{e}"
|
||||||
|
@ -99,4 +104,10 @@ class Middleman < Sinatra::Base
|
||||||
|
|
||||||
result || pass
|
result || pass
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
get %r{/(.*\.xml)} do |path|
|
||||||
|
content_type 'text/xml', :charset => 'utf-8'
|
||||||
|
haml(path.to_sym, :layout => false)
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Add table
Reference in a new issue