Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

:automatic_directory_matcher optionally converts a character sequence…

… in file names into a subdirectory. Closes #491
  • Loading branch information...
commit c3796a91615f8ae68652205b242db7285391a059 1 parent ddc0712
@tdreyno tdreyno authored
View
4 CHANGELOG.md
@@ -1,3 +1,7 @@
+Master
+===
+* automatic_directory_matcher (#491)
+
3.0.0.rc.2
====
* Doing a build now shows identical files (#475)
View
32 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"
View
1  middleman-core/fixtures/automatic-directory-matcher-app/config.rb
@@ -0,0 +1 @@
+set :automatic_directory_matcher, "--"
View
1  middleman-core/fixtures/automatic-directory-matcher-app/source/root-plain.html
@@ -0,0 +1 @@
+Root Plain
View
1  middleman-core/fixtures/automatic-directory-matcher-app/source/root.html.erb
@@ -0,0 +1 @@
+Root Erb
View
1  middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub--sub-plain.html
@@ -0,0 +1 @@
+Sub2 Plain
View
1  middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub--sub.html.erb
@@ -0,0 +1 @@
+Sub2 Erb
View
1  middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub-plain.html
@@ -0,0 +1 @@
+Sub1 Plain
View
1  middleman-core/fixtures/automatic-directory-matcher-app/source/sub--sub.html.erb
@@ -0,0 +1 @@
+Sub1 Erb
View
3  middleman-core/lib/middleman-core/sitemap.rb
@@ -19,6 +19,9 @@ def registered(app)
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
6 middleman-core/lib/middleman-core/sitemap/store.rb
@@ -174,6 +174,12 @@ def file_to_path(file)
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

2 comments on commit c3796a9

@bhollis
Owner

This is pretty cool, but wouldn't it be more consistent to implement this as a Sitemap plugin?

@tdreyno
Owner

Not sure, it only effects when we load files off disk so it should probably be part of OnDisk

Please sign in to comment.
Something went wrong with that request. Please try again.