content_block_tools 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. checksums.yaml +4 -4
  2. data/app/components/content_block_tools/base_component.rb +13 -0
  3. data/app/components/content_block_tools/contact_component.rb +29 -0
  4. data/app/components/content_block_tools/contacts/address_component.rb +42 -0
  5. data/app/components/content_block_tools/contacts/contact_link_component.rb +19 -0
  6. data/app/components/content_block_tools/contacts/email_address_component.rb +28 -0
  7. data/app/components/content_block_tools/contacts/telephone_component.rb +51 -0
  8. data/lib/content_block_tools/content_block.rb +1 -1
  9. data/lib/content_block_tools/engine.rb +8 -0
  10. data/lib/content_block_tools/version.rb +1 -1
  11. data/lib/content_block_tools.rb +0 -9
  12. metadata +20 -20
  13. data/lib/content_block_tools/components/base_component.rb +0 -15
  14. data/lib/content_block_tools/components/contact_component.rb +0 -31
  15. data/lib/content_block_tools/components/contacts/address_component.rb +0 -44
  16. data/lib/content_block_tools/components/contacts/contact_link_component.rb +0 -21
  17. data/lib/content_block_tools/components/contacts/email_address_component.rb +0 -30
  18. data/lib/content_block_tools/components/contacts/telephone_component.rb +0 -53
  19. /data/{lib/content_block_tools/components → app/components/content_block_tools}/contact_component.html.erb +0 -0
  20. /data/{lib/content_block_tools/components → app/components/content_block_tools}/contacts/address_component.html.erb +0 -0
  21. /data/{lib/content_block_tools/components → app/components/content_block_tools}/contacts/contact_link_component.html.erb +0 -0
  22. /data/{lib/content_block_tools/components → app/components/content_block_tools}/contacts/email_address_component.html.erb +0 -0
  23. /data/{lib/content_block_tools/components → app/components/content_block_tools}/contacts/telephone_component.html.erb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6e2e8e76c7ac69f15bcb193069f82be59acdd78b7291812cbff6f896e6c8c87
4
- data.tar.gz: f46aa1f1fac9b526a45811b367db042c4d9f48b29c9f629fb708cdf0693ad299
3
+ metadata.gz: fb006e7903ec6cae4253ae9332308c42accf3f4e424da21e3bdb3d5ce2efe89c
4
+ data.tar.gz: 5cfd7df4e3bfa56fcd4b1333e7d09d0ab26b71de12cc6e8f7f13855493d5d6c6
5
5
  SHA512:
6
- metadata.gz: 62173df5e11a6023a91f7f2c39378098c89293ae6f5db96aa2289aca1f9cdbc030d5ed932b2d8fba1dc914d8514e3e87cb240c2377f034968b5ccfe47c515675
7
- data.tar.gz: fb9389766399957affb5c8c45640bd4324f26c383057ec3e458fbf2719b6dfe7eca81c7006294b041b1ca5fc65e51280ace5b632a1de513149061f2dc753563a
6
+ metadata.gz: 4d084a5f1684a8189d3b38db0d8df0a453e461b7c96aba6612493a326232312593de5fb0ec97402141c8865862fd36b09c6ff7bfca5796c287aedce4b2e93e40
7
+ data.tar.gz: ddf80b36ba7d6292219afb73df52a6df83b04640c8a2befec36054e9382cd34d5b6b573de844e67dfdbe91d3f17fa72ec8cba3df12d0c40d1112dcaee3576eb0
@@ -0,0 +1,13 @@
1
+ module ContentBlockTools
2
+ class BaseComponent < ViewComponent::Base
3
+ def render
4
+ render_in(view_context)
5
+ end
6
+
7
+ private
8
+
9
+ def view_context
10
+ ActionView::Base.new(ActionView::LookupContext.new([]), {}, nil)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module ContentBlockTools
2
+ class ContactComponent < ContentBlockTools::BaseComponent
3
+ BLOCK_TYPES = %i[addresses email_addresses telephones contact_links].freeze
4
+
5
+ def initialize(content_block:, block_type: nil, block_name: nil)
6
+ @content_block = content_block
7
+ @block_type = block_type
8
+ @block_name = block_name
9
+ end
10
+
11
+ private
12
+
13
+ attr_reader :content_block, :block_type, :block_name
14
+
15
+ def component_for_block_type(block_type)
16
+ "ContentBlockTools::Contacts::#{block_type.to_s.singularize.camelize}Component".constantize
17
+ end
18
+
19
+ def content_by_block_type
20
+ @content_by_block_type ||= content_block.details.keys.map { |key|
21
+ [key, content_block.details[key]&.values]
22
+ }.to_h
23
+ end
24
+
25
+ def item_to_render
26
+ content_block.details.dig(block_type, block_name)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ module ContentBlockTools
2
+ module Contacts
3
+ class AddressComponent < ContentBlockTools::BaseComponent
4
+ include ContentBlockTools::Govspeak
5
+
6
+ def initialize(item:)
7
+ @item = item
8
+ end
9
+
10
+ private
11
+
12
+ attr_reader :item
13
+
14
+ def lines
15
+ address_parts.map { |attribute|
16
+ next if item[attribute].blank?
17
+
18
+ [attribute, item[attribute]]
19
+ }.compact.to_h
20
+ end
21
+
22
+ def address_parts
23
+ %i[recipient street_address town_or_city state_or_county postal_code country]
24
+ end
25
+
26
+ def address_line(field, value)
27
+ content_tag(:span, value, { class: class_for_field_name(field) })
28
+ end
29
+
30
+ def class_for_field_name(field_name)
31
+ {
32
+ recipient: "organization-name",
33
+ street_address: "street-address",
34
+ town_or_city: "locality",
35
+ state_or_county: "region",
36
+ postal_code: "postal-code",
37
+ country: "country-name",
38
+ }[field_name]
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,19 @@
1
+ module ContentBlockTools
2
+ module Contacts
3
+ class ContactLinkComponent < ContentBlockTools::BaseComponent
4
+ include ContentBlockTools::Govspeak
5
+
6
+ def initialize(item:)
7
+ @item = item
8
+ end
9
+
10
+ private
11
+
12
+ attr_reader :item
13
+
14
+ def link_text
15
+ item[:label] || item[:url]
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ module ContentBlockTools
2
+ module Contacts
3
+ class EmailAddressComponent < ContentBlockTools::BaseComponent
4
+ include ContentBlockTools::Govspeak
5
+
6
+ def initialize(item:)
7
+ @item = item
8
+ end
9
+
10
+ private
11
+
12
+ attr_reader :item
13
+
14
+ def query_params
15
+ params = {
16
+ subject: item[:subject],
17
+ body: item[:body],
18
+ }.compact.map { |k, v| "#{k}=#{v}" }.join("&")
19
+
20
+ "?#{params}" if params.present?
21
+ end
22
+
23
+ def link_text
24
+ item[:label] || item[:email_address]
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,51 @@
1
+ module ContentBlockTools
2
+ module Contacts
3
+ class TelephoneComponent < ContentBlockTools::BaseComponent
4
+ include ContentBlockTools::Govspeak
5
+
6
+ def initialize(item:)
7
+ @item = item
8
+ end
9
+
10
+ private
11
+
12
+ attr_reader :item
13
+
14
+ def video_relay_service
15
+ @video_relay_service ||= item[:video_relay_service] || {}
16
+ end
17
+
18
+ def show_video_relay_service?
19
+ video_relay_service[:show].present?
20
+ end
21
+
22
+ def video_relay_service_content
23
+ "#{video_relay_service[:prefix]} #{video_relay_service[:telephone_number]}"
24
+ end
25
+
26
+ def bsl_guidance
27
+ @bsl_guidance ||= item[:bsl_guidance] || {}
28
+ end
29
+
30
+ def show_bsl_guidance?
31
+ bsl_guidance[:show].present?
32
+ end
33
+
34
+ def opening_hours
35
+ @opening_hours ||= item[:opening_hours] || {}
36
+ end
37
+
38
+ def show_opening_hours?
39
+ opening_hours[:show_opening_hours].present?
40
+ end
41
+
42
+ def call_charges
43
+ @call_charges ||= item[:call_charges] || {}
44
+ end
45
+
46
+ def show_call_charges?
47
+ call_charges[:show_call_charges_info_url].present?
48
+ end
49
+ end
50
+ end
51
+ end
@@ -109,7 +109,7 @@ module ContentBlockTools
109
109
  end
110
110
 
111
111
  def component
112
- "ContentBlockTools::Components::#{document_type.camelize}Component".constantize
112
+ "ContentBlockTools::#{document_type.camelize}Component".constantize
113
113
  end
114
114
 
115
115
  def field_presenter(field)
@@ -1,7 +1,15 @@
1
+ require "rails/engine"
2
+ require "view_component"
3
+ require "view_component/version"
4
+
1
5
  module ContentBlockTools
