Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions features/config.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 | <span>{{ urls.production_url }}</span> |
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 | <span>{{ urls.production_url }}</span> |
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"
2 changes: 1 addition & 1 deletion features/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ def this_compiled_file

After do
FileUtils.remove_dir(SampleSitePath,1) if Dir.exists? SampleSitePath
end
end
8 changes: 4 additions & 4 deletions lib/ruhoh/cascade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/ruhoh/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)) || {}))
}
Expand Down
14 changes: 11 additions & 3 deletions lib/ruhoh/parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -84,4 +92,4 @@ def self.json_for_pages(front_matter, filepath)
JSON.load(front_matter[0]) || {}
end
end
end
end