content_block_tools 0.5.1 → 0.5.3

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: a8de300ea972686e97b1fcbe422979f9a3876060ae7e69d575b8270e65c0c509
4
- data.tar.gz: 4db995f515fdbcb10c22695f03e74ba7d0d5c2f037b9870c52e274a54bee7674
3
+ metadata.gz: eae6ff92c882ed6bfee080071382b326d498eb2c968c1a647862aec6a256c2ef
4
+ data.tar.gz: 01166220c324cc80e9aba6a6267dc52f63e1802e8f2a8ae1320146829bbf3d26
5
5
  SHA512:
6
- metadata.gz: c74f391d6df0c5feee05dfbfafdb59576a99226029252c849a8a5714b44ea87a09fc54b4583e0de5424ccb9dfcc131d02c8477b309c3230c9536e8cb09e191df
7
- data.tar.gz: b24e0e97e96edd7791cf586282c740feb13a2832a0d1c59234f93539e2b8b652851a387675a147703ac10ca041120c0ac150af803dad49e7cc6a1dcac5fc3dcc
6
+ metadata.gz: 000253f63e76b3a3c7ff5fa020aa1b96e8b05236cdc5fbe9b4757afe26b48deff4a052098a4ec39bb42502b30d291c6cb69a68cf0ad08523b49d43032bd30aec
7
+ data.tar.gz: 7fb4acf5cbfae9c4ed46df225a81e812b18d78c0b52fe834ce72cd4275a6e23d90e49c79094729a2b269dea9f430d0a0a1536dc77f64920df65a2256d1da4467
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.3
11
+
12
+ - Add spacing to contact item titles ([35](https://github.com/alphagov/govuk_content_block_tools/pull/35))
13
+ - Add new fields to contact items ([35](https://github.com/alphagov/govuk_content_block_tools/pull/35))
14
+
15
+ ## 0.5.2
16
+
17
+ - Use `deep_symbolize_keys` when initializing a block's details ([31](https://github.com/alphagov/govuk_content_block_tools/pull/31))
18
+
10
19
  ## 0.5.1
11
20
 
12
21
  - Update dependencies
@@ -60,7 +60,7 @@ module ContentBlockTools
60
60
  end
61
61
 
62
62
  def details
63
- to_h[:details].symbolize_keys
63
+ to_h[:details].deep_symbolize_keys
64
64
  end
65
65
  end
66
66
  end
@@ -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.1"
4
+ VERSION = "0.5.3"
5
5
  end
@@ -6,6 +6,12 @@ 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
17
  require "content_block_tools/presenters/email_address_presenter"
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.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -106,6 +106,11 @@ 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
115
  - lib/content_block_tools/presenters/email_address_presenter.rb
111
116
  - lib/content_block_tools/presenters/field_presenters/base_presenter.rb
@@ -131,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
136
  - !ruby/object:Gem::Version
132
137
  version: '0'
133
138
  requirements: []
134
- rubygems_version: 3.6.8
139
+ rubygems_version: 3.6.9
135
140
  specification_version: 4
136
141
  summary: A suite of tools for working with GOV.UK Content Blocks
137
142
  test_files: []