:automatic_directory_matcher optionally converts a character sequence in file names into a subdirectory. Closes #491

This commit is contained in:
Thomas Reynolds 2012-06-19 20:07:50 -07:00
parent ddc0712c1b
commit c3796a9161
11 changed files with 52 additions and 0 deletions

View file

@ -1,3 +1,7 @@
Master
===
* automatic_directory_matcher (#491)
3.0.0.rc.2
====
* Doing a build now shows identical files (#475)

View file

@ -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"

View file

@ -0,0 +1 @@
set :automatic_directory_matcher, "--"

View file

@ -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

View file

@ -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