mirror of
https://github.com/jekyll/jekyll.git
synced 2026-01-10 07:28:07 -05:00
0
test/fixtures/test-theme-w-empty-data/_data/.gitkeep
vendored
Normal file
0
test/fixtures/test-theme-w-empty-data/_data/.gitkeep
vendored
Normal file
11
test/fixtures/test-theme-w-empty-data/_layouts/default.html
vendored
Normal file
11
test/fixtures/test-theme-w-empty-data/_layouts/default.html
vendored
Normal 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>
|
||||
11
test/fixtures/test-theme-w-empty-data/test-theme-w-empty-data.gemspec
vendored
Normal file
11
test/fixtures/test-theme-w-empty-data/test-theme-w-empty-data.gemspec
vendored
Normal 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
|
||||
6
test/fixtures/test-theme/_data/cars.yml
vendored
Normal file
6
test/fixtures/test-theme/_data/cars.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
manufacturer: Mercedes
|
||||
models:
|
||||
- model: A-Klasse
|
||||
price: 32,000.00
|
||||
- model: B-Klasse
|
||||
price: 35,000.00
|
||||
6
test/fixtures/test-theme/_data/categories/dairy.yaml
vendored
Normal file
6
test/fixtures/test-theme/_data/categories/dairy.yaml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
name: Cheese Dairy
|
||||
products:
|
||||
- name: spread cheese
|
||||
price: 1.2
|
||||
- name: cheddar cheese
|
||||
price: 4.5
|
||||
1
test/fixtures/test-theme/_data/greetings.yml
vendored
Normal file
1
test/fixtures/test-theme/_data/greetings.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foo: "Hello! I’m bar. What’s up so far?"
|
||||
2
test/fixtures/test-theme/_data/i18n/testimonials.yml
vendored
Normal file
2
test/fixtures/test-theme/_data/i18n/testimonials.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
header: Testimonials
|
||||
footer: Design by FTC
|
||||
9
test/fixtures/test-theme/_includes/testimonials.html
vendored
Normal file
9
test/fixtures/test-theme/_includes/testimonials.html
vendored
Normal 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>
|
||||
1
test/source/_data/greetings.yml
Normal file
1
test/source/_data/greetings.yml
Normal file
@@ -0,0 +1 @@
|
||||
foo: "Hello! I’m foo. And who are you?"
|
||||
3
test/source/_data/i18n.yml
Normal file
3
test/source/_data/i18n.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
testimonials:
|
||||
header: Kundenstimmen
|
||||
# footer omitted by design
|
||||
@@ -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")
|
||||
|
||||
90
test/test_theme_data_reader.rb
Normal file
90
test/test_theme_data_reader.rb
Normal 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! I’m 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! I’m 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! I’m 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! I’m bar. What’s up so far?", @site.data["greetings"]["foo"]
|
||||
assert_equal "Hello! I’m 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
|
||||
Reference in New Issue
Block a user