diff --git a/CHANGELOG.md b/CHANGELOG.md index c9e2de95..e1239a0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ * Add pid for cleanup * Use guard/listen for file watching * Merge full i18n support +* Implied file extensions (style.scss => sytle.css) 2.0.14 ==== diff --git a/middleman-core/features/extensionless_text_files.feature b/middleman-core/features/extensionless_text_files.feature index a544f2e0..dd015440 100644 --- a/middleman-core/features/extensionless_text_files.feature +++ b/middleman-core/features/extensionless_text_files.feature @@ -13,23 +13,23 @@ Feature: Text Files Without Extensions Should Build and Preview | LICENSE | | README | - Scenario: Building Text Files with directory indexes + Scenario: Building Text Files with directory indexes - Given a fixture app "extensionless-text-files-app" - And a file named "config.rb" with: - """ - activate :directory_indexes - """ - And a successfully built app at "extensionless-text-files-app" - When I cd to "build" - Then the following files should exist: - | CNAME | - | LICENSE | - | README | - Then the following files should not exist: - | CNAME/index.html | - | LICENSE/index.html | - | README/index.html | + Given a fixture app "extensionless-text-files-app" + And a file named "config.rb" with: + """ + activate :directory_indexes + """ + And a successfully built app at "extensionless-text-files-app" + When I cd to "build" + Then the following files should exist: + | CNAME | + | LICENSE | + | README | + Then the following files should not exist: + | CNAME/index.html | + | LICENSE/index.html | + | README/index.html | Scenario: Previewing Text Files without directory indexes Given "directory_indexes" feature is "disabled" diff --git a/middleman-core/features/implied_extensions.feature b/middleman-core/features/implied_extensions.feature new file mode 100644 index 00000000..815d6745 --- /dev/null +++ b/middleman-core/features/implied_extensions.feature @@ -0,0 +1,52 @@ +Feature: Use default extensions when user doesn't supply them + + Scenario: Default extensions preview + Given the Server is running at "implied-extensions-app" + When I go to "/index.html" + Then I should see "hello: world" + When I go to "/index.erb" + Then I should see "File Not Found" + When I go to "/index" + Then I should see "File Not Found" + + Scenario: Default extensions preview + Given a fixture app "implied-extensions-app" + And a file named "config.rb" with: + """ + template_extensions :erb => :htm + """ + And the Server is running + When I go to "/index.htm" + Then I should see "hello: world" + When I go to "/index.erb" + Then I should see "File Not Found" + When I go to "/index" + Then I should see "File Not Found" + When I go to "/index.html" + Then I should see "File Not Found" + + Scenario: Default extensions build + Given a fixture app "implied-extensions-app" + And a successfully built app at "implied-extensions-app" + When I cd to "build" + Then the following files should exist: + | index.html | + Then the following files should not exist: + | index | + | index.erb | + And the file "index.html" should contain "hello: world" + + Scenario: Default extensions build with override + Given a fixture app "implied-extensions-app" + And a file named "config.rb" with: + """ + template_extensions :erb => :htm + """ + And a successfully built app at "implied-extensions-app" + When I cd to "build" + Then the following files should exist: + | index.htm | + Then the following files should not exist: + | index | + | index.erb | + | index.html | \ No newline at end of file diff --git a/middleman-core/fixtures/implied-extensions-app/config.rb b/middleman-core/fixtures/implied-extensions-app/config.rb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-core/fixtures/implied-extensions-app/source/index.erb b/middleman-core/fixtures/implied-extensions-app/source/index.erb new file mode 100644 index 00000000..89fb406c --- /dev/null +++ b/middleman-core/fixtures/implied-extensions-app/source/index.erb @@ -0,0 +1 @@ +hello: <%= "world" %> \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/core_extensions/rendering.rb b/middleman-core/lib/middleman-core/core_extensions/rendering.rb index 31e9ffde..3fa1d369 100644 --- a/middleman-core/lib/middleman-core/core_extensions/rendering.rb +++ b/middleman-core/lib/middleman-core/core_extensions/rendering.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/renderers/erb.rb b/middleman-core/lib/middleman-core/renderers/erb.rb index 4290affd..d7990dee 100644 --- a/middleman-core/lib/middleman-core/renderers/erb.rb +++ b/middleman-core/lib/middleman-core/renderers/erb.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/sitemap/store.rb b/middleman-core/lib/middleman-core/sitemap/store.rb index 07b9662a..499a74a2 100644 --- a/middleman-core/lib/middleman-core/sitemap/store.rb +++ b/middleman-core/lib/middleman-core/sitemap/store.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/step_definitions/server_steps.rb b/middleman-core/lib/middleman-core/step_definitions/server_steps.rb index 3f53867e..7a75cb20 100644 --- a/middleman-core/lib/middleman-core/step_definitions/server_steps.rb +++ b/middleman-core/lib/middleman-core/step_definitions/server_steps.rb @@ -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