content_block_tools 1.1.0 → 1.1.2

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 +14 -0
  3. data/{lib/content_block_tools/components → app/components/content_block_tools}/contact_component.html.erb +2 -2
  4. data/app/components/content_block_tools/contact_component.rb +27 -0
  5. data/app/components/content_block_tools/contacts/address_component.rb +40 -0
  6. data/app/components/content_block_tools/contacts/contact_link_component.rb +17 -0
  7. data/app/components/content_block_tools/contacts/email_address_component.rb +26 -0
  8. data/app/components/content_block_tools/contacts/telephone_component.rb +49 -0
  9. data/lib/content_block_tools/content_block.rb +5 -2
  10. data/lib/content_block_tools/engine.rb +8 -0
  11. data/lib/content_block_tools/version.rb +1 -1
  12. data/lib/content_block_tools.rb +0 -9
  13. metadata +34 -20
  14. data/lib/content_block_tools/components/base_component.rb +0 -15
  15. data/lib/content_block_tools/components/contact_component.rb +0 -31
  16. data/lib/content_block_tools/components/contacts/address_component.rb +0 -44
  17. data/lib/content_block_tools/components/contacts/contact_link_component.rb +0 -21
  18. data/lib/content_block_tools/components/contacts/email_address_component.rb +0 -30
  19. data/lib/content_block_tools/components/contacts/telephone_component.rb +0 -53
  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: dd6b4006445fa5c5a11bf7f14e6ccfcd1819a9bc043af6f3ad19a56334d54172
4
+ data.tar.gz: 8c513039b815152a5a3bdb0171dc89e4ec6934068ebc46c25c93d64801943d1f
5
5
  SHA512:
6
- metadata.gz: 62173df5e11a6023a91f7f2c39378098c89293ae6f5db96aa2289aca1f9cdbc030d5ed932b2d8fba1dc914d8514e3e87cb240c2377f034968b5ccfe47c515675
7
- data.tar.gz: fb9389766399957affb5c8c45640bd4324f26c383057ec3e458fbf2719b6dfe7eca81c7006294b041b1ca5fc65e51280ace5b632a1de513149061f2dc753563a
6
+ metadata.gz: 2c96843959e74701746dc5aa20e8b605ad811c810b703f55d6d2cd3ad84a5c17c43bfefe741a5099fedc31f3a67480ee3c4e1d9d8a0ef24d9d4fe4f9ea3eec54
7
+ data.tar.gz: d7a5a5463e75a58b615fa680e4f0ef264d95e1b5c14c2474b40fdc2e61c9bcb01064052cbcf70461968c059206b3fb288ea658328b9554bd3a15e002e17283a9
@@ -0,0 +1,14 @@
1
+ module ContentBlockTools
2
+ class BaseComponent < ViewComponent::Base
3
+ include ContentBlockTools::Govspeak
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
@@ -1,13 +1,13 @@
1
1
  <div class="vcard">
2
2
  <p class="fn org content-block__title"><%= content_block.title %></p>
3
3
 
4
- <% if block_type.present? && content_block.details[:description] %>
4
+ <% if !block_type.present? && content_block.details[:description] %>
5
5
  <%= render_govspeak(content_block.details[:description]) %>
6
6
  <% end %>
7
7
 
8
8
  <% if block_type.nil? %>
9
9
  <% BLOCK_TYPES.each do |block_type| %>
10
- <% content_by_block_type[block_type].each do |item| %>
10
+ <% content_for_block_type(block_type).each do |item| %>
11
11
  <p class="content-block__subtitle"><%= item[:title] %></p>
12
12
  <%= component_for_block_type(block_type).new(item:).render.html_safe %>
13
13
  <% end %>
