From c3796a91615f8ae68652205b242db7285391a059 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Tue, 19 Jun 2012 20:07:50 -0700 Subject: [PATCH] :automatic_directory_matcher optionally converts a character sequence in file names into a subdirectory. Closes #491 --- CHANGELOG.md | 4 +++ .../automatic_directory_matcher.feature | 32 +++++++++++++++++++ .../automatic-directory-matcher-app/config.rb | 1 + .../source/root-plain.html | 1 + .../source/root.html.erb | 1 + .../source/sub--sub--sub-plain.html | 1 + .../source/sub--sub--sub.html.erb | 1 + .../source/sub--sub-plain.html | 1 + .../source/sub--sub.html.erb | 1 + middleman-core/lib/middleman-core/sitemap.rb | 3 ++ .../lib/middleman-core/sitemap/store.rb | 6 ++++ 11 files changed, 52 insertions(+) create mode 100644 middleman-core/features/automatic_directory_matcher.feature create mode 100644 middleman-core/fixtures/automatic-directory-matcher-app/config.rb create mode 100644 middleman-core/fixtures/automatic-directory-matcher-app/source/root-plain.html create mode 100644 middleman-core/fixtures/automatic-directory-matcher-app/source/root.html.erb create mode 100644 middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub--sub-plain.html create mode 100644 middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub--sub.html.erb create mode 100644 middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub-plain.html create mode 100644 middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub.html.erb diff --git a/CHANGELOG.md b/CHANGELOG.md index 8eff989c..f39c5c91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +Master +=== +* automatic_directory_matcher (#491) + 3.0.0.rc.2 ==== * Doing a build now shows identical files (#475) diff --git a/middleman-core/features/automatic_directory_matcher.feature b/middleman-core/features/automatic_directory_matcher.feature new file mode 100644 index 00000000..7236c8a9 --- /dev/null +++ b/middleman-core/features/automatic_directory_matcher.feature @@ -0,0 +1,32 @@ +Feature: Map special characters to automatically put files in a directory + + Scenario: Building files with special character escape + Given a successfully built app at "automatic-directory-matcher-app" + When I cd to "build" + Then the following files should exist: + | root.html | + | root-plain.html | + | sub/sub.html | + | sub/sub-plain.html | + | sub/sub/sub.html | + | sub/sub/sub-plain.html | + Then the following files should not exist: + | sub--sub.html | + | sub--sub-plain.html | + | sub--sub--sub.html | + | sub--sub--sub-plain.html | + + Scenario: Previewing files with special character escape + Given the Server is running at "automatic-directory-matcher-app" + When I go to "/root.html" + Then I should see "Root Erb" + When I go to "/root-plain.html" + Then I should see "Root Plain" + When I go to "/sub/sub.html" + Then I should see "Sub1 Erb" + When I go to "/sub/sub-plain.html" + Then I should see "Sub1 Plain" + When I go to "/sub/sub/sub.html" + Then I should see "Sub2 Erb" + When I go to "/sub/sub/sub-plain.html" + Then I should see "Sub2 Plain" \ No newline at end of file diff --git a/middleman-core/fixtures/automatic-directory-matcher-app/config.rb b/middleman-core/fixtures/automatic-directory-matcher-app/config.rb new file mode 100644 index 00000000..25640d3e --- /dev/null +++ b/middleman-core/fixtures/automatic-directory-matcher-app/config.rb @@ -0,0 +1 @@ +set :automatic_directory_matcher, "--" \ No newline at end of file diff --git a/middleman-core/fixtures/automatic-directory-matcher-app/source/root-plain.html b/middleman-core/fixtures/automatic-directory-matcher-app/source/root-plain.html new file mode 100644 index 00000000..12807402 --- /dev/null +++ b/middleman-core/fixtures/automatic-directory-matcher-app/source/root-plain.html @@ -0,0 +1 @@ +Root Plain \ No newline at end of file diff --git a/middleman-core/fixtures/automatic-directory-matcher-app/source/root.html.erb b/middleman-core/fixtures/automatic-directory-matcher-app/source/root.html.erb new file mode 100644 index 00000000..12ecf7e8 --- /dev/null +++ b/middleman-core/fixtures/automatic-directory-matcher-app/source/root.html.erb @@ -0,0 +1 @@ +Root Erb \ No newline at end of file diff --git a/middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub--sub-plain.html b/middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub--sub-plain.html new file mode 100644 index 00000000..0c335441 --- /dev/null +++ b/middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub--sub-plain.html @@ -0,0 +1 @@ +Sub2 Plain \ No newline at end of file diff --git a/middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub--sub.html.erb b/middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub--sub.html.erb new file mode 100644 index 00000000..997645de --- /dev/null +++ b/middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub--sub.html.erb @@ -0,0 +1 @@ +Sub2 Erb \ No newline at end of file diff --git a/middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub-plain.html b/middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub-plain.html new file mode 100644 index 00000000..3ad25301 --- /dev/null +++ b/middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub-plain.html @@ -0,0 +1 @@ +Sub1 Plain \ No newline at end of file diff --git a/middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub.html.erb b/middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub.html.erb new file mode 100644 index 00000000..757b10d3 --- /dev/null +++ b/middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub.html.erb @@ -0,0 +1 @@ +Sub1 Erb \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/sitemap.rb b/middleman-core/lib/middleman-core/sitemap.rb index c69e3b6a..24a1c366 100644 --- a/middleman-core/lib/middleman-core/sitemap.rb +++ b/middleman-core/lib/middleman-core/sitemap.rb @@ -19,6 +19,9 @@ module Middleman app.register Middleman::Sitemap::Extensions::Proxies app.register Middleman::Sitemap::Extensions::Ignores + # Set to automatically convert some characters into a directory + app.set :automatic_directory_matcher, nil + # Setup callbacks which can exclude paths from the sitemap app.set :ignored_sitemap_matchers, { # dotfiles and folders in the root diff --git a/middleman-core/lib/middleman-core/sitemap/store.rb b/middleman-core/lib/middleman-core/sitemap/store.rb index 5e425927..a72f9512 100644 --- a/middleman-core/lib/middleman-core/sitemap/store.rb +++ b/middleman-core/lib/middleman-core/sitemap/store.rb @@ -174,6 +174,12 @@ module Middleman return false unless file.include?(prefix) path = file.sub(prefix, "") + + # Replace a file name containing automatic_directory_matcher with a folder + unless @app.automatic_directory_matcher.nil? + path = path.gsub(@app.automatic_directory_matcher, "/") + end + extensionless_path(path) end