Implied extensions. Closes #304

This commit is contained in:
Thomas Reynolds 2012-03-29 18:22:43 +01:00
parent aab9644185
commit e769477e93
9 changed files with 102 additions and 19 deletions

View file

@ -33,6 +33,11 @@ module Middleman::CoreExtensions::Rendering
# Override init to clear cache on file removal
def initialize
# Default extension map
@_template_extensions = {
}
super
static_path = source_dir.sub(self.root, "").sub(/^\//, "")
@ -44,6 +49,14 @@ module Middleman::CoreExtensions::Rendering
end
end
# Add or overwrite a default template extension
#
# @param [Hash] extension_map
# @return [void]
def template_extensions(extension_map={})
@_template_extensions.merge!(extension_map)
end
# Render a template, with layout, given a path
#
# @param [String] path

View file

@ -10,6 +10,10 @@ module Middleman::Renderers::ERb
app.set :erb_engine, :erb
app.set :erb_engine_prefix, ::Tilt
app.before_configuration do
template_extensions :erb => :html
end
# After config
app.after_configuration do
# Find the user's prefered engine

View file

@ -176,6 +176,15 @@ module Middleman::Sitemap
end
end
# If there is no extension, look for one
if File.extname(path).empty?
input_ext = File.extname(file).split(".").last.to_sym
if app.template_extensions.has_key?(input_ext)
path << ".#{app.template_extensions[input_ext]}"
end
end
path
end
end

View file

@ -21,9 +21,7 @@ Given /^current environment is "([^\"]*)"$/ do |env|
@current_env = env.to_sym
end
Given /^the Server is running at "([^\"]*)"$/ do |app_path|
step %Q{a fixture app "#{app_path}"}
Given /^the Server is running$/ do
root_dir = File.expand_path(current_dir)
if File.exists?(File.join(root_dir, "source"))
@ -49,6 +47,11 @@ Given /^the Server is running at "([^\"]*)"$/ do |app_path|
@browser = ::Rack::Test::Session.new(::Rack::MockSession.new(app_rack))
end
Given /^the Server is running at "([^\"]*)"$/ do |app_path|
step %Q{a fixture app "#{app_path}"}
step %Q{the Server is running}
end
When /^I go to "([^\"]*)"$/ do |url|
@browser.get(url)
end