allow setting a destination_dir for SourceWatchers

This change lets a source be defined with a destination directory. That way we can mount a source (say a gem’s ‘doc’ directory) in a namespace and worry less about name collisions with  files in other sources.
This commit is contained in:
Steven Sloan 2015-04-17 13:28:23 -04:00
parent f61e08a9c3
commit 3b1a00cf47
5 changed files with 17 additions and 2 deletions

View file

@ -25,3 +25,11 @@ Feature: Allow multiple sources to be setup.
Then I should see "Data 2: Data 2"
Then I should see "Override in Two: Overridden 2"
Then I should see "Override in One: Opposite 2"
Scenario: Set source with destination_dir
Given the Server is running at "multiple-sources-with-duplicate-file-names-app"
When I go to "/index.html"
Then I should see "Default Source"
When I go to "/source2/index.html"
Then I should see "Second Source"

View file

@ -0,0 +1,2 @@
files.watch :source, path: File.join(root, 'source2'),
destination_dir: 'source2'

View file

@ -279,8 +279,11 @@ module Middleman
def path_to_source_file(path)
types = Set.new([@type])
::Middleman::SourceFile.new(
path.relative_path_from(@directory), path, @directory, types)
relative_path = path.relative_path_from(@directory)
destination_dir = @options.fetch(:destination_dir, false)
relative_path = File.join(destination_dir, relative_path) if destination_dir
::Middleman::SourceFile.new(Pathname(relative_path), path, @directory, types)
end
# Notify callbacks for a file given an array of callbacks