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 def y_day
@obj.date.strftime("%j") @obj.date.strftime("%j")
end end
private
def fallback_data
{}
end
end end
end end
end end

View File

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

View File

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