Refactored url.rb to compliant with Ruby Style Guide.

- Single Quotes
 - Fixed Typo's in variable names.
 - Removed Redundant Escaping in Regular Expressions.

Signed-off-by: Martin Jorn Rogalla <martin@martinrogalla.com>
This commit is contained in:
Martin Jorn Rogalla 2015-03-04 14:16:55 +01:00
parent 5e9b7343bf
commit 2ef9bae75a
1 changed files with 6 additions and 6 deletions

View File

@ -29,7 +29,7 @@ module Jekyll
@permalink = options[:permalink] @permalink = options[:permalink]
if (@template || @permalink).nil? if (@template || @permalink).nil?
raise ArgumentError, "One of :template or :permalink must be supplied." raise ArgumentError, 'One of :template or :permalink must be supplied.'
end end
end end
@ -44,12 +44,12 @@ module Jekyll
# #
# Returns the _unsanitized String URL # Returns the _unsanitized String URL
def generated_permalink def generated_permalink
(@generated_permlink ||= generate_url(@permalink)) if @permalink (@generated_permalink ||= generate_url(@permalink)) if @permalink
end end
# Generates a URL from the template # Generates a URL from the template
# #
# Returns the _unsanitized String URL # Returns the unsanitized String URL
def generated_url def generated_url
@generated_url ||= generate_url(@template) @generated_url ||= generate_url(@template)
end end
@ -57,7 +57,7 @@ module Jekyll
# Internal: Generate the URL by replacing all placeholders with their # Internal: Generate the URL by replacing all placeholders with their
# respective values in the given template # respective values in the given template
# #
# Returns the _unsanitizied_ String URL # Returns the unsanitized String URL
def generate_url(template) def generate_url(template)
@placeholders.inject(template) do |result, token| @placeholders.inject(template) do |result, token|
break result if result.index(':').nil? break result if result.index(':').nil?
@ -81,7 +81,7 @@ module Jekyll
.gsub(/\A([^\/])/, '/\1') .gsub(/\A([^\/])/, '/\1')
# Append a trailing slash to the URL if the unsanitized URL had one # Append a trailing slash to the URL if the unsanitized URL had one
url << "/" if in_url[-1].eql?('/') url << '/' if in_url[-1].eql?('/')
url url
end end
@ -107,7 +107,7 @@ module Jekyll
# pct-encoded = "%" HEXDIG HEXDIG # pct-encoded = "%" HEXDIG HEXDIG
# sub-delims = "!" / "$" / "&" / "'" / "(" / ")" # sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
# / "*" / "+" / "," / ";" / "=" # / "*" / "+" / "," / ";" / "="
URI.escape(path, /[^a-zA-Z\d\-._~!$&\'()*+,;=:@\/]/).encode('utf-8') URI.escape(path, /[^a-zA-Z\d\-._~!$&'()*+,;=:@\/]/).encode('utf-8')
end end
# Unescapes a URL path segment # Unescapes a URL path segment