Skip to content

Commit 01b9369

Browse files
committed
refactor: namespace components and specs
1 parent 8dc8f70 commit 01b9369

73 files changed

Lines changed: 745 additions & 709 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
module ApplianceCalculator
4+
class GroupedSelectComponent < CitizensAdviceComponents::Select
5+
def call
6+
render CitizensAdviceComponents::Input.new(**base_input_args) do
7+
tag.select(class: select_classes, **input_attributes) do
8+
grouped_options_for_select(select_options, value)
9+
end
10+
end
11+
end
12+
end
13+
end

app/components/content/rebel_energy_bust_banner_component.rb

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

app/components/content/rebel_energy_bust_banner_component.html.haml renamed to app/components/csr_table/content/rebel_energy_bust_banner_component.html.haml

File renamed without changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
module CsrTable
4+
module Content
5+
class RebelEnergyBustBannerComponent < ViewComponent::Base
6+
def initialize(supplier:, current_country: nil)
7+
super()
8+
@supplier = supplier
9+
@current_country = current_country
10+
end
11+
12+
def render?
13+
# show on the main table page
14+
return true if @supplier.blank?
15+
16+
# show on the rebel energy details page
17+
@supplier.id == "rebel-energy"
18+
end
19+
20+
def link
21+
"#{country_prefix}/consumer/energy/energy-supply/problems-with-your-energy-supply/your-energy-supplier-has-gone-bust/"
22+
end
23+
24+
private
25+
26+
attr_reader :supplier, :current_country
27+
28+
def country_prefix
29+
return if current_country.blank? || current_country == "england"
30+
31+
"/#{current_country}"
32+
end
33+
end
34+
end
35+
end

app/components/description_list_component.html.haml renamed to app/components/csr_table/description_list_component.html.haml

File renamed without changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
module CsrTable
4+
class DescriptionListComponent < ViewComponent::Base
5+
renders_one :title
6+
renders_many :descriptions, "DescriptionComponent"
7+
8+
def render?
9+
descriptions?
10+
end
11+
12+
class DescriptionComponent < ViewComponent::Base
13+
attr_reader :term, :description, :intro
14+
15+
def initialize(term:, description:, intro: nil)
16+
@term = term
17+
@description = description
18+
@intro = intro
19+
end
20+
end
21+
end
22+
end
File renamed without changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
module CsrTable
4+
class FuelMixComponent < ViewComponent::Base
5+
attr_reader :supplier, :renderer
6+
7+
delegate :contact_details_fragment, to: :helpers
8+
9+
def initialize(supplier)
10+
super()
11+
@supplier = supplier
12+
@renderer = Renderers::RichTextRenderer.new
13+
end
14+
15+
def render?
16+
supplier.present?
17+
end
18+
19+
def descriptions
20+
[
21+
{
22+
term: content_tag(:h3, "Fuel Mix"),
23+
intro: fuel_mix_intro,
24+
description: fuel_mix
25+
}
26+
].reject { |desc| desc[:description].blank? }
27+
end
28+
29+
def fuel_mix
30+
renderer.render_without_breaks(supplier.fuel_mix)
31+
end
32+
33+
def fuel_mix_intro
34+
content_tag(:p, "The fuel mix is the percentage of energy sources used by this supplier. #{supplier.name} uses:")
35+
end
36+
end
37+
end

app/components/location_switcher_component.html.haml renamed to app/components/csr_table/location_switcher_component.html.haml

File renamed without changes.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# frozen_string_literal: true
2+
3+
module CsrTable
4+
class LocationSwitcherComponent < ViewComponent::Base
5+
attr_reader :current_country
6+
7+
def initialize(current_country:)
8+
super()
9+
10+
@current_country = current_country || "england"
11+
@available_country_urls = available_country_urls
12+
end
13+
14+
def localised_current_country
15+
localise_country(@current_country)
16+
end
17+
18+
def country_urls
19+
@available_country_urls.reject { |country| country == @current_country }
20+
end
21+
22+
def country_links
23+
links = country_urls.map do |country, url|
24+
link_to url, class: "location-switcher__link" do
25+
tag.span("See advice for ", class: "cads-sr-only") + localise_country(country)
26+
end
27+
end
28+
safe_join(links, ", ")
29+
end
30+
31+
def render?
32+
@available_country_urls.present?
33+
end
34+
35+
private
36+
37+
def localise_country(country)
38+
{
39+
england: "England",
40+
scotland: "Scotland",
41+
wales: "Wales"
42+
}.fetch(country.to_sym)
43+
end
44+
45+
def available_country_urls
46+
{
47+
"england" => CSR_APP_PATH,
48+
"scotland" => "/scotland#{CSR_APP_PATH}",
49+
"wales" => "/wales#{CSR_APP_PATH}"
50+
}
51+
end
52+
end
53+
end

0 commit comments

Comments
 (0)