Skip to content

Commit

Permalink
Allow Configurable Converters on CSV
Browse files Browse the repository at this point in the history
Lets the user specify which converters to pass to `CSV`, defaulting to `nil` if not present in config. This is specifically so that numeric values in a CSV file can be parsed as something other than strings.
  • Loading branch information
MichaelCordingley committed Oct 29, 2021
1 parent 10a7359 commit 734bbf9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/jekyll/readers/data_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ def read_data_file(path)
case File.extname(path).downcase
when ".csv"
CSV.read(path,
:headers => true,
:encoding => site.config["encoding"]).map(&:to_hash)
:converters => site.config["csv_converters"]&.map(&:to_sym),
:headers => true,
:encoding => site.config["encoding"]).map(&:to_hash)
when ".tsv"
CSV.read(path,
:col_sep => "\t",
:headers => true,
:encoding => site.config["encoding"]).map(&:to_hash)
:col_sep => "\t",
:converters => site.config["csv_converters"]&.map(&:to_sym),
:headers => true,
:encoding => site.config["encoding"]).map(&:to_hash)
else
SafeYAML.load_file(path)
end
Expand Down

0 comments on commit 734bbf9

Please sign in to comment.