diff --git a/CHANGELOG b/CHANGELOG index d1e8ff1b..fa4ca23a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,4 +10,5 @@ - Added callback to run code after Compass is configured - Added support for a compass.config file which is passed directly to Compass - Blog-aware Feature (and project template) -- Thor-based, unified `middleman` binary \ No newline at end of file +- Thor-based, unified `middleman` binary +- :directory_indexes feature \ No newline at end of file diff --git a/features/asset_host.feature b/features/asset_host.feature index 491f9757..3736643b 100644 --- a/features/asset_host.feature +++ b/features/asset_host.feature @@ -3,12 +3,12 @@ Feature: Alternate between multiple asset hosts Scenario: Rendering css with the feature enabled Given I am using an asset host - And the Server is running + And the Server is running at "test-app" When I go to "/stylesheets/asset_host.css" Then I should see "http://assets" Scenario: Rendering html with the feature enabled Given I am using an asset host - And the Server is running + And the Server is running at "test-app" When I go to "/asset_host.html" Then I should see "http://assets" \ No newline at end of file diff --git a/features/automatic_image_sizes.feature b/features/automatic_image_sizes.feature index 1548e270..a4dc9681 100644 --- a/features/automatic_image_sizes.feature +++ b/features/automatic_image_sizes.feature @@ -3,14 +3,14 @@ Feature: Automatically detect and insert image dimensions into tags Scenario: Rendering an image with the feature disabled Given "automatic_image_sizes" feature is "disabled" - And the Server is running + And the Server is running at "test-app" When I go to "/auto-image-sizes.html" Then I should not see "width=" And I should not see "height=" Scenario: Rendering an image with the feature enabled Given "automatic_image_sizes" feature is "enabled" - And the Server is running + And the Server is running at "test-app" When I go to "/auto-image-sizes.html" Then I should see "width=" And I should see "height=" \ No newline at end of file diff --git a/features/builder.feature b/features/builder.feature index 186703f5..e20db399 100644 --- a/features/builder.feature +++ b/features/builder.feature @@ -2,22 +2,22 @@ Feature: Builder In order to output static html and css for delivery Scenario: Checking built folder for content - Given a built test app - Then "index.html" should exist and include "Comment in layout" - Then "javascripts/coffee_test.js" should exist and include "Array.prototype.slice" - Then "index.html" should exist and include "

Welcome

" - Then "static.html" should exist and include "Static, no code!" - Then "services/index.html" should exist and include "Services" - Then "stylesheets/site.css" should exist and include "html, body, div, span" - Then "stylesheets/site_scss.css" should exist and include "html, body, div, span" - Then "stylesheets/static.css" should exist and include "body" - Then "_partial.html" should not exist - Then "spaces in file.html" should exist and include "spaces" - Then "images/Read me (example).txt" should exist - Then "images/Child folder/regular_file(example).txt" should exist - And cleanup built test app + Given a built app at "test-app" + Then "index.html" should exist at "test-app" and include "Comment in layout" + Then "javascripts/coffee_test.js" should exist at "test-app" and include "Array.prototype.slice" + Then "index.html" should exist at "test-app" and include "

Welcome

