check for the urldrop key first

This commit is contained in:
fen 2016-11-02 21:30:23 +01:00
parent 2d35364c02
commit e92dd2055d
3 changed files with 16 additions and 11 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,15 +86,14 @@ module Jekyll
def generate_url_from_drop(template)
template.gsub(%r!:([a-z_]+)!) do |match|
begin
replacement = @placeholders.public_send(match.sub(":".freeze, "".freeze))
rescue NoMethodError
Jekyll.logger.warn "", "#{match} is not defined!"
key = match.sub(":".freeze, "".freeze)
unless @placeholders.key?(key)
raise NoMethodError, "The URL template key #{key} doesn't exist!"
end
if replacement.nil?
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

@ -93,11 +93,12 @@ class TestURL < JekyllUnitTest
matching_doc = site.collections["methods"].docs.find do |doc|
doc.relative_path == "_methods/escape-+ #%20[].md"
end
URL.new(
:template => "/methods/:title/:headline",
:placeholders => matching_doc.url_placeholders
).to_s
pass
assert_raises NoMethodError do
URL.new(
:template => "/methods/:headline",
:placeholders => matching_doc.url_placeholders
).to_s
end
end
end
end