Implement @parkr's suggestions
This commit is contained in:
parent
cd9d38c5ea
commit
02e53fb6ff
|
@ -37,15 +37,29 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the String URL
|
# Returns the String URL
|
||||||
def to_s
|
def to_s
|
||||||
sanitize_url(generate_url)
|
sanitize_url(generated_permalink || generated_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Generates a URL from the permalink
|
||||||
|
#
|
||||||
|
# Returns the _unsanitized String URL
|
||||||
|
def generated_permalink
|
||||||
|
(@generated_permlink ||= generate_url(@permalink)) if @permalink
|
||||||
|
end
|
||||||
|
|
||||||
|
# Generates a URL from the template
|
||||||
|
#
|
||||||
|
# Returns the _unsanitized String URL
|
||||||
|
def generated_url
|
||||||
|
@generated_url ||= generate_url(@template)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Internal: Generate the URL by replacing all placeholders with their
|
# Internal: Generate the URL by replacing all placeholders with their
|
||||||
# respective values in the template or permalink
|
# respective values in the given template
|
||||||
#
|
#
|
||||||
# Returns the _unsanitizied_ String URL
|
# Returns the _unsanitizied_ String URL
|
||||||
def generate_url
|
def generate_url(template)
|
||||||
@placeholders.inject(@permalink || @template) do |result, token|
|
@placeholders.inject(template) do |result, token|
|
||||||
break result if result.index(':').nil?
|
break result if result.index(':').nil?
|
||||||
result.gsub(/:#{token.first}/, self.class.escape_path(token.last))
|
result.gsub(/:#{token.first}/, self.class.escape_path(token.last))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue