add /_data/*.tsv support (#5985)

* Update data.feature

- add .tsv
- add .csv with `\t`
- add .csv with `;`

* Fix Appveyor with dst-aware cucumber steps

* Check for given content in posts

* mention Ruby > 2.1.0 in docs

* Update history to reflect merge of #5983 [ci skip]

* Update history to reflect merge of #5961 [ci skip]

* Update data_reader.rb

- add .tsv support with tab separated columns
- not adding support for auto-detecting `:col_sep`

ftp://ftp.iana.org/assignments/media-types/text/tab-separated-values
https://www.ietf.org/rfc/rfc4180.txt (CSV)
https://ruby-doc.org/stdlib-2.4.1/libdoc/csv/rdoc/CSV.html

* Update data.feature

don't do semicolons and tabs in .csv within this patch

* Update data.feature

I don't know which component replaced my tab characters by space before.

* Update data.feature

t

* Update data_reader.rb

add a single space to satisfy format checker
This commit is contained in:
Christoph Päper 2017-03-29 00:36:29 +02:00 committed by Parker Moore
parent 73e70da9e5
commit 3688640d59
2 changed files with 22 additions and 2 deletions

View File

@ -59,6 +59,20 @@ Feature: Data
And I should see "Jack" in "_site/index.html"
And I should see "Leon" in "_site/index.html"
Scenario: autoload *.tsv files in _data directory
Given I have a _data directory
And I have a "_data/members.tsv" file with content:
"""
name age
Jack 28
Leon 34
"""
And I have an "index.html" page that contains "{% for member in site.data.members %}{{member.name}}{% endfor %}"
When I run jekyll build
Then the "_site/index.html" file should exist
And I should see "Jack" in "_site/index.html"
And I should see "Leon" in "_site/index.html"
Scenario: autoload *.yml files in _data directory with space in file name
Given I have a _data directory
And I have a "_data/team members.yml" file with content:

View File

@ -19,7 +19,7 @@ module Jekyll
@content
end
# Read and parse all .yaml, .yml, .json, and .csv
# Read and parse all .yaml, .yml, .json, .csv and .tsv
# files under <dir> and add them to the <data> variable.
#
# dir - The string absolute path of the directory to read.
@ -30,7 +30,7 @@ module Jekyll
return unless File.directory?(dir) && !@entry_filter.symlink?(dir)
entries = Dir.chdir(dir) do
Dir["*.{yaml,yml,json,csv}"] + Dir["*"].select { |fn| File.directory?(fn) }
Dir["*.{yaml,yml,json,csv,tsv}"] + Dir["*"].select { |fn| File.directory?(fn) }
end
entries.each do |entry|
@ -56,6 +56,12 @@ module Jekyll
: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)
else
SafeYAML.load_file(path)
end