" + Then "static.html" should exist at "test-app" and include "Static, no code!" + Then "services/index.html" should exist at "test-app" and include "Services" + Then "stylesheets/site.css" should exist at "test-app" and include "html, body, div, span" + Then "stylesheets/site_scss.css" should exist at "test-app" and include "html, body, div, span" + Then "stylesheets/static.css" should exist at "test-app" and include "body" + Then "_partial.html" should not exist at "test-app" + Then "spaces in file.html" should exist at "test-app" and include "spaces" + Then "images/Read me (example).txt" should exist at "test-app" + Then "images/Child folder/regular_file(example).txt" should exist at "test-app" + And cleanup built app at "test-app" Scenario: Force relative assets Given a built test app with flags "--relative" - Then "stylesheets/relative_assets.css" should exist and include "../" - And cleanup built test app \ No newline at end of file + Then "stylesheets/relative_assets.css" should exist at "test-app" and include "../" + And cleanup built app at "test-app" \ No newline at end of file diff --git a/features/cache_buster.feature b/features/cache_buster.feature index 642abd51..a7bc7723 100644 --- a/features/cache_buster.feature +++ b/features/cache_buster.feature @@ -3,24 +3,24 @@ Feature: Generate mtime-based query string for busting browser caches Scenario: Rendering css with the feature disabled Given "cache_buster" feature is "disabled" - And the Server is running + And the Server is running at "test-app" When I go to "/stylesheets/relative_assets.css" Then I should not see "?" Scenario: Rendering html with the feature disabled Given "cache_buster" feature is "disabled" - And the Server is running + And the Server is running at "test-app" When I go to "/cache-buster.html" Then I should not see "?" Scenario: Rendering css with the feature enabled Given "cache_buster" feature is "enabled" - And the Server is running + And the Server is running at "test-app" When I go to "/stylesheets/relative_assets.css" Then I should see "?" Scenario: Rendering html with the feature enabled Given "cache_buster" feature is "enabled" - And the Server is running + And the Server is running at "test-app" When I go to "/cache-buster.html" Then I should not see "?" \ No newline at end of file diff --git a/features/coffee-script.feature b/features/coffee-script.feature index 62495577..87ddc6d8 100644 --- a/features/coffee-script.feature +++ b/features/coffee-script.feature @@ -2,16 +2,16 @@ Feature: Support coffee-script In order to offer an alternative when writing Javascript Scenario: Rendering coffee script - Given the Server is running + Given the Server is running at "test-app" When I go to "/javascripts/coffee_test.js" Then I should see "Array.prototype.slice" Scenario: Rendering coffee-script with :coffeescript haml-filter - Given the Server is running + Given the Server is running at "test-app" When I go to "/inline-coffeescript.html" Then I should see "Array.prototype.slice" Scenario: Rendering broken coffee - Given the Server is running + Given the Server is running at "test-app" When I go to "/javascripts/broken-coffee.js" Then I should see "Reserved word" \ No newline at end of file diff --git a/features/data.feature b/features/data.feature index 5e7204d3..e803a603 100644 --- a/features/data.feature +++ b/features/data.feature @@ -2,6 +2,6 @@ Feature: Local Data API In order to abstract content from structure Scenario: Rendering html - Given the Server is running + Given the Server is running at "test-app" When I go to "/data.html" Then I should see "One:Two" \ No newline at end of file diff --git a/features/directory_index.feature b/features/directory_index.feature new file mode 100644 index 00000000..4eb6e276 --- /dev/null +++ b/features/directory_index.feature @@ -0,0 +1,27 @@ +Feature: Directory Index + In order output Apache-friendly directories and indexes + + Scenario: Checking built folder for content + Given a built app at "indexable-app" + Then "needs_index/index.html" should exist at "indexable-app" and include "Indexable" + Then "a_folder/needs_index/index.html" should exist at "indexable-app" and include "Indexable" + Then "leave_me_alone.html" should exist at "indexable-app" and include "Stay away" + Then "needs_index.html" should not exist at "indexable-app" + Then "a_folder/needs_index.html" should not exist at "indexable-app" + Then "leave_me_alone/index.html" should not exist at "indexable-app" + And cleanup built app at "indexable-app" + + Scenario: Preview normal file + Given the Server is running at "indexable-app" + When I go to "/needs_index/" + Then I should see "Indexable" + + Scenario: Preview normal file subdirectory + Given the Server is running at "indexable-app" + When I go to "/a_folder/needs_index/" + Then I should see "Indexable" + + Scenario: Preview ignored file + Given the Server is running at "indexable-app" + When I go to "/leave_me_alone/" + Then I should see "File Not Found" \ No newline at end of file diff --git a/features/dynamic_pages.feature b/features/dynamic_pages.feature index dd9217bb..3de38a0d 100644 --- a/features/dynamic_pages.feature +++ b/features/dynamic_pages.feature @@ -2,27 +2,32 @@ Feature: Dynamic Pages In order to use a single view to generate multiple output files Scenario: Checking built folder for content - Given a built test app - Then "fake.html" should exist and include "I am real" - Then "fake/one.html" should exist and include "I am real: one" - Then "fake/two.html" should exist and include "I am real: two" - Then "target_ignore.html" should exist and include "Ignore me" - Then "should_be_ignored.html" should not exist - Then "should_be_ignored2.html" should not exist - Then "should_be_ignored3.html" should not exist - And cleanup built test app + Given a built app at "test-app" + Then "fake.html" should exist at "test-app" and include "I am real" + Then "fake/one.html" should exist at "test-app" and include "I am real: one" + Then "fake/two.html" should exist at "test-app" and include "I am real: two" + Then "target_ignore.html" should exist at "test-app" and include "Ignore me" + Then "should_be_ignored.html" should not exist at "test-app" + Then "should_be_ignored2.html" should not exist at "test-app" + Then "should_be_ignored3.html" should not exist at "test-app" + And cleanup built app at "test-app" Scenario: Preview basic proxy - Given the Server is running + Given the Server is running at "test-app" When I go to "/fake.html" Then I should see "I am real" Scenario: Preview proxy with variable one - Given the Server is running + Given the Server is running at "test-app" When I go to "/fake/one.html" Then I should see "I am real: one" Scenario: Preview proxy with variable two - Given the Server is running + Given the Server is running at "test-app" When I go to "/fake/two.html" - Then I should see "I am real: two" \ No newline at end of file + Then I should see "I am real: two" + + Scenario: Preview ignored paths + Given the Server is running at "test-app" + When I go to "/should_be_ignored.html" + Then I should see "File Not Found" \ No newline at end of file diff --git a/features/front-matter.feature b/features/front-matter.feature index e2c58286..c8c87bd0 100644 --- a/features/front-matter.feature +++ b/features/front-matter.feature @@ -2,6 +2,6 @@ Feature: YAML Front Matter In order to specific options and data inline Scenario: Rendering html - Given the Server is running + Given the Server is running at "test-app" When I go to "/front-matter.html" Then I should see "

