DEM TESTS
This commit is contained in:
parent
08162dbb50
commit
90807ac6e7
|
@ -15,6 +15,7 @@ module Jekyll
|
||||||
Dir.glob(File.join(directory, "**", "*.*")).each do |file_path|
|
Dir.glob(File.join(directory, "**", "*.*")).each do |file_path|
|
||||||
if allowed_document?(file_path)
|
if allowed_document?(file_path)
|
||||||
doc = Jekyll::Document.new(file_path, { site: site, collection: self })
|
doc = Jekyll::Document.new(file_path, { site: site, collection: self })
|
||||||
|
doc.read
|
||||||
docs << doc
|
docs << doc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,6 +28,10 @@ module Jekyll
|
||||||
Pathname.new(path).relative_path_from(Pathname.new(site.source)).to_s
|
Pathname.new(path).relative_path_from(Pathname.new(site.source)).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def basename(suffix = "")
|
||||||
|
File.basename(path, suffix)
|
||||||
|
end
|
||||||
|
|
||||||
def extname
|
def extname
|
||||||
File.extname(path)
|
File.extname(path)
|
||||||
end
|
end
|
||||||
|
@ -56,7 +60,7 @@ module Jekyll
|
||||||
# Read in the file and assign the content and data based on the file contents.
|
# Read in the file and assign the content and data based on the file contents.
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def read
|
def read(opts = {})
|
||||||
if yaml_file?
|
if yaml_file?
|
||||||
@data = SafeYAML.load_file(path)
|
@data = SafeYAML.load_file(path)
|
||||||
else
|
else
|
||||||
|
|
|
@ -175,16 +175,9 @@ module Jekyll
|
||||||
entries = Dir.chdir(base) { Dir['*.{yaml,yml}'] }
|
entries = Dir.chdir(base) { Dir['*.{yaml,yml}'] }
|
||||||
entries.delete_if { |e| File.directory?(File.join(base, e)) }
|
entries.delete_if { |e| File.directory?(File.join(base, e)) }
|
||||||
data_collection = Jekyll::Collection.new(self, "data")
|
data_collection = Jekyll::Collection.new(self, "data")
|
||||||
|
data_collection.read
|
||||||
entries.each do |entry|
|
data_collection.docs.each do |doc|
|
||||||
path = File.join(source, dir, entry)
|
key = sanitize_filename(doc.basename(".*"))
|
||||||
next if File.symlink?(path) && safe
|
|
||||||
|
|
||||||
key = sanitize_filename(File.basename(entry, '.*'))
|
|
||||||
|
|
||||||
doc = Jekyll::Document.new(path, { site: self, collection: data_collection })
|
|
||||||
doc.read
|
|
||||||
|
|
||||||
self.data[key] = doc.data
|
self.data[key] = doc.data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
test/source/_methods/sanitized_path.md
|
./site/generate.md
|
|
@ -0,0 +1,45 @@
|
||||||
|
require 'helper'
|
||||||
|
|
||||||
|
class TestDocument < Test::Unit::TestCase
|
||||||
|
|
||||||
|
context "" do
|
||||||
|
setup do
|
||||||
|
@site = Site.new(Jekyll.configuration({
|
||||||
|
"collections" => ["methods"],
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir
|
||||||
|
}))
|
||||||
|
@site.process
|
||||||
|
@document = @site.collections["methods"].docs.first
|
||||||
|
end
|
||||||
|
|
||||||
|
should "know its relative path" do
|
||||||
|
assert_equal "_methods/configuration.md", @document.relative_path
|
||||||
|
end
|
||||||
|
|
||||||
|
should "knows its extname" do
|
||||||
|
assert_equal ".md", @document.extname
|
||||||
|
end
|
||||||
|
|
||||||
|
should "know its basename" do
|
||||||
|
assert_equal "configuration.md", @document.basename
|
||||||
|
end
|
||||||
|
|
||||||
|
should "allow the suffix to be specified for the basename" do
|
||||||
|
assert_equal "configuration", @document.basename(".*")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "know whether its a yaml file" do
|
||||||
|
assert_equal false, @document.yaml_file?
|
||||||
|
end
|
||||||
|
|
||||||
|
should "know its data" do
|
||||||
|
assert_equal({
|
||||||
|
"title" => "Jekyll.configuration",
|
||||||
|
"whatever" => "foo.bar"
|
||||||
|
}, @document.data)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue