From e4abfa4668855f9741ac854b4d73a9eb8b0e850e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zsolt=20Sz=2E=20Sztup=C3=A1k?= Date: Sun, 2 Mar 2014 14:12:09 +0000 Subject: [PATCH 1/2] Fix issues when a `config.rb` file is present somewhere in the directories In this case the `config.yml` or `config.json` files might not get parsed, resulting in missing configuration --- features/config.feature | 10 ++++++++++ features/support/helpers.rb | 2 +- lib/ruhoh/cascade.rb | 8 ++++---- lib/ruhoh/config.rb | 2 +- lib/ruhoh/parse.rb | 14 +++++++++++--- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/features/config.feature b/features/config.feature index 4e9f66a..4d6943e 100644 --- a/features/config.feature +++ b/features/config.feature @@ -20,3 +20,13 @@ 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" 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..534bdf2 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 From b1f8c2c0c4bdd7ccb43c90857c2d58686e8bcd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zsolt=20Sz=2E=20Sztup=C3=A1k?= Date: Tue, 4 Mar 2014 21:27:36 +0000 Subject: [PATCH 2/2] Fixed issue with config files not loaded from subdirectories --- features/config.feature | 11 +++++++++++ lib/ruhoh/config.rb | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/features/config.feature b/features/config.feature index 4d6943e..e5b6cf2 100644 --- a/features/config.feature +++ b/features/config.feature @@ -30,3 +30,14 @@ 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: 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/lib/ruhoh/config.rb b/lib/ruhoh/config.rb index 534bdf2..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.{yml|yaml|json}"].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)) || {})) }