This is the title

" \ No newline at end of file diff --git a/features/helpers_auto_javascript_include_tag.feature b/features/helpers_auto_javascript_include_tag.feature index 193f074d..2d9b7f0e 100644 --- a/features/helpers_auto_javascript_include_tag.feature +++ b/features/helpers_auto_javascript_include_tag.feature @@ -2,26 +2,26 @@ Feature: Built-in auto_javascript_include_tag view helper In order to simplify including javascript files Scenario: Viewing the root path - Given the Server is running + Given the Server is running at "test-app" When I go to "/auto-js.html" Then I should see "javascripts/auto-js.js" Scenario: Viewing a tier-1 path - Given the Server is running + Given the Server is running at "test-app" When I go to "/auto-js/auto-js.html" Then I should see "javascripts/auto-js/auto-js.js" Scenario: Viewing the index file of a tier-1 path, without filename - Given the Server is running + Given the Server is running at "test-app" When I go to "/auto-js" Then I should see "javascripts/auto-js/index.js" Scenario: Viewing the index file of a tier-1 path, without filename, with a trailing slash - Given the Server is running + Given the Server is running at "test-app" When I go to "/auto-js/" Then I should see "javascripts/auto-js/index.js" Scenario: Viewing a tier-2 path - Given the Server is running + Given the Server is running at "test-app" When I go to "/auto-js/sub/auto-js.html" Then I should see "javascripts/auto-js/sub/auto-js.js" diff --git a/features/helpers_auto_stylesheet_link_tag.feature b/features/helpers_auto_stylesheet_link_tag.feature index e4ef140b..c6d64973 100644 --- a/features/helpers_auto_stylesheet_link_tag.feature +++ b/features/helpers_auto_stylesheet_link_tag.feature @@ -2,26 +2,26 @@ Feature: Built-in auto_stylesheet_link_tag view helper In order to simplify including css files Scenario: Viewing the root path - Given the Server is running + Given the Server is running at "test-app" When I go to "/auto-css.html" Then I should see "stylesheets/auto-css.css" Scenario: Viewing a tier-1 path - Given the Server is running + Given the Server is running at "test-app" When I go to "/auto-css/auto-css.html" Then I should see "stylesheets/auto-css/auto-css.css" Scenario: Viewing the index file of a tier-1 path, without filename - Given the Server is running + Given the Server is running at "test-app" When I go to "/auto-css" Then I should see "stylesheets/auto-css/index.css" Scenario: Viewing the index file of a tier-1 path, without filename, with a trailing slash - Given the Server is running + Given the Server is running at "test-app" When I go to "/auto-css/" Then I should see "stylesheets/auto-css/index.css" Scenario: Viewing a tier-2 path - Given the Server is running + Given the Server is running at "test-app" When I go to "/auto-css/sub/auto-css.html" Then I should see "stylesheets/auto-css/sub/auto-css.css" diff --git a/features/helpers_page_classes.feature b/features/helpers_page_classes.feature index 38c67759..c2c874f9 100644 --- a/features/helpers_page_classes.feature +++ b/features/helpers_page_classes.feature @@ -2,16 +2,16 @@ Feature: Built-in page_classes view helper In order to generate body classes for views Scenario: Viewing the root path - Given the Server is running + Given the Server is running at "test-app" When I go to "/page-classes.html" Then I should see "page-classes" Scenario: Viewing a tier-1 path - Given the Server is running + Given the Server is running at "test-app" When I go to "/sub1/page-classes.html" Then I should see "sub1 sub1_page-classes" Scenario: Viewing a tier-2 path - Given the Server is running + Given the Server is running at "test-app" When I go to "/sub1/sub2/page-classes.html" Then I should see "sub1 sub1_sub2 sub1_sub2_page-classes" \ No newline at end of file diff --git a/features/minify_css.feature b/features/minify_css.feature index 60028d1d..67922cb0 100644 --- a/features/minify_css.feature +++ b/features/minify_css.feature @@ -8,7 +8,7 @@ Feature: Minify CSS Scenario: Rendering external css with the feature disabled Given "minify_css" feature is "disabled" - And the Server is running + And the Server is running at "test-app" When I go to "/stylesheets/site.css" Then I should see "55" lines @@ -19,6 +19,6 @@ Feature: Minify CSS Scenario: Rendering external css with the feature enabled Given "minify_css" feature is "enabled" - And the Server is running + And the Server is running at "test-app" When I go to "/stylesheets/site.css" Then I should see "1" lines \ No newline at end of file diff --git a/features/minify_javascript.feature b/features/minify_javascript.feature index 0c0c5bd0..596f4066 100644 --- a/features/minify_javascript.feature +++ b/features/minify_javascript.feature @@ -6,18 +6,18 @@ Feature: Minify Javascript Scenario: Rendering inline js with the feature disabled Given "minify_javascript" feature is "disabled" - And the Server is running + And the Server is running at "test-app" When I go to "/inline-js.html" Then I should see "10" lines Scenario: Rendering inline js with the feature enabled Given "minify_javascript" feature is "enabled" - And the Server is running + And the Server is running at "test-app" When I go to "/inline-js.html" Then I should see "5" lines Scenario: Rendering inline js (coffeescript) with the feature enabled Given "minify_javascript" feature is "enabled" - And the Server is running + And the Server is running at "test-app" When I go to "/inline-coffeescript.html" Then I should see "5" lines \ No newline at end of file diff --git a/features/padrino_helpers.feature b/features/padrino_helpers.feature index a8dd3021..c354f2b1 100644 --- a/features/padrino_helpers.feature +++ b/features/padrino_helpers.feature @@ -2,7 +2,7 @@ Feature: Built-in macro view helpers In order to simplify generating HTML Scenario: Using the link_to helper - Given the Server is running + Given the Server is running at "test-app" When I go to "/padrino_test.html" And I should see 'href="test2.com"' And I should see 'src="/images/test2.png"' diff --git a/features/page_alias_and_layouts.feature b/features/page_alias_and_layouts.feature index 1d0be362..b3ff6fb7 100644 --- a/features/page_alias_and_layouts.feature +++ b/features/page_alias_and_layouts.feature @@ -3,19 +3,19 @@ Feature: Custom layouts Scenario: Using custom :layout attribute Given page "/custom-layout.html" has layout "custom" - And the Server is running + And the Server is running at "test-app" When I go to "/custom-layout.html" Then I should see "Custom Layout" Scenario: Using with_layout block Given "/custom-layout.html" with_layout block has layout "custom" - And the Server is running + And the Server is running at "test-app" When I go to "/custom-layout.html" Then I should see "Custom Layout" Scenario: Using custom :layout attribute with folders Given page "/custom-layout-dir/" has layout "custom" - And the Server is running + And the Server is running at "test-app" When I go to "/custom-layout-dir" Then I should see "Custom Layout" When I go to "/custom-layout-dir/" @@ -25,7 +25,7 @@ Feature: Custom layouts Scenario: Using custom :layout attribute with folders Given page "/custom-layout-dir" has layout "custom" - And the Server is running + And the Server is running at "test-app" When I go to "/custom-layout-dir" Then I should see "Custom Layout" When I go to "/custom-layout-dir/" @@ -35,7 +35,7 @@ Feature: Custom layouts Scenario: Using custom :layout attribute with folders Given page "/custom-layout-dir/index.html" has layout "custom" - And the Server is running + And the Server is running at "test-app" When I go to "/custom-layout-dir" Then I should see "Custom Layout" When I go to "/custom-layout-dir/" diff --git a/features/relative_assets.feature b/features/relative_assets.feature index 5902ac2d..62334f26 100644 --- a/features/relative_assets.feature +++ b/features/relative_assets.feature @@ -3,26 +3,26 @@ Feature: Relative Assets Scenario: Rendering css with the feature disabled Given "relative_assets" feature is "disabled" - And the Server is running + And the Server is running at "test-app" When I go to "/stylesheets/relative_assets.css" Then I should not see "url('../" And I should see "/images/blank.gif" Scenario: Rendering html with the feature disabled Given "relative_assets" feature is "disabled" - And the Server is running + And the Server is running at "test-app" When I go to "/relative_image.html" Then I should see "/images/blank.gif" Scenario: Rendering css with the feature enabled Given "relative_assets" feature is "enabled" - And the Server is running + And the Server is running at "test-app" When I go to "/stylesheets/relative_assets.css" Then I should see "url('../images/blank.gif" Scenario: Rendering html with the feature disabled Given "relative_assets" feature is "enabled" - And the Server is running + And the Server is running at "test-app" When I go to "/relative_image.html" Then I should not see "/images/blank.gif" And I should see "images/blank.gif" @@ -30,14 +30,14 @@ Feature: Relative Assets Scenario: Rendering html with a custom images_dir Given "relative_assets" feature is "enabled" And "images_dir" is set to "img" - And the Server is running + And the Server is running at "test-app" When I go to "/stylesheets/relative_assets.css" Then I should see "url('../img/blank.gif" Scenario: Rendering css with a custom images_dir Given "relative_assets" feature is "enabled" And "images_dir" is set to "img" - And the Server is running + And the Server is running at "test-app" When I go to "/relative_image.html" Then I should not see "/images/blank.gif" Then I should not see "/img/blank.gif" diff --git a/features/scss-support.feature b/features/scss-support.feature index a8f0fb2c..44513c35 100644 --- a/features/scss-support.feature +++ b/features/scss-support.feature @@ -2,11 +2,11 @@ Feature: Support SCSS Syntax In order to offer an alternative when writing Sass Scenario: Rendering scss - Given the Server is running + Given the Server is running at "test-app" When I go to "/stylesheets/site_scss.css" Then I should see "html" Scenario: Rendering scss - Given the Server is running + Given the Server is running at "test-app" When I go to "/stylesheets/layout.css" Then I should see "html" \ No newline at end of file diff --git a/features/sinatra.feature b/features/sinatra.feature index 98bd30ef..651a7fcd 100644 --- a/features/sinatra.feature +++ b/features/sinatra.feature @@ -1,6 +1,6 @@ Feature: Sinatra Routes Scenario: Rendering html - Given the Server is running + Given the Server is running at "test-app" When I go to "/sinatra_test" Then I should see "Ratpack" \ No newline at end of file diff --git a/features/slim.feature b/features/slim.feature index e3d2975d..436050eb 100644 --- a/features/slim.feature +++ b/features/slim.feature @@ -2,6 +2,6 @@ Feature: Support slim templating language In order to offer an alternative to Haml Scenario: Rendering Slim - Given the Server is running + Given the Server is running at "test-app" When I go to "/slim.html" Then I should see "

Welcome to Slim

" \ No newline at end of file diff --git a/features/sprockets.feature b/features/sprockets.feature index cf9bafb0..69cbfe63 100644 --- a/features/sprockets.feature +++ b/features/sprockets.feature @@ -1,6 +1,6 @@ Feature: Sprockets Scenario: Sprockets require - Given the Server is running + Given the Server is running at "test-app" When I go to "/javascripts/sprockets_base.js" Then I should see "sprockets_sub_function" \ No newline at end of file diff --git a/features/step_definitions/builder_steps.rb b/features/step_definitions/builder_steps.rb index 541d121c..893fbc3e 100644 --- a/features/step_definitions/builder_steps.rb +++ b/features/step_definitions/builder_steps.rb @@ -1,35 +1,39 @@ require 'fileutils' -require 'middleman/cli' -Given /^a built test app$/ do - target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app") - build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "middleman build")) +Given /^a built app at "([^"]*)"$/ do |path| + root = File.dirname(File.dirname(File.dirname(__FILE__))) + target = File.join(root, "fixtures", path) + build_cmd = File.expand_path(File.join(root, "bin", "middleman build")) `cd #{target} && #{build_cmd}` end +Then /^cleanup built app at "([^"]*)"$/ do |path| + root = File.dirname(File.dirname(File.dirname(__FILE__))) + target = File.join(root, "fixtures", path, "build") + FileUtils.rm_rf(target) +end + Given /^a built test app with flags "([^"]*)"$/ do |flags| target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app") build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "middleman build")) `cd #{target} && #{build_cmd} #{flags}` end -Given /^cleanup built test app$/ do - target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app", "build") - FileUtils.rm_rf(target) -end - -Then /^"([^"]*)" should exist$/ do |target_file,| - target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app", "build", target_file) +Then /^"([^"]*)" should exist at "([^"]*)"$/ do |target_file, path| + root = File.dirname(File.dirname(File.dirname(__FILE__))) + target = File.join(root, "fixtures", path, "build", target_file) File.exists?(target).should be_true end -Then /^"([^"]*)" should exist and include "([^"]*)"$/ do |target_file, expected| - target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app", "build", target_file) +Then /^"([^"]*)" should exist at "([^"]*)" and include "([^"]*)"$/ do |target_file, path, expected| + root = File.dirname(File.dirname(File.dirname(__FILE__))) + target = File.join(root, "fixtures", path, "build", target_file) File.exists?(target).should be_true File.read(target).should include(expected) end -Then /^"([^"]*)" should not exist$/ do |target_file| - target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app", "build", target_file) +Then /^"([^"]*)" should not exist at "([^"]*)"$/ do |target_file, path| + root = File.dirname(File.dirname(File.dirname(__FILE__))) + target = File.join(root, "fixtures", path, "build", target_file) File.exists?(target).should be_false end \ No newline at end of file diff --git a/features/step_definitions/middleman_steps.rb b/features/step_definitions/middleman_steps.rb index fc8bc5e0..b8fe0f94 100644 --- a/features/step_definitions/middleman_steps.rb +++ b/features/step_definitions/middleman_steps.rb @@ -15,9 +15,10 @@ Given /^current environment is "([^\"]*)"$/ do |env| @current_env = env.to_sym end -Given /^the Server is running$/ do +Given /^the Server is running at "([^\"]*)"$/ do |app_path| @server ||= Middleman.server - @server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app") + root = File.dirname(File.dirname(File.dirname(__FILE__))) + @server.set :root, File.join(root, "fixtures", app_path) @browser = Rack::Test::Session.new(Rack::MockSession.new(@server.new)) end diff --git a/features/tiny_src.feature b/features/tiny_src.feature index 117f824b..01ee0bd6 100644 --- a/features/tiny_src.feature +++ b/features/tiny_src.feature @@ -4,12 +4,12 @@ Feature: Tiny Src Scenario: Rendering html with the feature disabled Given "tiny_src" feature is "disabled" - And the Server is running + And the Server is running at "test-app" When I go to "/tiny_src.html" Then I should see "http://test.com/image.jpg" Scenario: Rendering html with the feature enabled Given "tiny_src" feature is "enabled" - And the Server is running + And the Server is running at "test-app" When I go to "/tiny_src.html" Then I should see "http://i.tinysrc.mobi/http://test.com/image.jpg" \ No newline at end of file diff --git a/fixtures/indexable-app/# b/fixtures/indexable-app/# new file mode 100644 index 00000000..1eeec11b --- /dev/null +++ b/fixtures/indexable-app/# @@ -0,0 +1 @@ +Indexable \ No newline at end of file diff --git a/fixtures/indexable-app/config.rb b/fixtures/indexable-app/config.rb new file mode 100644 index 00000000..d770e11f --- /dev/null +++ b/fixtures/indexable-app/config.rb @@ -0,0 +1,2 @@ +activate :directory_indexes +page "/leave_me_alone.html", :directory_index => false \ No newline at end of file diff --git a/fixtures/indexable-app/source/a_folder/needs_index.html b/fixtures/indexable-app/source/a_folder/needs_index.html new file mode 100644 index 00000000..1eeec11b --- /dev/null +++ b/fixtures/indexable-app/source/a_folder/needs_index.html @@ -0,0 +1 @@ +Indexable \ No newline at end of file diff --git a/fixtures/indexable-app/source/leave_me_alone.html b/fixtures/indexable-app/source/leave_me_alone.html new file mode 100644 index 00000000..163cebf8 --- /dev/null +++ b/fixtures/indexable-app/source/leave_me_alone.html @@ -0,0 +1 @@ +Stay away \ No newline at end of file diff --git a/fixtures/indexable-app/source/needs_index.html b/fixtures/indexable-app/source/needs_index.html new file mode 100644 index 00000000..1eeec11b --- /dev/null +++ b/fixtures/indexable-app/source/needs_index.html @@ -0,0 +1 @@ +Indexable \ No newline at end of file diff --git a/fixtures/test-app/source/a_folder/needs_index.html b/fixtures/test-app/source/a_folder/needs_index.html new file mode 100644 index 00000000..1eeec11b --- /dev/null +++ b/fixtures/test-app/source/a_folder/needs_index.html @@ -0,0 +1 @@ +Indexable \ No newline at end of file diff --git a/fixtures/test-app/source/needs_index.html b/fixtures/test-app/source/needs_index.html new file mode 100644 index 00000000..1eeec11b --- /dev/null +++ b/fixtures/test-app/source/needs_index.html @@ -0,0 +1 @@ +Indexable \ No newline at end of file diff --git a/lib/middleman.rb b/lib/middleman.rb index a17142a8..5018ccb7 100755 --- a/lib/middleman.rb +++ b/lib/middleman.rb @@ -149,6 +149,9 @@ module Middleman # Automatically resize images for mobile devises # autoload :TinySrc, "middleman/features/tiny_src" + + # Automatically convert filename.html files into filename/index.html + autoload :DirectoryIndexes, "middleman/features/directory_indexes" end def self.server(&block) diff --git a/lib/middleman/base.rb b/lib/middleman/base.rb index 68d5926e..ce723ead 100644 --- a/lib/middleman/base.rb +++ b/lib/middleman/base.rb @@ -86,7 +86,9 @@ module Middleman::Base request_path = request.path_info.gsub("%20", " ") result = resolve_template(request_path, :raise_exceptions => false) - if result + should_be_ignored = !(request["is_proxy"]) && settings.excluded_paths.include?("/#{request_path}") + + if result && !should_be_ignored extensionless_path, template_engine = result # Return static files @@ -119,6 +121,27 @@ module Middleman::Base super(option, value, &nil) end + def build_reroute(&block) + @build_rerouters ||= [] + @build_rerouters << block + end + + def reroute_builder(desination, request_path) + @build_rerouters ||= [] + + result = [desination, request_path] + + @build_rerouters.each do |block| + output = block.call(desination, request_path) + if output + result = output + break + end + end + + result + end + def before_processing(&block) @before_processes ||= [] @before_processes << block diff --git a/lib/middleman/builder.rb b/lib/middleman/builder.rb index 28224273..e30bbb10 100644 --- a/lib/middleman/builder.rb +++ b/lib/middleman/builder.rb @@ -15,11 +15,15 @@ module Middleman context = instance_eval('binding') request_path = destination.sub(/^#{SHARED_SERVER.build_dir}/, "") - return if SHARED_SERVER.excluded_paths.include?(request_path) - create_file destination, nil, config do - Middleman::Builder.shared_rack.get(request_path.gsub(/\s/, "%20")) - Middleman::Builder.shared_rack.last_response.body + begin + destination, request_page = SHARED_SERVER.reroute_builder(destination, request_path) + + create_file destination, nil, config do + Middleman::Builder.shared_rack.get(request_path.gsub(/\s/, "%20")) + Middleman::Builder.shared_rack.last_response.body + end + rescue end end end diff --git a/lib/middleman/core_extensions/routing.rb b/lib/middleman/core_extensions/routing.rb index 03253306..d22b9be7 100644 --- a/lib/middleman/core_extensions/routing.rb +++ b/lib/middleman/core_extensions/routing.rb @@ -6,6 +6,10 @@ module Middleman::CoreExtensions::Routing app.set :proxied_paths, {} app.set :excluded_paths, [] + app.build_reroute do |destination, request_path| + throw if app.settings.excluded_paths.include?(request_path) + end + # Normalize the path and add index if we're looking at a directory app.before_processing do request.path_info = self.class.path_to_index(request.path) @@ -39,7 +43,7 @@ module Middleman::CoreExtensions::Routing end def paths_for_url(url) - url = url.gsub(%r{#{settings.index_file}$}, "") + url = url.gsub(%r{\/#{settings.index_file}$}, "") url = url.gsub(%r{(\/)$}, "") if url.length > 1 paths = [url] @@ -76,6 +80,7 @@ module Middleman::CoreExtensions::Routing paths_for_url(url).each do |p| get(p) do if settings.proxied_paths.has_key?(url) + request["is_proxy"] = true request.path_info = settings.proxied_paths[url] end diff --git a/lib/middleman/features/blog.rb b/lib/middleman/features/blog.rb index a2d6356b..9a456a73 100644 --- a/lib/middleman/features/blog.rb +++ b/lib/middleman/features/blog.rb @@ -46,7 +46,6 @@ module Middleman end app.get("/#{app.blog_permalink}") do - $stderr.puts "*" * 500 process_request({ :layout => app.blog_layout, :layout_engine => app.blog_layout_engine diff --git a/lib/middleman/features/directory_indexes.rb b/lib/middleman/features/directory_indexes.rb new file mode 100644 index 00000000..8be607c5 --- /dev/null +++ b/lib/middleman/features/directory_indexes.rb @@ -0,0 +1,47 @@ +module Middleman::Features::DirectoryIndexes + class << self + def registered(app) + app.set :ignored_directory_indexes, [] + app.extend ClassMethods + + app.build_reroute do |destination, request_path| + indexed_path = request_path.gsub(/\/$/, "") + ".html" + + if app.settings.ignored_directory_indexes.include?(request_path) + false + else + [ + destination.gsub(/\.html$/, "/index.html"), + request_path.gsub(/\.html$/, "/index.html") + ] + end + end + + app.before do + indexed_path = request.path_info.gsub(/\/$/, "") + ".html" + + if !settings.ignored_directory_indexes.include?(indexed_path) + parts = request.path_info.split("/") + last_part = parts.last + last_part_ext = File.extname(last_part) + + if last_part_ext.blank? + # This is a folder, redirect to index + request.path_info = indexed_path + end + end + end + end + alias :included :registered + end + + module ClassMethods + def page(url, options={}, &block) + if options.has_key?(:directory_index) && !options["directory_index"] + settings.ignored_directory_indexes << url + else + super + end + end + end +end \ No newline at end of file