content_block_tools 1.1.1 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb006e7903ec6cae4253ae9332308c42accf3f4e424da21e3bdb3d5ce2efe89c
4
- data.tar.gz: 5cfd7df4e3bfa56fcd4b1333e7d09d0ab26b71de12cc6e8f7f13855493d5d6c6
3
+ metadata.gz: dd6b4006445fa5c5a11bf7f14e6ccfcd1819a9bc043af6f3ad19a56334d54172
4
+ data.tar.gz: 8c513039b815152a5a3bdb0171dc89e4ec6934068ebc46c25c93d64801943d1f
5
5
  SHA512:
6
- metadata.gz: 4d084a5f1684a8189d3b38db0d8df0a453e461b7c96aba6612493a326232312593de5fb0ec97402141c8865862fd36b09c6ff7bfca5796c287aedce4b2e93e40
7
- data.tar.gz: ddf80b36ba7d6292219afb73df52a6df83b04640c8a2befec36054e9382cd34d5b6b573de844e67dfdbe91d3f17fa72ec8cba3df12d0c40d1112dcaee3576eb0
6
+ metadata.gz: 2c96843959e74701746dc5aa20e8b605ad811c810b703f55d6d2cd3ad84a5c17c43bfefe741a5099fedc31f3a67480ee3c4e1d9d8a0ef24d9d4fe4f9ea3eec54
7
+ data.tar.gz: d7a5a5463e75a58b615fa680e4f0ef264d95e1b5c14c2474b40fdc2e61c9bcb01064052cbcf70461968c059206b3fb288ea658328b9554bd3a15e002e17283a9
@@ -1,5 +1,6 @@
1
1
  module ContentBlockTools
2
2
  class BaseComponent < ViewComponent::Base
3
+ include ContentBlockTools::Govspeak
3
4
  def render
4
5
  render_in(view_context)
5
6
  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 %>
@@ -16,10 +16,8 @@ module ContentBlockTools
16
16
  "ContentBlockTools::Contacts::#{block_type.to_s.singularize.camelize}Component".constantize
17
17
  end
18
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
19
+ def content_for_block_type(block_type)
20
+ content_block.details.fetch(block_type, {}).values
23
21
  end
24
22
 
25
23
  def item_to_render
@@ -1,8 +1,6 @@
1
1
  module ContentBlockTools
2
2
  module Contacts
3
3
  class AddressComponent < ContentBlockTools::BaseComponent
4
- include ContentBlockTools::Govspeak
5
-
6
4
  def initialize(item:)
7
5
  @item = item
8
6
  end
@@ -1,8 +1,6 @@
1
1
  module ContentBlockTools
2
2
  module Contacts
3
3
  class ContactLinkComponent < ContentBlockTools::BaseComponent
4
- include ContentBlockTools::Govspeak
5
-
6
4
  def initialize(item:)
7
5
  @item = item
8
6
  end
@@ -1,8 +1,6 @@
1
1
  module ContentBlockTools
2
2
  module Contacts
3
3
  class EmailAddressComponent < ContentBlockTools::BaseComponent
4
- include ContentBlockTools::Govspeak
5
-
6
4
  def initialize(item:)
7
5
  @item = item
8
6
  end
@@ -1,8 +1,6 @@
1
1
  module ContentBlockTools
2
2
  module Contacts
3
3
  class TelephoneComponent < ContentBlockTools::BaseComponent
4
- include ContentBlockTools::Govspeak
5
-
6
4
  def initialize(item:)
7
5
  @item = item
8
6
  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
 
@@ -110,6 +111,8 @@ module ContentBlockTools
110
111
 
111
112
  def component
112
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,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentBlockTools
4
- VERSION = "1.1.1"
4
+ VERSION = "1.1.2"
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: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -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