Propagate _data folder from theme (#8815)

Merge pull request 8815
This commit is contained in:
Michael Gerzabek
2021-11-22 14:01:33 +01:00
committed by GitHub
parent 9a3122020e
commit a8ccdd6d2f
19 changed files with 259 additions and 9 deletions

View File

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Skinny</title>
</head>
<body>
<h1>Hello World</h1>
{{ content }}
</body>
</html>

View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
Gem::Specification.new do |s|
s.name = "test-theme-w-empty-data"
s.version = "0.1.0"
s.licenses = ["MIT"]
s.summary = "This is a theme with just one layout and an empty _data folder used to test Jekyll"
s.authors = ["Jekyll"]
s.files = ["lib/example.rb"]
s.homepage = "https://github.com/jekyll/jekyll"
end

View File

@@ -0,0 +1,6 @@
manufacturer: Mercedes
models:
- model: A-Klasse
price: 32,000.00
- model: B-Klasse
price: 35,000.00

View File

@@ -0,0 +1,6 @@
name: Cheese Dairy
products:
- name: spread cheese
price: 1.2
- name: cheddar cheese
price: 4.5

View File

@@ -0,0 +1 @@
foo: "Hello! Im bar. Whats up so far?"

View File

@@ -0,0 +1,2 @@
header: Testimonials
footer: Design by FTC

View File

@@ -0,0 +1,9 @@
<section class="testimonials">
<h3>{{ site.data.i18n.testimonials.header }}</h3>
<!-- for testimonial in site.data.testimonial }} -->
<!-- endfor -->
<footer class="testimonials-footer">
{{ site.data.i18n.testimonials.footer }}
</footer>
</section>

View File

@@ -0,0 +1 @@
foo: "Hello! Im foo. And who are you?"

View File

@@ -0,0 +1,3 @@
testimonials:
header: Kundenstimmen
# footer omitted by design

View File

@@ -29,7 +29,7 @@ class TestTheme < JekyllUnitTest
end
context "path generation" do
[:assets, :_layouts, :_includes, :_sass].each do |folder|
[:assets, :_data, :_layouts, :_includes, :_sass].each do |folder|
should "know the #{folder} path" do
expected = theme_dir(folder.to_s)
assert_equal expected, @theme.public_send("#{folder.to_s.tr("_", "")}_path")

View File

@@ -0,0 +1,90 @@
# frozen_string_literal: true
require "helper"
class TestThemeDataReader < JekyllUnitTest
context "site without a theme" do
setup do
@site = fixture_site("theme" => nil)
@site.reader.read_data
assert @site.data["greetings"]
assert @site.data["categories"]["dairy"]
end
should "should read data from source" do
assert_equal "Hello! Im foo. And who are you?", @site.data["greetings"]["foo"]
assert_equal "Dairy", @site.data["categories"]["dairy"]["name"]
end
end
context "site with a theme without _data" do
setup do
@site = fixture_site("theme" => "test-theme-skinny")
@site.reader.read_data
assert @site.data["greetings"]
assert @site.data["categories"]["dairy"]
end
should "should read data from source" do
assert_equal "Hello! Im foo. And who are you?", @site.data["greetings"]["foo"]
assert_equal "Dairy", @site.data["categories"]["dairy"]["name"]
end
end
context "site with a theme with empty _data directory" do
setup do
@site = fixture_site("theme" => "test-theme-w-empty-data")
@site.reader.read_data
assert @site.data["greetings"]
assert @site.data["categories"]["dairy"]
end
should "should read data from source" do
assert_equal "Hello! Im foo. And who are you?", @site.data["greetings"]["foo"]
assert_equal "Dairy", @site.data["categories"]["dairy"]["name"]
end
end
context "site with a theme with data at root of _data" do
setup do
@site = fixture_site("theme" => "test-theme")
@site.reader.read_data
assert @site.data["greetings"]
assert @site.data["categories"]["dairy"]
assert @site.data["cars"]
end
should "should merge nested keys" do
refute_equal "Hello! Im bar. Whats up so far?", @site.data["greetings"]["foo"]
assert_equal "Hello! Im foo. And who are you?", @site.data["greetings"]["foo"]
assert_equal "Mercedes", @site.data["cars"]["manufacturer"]
end
end
context "site with a theme with data at root of _data and in a subdirectory" do
setup do
@site = fixture_site("theme" => "test-theme")
@site.reader.read_data
assert @site.data["greetings"]
assert @site.data["categories"]["dairy"]
assert @site.data["cars"]
end
should "should merge nested keys" do
refute_equal "Cheese Dairy", @site.data["categories"]["dairy"]["name"]
expected_names = %w(cheese milk)
product_names = @site.data["categories"]["dairy"]["products"].map do |product|
product["name"]
end
expected_names.each do |expected_name|
assert_includes product_names, expected_name
end
assert_equal "Dairy", @site.data["categories"]["dairy"]["name"]
end
should "should illustrate the documented sample" do
assert_equal "Kundenstimmen", @site.data["i18n"]["testimonials"]["header"]
assert_equal "Design by FTC", @site.data["i18n"]["testimonials"]["footer"]
end
end
end