Merge pull request #5524 from fene/nomethoderror

Merge pull request 5524
This commit is contained in:
jekyllbot 2016-11-08 17:05:18 -08:00 committed by GitHub
commit f10c914fd5
3 changed files with 31 additions and 3 deletions

View File

@ -78,6 +78,11 @@ module Jekyll
def y_day
@obj.date.strftime("%j")
end
private
def fallback_data
{}
end
end
end
end

View File

@ -86,11 +86,14 @@ module Jekyll
def generate_url_from_drop(template)
template.gsub(%r!:([a-z_]+)!) do |match|
replacement = @placeholders.public_send(match.sub(":".freeze, "".freeze))
if replacement.nil?
key = match.sub(":".freeze, "".freeze)
unless @placeholders.key?(key)
raise NoMethodError, "The URL template key #{key} doesn't exist!"
end
if @placeholders[key].nil?
"".freeze
else
self.class.escape_path(replacement)
self.class.escape_path(@placeholders[key])
end
end.gsub(%r!//!, "/".freeze)
end

View File

@ -80,5 +80,25 @@ class TestURL < JekyllUnitTest
url.to_s
end
end
should "ignore NoMethodErrors when a placeholder is not found" do
site = fixture_site({
"collections" => {
"methods" => {
"output" => true
}
}
})
site.read
matching_doc = site.collections["methods"].docs.find do |doc|
doc.relative_path == "_methods/escape-+ #%20[].md"
end
assert_raises NoMethodError do
URL.new(
:template => "/methods/:headline",
:placeholders => matching_doc.url_placeholders
).to_s
end
end
end
end