Remove duplicate code

This commit is contained in:
Alfred Xing 2014-10-26 21:38:19 -07:00
parent 0fe1d0686a
commit cd9d38c5ea
1 changed files with 3 additions and 16 deletions

View File

@ -37,33 +37,20 @@ module Jekyll
#
# Returns the String URL
def to_s
sanitize_url(generate_permalink_url || generate_url)
sanitize_url(generate_url)
end
# Internal: Generate the URL by replacing all placeholders with their
# respective values in the template
# respective values in the template or permalink
#
# Returns the _unsanitizied_ String URL
def generate_url
@placeholders.inject(@template) do |result, token|
@placeholders.inject(@permalink || @template) do |result, token|
break result if result.index(':').nil?
result.gsub(/:#{token.first}/, self.class.escape_path(token.last))
end
end
# Internal: Generate the URL by replacing all placeholders with their
# respective values in the permalink
#
# Returns the _unsanitizied_ String URL
def generate_permalink_url
if not @permalink.nil?
@placeholders.inject(@permalink) do |result, token|
break result if result.index(':').nil?
result.gsub(/:#{token.first}/, self.class.escape_path(token.last))
end
end
end
# Returns a sanitized String URL
def sanitize_url(in_url)
url = in_url \