Factor out a `read_data_file` call to keep things clean
This commit is contained in:
parent
69e8f1923c
commit
e1e60499b1
|
@ -258,13 +258,20 @@ module Jekyll
|
||||||
if File.directory?(path)
|
if File.directory?(path)
|
||||||
read_data_to(path, data[key] = {})
|
read_data_to(path, data[key] = {})
|
||||||
else
|
else
|
||||||
|
data[key] = read_data_file(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Determines how to read a data file.
|
||||||
|
#
|
||||||
|
# Returns the contents of the data file.
|
||||||
|
def read_data_file(path)
|
||||||
case File.extname(path).downcase
|
case File.extname(path).downcase
|
||||||
when '.csv'
|
when '.csv'
|
||||||
data[key] = CSV.read(path, :headers => true).map(&:to_hash)
|
CSV.read(path, :headers => true).map(&:to_hash)
|
||||||
else
|
else
|
||||||
data[key] = SafeYAML.load_file(path)
|
SafeYAML.load_file(path)
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue