Skip to content

Commit

Permalink
TRG-668: Resolve Rubocop violations.
Browse files Browse the repository at this point in the history
Not entirely sure I think all of Rubocop's corrections make the code more readable, but this is what it wants in order to pass its checks.
  • Loading branch information
eddgrant committed May 19, 2023
1 parent 6a1f3e1 commit 38c3bf1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
2 changes: 1 addition & 1 deletion govuk_tech_docs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "autoprefixer-rails", "~> 10.2"
spec.add_dependency "chronic", "~> 0.10.2"
spec.add_dependency "haml", "< 6.0.0"
spec.add_dependency "middleman", "~> 4.0"
spec.add_dependency "middleman-autoprefixer", "~> 2.10.0"
spec.add_dependency "middleman-compass", ">= 4.0.0"
Expand All @@ -47,7 +48,6 @@ Gem::Specification.new do |spec|
spec.add_dependency "nokogiri"
spec.add_dependency "openapi3_parser", "~> 0.9.0"
spec.add_dependency "redcarpet", "~> 3.5.1"
spec.add_dependency "haml", "< 6.0.0"

spec.add_development_dependency "byebug"
spec.add_development_dependency "capybara", "~> 3.32"
Expand Down
27 changes: 8 additions & 19 deletions lib/govuk_tech_docs/path_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module GovukTechDocs
module PathHelpers

require 'uri'
require "uri"

# Some useful notes from https://www.rubydoc.info/github/middleman/middleman/Middleman/Sitemap/Resource#url-instance_method :
# 'resource.path' is "The source path of this resource (relative to the source directory, without template extensions)."
Expand All @@ -18,24 +17,14 @@ module PathHelpers
# @param [Object] current_page
def get_path_to_resource(config, resource, current_page)
if resource.instance_of?(Middleman::Sitemap::Resource)
if config[:relative_links]
resolved_path = get_resource_path_relative_to_current_page(config, current_page.path, resource.path)
else
resolved_path = resource.url
end
config[:relative_links] ? get_resource_path_relative_to_current_page(config, current_page.path, resource.path) : resource.url
elsif external_url?(resource)
resource
elsif config[:relative_links]
get_resource_path_relative_to_current_page(config, current_page.path, resource)
else
if external_url?(resource)
resolved_path = resource
else
if config[:relative_links]
resolved_path = get_resource_path_relative_to_current_page(config, current_page.path, resource)
else
resolved_path = resource
end
end
resource
end

resolved_path
end

def path_to_site_root(config, page_path)
Expand All @@ -50,7 +39,7 @@ def path_to_site_root(config, page_path)
path_to_site_root
end

private
private

# Calculates the path to the sought resource, relative to the current page.
# @param [Object] config Middleman config.
Expand Down
4 changes: 2 additions & 2 deletions spec/govuk_tech_docs/path_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def create_resource_double(**kwargs)
"https://www.example.com/some-page.html", # With scheme included.
"www.example.com/some-page.html", # With scheme omitted.
]
external_urls.each { | external_url |
external_urls.each do |external_url|
current_page_path = "/documentation/introduction/section-one/index.html"

it "when the site is configured to generate absolute links" do
Expand All @@ -87,7 +87,7 @@ def create_resource_double(**kwargs)

expect(resource_path).to eql(external_url)
end
}
end
end
end

Expand Down

0 comments on commit 38c3bf1

Please sign in to comment.