Merge pull request #1498 from stevenosloan/allow_setting_destination_directory_for_source_watchers

allow setting a destination_dir for SourceWatcher(s)
This commit is contained in:
Thomas Reynolds 2015-04-17 15:03:29 -07:00
commit 40e01b0b21
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 "Data 2: Data 2"
Then I should see "Override in Two: Overridden 2" Then I should see "Override in Two: Overridden 2"
Then I should see "Override in One: Opposite 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) def path_to_source_file(path)
types = Set.new([@type]) types = Set.new([@type])
::Middleman::SourceFile.new( relative_path = path.relative_path_from(@directory)
path.relative_path_from(@directory), path, @directory, types) 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 end
# Notify callbacks for a file given an array of callbacks # Notify callbacks for a file given an array of callbacks