content_block_tools 0.7.0 → 0.9.0

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: 55ffab3c548b42f43db5e9ea658b4fc6cdd13e0d51eaef12c1c7b60a72f00bb7
4
- data.tar.gz: e6ca9db8eddd145974c49edb2a57b4f6b1b327b1f94a855a9ae2e61dc2765261
3
+ metadata.gz: 565c412328ad54e9e45ca5ce473e6876147543cf88900dafde91083042c6b0ab
4
+ data.tar.gz: 8de3aab0cbfb65213cf1dceadd420ebdd1c006d6f9e715963bb6e49383617b1b
5
5
  SHA512:
6
- metadata.gz: 6ce195b0111b12dcf83b791f3702e75e2d4edeb2abb1bb8caa827257780eb1f858b8a1f78bbdd4c7ae439968eed27d360d59026ad0a46bfb170930bbe67fd6bd
7
- data.tar.gz: a33e0a2898e36fd0c73245e115f9eac3732bf183c59c4836621b20ac89138a69d87ee234714b201c92421f49d035a8ee8c9dc35ad14601fdfb782d417c1a2612
6
+ metadata.gz: ffda22c0d89798cea8b029ee90c2bc65564ab25fe7de67047251aafd53b01b1a7f127bc5c4af9deebba2e21e968767380dbde01993d9d9143394f7e0308ad5a4
7
+ data.tar.gz: '07429aa7168f233ca8935cf7c20c4e30221bdf0a1970f4376ffa30214e5bd09307509f331e97fd86e30d8babe94c7e4242c5a2cfe757dc0bfacf00a4362e351b'
data/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@
7
7
  useful summary for people upgrading their application, not a replication
8
8
  of the commit log.
9
9
 