@@ -0,0 +1,27 @@
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_for_block_type(block_type)
20
+ content_block.details.fetch(block_type, {}).values
21
+ end
22
+
23
+ def item_to_render
24
+ content_block.details.dig(block_type, block_name)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,40 @@
1
+ module ContentBlockTools
2
+ module Contacts
3
+ class AddressComponent < ContentBlockTools::BaseComponent
4
+ def initialize(item:)
5
+ @item = item
6
+ end
7
+
8
+ private
9
+
10
+ attr_reader :item
11
+
12
+ def lines
13
+ address_parts.map { |attribute|
14
+ next if item[attribute].blank?
15
+
16
+ [attribute, item[attribute]]
17
+ }.compact.to_h
18
+ end
19
+
20
+ def address_parts
21
+ %i[recipient street_address town_or_city state_or_county postal_code country]
22
+ end
23
+
24
+ def address_line(field, value)
25
+ content_tag(:span, value, { class: class_for_field_name(field) })
26
+ end
27
+
28
+ def class_for_field_name(field_name)
29
+ {
30
+ recipient: "organization-name",
31
+ street_address: "street-address",
32
+ town_or_city: "locality",
33
+ state_or_county: "region",
34
+ postal_code: "postal-code",
35
+ country: "country-name",
36
+ }[field_name]
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ module ContentBlockTools
2
+ module Contacts
3
+ class ContactLinkComponent < ContentBlockTools::BaseComponent
4
+ def initialize(item:)
5
+ @item = item
6
+ end
7
+
8
+ private
9
+
10
+ attr_reader :item
11
+
12
+ def link_text
13
+ item[:label] || item[:url]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ module ContentBlockTools
2
+ module Contacts
3
+ class EmailAddressComponent < ContentBlockTools::BaseComponent
4
+ def initialize(item:)
5
+ @item = item
6
+ end
7
+
8
+ private
9
+
10
+ attr_reader :item
11
+
12
+ def query_params
13
+ params = {
14
+ subject: item[:subject],
15
+ body: item[:body],
16
+ }.compact.map { |k, v| "#{k}=#{v}" }.join("&")
17
+
18
+ "?#{params}" if params.present?
19
+ end
20
+
21
+ def link_text
22
+ item[:label] || item[:email_address]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,49 @@
1
+ module ContentBlockTools
2
+ module Contacts
3
+ class TelephoneComponent < ContentBlockTools::BaseComponent
4
+ def initialize(item:)
5
+ @item = item
6
+ end
7
+
8
+ private
9
+
10
+ attr_reader :item
11
+
12
+ def video_relay_service
13
+ @video_relay_service ||= item[:video_relay_service] || {}
14
+ end
15
+
16
+ def show_video_relay_service?
17
+ video_relay_service[:show].present?
18
+ end
19
+
20
+ def video_relay_service_content
21
+ "#{video_relay_service[:prefix]} #{video_relay_service[:telephone_number]}"
22
+ end
23
+
24
+ def bsl_guidance
25
+ @bsl_guidance ||= item[:bsl_guidance] || {}
26
+ end
27
+
28
+ def show_bsl_guidance?
29
+ bsl_guidance[:show].present?
30
+ end
31
+
32
+ def opening_hours
33
+ @opening_hours ||= item[:opening_hours] || {}
34
+ end
35
+
36
+ def show_opening_hours?
37
+ opening_hours[:show_opening_hours].present?
38
+ end
39
+
40
+ def call_charges
41
+ @call_charges ||= item[:call_charges] || {}
42
+ end
43
+
44
+ def show_call_charges?
45
+ call_charges[:show_call_charges_info_url].present?
46
+ end
47
+ end
48
+ end
49
+ end
@@ -40,6 +40,7 @@ module ContentBlockTools
40
40
  # @return [String]
41
41
  class ContentBlock
42
42
  include ActionView::Helpers::TagHelper
43
+ class UnknownComponentError < StandardError; end
43
44
 
44
45
  CONTENT_BLOCK_PREFIX = "content_block_".freeze
45
46
 
@@ -87,7 +88,7 @@ module ContentBlockTools
87
88
 
88
89
  def content
89
90
  field_names.present? ? field_or_block_content : component.new(content_block: self).render
90
- rescue NameError
91
+ rescue UnknownComponentError
91
92
  title
92
93
  end
93
94
 
@@ -109,7 +110,9 @@ module ContentBlockTools
109
110
  end
110
111
 
111
112
  def component
112
- "ContentBlockTools::Components::#{document_type.camelize}Component".constantize
113
+ "ContentBlockTools::#{document_type.camelize}Component".constantize
114
+ rescue NameError
115
+ raise UnknownComponentError
113
116
  end
114
117
 
115
118
  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.2"
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.2
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
@@ -65,6 +65,20 @@ dependencies:
65
65
  - - '='
66
66
  - !ruby/object:Gem::Version
67
67
  version: 5.1.18
68
+ - !ruby/object:Gem::Dependency
69
+ name: simplecov
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
68
82
  - !ruby/object:Gem::Dependency
69
83
  name: actionview
70
84
  requirement: !ruby/object:Gem::Requirement
@@ -130,18 +144,18 @@ files:
130
144
  - README.md
131
145
  - app/assets/stylesheets/blocks/_contact.scss
132
146
  - app/assets/stylesheets/content_block_tools.scss
147
+ - app/components/content_block_tools/base_component.rb
148
+ - app/components/content_block_tools/contact_component.html.erb
149
+ - app/components/content_block_tools/contact_component.rb
150
+ - app/components/content_block_tools/contacts/address_component.html.erb
151
+ - app/components/content_block_tools/contacts/address_component.rb
152
+ - app/components/content_block_tools/contacts/contact_link_component.html.erb
153
+ - app/components/content_block_tools/contacts/contact_link_component.rb
154
+ - app/components/content_block_tools/contacts/email_address_component.html.erb
155
+ - app/components/content_block_tools/contacts/email_address_component.rb
156
+ - app/components/content_block_tools/contacts/telephone_component.html.erb
157
+ - app/components/content_block_tools/contacts/telephone_component.rb
133
158
  - 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
159
  - lib/content_block_tools/content_block.rb
146
160
  - lib/content_block_tools/content_block_reference.rb
147
161
  - 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