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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 225bb65ced69b2b51cb081edfe13a9c6456747d64d3a1f7b561d58dc2c9aa47c
|
|
4
|
+
data.tar.gz: 58a80f5c4111e17f38a2eb1baffa6921fea0f7d405a69180423f5599b8473cc6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
|
|
66
|
+
failure_message
|
|
63
67
|
end
|
|
64
68
|
end
|
|
65
69
|
|