content_block_tools 2.0.0 → 2.1.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: 99811790c4d8143e24ce25e8363e24daa1f1357abe68e4774e80762540a7a99e
4
- data.tar.gz: 25d492eae3b951462342163d5d05388556d190e469215ff8e2dd4fb8a8083f21
3
+ metadata.gz: 225bb65ced69b2b51cb081edfe13a9c6456747d64d3a1f7b561d58dc2c9aa47c
4
+ data.tar.gz: 58a80f5c4111e17f38a2eb1baffa6921fea0f7d405a69180423f5599b8473cc6
5
5
  SHA512:
6
- metadata.gz: 62056453f1c35fb2c14016cb6f514e473f8d6f49208cf7355917086cd0b80b3fd58e5f3e66fc5addd8fc26fcb515e91fc1b9c24e4ce2d975d584c817feaac872
7
- data.tar.gz: 961d83d5c8bf96dd0699dc58c8f4f60e69b17e9707bd6e9c205dec1b3c981641c6db1431ae068ed389cc4bcac8daf4d362f594ae28c8ef2273ef6e2f3a20c2ff
6
+ metadata.gz: 4b9f52c49ce3fe7ee95fcde5c5973e8c8d76c70dbb740fd4f96e0c6a57806c526f82257c0a88f2b9b58c5d404c3835d3dc756c587d49ef0748d1dc9f9f18e96d
7
+ data.tar.gz: 197c2203d07a5bb9b16efe787a60d741b28e81eabd7156e5708d1939b363e6a012fff0cc94e2b34f85c9ae414d37c3df84c107a65e5ddab0b1f21f45d01c8037
@@ -8,11 +8,10 @@ module ContentBlockTools
8
8
  def initialize(content_block:, _block_type: nil, _block_name: nil)
9
9
  @content_block = content_block
10
10
  validate_format!
11
- validate_presence_of_income_tax_rates! if tax_table_format?
12
11
  end
13
12
 
14
13
  def render
15
- return "" unless tax_table_format?
14
+ raise format_inapplicable_error unless tax_table_format? && able_to_format_as_table?
16
15
 
17
16
  Tax::TaxTableComponent.new(rates: income_tax_rates).render
18
17
  end
@@ -23,17 +22,18 @@ module ContentBlockTools
23
22
 
24
23
  delegate :format, :details, to: :content_block
25
24
 
25
+ def format_inapplicable_error
26
+ InvalidFormatError.new("Cannot render 'tax_table' format: missing income tax rates")
27
+ end
28
+
26
29
  def validate_format!
27
30
  return if SUPPORTED_FORMATS.include?(format)
28
31
 
29
32
  raise InvalidFormatError, "Unknown format '#{format}' for tax"
30
33
  end
31
34
 
32
- def validate_presence_of_income_tax_rates!
33
- return if income_tax_rates&.any?
34
-
35
- raise InvalidFormatError,
36
- "Cannot render 'tax_table' format: missing income tax rates"
35
+ def able_to_format_as_table?
36
+ income_tax_rates&.present?
37
37
  end
38
38
 
39
39
  def tax_table_format?
@@ -39,14 +39,18 @@ module ContentBlockTools
39
39
 
40
40
  attr_reader :content_block
41
41
 
42
+ def failure_message
43
+ "Unable to render block '#{content_block.title}' #{content_block.embed_code}"
44
+ end
45
+
42
46
  def base_tag
43
47
  rendering_block? ? :div : :span
44
48
  end
45
49
 
46
50
  def content
47
51
  internal_content_path.present? ? field_or_block_content : component.new(content_block:).render
48
- rescue UnknownComponentError
49
- content_block.title
52
+ rescue UnknownComponentError, InvalidFormatError
53
+ failure_message
50
54
  end
51
55
 
52
56
  def field_or_block_content
@@ -59,7 +63,7 @@ module ContentBlockTools
59
63
  render_hash_content(field_content)
60
64
  else
61
65
  log_content_not_found
62
- content_block.embed_code
66
+ failure_message
63
67
  end
64
68
  end
65
69
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentBlockTools
4
- VERSION = "2.0.0"
4
+ VERSION = "2.1.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: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev