diff --git a/features/config.feature b/features/config.feature
index 4e9f66a..e5b6cf2 100644
--- a/features/config.feature
+++ b/features/config.feature
@@ -20,3 +20,24 @@ Feature: Config
When I compile my site
Then my compiled site should have the file "index.html"
And this file should contain the content node "span|http://hello-world.com"
+
+ Scenario: Compass config.rb files should not be parsed when loading configs
+ Given some files with values:
+ | file | body |
+ | config.yml | production_url: 'http://hello-world.com' |
+ | config.rb | this is not YML data |
+ | _root/index.html | {{ urls.production_url }} |
+ When I compile my site
+ Then my compiled site should have the file "index.html"
+ And this file should contain the content node "span|http://hello-world.com"
+
+ Scenario: Config files are properly loaded from subdirectories
+ Given some files with values:
+ | file | body |
+ | config.rb | this is not YML data |
+ | template/config.yml | production_url: 'http://hello-world.com' |
+ | template/config.rb | this is not YML data |
+ | _root/index.html | {{ urls.production_url }} |
+ When I compile my site
+ Then my compiled site should have the file "index.html"
+ And this file should contain the content node "span|http://hello-world.com"
diff --git a/features/support/helpers.rb b/features/support/helpers.rb
index 2e5050d..b8a4642 100644
--- a/features/support/helpers.rb
+++ b/features/support/helpers.rb
@@ -75,4 +75,4 @@ def this_compiled_file
After do
FileUtils.remove_dir(SampleSitePath,1) if Dir.exists? SampleSitePath
-end
\ No newline at end of file
+end
diff --git a/lib/ruhoh/cascade.rb b/lib/ruhoh/cascade.rb
index be64174..07e45b5 100644
--- a/lib/ruhoh/cascade.rb
+++ b/lib/ruhoh/cascade.rb
@@ -19,14 +19,14 @@ def find_file(key)
def merge_data_file(key)
realpaths = []
paths.map{ |a| a['path'] }.each do |path|
- FileUtils.cd(path) {
- match = Dir["*"].find { |id|
+ FileUtils.cd(path) {
+ Dir["*"].find_all { |id|
File.exist?(id) &&
FileTest.file?(id) &&
id.gsub(/.[^.]+$/, '') == key
+ }.each { |match|
+ realpaths << File.realpath(match)
}
- next unless match
- realpaths << File.realpath(match)
}
end
diff --git a/lib/ruhoh/config.rb b/lib/ruhoh/config.rb
index aa347c7..6822a13 100644
--- a/lib/ruhoh/config.rb
+++ b/lib/ruhoh/config.rb
@@ -54,7 +54,7 @@ def collections_config
data = {}
@ruhoh.cascade.paths.map{ |a| a['path'] }.each do |path|
FileUtils.cd(path) {
- Dir["*/config.*"].each { |id|
+ Dir["*/config.{yml,yaml,json}"].each { |id|
next unless File.exist?(id) && FileTest.file?(id)
data = Ruhoh::Utils.deep_merge(data, (Ruhoh::Parse.data_file(File.realpath(id)) || {}))
}
diff --git a/lib/ruhoh/parse.rb b/lib/ruhoh/parse.rb
index 9598a82..6c0bd54 100644
--- a/lib/ruhoh/parse.rb
+++ b/lib/ruhoh/parse.rb
@@ -48,13 +48,21 @@ def self.data_file(*args)
["#{ filepath }.json", "#{ filepath }.yml", "#{ filepath }.yaml"].each do |result|
filepath = path = result and break if File.exist?(result)
end
-
return nil unless path
end
file = File.open(filepath, 'r:UTF-8') { |f| f.read }
- File.extname(filepath) == ".json" ? json(file) : yaml(file)
+ case File.extname(filepath)
+ when ".json"
+ json(file)
+ when ".yml"
+ yaml(file)
+ when ".yaml"
+ yaml(file)
+ else
+ {}
+ end
end
def self.yaml(file)
@@ -84,4 +92,4 @@ def self.json_for_pages(front_matter, filepath)
JSON.load(front_matter[0]) || {}
end
end
-end
\ No newline at end of file
+end