content_block_tools 0.5.2 → 0.5.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe6e7c2a4c34c9af7eeee0764b6021b65b0cbaf6db769b27a16119faf9775b2e
4
- data.tar.gz: 0d5664a937d3891d536c79915861d91be62b070015bddfaab625299be7f36423
3
+ metadata.gz: 317a33abd963522a97d5421d905b916f8c178935645081bba320b984ed0108b4
4
+ data.tar.gz: 9503e913fb0c5826cfbafae81e7263351e149b44009e0bb836ac1d1dc00c8ca4
5
5
  SHA512:
6
- metadata.gz: ea555fd3c90f65675e1d81925cc78a1e96643cdd69104a32628a155fef2e262596dc7263c2bbe885510f4f5467b4e64e93ff9e1c86d3fe0ba39c5e0d5bdef5e6
7
- data.tar.gz: bc3208ed4bab8c233385f1fbf5d4f6c5170e69cd3f051c5c85b42975297053e2f222fe24446da59d9c700f00270862da2ad31639a99e512a4abff98345e456b9
6
+ metadata.gz: 716b6950c8633ccc8f80eba30d685e117ce638471f9eadc5c7353e8189a2e2d0eb263e86dd4f6e340cc68d3c54b234e758fc3211ff0078e5ab0dba12c298695e
7
+ data.tar.gz: '078faf1ebb791e906f33744cf8dd0f3a6a8c5355c5b2296926bc68eaccff13c931df39786ac59b5af9958fbe61b7162a9868cb50edf5afb94e4b7f33a06f39d5'
data/CHANGELOG.md CHANGED
@@ -7,6 +7,15 @@
7
7
  useful summary for people upgrading their application, not a replication
8
8
  of the commit log.
9
9
 
