Skip to content

Commit

Permalink
:automatic_directory_matcher optionally converts a character sequence…
Browse files Browse the repository at this point in the history
… in file names into a subdirectory. Closes #491
  • Loading branch information
tdreyno committed Jun 20, 2012
1 parent ddc0712 commit c3796a9
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Master
===
* automatic_directory_matcher (#491)

3.0.0.rc.2
====
* Doing a build now shows identical files (#475)
Expand Down
32 changes: 32 additions & 0 deletions middleman-core/features/automatic_directory_matcher.feature
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set :automatic_directory_matcher, "--"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Root Plain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Root Erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sub2 Plain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sub2 Erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sub1 Plain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sub1 Erb
3 changes: 3 additions & 0 deletions middleman-core/lib/middleman-core/sitemap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions middleman-core/lib/middleman-core/sitemap/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

2 comments on commit c3796a9

@bhollis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@tdreyno
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.