Separated some more readers from the main reader.rb file.

- Draft Reader
 - Collection Reader
 - Page Reader
 - Post Reader
 - Static File Reader

Fixed references and ran tests.

Signed-off-by: Martin Jorn Rogalla <martin@martinrogalla.com>
This commit is contained in:
Martin Jorn Rogalla
2015-03-06 17:20:25 +01:00
parent bebd80342e
commit 00cdcbc184
30 changed files with 467 additions and 214 deletions

View File

@@ -42,12 +42,12 @@ class TestConfiguration < JekyllUnitTest
assert_equal [source_dir("_config.yml")], @config.config_files(@no_override)
end
should "return .yaml if it exists but .yml does not" do
mock(File).exists?(source_dir("_config.yml")) { false }
mock(File).exists?(source_dir("_config.yaml")) { true }
mock(File).exist?(source_dir("_config.yml")) { false }
mock(File).exist?(source_dir("_config.yaml")) { true }
assert_equal [source_dir("_config.yaml")], @config.config_files(@no_override)
end
should "return .yml if both .yml and .yaml exist" do
mock(File).exists?(source_dir("_config.yml")) { true }
mock(File).exist?(source_dir("_config.yml")) { true }
assert_equal [source_dir("_config.yml")], @config.config_files(@no_override)
end
should "return the config if given one config file" do

View File

@@ -219,7 +219,31 @@ class TestDocument < JekyllUnitTest
assert_equal "/slides/test/example-slide-1", @document.url
end
should "produce the right destination" do
should "produce the right destination file" do
assert_equal @dest_file, @document.destination(dest_dir)
end
end
context "a document in a collection with pretty permalink style" do
setup do
@site = fixture_site({
"collections" => {
"slides" => {
"output" => true,
}
},
})
@site.permalink_style = :pretty
@site.process
@document = @site.collections["slides"].docs[0]
@dest_file = dest_dir("slides/example-slide-1/index.html")
end
should "produce the right URL" do
assert_equal "/slides/example-slide-1/", @document.url
end
should "produce the right destination file" do
assert_equal @dest_file, @document.destination(dest_dir)
end
end

View File

@@ -280,6 +280,12 @@ class TestFilters < JekyllUnitTest
end
context "sort filter" do
should "raise Exception when input is nil" do
err = assert_raises ArgumentError do
@filter.sort(nil)
end
assert_equal "Cannot sort a null object.", err.message
end
should "return sorted numbers" do
assert_equal [1, 2, 2.2, 3], @filter.sort([3, 2.2, 2, 1])
end

View File

@@ -46,7 +46,7 @@ class TestPage < JekyllUnitTest
should "create index url based on filename" do
@page = setup_page('/contacts', 'index.html')
assert_equal "/contacts/index.html", @page.url
assert_equal "/contacts/", @page.url
end
end
@@ -129,6 +129,58 @@ class TestPage < JekyllUnitTest
end
end
context "with date permalink style" do
setup do
@site.permalink_style = :date
end
should "return url and destination correctly" do
@page = setup_page('contacts.html')
@dest_file = dest_dir("contacts.html")
assert_equal '/contacts.html', @page.url
assert_equal @dest_file, @page.destination(dest_dir)
end
end
context "with custom permalink style with trailing slash" do
setup do
@site.permalink_style = "/:title/"
end
should "return url and destination correctly" do
@page = setup_page('contacts.html')
@dest_file = dest_dir("contacts/index.html")
assert_equal '/contacts/', @page.url
assert_equal @dest_file, @page.destination(dest_dir)
end
end
context "with custom permalink style with file extension" do
setup do
@site.permalink_style = "/:title:output_ext"
end
should "return url and destination correctly" do
@page = setup_page('contacts.html')
@dest_file = dest_dir("contacts.html")
assert_equal '/contacts.html', @page.url
assert_equal @dest_file, @page.destination(dest_dir)
end
end
context "with custom permalink style with no extension" do
setup do
@site.permalink_style = "/:title"
end
should "return url and destination correctly" do
@page = setup_page('contacts.html')
@dest_file = dest_dir("contacts.html")
assert_equal '/contacts', @page.url
assert_equal @dest_file, @page.destination(dest_dir)
end
end
context "with any other permalink style" do
should "return dir correctly" do
@site.permalink_style = nil

View File

@@ -143,7 +143,7 @@ class TestSite < JekyllUnitTest
# simulate destination file deletion
File.unlink dest
refute File.exists?(dest)
refute File.exist?(dest)
sleep 1
@site.process
@@ -369,7 +369,7 @@ class TestSite < JekyllUnitTest
site = Site.new(site_configuration)
site.process
file_content = site.reader.read_data_file(source_dir('_data', 'members.yaml'))
file_content = DataReader.new(site).read_data_file(source_dir('_data', 'members.yaml'))
assert_equal site.data['members'], file_content
assert_equal site.site_payload['site']['data']['members'], file_content

View File

@@ -166,4 +166,18 @@ class TestUtils < JekyllUnitTest
end
end
context "The \`Utils.add_permalink_suffix\` method" do
should "handle built-in permalink styles" do
assert_equal "/:basename/", Utils.add_permalink_suffix("/:basename", :pretty)
assert_equal "/:basename:output_ext", Utils.add_permalink_suffix("/:basename", :date)
assert_equal "/:basename:output_ext", Utils.add_permalink_suffix("/:basename", :ordinal)
assert_equal "/:basename:output_ext", Utils.add_permalink_suffix("/:basename", :none)
end
should "handle custom permalink styles" do
assert_equal "/:basename/", Utils.add_permalink_suffix("/:basename", "/:title/")
assert_equal "/:basename:output_ext", Utils.add_permalink_suffix("/:basename", "/:title:output_ext")
assert_equal "/:basename", Utils.add_permalink_suffix("/:basename", "/:title")
end
end
end