10
+ ## 0.9.0
11
+
12
+ - Render addresses within a `contact` div ([58](https://github.com/alphagov/govuk_content_block_tools/pull/58))
13
+
14
+ ## 0.8.0
15
+
16
+ - Add wrapper classes to contact sub-blocks ([57](https://github.com/alphagov/govuk_content_block_tools/pull/57))
17
+
10
18
  ## 0.7.0
11
19
 
12
20
  - Alter markup of contact ([55](https://github.com/alphagov/govuk_content_block_tools/pull/55))
@@ -75,7 +75,7 @@ module ContentBlockTools
75
75
  return content_block.embed_code
76
76
  end
77
77
 
78
- field_or_block_presenter.new(field_or_block_content).render
78
+ field_or_block_presenter.new(field_or_block_content, rendering_context: :field_names).render
79
79
  end
80
80
 
81
81
  def field_names
@@ -8,7 +8,7 @@ module ContentBlockTools
8
8
 
9
9
  attr_reader :item
10
10
 
11
- def initialize(item)
11
+ def initialize(item, **_args)
12
12
  @item = item
13
13
  end
14
14
 
@@ -1,15 +1,31 @@
1
+ require_relative "./block_level_contact_item"
2
+
1
3
  module ContentBlockTools
2
4
  module Presenters
3
5
  module BlockPresenters
4
6
  module Contact
5
7
  class AddressPresenter < ContentBlockTools::Presenters::BlockPresenters::BasePresenter
8
+ include ContentBlockTools::Presenters::BlockPresenters::Contact::BlockLevelContactItem
9
+
6
10
  def render
7
- content_tag(:p, class: "adr") do
8
- %i[street_address locality region postal_code country].map { |field|
9
- next if item[field].blank?
11
+ wrapper do
12
+ content_tag(:p, class: "adr") do
13
+ %i[street_address locality region postal_code country].map { |field|
14
+ next if item[field].blank?
15
+
16
+ content_tag(:span, item[field], { class: class_for_field_name(field) })
17
+ }.compact_blank.join(",<br/>").html_safe
18
+ end
19
+ end
20
+ end
10
21
 
11
- content_tag(:span, item[field], { class: class_for_field_name(field) })
12
- }.compact_blank.join(",<br/>").html_safe
22
+ def wrapper(&block)
23
+ if @rendering_context == :field_names
24
+ content_tag(:div, class: "contact") do
25
+ yield block
26
+ end
27
+ else
28
+ yield block
13
29
  end
14
30
  end
15
31
 
@@ -0,0 +1,26 @@
1
+ module ContentBlockTools
2
+ module Presenters
3
+ module BlockPresenters
4
+ module Contact
5
+ module BlockLevelContactItem
6
+ BASE_TAG_TYPE = :div
7
+
8
+ def initialize(item, rendering_context: :block, **_args)
9
+ @item = item
10
+ @rendering_context = rendering_context
11
+ end
12
+
13
+ def wrapper(&block)
14
+ if @rendering_context == :field_names
15
+ content_tag(:div, class: "contact") do
16
+ yield block
17
+ end
18
+ else
19
+ yield block
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,16 +1,22 @@
1
+ require_relative "./block_level_contact_item"
2
+
1
3
  module ContentBlockTools
2
4
  module Presenters
3
5
  module BlockPresenters
4
6
  module Contact
5
7
  class ContactFormPresenter < ContentBlockTools::Presenters::BlockPresenters::BasePresenter
8
+ include ContentBlockTools::Presenters::BlockPresenters::Contact::BlockLevelContactItem
9
+
6
10
  def render
7
- content_tag(:div, class: "email-url-number") do
8
- content_tag(:p) do
9
- concat content_tag(:span, item[:title])
10
- concat content_tag(:a,
11
- item[:url],
12
- class: "url",
13
- href: item[:url])
11
+ wrapper do
12
+ content_tag(:div, class: "email-url-number") do
13
+ content_tag(:p) do
14
+ concat content_tag(:span, item[:title])
15
+ concat content_tag(:a,
16
+ item[:url],
17
+ class: "url",
18
+ href: item[:url])
19
+ end
14
20
  end
15
21
  end
16
22
  end
@@ -1,16 +1,22 @@
1
+ require_relative "./block_level_contact_item"
2
+
1
3
  module ContentBlockTools
2
4
  module Presenters
3
5
  module BlockPresenters
4
6
  module Contact
5
7
  class EmailAddressPresenter < ContentBlockTools::Presenters::BlockPresenters::BasePresenter
8
+ include ContentBlockTools::Presenters::BlockPresenters::Contact::BlockLevelContactItem
9
+
6
10
  def render
7
- content_tag(:div, class: "email-url-number") do
8
- content_tag(:p) do
9
- concat content_tag(:span, item[:title])
10
- concat content_tag(:a,
11
- item[:email_address],
12
- class: "email",
13
- href: "mailto:#{item[:email_address]}")
11
+ wrapper do
12
+ content_tag(:div, class: "email-url-number") do
13
+ content_tag(:p) do
14
+ concat content_tag(:span, item[:title])
15
+ concat content_tag(:a,
16
+ item[:email_address],
17
+ class: "email",
18
+ href: "mailto:#{item[:email_address]}")
19
+ end
14
20
  end
15
21
  end
16
22
  end
@@ -1,15 +1,19 @@
1
+ require_relative "./block_level_contact_item"
2
+
1
3
  module ContentBlockTools
2
4
  module Presenters
3
5
  module BlockPresenters
4
6
  module Contact
5
7
  class TelephonePresenter < ContentBlockTools::Presenters::BlockPresenters::BasePresenter
6
- BASE_TAG_TYPE = :div
8
+ include ContentBlockTools::Presenters::BlockPresenters::Contact::BlockLevelContactItem
7
9
 
8
10
  def render
9
- content_tag(:div, class: "email-url-number") do
10
- concat number_list
11
- concat opening_hours_list if item[:opening_hours].present?
12
- concat call_charges_link
11
+ wrapper do
12
+ content_tag(:div, class: "email-url-number") do
13
+ concat number_list
14
+ concat opening_hours_list if item[:opening_hours].present?
15
+ concat call_charges_link
16
+ end
13
17
  end
14
18
  end
15
19
 
@@ -12,6 +12,8 @@ module ContentBlockTools
12
12
  BLOCK_PRESENTERS = {
13
13
  addresses: ContentBlockTools::Presenters::BlockPresenters::Contact::AddressPresenter,
14
14
  telephones: ContentBlockTools::Presenters::BlockPresenters::Contact::TelephonePresenter,
15
+ email_addresses: ContentBlockTools::Presenters::BlockPresenters::Contact::EmailAddressPresenter,
16
+ contact_forms: ContentBlockTools::Presenters::BlockPresenters::Contact::ContactFormPresenter,
15
17
  }.freeze
16
18
 
17
19
  has_embedded_objects :addresses, :email_addresses, :telephones, :contact_forms
@@ -8,7 +8,7 @@ module ContentBlockTools
8
8
 
9
9
  attr_reader :field
10
10
 
11
- def initialize(field)
11
+ def initialize(field, **_args)
12
12
  @field = field
13
13
  end
14
14
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentBlockTools
4
- VERSION = "0.7.0"
4
+ VERSION = "0.9.0"
5
5
  end
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.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -108,6 +108,7 @@ files:
108
108
  - lib/content_block_tools/presenters/base_presenter.rb
109
109
  - lib/content_block_tools/presenters/block_presenters/base_presenter.rb
110
110
  - lib/content_block_tools/presenters/block_presenters/contact/address_presenter.rb
111
+ - lib/content_block_tools/presenters/block_presenters/contact/block_level_contact_item.rb
111
112
  - lib/content_block_tools/presenters/block_presenters/contact/contact_form_presenter.rb
112
113
  - lib/content_block_tools/presenters/block_presenters/contact/email_address_presenter.rb
113
114
  - lib/content_block_tools/presenters/block_presenters/contact/telephone_presenter.rb