Skip to content

Commit b3a9903

Browse files
committed
Fix typos and undo refactor
Fix typos Undo refactor as it's out of scope for this ticket
1 parent 68d1c8d commit b3a9903

7 files changed

Lines changed: 139 additions & 243 deletions

File tree

app/services/dgu/collections_service.rb

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
module Dgu
22
class CollectionsService
3+
COLLECTIONS_LOCATION = Rails.configuration.x.generated_collections_location
4+
COLLECTION_PAGES = Rails.configuration.x.collection_pages.deep_dup
5+
36
attr_reader :collection, :page_name, :collection_pages
47

58
def initialize(collection, page_name = nil)
69
unless collection?(collection)
7-
raise Dgu::CollectionNotFound, "Collection #{collection} does not exist"
10+
raise Dgu::CollectionNotFound
811
end
912

1013
@collection = collection
11-
@collection_pages = collection_pages_config[collection].map do |collection_page|
14+
@collection_pages = COLLECTION_PAGES[collection].map do |collection_page|
1215
{
1316
url: "/collections/#{@collection}/#{collection_page[:slug]}",
1417
slug: collection_page[:slug],
@@ -28,12 +31,18 @@ def page
2831
end
2932

3033
def image_path
31-
"/v2/collections/badge-#{collection}.png"
34+
"/images/collections/#{collection}.jpg"
3235
end
3336

3437
def collections_slugs
35-
@collections_slugs ||= collection_pages_config.keys.map do |collection_slug|
36-
Struct.new(:slug, :title).new(collection_slug.to_s, collection_slug.to_s.tr("-", " ").humanize)
38+
Dir.entries(Rails.root.join(COLLECTIONS_LOCATION)).sort
39+
.reject { |files|
40+
[".", ".."].include?(files)
41+
}.map do |collection|
42+
Struct.new(:slug, :title).new(
43+
collection,
44+
collection.gsub("-", " ").humanize,
45+
)
3746
end
3847
end
3948

@@ -63,22 +72,24 @@ def title
6372

6473
private
6574

66-
def collection_pages_config
67-
@collection_pages_config ||= YAML.load_file(Rails.root.join("config/collections.yml")).with_indifferent_access
68-
end
69-
7075
def pages
71-
@pages ||= collection_pages_config[@collection].map { |page| page[:slug] }
76+
Dir.entries(Rails.root.join(COLLECTIONS_LOCATION, @collection)).sort
77+
.reject { |entry|
78+
[".", ".."].include?(entry)
79+
}
80+
.map do |page_file_name|
81+
page_file_name.gsub(".html.erb", "")
82+
end
7283
end
7384

7485
def page?(page = nil)
7586
return true if page.blank?
7687

77-
pages.include?(page)
88+
Rails.root.join(COLLECTIONS_LOCATION, @collection, "#{page}.html.erb").exist?
7889
end
7990

8091
def collection?(collection)
81-
collections_slugs.map(&:slug).include?(collection)
92+
Rails.root.join(COLLECTIONS_LOCATION, collection).exist?
8293
end
8394

8495
def current_page_index

config/application.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# require "action_cable/engine"
1515
require "sprockets/railtie"
1616
require "rails/test_unit/railtie"
17+
require_relative "./collections"
1718

1819
# Require the gems listed in Gemfile, including any gems
1920
# you've limited to :test, :development, or :production.
@@ -43,6 +44,8 @@ class Application < Rails::Application
4344
config.x.markdown_data_manual_location = "app/content/data-manual"
4445
config.x.markdown_content_pages_location = "app/content/content-pages"
4546

47+
config.x.collection_pages = Collections::COLLECTIONS.with_indifferent_access
48+
4649
config.ssl_options = { hsts: { expires: 1.week } }
4750

4851
config.action_dispatch.default_headers = {

config/collections.rb

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
module Collections
2+
COLLECTIONS = {
3+
"business-and-economy": [
4+
{ "title": "UK trade", "slug": "uk-trade" },
5+
{ "title": "Inflation", "slug": "inflation" },
6+
{ "title": "Bank of England interest rates", "slug": "bank-of-england-interest-rates" },
7+
{ "title": "Get company information", "slug": "get-company-information" },
8+
{ "title": "Get charity information", "slug": "get-charity-information" },
9+
{ "title": "Food hygiene ratings", "slug": "food-hygiene-ratings" },
10+
{ "title": "Fuel and oil prices", "slug": "fuel-and-oil-prices" },
11+
{ "title": "Energy prices", "slug": "energy-prices" },
12+
{ "title": "Electricity", "slug": "electricity" },
13+
{ "title": "Agricultural commodity prices", "slug": "agricultural-commodity-prices" },
14+
],
15+
"environment": [
16+
{ "title": "Weather", "slug": "weather" },
17+
{ "title": "Air quality", "slug": "air-quality" },
18+
{ "title": "Water quality", "slug": "water-quality" },
19+
{ "title": "Long-term flood risk", "slug": "long-term-flood-risk" },
20+
{ "title": "Flood alerts", "slug": "flood-alerts" },
21+
{ "title": "Storm overflows", "slug": "storm-overflows" },
22+
{ "title": "Main rivers", "slug": "main-rivers" },
23+
{ "title": "Coastal erosion", "slug": "coastal-erosion" },
24+
{ "title": "Climate projections", "slug": "climate-projections" },
25+
{ "title": "Environmental public registers", "slug": "public-registers" },
26+
{ "title": "LIDAR mapping", "slug": "lidar" },
27+
{ "title": "Aerial photography mapping", "slug": "aerial-photography" },
28+
{ "title": "Landfill sites", "slug": "landfill-sites" },
29+
{ "title": "Road noise", "slug": "road-noise" },
30+
{ "title": "Rail noise", "slug": "rail-noise" },
31+
{ "title": "Forest and woodlands", "slug": "forest-and-woodlands" },
32+
{ "title": "Non-woodland trees", "slug": "non-woodland-trees" },
33+
{ "title": "Sites of Special Scientific Interest", "slug": "sites-of-special-scientific-interest" },
34+
],
35+
"government": [
36+
{ "title": "Election results", "slug": "election-results" },
37+
{ "title": "Service assessment reports", "slug": "service-assessment-reports" },
38+
{ "title": "Local government finance", "slug": "local-government-finance" },
39+
{ "title": "Council Tax statistics", "slug": "council-tax-statistics" },
40+
{ "title": "Contracts finder", "slug": "contracts-finder" },
41+
{ "title": "Transparency data", "slug": "transparency-data" },
42+
],
43+
"land-and-property": [
44+
{ "title": "UK house prices", "slug": "uk-house-prices" },
45+
{ "title": "Property price paid", "slug": "property-price-paid" },
46+
{ "title": "Land and property ownership", "slug": "land-and-property-ownership" },
47+
{ "title": "Planning data", "slug": "planning-data" },
48+
{ "title": "Addresses", "slug": "addresses" },
49+
{ "title": "Dwelling stock (including vacancies)", "slug": "dwelling-stock" },
50+
{ "title": "Rents, lettings and tenancies", "slug": "rents-lettings-and-tenancies" },
51+
{ "title": "English Housing Survey", "slug": "english-housing-survey" },
52+
{ "title": "Housing supply", "slug": "housing-supply" },
53+
{ "title": "Energy performance of buildings", "slug": "energy-performance-of-buildings" },
54+
{ "title": "Fire statistics", "slug": "fire-statistics" },
55+
],
56+
"people": [
57+
{ "title": "Births", "slug": "births" },
58+
{ "title": "Deaths", "slug": "deaths" },
59+
{ "title": "Public health dashboard", "slug": "public-health-dashboard" },
60+
{ "title": "Population estimates", "slug": "population-estimates" },
61+
{ "title": "Immigration", "slug": "immigration" },
62+
{ "title": "Social mobility", "slug": "social-mobility" },
63+
{ "title": "Deprivation", "slug": "deprivation" },
64+
{ "title": "Homelessness", "slug": "homelessness" },
65+
{ "title": "Police recorded crime and outcomes", "slug": "police-recorded-crime-and-outcomes" },
66+
{ "title": "Courts management", "slug": "courts-management" },
67+
{ "title": "Early years and childcare inspections and outcomes", "slug": "early-years-and-childcare-inspections-and-outcomes" },
68+
{ "title": "State-funded schools inspections and outcomes", "slug": "state-funded-schools-inspections-and-outcomes" },
69+
{ "title": "Pupil attendance", "slug": "pupil-attendance" },
70+
{ "title": "Compare school performance", "slug": "compare-school-performance" },
71+
{ "title": "Vocational qualifications", "slug": "vocational-qualifications" },
72+
{ "title": "Museum and gallery visits", "slug": "museum-and-gallery-visits" },
73+
{ "title": "Family food statistics", "slug": "family-food-statistics" },
74+
],
75+
"transport": [
76+
{ "title": "Road traffic", "slug": "road-traffic" },
77+
{ "title": "Road safety", "slug": "road-safety" },
78+
{ "title": "Road conditions", "slug": "road-conditions" },
79+
{ "title": "Real-time and historic train information", "slug": "real-time-and-historic-train-information" },
80+
{ "title": "Bus statistics", "slug": "bus-statistics" },
81+
{ "title": "MOT test results", "slug": "mot-results" },
82+
{ "title": "Driving tests", "slug": "driving-tests" },
83+
{ "title": "Fishing vessels", "slug": "fishing-vessels" },
84+
{ "title": "National Travel Survey", "slug": "national-travel-survey" },
85+
{ "title": "Transport connectivity", "slug": "transport-connectivity" },
86+
{ "title": "Maritime and shipping", "slug": "maritime-and-shipping" },
87+
],
88+
}.freeze
89+
end

config/collections.yml

Lines changed: 0 additions & 157 deletions
This file was deleted.

spec/rails_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
require "webmock/rspec"
2222
require "rake"
2323

24-
2524
# Requires supporting ruby files with custom matchers and macros, etc, in
2625
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
2726
# run as spec files by default. This means that files in spec/support that end

0 commit comments

Comments
 (0)