10
+ ## 0.5.4
11
+
12
+ - Remove old email_address and postal_address types ([38](https://github.com/alphagov/govuk_content_block_tools/pull/38))
13
+
14
+ ## 0.5.3
15
+
16
+ - Add spacing to contact item titles ([35](https://github.com/alphagov/govuk_content_block_tools/pull/35))
17
+ - Add new fields to contact items ([35](https://github.com/alphagov/govuk_content_block_tools/pull/35))
18
+
10
19
  ## 0.5.2
11
20
 
12
21
  - Use `deep_symbolize_keys` when initializing a block's details ([31](https://github.com/alphagov/govuk_content_block_tools/pull/31))
data/README.md CHANGED
@@ -19,13 +19,13 @@ or add it to your Gemfile
19
19
  To find embed code in a block of text, use `ContentBlockReference.find_all_in_document`:
20
20
 
21
21
  ```ruby
22
- content = "Hello - here is a embed code {{embed:content_block_email_address:be24ee44-b636-4a3e-b979-0da27b4a8e62}}"
22
+ content = "Hello - here is a embed code {{embed:content_block_pension:be24ee44-b636-4a3e-b979-0da27b4a8e62}}"
23
23
  ContentBlockReference.find_all_in_document(content)
24
24
  # =>
25
25
  #[#<data ContentBlockTools::ContentBlockReference
26
- # document_type="content_block_email_address",
26
+ # document_type="content_block_pension",
27
27
  # content_id="be24ee44-b636-4a3e-b979-0da27b4a8e62",
28
- # embed_code="{{embed:content_block_email_address:be24ee44-b636-4a3e-b979-0da27b4a8e62}}">]
28
+ # embed_code="{{embed:content_block_pension:be24ee44-b636-4a3e-b979-0da27b4a8e62}}">]
29
29
  ```
30
30
 
31
31
  ### Rendering a content block
@@ -23,7 +23,7 @@ module ContentBlockTools
23
23
  # will be used to render the content block. All supported document_types are documented in
24
24
  # {ContentBlockTools::ContentBlockReference::SUPPORTED_DOCUMENT_TYPES}
25
25
  # @example
26
- # content_block.document_type #=> "content_block_email_address"
26
+ # content_block.document_type #=> "content_block_pension"
27
27
  # @return [String] the document type
28
28
  # @api public
29
29
  #
@@ -37,15 +37,13 @@ module ContentBlockTools
37
37
  # @!attribute [r] embed_code
38
38
  # The embed_code used for a block containing optional field name
39
39
  # @example
40
- # content_block_reference.embed_code #=> "{{embed:content_block_email_address:2b92cade-549c-4449-9796-e7a3957f3a86}}"
41
- # content_block_reference.embed_code #=> "{{embed:content_block_postal_address:2b92cade-549c-4449-9796-e7a3957f3a86/field_name}}"
40
+ # content_block_reference.embed_code #=> "{{embed:content_block_pension:2b92cade-549c-4449-9796-e7a3957f3a86}}"
41
+ # content_block_reference.embed_code #=> "{{embed:content_block_contact:2b92cade-549c-4449-9796-e7a3957f3a86/field_name}}"
42
42
  # @return [String]
43
43
  class ContentBlock < Data
44
44
  # A lookup of presenters for particular content block types
45
45
  CONTENT_PRESENTERS = {
46
46
  "content_block_contact" => ContentBlockTools::Presenters::ContactPresenter,
47
- "content_block_email_address" => ContentBlockTools::Presenters::EmailAddressPresenter,
48
- "content_block_postal_address" => ContentBlockTools::Presenters::PostalAddressPresenter,
49
47
  "content_block_pension" => ContentBlockTools::Presenters::PensionPresenter,
50
48
  }.freeze
51
49
 
@@ -9,7 +9,7 @@ module ContentBlockTools
9
9
  # will be used to render the content block. All supported document_types are documented in
10
10
  # {ContentBlockTools::ContentBlockReference::SUPPORTED_DOCUMENT_TYPES}
11
11
  # @example
12
- # content_block_reference.document_type #=> "content_block_email_address"
12
+ # content_block_reference.document_type #=> "content_block_pension"
13
13
  # @return [String] the document type
14
14
  # @api public
15
15
  #
@@ -24,11 +24,11 @@ module ContentBlockTools
24
24
  # @!attribute [r] embed_code
25
25
  # The embed_code used for a block
26
26
  # @example
27
- # content_block_reference.embed_code #=> "{{embed:content_block_email_address:2b92cade-549c-4449-9796-e7a3957f3a86}}"
27
+ # content_block_reference.embed_code #=> "{{embed:content_block_pension:2b92cade-549c-4449-9796-e7a3957f3a86}}"
28
28
  # @return [String]
29
29
  class ContentBlockReference < Data
30
30
  # An array of the supported document types
31
- SUPPORTED_DOCUMENT_TYPES = %w[contact content_block_email_address content_block_postal_address content_block_pension content_block_contact].freeze
31
+ SUPPORTED_DOCUMENT_TYPES = %w[contact content_block_pension content_block_contact].freeze
32
32
  # The regex used to find UUIDs
33
33
  UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
34
34
  # The regex used to find content ID aliases
@@ -10,6 +10,16 @@ module ContentBlockTools
10
10
  # A lookup of presenters for particular fields - can be overridden in a subclass
11
11
  FIELD_PRESENTERS = {}.freeze
12
12
 
13
+ def self.has_embedded_objects(*object_types)
14
+ @embedded_objects = object_types
15
+
16
+ object_types.each do |object_type|
17
+ define_method(object_type) do
18
+ embedded_objects_of_type(object_type)
19
+ end
20
+ end
21
+ end
22
+
13
23
  # Returns a new presenter object
14
24
  #
15
25
  # @param [{ContentBlockTools::ContentBlock}] content_block A content block object
@@ -88,6 +98,14 @@ module ContentBlockTools
88
98
  def base_tag
89
99
  field_names ? :span : self.class::BASE_TAG_TYPE
90
100
  end
101
+
102
+ def embedded_objects_of_type(type)
103
+ content_block.details.fetch(type, {}).values
104
+ end
105
+
106
+ def embedded_objects
107
+ self.class.instance_variable_get("@embedded_objects")
108
+ end
91
109
  end
92
110
  end
93
111
  end
@@ -0,0 +1,22 @@
1
+ module ContentBlockTools
2
+ module Presenters
3
+ module BlockPresenters
4
+ class BasePresenter
5
+ include ActionView::Context
6
+ include ActionView::Helpers::TextHelper
7
+
8
+ attr_reader :item
9
+
10
+ def initialize(item)
11
+ @item = item
12
+ end
13
+
14
+ def title_content
15
+ "#{item[:title]}: "
16
+ end
17
+
18
+ def render; end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module ContentBlockTools
2
+ module Presenters
3
+ module BlockPresenters
4
+ module Contact
5
+ class AddressPresenter < ContentBlockTools::Presenters::BlockPresenters::BasePresenter
6
+ def render
7
+ content_tag(:p, class: "govuk-body govuk-!-margin-bottom-4") do
8
+ [
9
+ item[:street_address],
10
+ item[:locality],
11
+ item[:region],
12
+ item[:postal_code],
13
+ item[:country],
14
+ ].compact_blank.join(",<br/>").html_safe
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module ContentBlockTools
2
+ module Presenters
3
+ module BlockPresenters
4
+ module Contact
5
+ class ContactFormPresenter < ContentBlockTools::Presenters::BlockPresenters::BasePresenter
6
+ def render
7
+ content_tag(:p, class: "govuk-body govuk-!-margin-bottom-4") do
8
+ concat content_tag(:span, title_content)
9
+ concat content_tag(:a,
10
+ item[:url],
11
+ class: "govuk-link",
12
+ href: item[:url])
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module ContentBlockTools
2
+ module Presenters
3
+ module BlockPresenters
4
+ module Contact
5
+ class EmailAddressPresenter < ContentBlockTools::Presenters::BlockPresenters::BasePresenter
6
+ def render
7
+ content_tag(:p, class: "govuk-body govuk-!-margin-bottom-4") do
8
+ concat content_tag(:span, title_content)
9
+ concat content_tag(:a,
10
+ item[:email_address],
11
+ class: "govuk-link",
12
+ href: "mailto:#{item[:email_address]}")
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module ContentBlockTools
2
+ module Presenters
3
+ module BlockPresenters
4
+ module Contact
5
+ class TelephonePresenter < ContentBlockTools::Presenters::BlockPresenters::BasePresenter
6
+ def render
7
+ content_tag(:p, class: "govuk-body govuk-!-margin-bottom-4") do
8
+ concat content_tag(:span, title_content)
9
+ concat content_tag(:a,
10
+ item[:telephone],
11
+ class: "govuk-link",
12
+ href: "tel:#{CGI.escape item[:telephone]}")
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -9,42 +9,22 @@ module ContentBlockTools
9
9
  email_address: ContentBlockTools::Presenters::FieldPresenters::Contact::EmailAddressPresenter,
10
10
  }.freeze
11
11
 
12
+ has_embedded_objects :addresses, :email_addresses, :telephones, :contact_forms
13
+
12
14
  private
13
15
 
14
16
  def default_content
15
17
  content_tag(:div, class: "contact") do
16
18
  concat content_tag(:p, content_block.title, class: "govuk-body")
17
- concat(email_addresses.map { |email_address| email_address_content(email_address) }.join.html_safe) if email_addresses.any?
18
- concat(phone_numbers.map { |phone_number| phone_number_content(phone_number) }.join.html_safe) if phone_numbers.any?
19
+ embedded_objects.each do |object|
20
+ items = send(object)
21
+ concat(items.map { |item| presenter_for_object_type(object).new(item).render }.join.html_safe)
22
+ end
19
23
  end
20
24
  end
21
25
 
22
- def email_address_content(email_address)
23
- content_tag(:p, class: "govuk-body govuk-!-margin-bottom-4") do
24
- concat content_tag(:span, email_address[:title])
25
- concat content_tag(:a,
26
- email_address[:email_address],
27
- class: "govuk-link",
28
- href: "mailto:#{email_address[:email_address]}")
29
- end
30
- end
31
-
32
- def phone_number_content(phone_number)
33
- content_tag(:p, class: "govuk-body govuk-!-margin-bottom-4") do
34
- concat content_tag(:span, phone_number[:title])
35
- concat content_tag(:a,
36
- phone_number[:telephone],
37
- class: "govuk-link",
38
- href: "tel:#{CGI.escape phone_number[:telephone]}")
39
- end
40
- end
41
-
42
- def email_addresses
43
- content_block.details[:email_addresses]&.values
44
- end
45
-
46
- def phone_numbers
47
- content_block.details[:telephones]&.values
26
+ def presenter_for_object_type(type)
27
+ "ContentBlockTools::Presenters::BlockPresenters::Contact::#{type.to_s.singularize.underscore.camelize}Presenter".constantize
48
28
  end
49
29
  end
50
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentBlockTools
4
- VERSION = "0.5.2"
4
+ VERSION = "0.5.4"
5
5
  end
@@ -6,10 +6,14 @@ require "uri"
6
6
  require "content_block_tools/presenters/field_presenters/base_presenter"
7
7
  require "content_block_tools/presenters/field_presenters/contact/email_address_presenter"
8
8
 
9
+ require "content_block_tools/presenters/block_presenters/base_presenter"
10
+ require "content_block_tools/presenters/block_presenters/contact/address_presenter"
11
+ require "content_block_tools/presenters/block_presenters/contact/contact_form_presenter"
12
+ require "content_block_tools/presenters/block_presenters/contact/email_address_presenter"
13
+ require "content_block_tools/presenters/block_presenters/contact/telephone_presenter"
14
+
9
15
  require "content_block_tools/presenters/base_presenter"
10
16
  require "content_block_tools/presenters/contact_presenter"
11
- require "content_block_tools/presenters/email_address_presenter"
12
- require "content_block_tools/presenters/postal_address_presenter"
13
17
  require "content_block_tools/presenters/pension_presenter"
14
18
 
15
19
  require "content_block_tools/content_block"
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: 0.5.2
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -106,12 +106,15 @@ files:
106
106
  - lib/content_block_tools/content_block.rb
107
107
  - lib/content_block_tools/content_block_reference.rb
108
108
  - lib/content_block_tools/presenters/base_presenter.rb
109
+ - lib/content_block_tools/presenters/block_presenters/base_presenter.rb
110
+ - lib/content_block_tools/presenters/block_presenters/contact/address_presenter.rb
111
+ - lib/content_block_tools/presenters/block_presenters/contact/contact_form_presenter.rb
112
+ - lib/content_block_tools/presenters/block_presenters/contact/email_address_presenter.rb
113
+ - lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb
109
114
  - lib/content_block_tools/presenters/contact_presenter.rb
110
- - lib/content_block_tools/presenters/email_address_presenter.rb
111
115
  - lib/content_block_tools/presenters/field_presenters/base_presenter.rb
112
116
  - lib/content_block_tools/presenters/field_presenters/contact/email_address_presenter.rb
113
117
  - lib/content_block_tools/presenters/pension_presenter.rb
114
- - lib/content_block_tools/presenters/postal_address_presenter.rb
115
118
  - lib/content_block_tools/version.rb
116
119
  homepage: https://github.com/alphagov/content_block_tools
117
120
  licenses:
@@ -131,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
134
  - !ruby/object:Gem::Version
132
135
  version: '0'
133
136
  requirements: []
134
- rubygems_version: 3.6.8
137
+ rubygems_version: 3.6.9
135
138
  specification_version: 4
136
139
  summary: A suite of tools for working with GOV.UK Content Blocks
137
140
  test_files: []
@@ -1,14 +0,0 @@
1
- module ContentBlockTools
2
- module Presenters
3
- class EmailAddressPresenter < BasePresenter
4
- private
5
-
6
- def content
7
- content_tag(:a,
8
- content_block.details[:email_address],
9
- class: "govuk-link",
10
- href: "mailto:#{content_block.details[:email_address]}")
11
- end
12
- end
13
- end
14
- end
@@ -1,11 +0,0 @@
1
- module ContentBlockTools
2
- module Presenters
3
- class PostalAddressPresenter < BasePresenter
4
- private
5
-
6
- def default_content
7
- "#{content_block.details[:line_1]}, #{content_block.details[:town_or_city]}, #{content_block.details[:postcode]}"
8
- end
9
- end
10
- end
11
- end