2
6
  class Engine < ::Rails::Engine
3
7
  isolate_namespace ContentBlockTools
4
8
 
9
+ config.autoload_paths = %W[
10
+ "#{root}/app/components"
11
+ ]
12
+
5
13
  initializer "content_block_tools.assets" do
6
14
  if defined? Rails.application.config.assets
7
15
  Rails.application.config.assets.paths += %w[
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentBlockTools
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.1"
5
5
  end
@@ -1,20 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "action_view"
4
- require "rails"
5
4
  require "uri"
6
5
  require "govspeak"
7
- require "view_component/base"
8
6
 
9
7
  require "content_block_tools/helpers/govspeak"
10
8
 
11
- require "content_block_tools/components/base_component"
12
- require "content_block_tools/components/contact_component"
13
- require "content_block_tools/components/contacts/address_component"
14
- require "content_block_tools/components/contacts/contact_link_component"
15
- require "content_block_tools/components/contacts/email_address_component"
16
- require "content_block_tools/components/contacts/telephone_component"
17
-
18
9
  require "content_block_tools/presenters/field_presenters/base_presenter"
19
10
  require "content_block_tools/presenters/field_presenters/contact/email_presenter"
20
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content_block_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -24,33 +24,33 @@ dependencies:
24
24
  - !ruby/object:Gem::Version
25
25
  version: 13.3.0
26
26
  - !ruby/object:Gem::Dependency
27
- name: rspec
27
+ name: rspec-html-matchers
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - '='
31
31
  - !ruby/object:Gem::Version
32
- version: 3.13.1
32
+ version: 0.10.0
33
33
  type: :development
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 3.13.1
39
+ version: 0.10.0
40
40
  - !ruby/object:Gem::Dependency
41
- name: rspec-html-matchers
41
+ name: rspec-rails
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 0.10.0
46
+ version: '0'
47
47
  type: :development
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 0.10.0
53
+ version: '0'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: rubocop-govuk
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -130,18 +130,18 @@ files:
130
130
  - README.md
131
131
  - app/assets/stylesheets/blocks/_contact.scss
132
132
  - app/assets/stylesheets/content_block_tools.scss
133
+ - app/components/content_block_tools/base_component.rb
134
+ - app/components/content_block_tools/contact_component.html.erb
135
+ - app/components/content_block_tools/contact_component.rb
136
+ - app/components/content_block_tools/contacts/address_component.html.erb
137
+ - app/components/content_block_tools/contacts/address_component.rb
138
+ - app/components/content_block_tools/contacts/contact_link_component.html.erb
139
+ - app/components/content_block_tools/contacts/contact_link_component.rb
140
+ - app/components/content_block_tools/contacts/email_address_component.html.erb
141
+ - app/components/content_block_tools/contacts/email_address_component.rb
142
+ - app/components/content_block_tools/contacts/telephone_component.html.erb
143
+ - app/components/content_block_tools/contacts/telephone_component.rb
133
144
  - lib/content_block_tools.rb
134
- - lib/content_block_tools/components/base_component.rb
135
- - lib/content_block_tools/components/contact_component.html.erb
136
- - lib/content_block_tools/components/contact_component.rb
137
- - lib/content_block_tools/components/contacts/address_component.html.erb
138
- - lib/content_block_tools/components/contacts/address_component.rb
139
- - lib/content_block_tools/components/contacts/contact_link_component.html.erb
140
- - lib/content_block_tools/components/contacts/contact_link_component.rb
141
- - lib/content_block_tools/components/contacts/email_address_component.html.erb
142
- - lib/content_block_tools/components/contacts/email_address_component.rb
143
- - lib/content_block_tools/components/contacts/telephone_component.html.erb
144
- - lib/content_block_tools/components/contacts/telephone_component.rb
145
145
  - lib/content_block_tools/content_block.rb
146
146
  - lib/content_block_tools/content_block_reference.rb
147
147
  - lib/content_block_tools/engine.rb
@@ -1,15 +0,0 @@
1
- module ContentBlockTools
2
- module Components
3
- class BaseComponent < ViewComponent::Base
4
- def render
5
- render_in(view_context)
6
- end
7
-
8
- private
9
-
10
- def view_context
11
- ActionView::Base.new(ActionView::LookupContext.new([]), {}, nil)
12
- end
13
- end
14
- end
15
- end
@@ -1,31 +0,0 @@
1
- module ContentBlockTools
2
- module Components
3
- class ContactComponent < ContentBlockTools::Components::BaseComponent
4
- BLOCK_TYPES = %i[addresses email_addresses telephones contact_links].freeze
5
-
6
- def initialize(content_block:, block_type: nil, block_name: nil)
7
- @content_block = content_block
8
- @block_type = block_type
9
- @block_name = block_name
10
- end
11
-
12
- private
13
-
14
- attr_reader :content_block, :block_type, :block_name
15
-
16
- def component_for_block_type(block_type)
17
- "ContentBlockTools::Components::Contacts::#{block_type.to_s.singularize.camelize}Component".constantize
18
- end
19
-
20
- def content_by_block_type
21
- @content_by_block_type ||= content_block.details.keys.map { |key|
22
- [key, content_block.details[key]&.values]
23
- }.to_h
24
- end
25
-
26
- def item_to_render
27
- content_block.details.dig(block_type, block_name)
28
- end
29
- end
30
- end
31
- end
@@ -1,44 +0,0 @@
1
- module ContentBlockTools
2
- module Components
3
- module Contacts
4
- class AddressComponent < ContentBlockTools::Components::BaseComponent
5
- include ContentBlockTools::Govspeak
6
-
7
- def initialize(item:)
8
- @item = item
9
- end
10
-
11
- private
12
-
13
- attr_reader :item
14
-
15
- def lines
16
- address_parts.map { |attribute|
17
- next if item[attribute].blank?
18
-
19
- [attribute, item[attribute]]
20
- }.compact.to_h
21
- end
22
-
23
- def address_parts
24
- %i[recipient street_address town_or_city state_or_county postal_code country]
25
- end
26
-
27
- def address_line(field, value)
28
- content_tag(:span, value, { class: class_for_field_name(field) })
29
- end
30
-
31
- def class_for_field_name(field_name)
32
- {
33
- recipient: "organization-name",
34
- street_address: "street-address",
35
- town_or_city: "locality",
36
- state_or_county: "region",
37
- postal_code: "postal-code",
38
- country: "country-name",
39
- }[field_name]
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,21 +0,0 @@
1
- module ContentBlockTools
2
- module Components
3
- module Contacts
4
- class ContactLinkComponent < ContentBlockTools::Components::BaseComponent
5
- include ContentBlockTools::Govspeak
6
-
7
- def initialize(item:)
8
- @item = item
9
- end
10
-
11
- private
12
-
13
- attr_reader :item
14
-
15
- def link_text
16
- item[:label] || item[:url]
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,30 +0,0 @@
1
- module ContentBlockTools
2
- module Components
3
- module Contacts
4
- class EmailAddressComponent < ContentBlockTools::Components::BaseComponent
5
- include ContentBlockTools::Govspeak
6
-
7
- def initialize(item:)
8
- @item = item
9
- end
10
-
11
- private
12
-
13
- attr_reader :item
14
-
15
- def query_params
16
- params = {
17
- subject: item[:subject],
18
- body: item[:body],
19
- }.compact.map { |k, v| "#{k}=#{v}" }.join("&")
20
-
21
- "?#{params}" if params.present?
22
- end
23
-
24
- def link_text
25
- item[:label] || item[:email_address]
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,53 +0,0 @@
1
- module ContentBlockTools
2
- module Components
3
- module Contacts
4
- class TelephoneComponent < ContentBlockTools::Components::BaseComponent
5
- include ContentBlockTools::Govspeak
6
-
7
- def initialize(item:)
8
- @item = item
9
- end
10
-
11
- private
12
-
13
- attr_reader :item
14
-
15
- def video_relay_service
16
- @video_relay_service ||= item[:video_relay_service] || {}
17
- end
18
-
19
- def show_video_relay_service?
20
- video_relay_service[:show].present?
21
- end
22
-
23
- def video_relay_service_content
24
- "#{video_relay_service[:prefix]} #{video_relay_service[:telephone_number]}"
25
- end
26
-
27
- def bsl_guidance
28
- @bsl_guidance ||= item[:bsl_guidance] || {}
29
- end
30
-
31
- def show_bsl_guidance?
32
- bsl_guidance[:show].present?
33
- end
34
-
35
- def opening_hours
36
- @opening_hours ||= item[:opening_hours] || {}
37
- end
38
-
39
- def show_opening_hours?
40
- opening_hours[:show_opening_hours].present?
41
- end
42
-
43
- def call_charges
44
- @call_charges ||= item[:call_charges] || {}
45
- end
46
-
47
- def show_call_charges?
48
- call_charges[:show_call_charges_info_url].present?
49
- end
50
- end
51
- end
52
- end
53
- end