content_block_tools 1.12.2 → 1.14.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: bab802e5506b1e8ead0575aa9b4bb1ea55f758ddd8718807b36a28e2ebe1a2e2
4
- data.tar.gz: d738076ac485af7f80aa4f654be65453c5b0350e1bcb449639d7038eab6d9733
3
+ metadata.gz: d0a288bfcedc47c6be204b60ef1535f1cbe1d72d71bdcd14ec31f12028ebe0ba
4
+ data.tar.gz: 3c2e76b989fb4f3f2d6a4fdc23028e13a3a6f8825bcc5e65753456f2e0d56010
5
5
  SHA512:
6
- metadata.gz: 999755205255734045f09e4ab0e7aeded0df0e6a74b7bff41379ef93648acaf614b6ed64906f4b26ecfb70feab499756692bb9bb73daa946912f291b90f66993
7
- data.tar.gz: d21b1892b1506df372be1249f476c20f320c6b4d9a4828080506070f99d5a92b0b0a382929f0c66268d64f1f4d651bea6ba676ae155f5225193696fe358082fb
6
+ metadata.gz: d9c5da6afdb124ba34a81e510f202249018418e2333472f9c2ee6b39c785e970999a957773b18dc79cb78882aef8e78aef0900772b4cd1a0a2a772fd6ecc8409
7
+ data.tar.gz: e99a7f610c0bbfb25a19ebe7958d7a38dd226eb30feece6c425b1cf1dd92a32a04b07ca82b2fac99afd264734bed5a6b20075cdb6845f710b186a22c434623a3
@@ -0,0 +1,18 @@
1
+ <table class="govuk-table">
2
+ <thead class="govuk-table__head">
3
+ <tr class="govuk-table__row">
4
+ <% table_head.each do |header| %>
5
+ <th scope="col" class="govuk-table__header"><%= header[:text] %></th>
6
+ <% end %>
7
+ </tr>
8
+ </thead>
9
+ <tbody class="govuk-table__body">
10
+ <% table_rows.each do |row| %>
11
+ <tr class="govuk-table__row">
12
+ <% row.each do |cell| %>
13
+ <td class="govuk-table__cell"><%= cell[:text] %></td>
14
+ <% end %>
15
+ </tr>
16
+ <% end %>
17
+ </tbody>
18
+ </table>
@@ -0,0 +1,73 @@
1
+ module ContentBlockTools
2
+ module Tax
3
+ class TaxTableComponent < ContentBlockTools::BaseComponent
4
+ def initialize(rates:)
5
+ @rates = rates
6
+ end
7
+
8
+ def render
9
+ render_in(view_context)
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :rates
15
+
16
+ def table_head
17
+ [
18
+ { text: "Band" },
19
+ { text: "Taxable income" },
20
+ { text: "Tax rate" },
21
+ ]
22
+ end
23
+
24
+ def table_rows
25
+ rates.each_with_index.map do |rate, index|
26
+ [
27
+ { text: band_name(rate) },
28
+ { text: taxable_income_text(rate, index) },
29
+ { text: rate_value(rate) },
30
+ ]
31
+ end
32
+ end
33
+
34
+ def band_name(rate)
35
+ rate.dig(:bands, 0, :name)
36
+ end
37
+
38
+ def rate_value(rate)
39
+ rate[:value]
40
+ end
41
+
42
+ def taxable_income_text(rate, index)
43
+ if only_one_rate? || last_row?(index)
44
+ "over #{lower_threshold(rate)}"
45
+ elsif first_row?(index)
46
+ "Up to #{upper_threshold(rate)}"
47
+ else
48
+ "#{lower_threshold(rate)} to #{upper_threshold(rate)}"
49
+ end
50
+ end
51
+
52
+ def only_one_rate?
53
+ rates.length == 1
54
+ end
55
+
56
+ def first_row?(index)
57
+ index.zero?
58
+ end
59
+
60
+ def last_row?(index)
61
+ index == rates.length - 1
62
+ end
63
+
64
+ def lower_threshold(rate)
65
+ rate.dig(:bands, 0, :lower_threshold, :value)
66
+ end
67
+
68
+ def upper_threshold(rate)
69
+ rate.dig(:bands, 0, :upper_threshold, :value)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,47 @@
1
+ module ContentBlockTools
2
+ class TaxComponent < ContentBlockTools::BaseComponent
3
+ SUPPORTED_FORMATS = %w[
4
+ default
5
+ tax_table
6
+ ].freeze
7
+
8
+ def initialize(content_block:, _block_type: nil, _block_name: nil)
9
+ @content_block = content_block
10
+ validate_format!
11
+ validate_presence_of_income_tax_rates! if tax_table_format?
12
+ end
13
+
14
+ def render
15
+ return "" unless tax_table_format?
16
+
17
+ Tax::TaxTableComponent.new(rates: income_tax_rates).render
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :content_block
23
+
24
+ delegate :format, :details, to: :content_block
25
+
26
+ def validate_format!
27
+ return if SUPPORTED_FORMATS.include?(format)
28
+
29
+ raise InvalidFormatError, "Unknown format '#{format}' for tax"
30
+ end
31
+
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"
37
+ end
38
+
39
+ def tax_table_format?
40
+ format == "tax_table"
41
+ end
42
+
43
+ def income_tax_rates
44
+ details.dig(:things_taxed, :income, :rates)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ module ContentBlockTools
2
+ module Presenters
3
+ module FieldPresenters
4
+ module Pension
5
+ class AmountPresenter < BasePresenter
6
+ def render
7
+ field.start_with?("£") ? field : "£#{field}"
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentBlockTools
4
- VERSION = "1.12.2"
4
+ VERSION = "1.14.0"
5
5
  end
@@ -15,6 +15,7 @@ require "content_block_tools/presenters/field_presenters/time_period/date_presen
15
15
  require "content_block_tools/presenters/field_presenters/time_period/time_presenter"
16
16
  require "content_block_tools/presenters/field_presenters/time_period/start_presenter"
17
17
  require "content_block_tools/presenters/field_presenters/time_period/end_presenter"
18
+ require "content_block_tools/presenters/field_presenters/pension/amount_presenter"
18
19
 
19
20
  require "content_block_tools/content_block"
20
21
  require "content_block_tools/content_block_reference"
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.12.2
4
+ version: 1.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -9,6 +9,20 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: capybara
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: cucumber
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -208,6 +222,9 @@ files:
208
222
  - app/components/content_block_tools/contacts/email_address_component.rb
209
223
  - app/components/content_block_tools/contacts/telephone_component.html.erb
210
224
  - app/components/content_block_tools/contacts/telephone_component.rb
225
+ - app/components/content_block_tools/tax/tax_table_component.html.erb
226
+ - app/components/content_block_tools/tax/tax_table_component.rb
227
+ - app/components/content_block_tools/tax_component.rb
211
228
  - app/components/content_block_tools/time_period/long_form_component.html.erb
212
229
  - app/components/content_block_tools/time_period/long_form_component.rb
213
230
  - app/components/content_block_tools/time_period/months_and_years_long_component.html.erb
@@ -233,6 +250,7 @@ files:
233
250
  - lib/content_block_tools/normalised_date_range.rb
234
251
  - lib/content_block_tools/presenters/field_presenters/base_presenter.rb
235
252
  - lib/content_block_tools/presenters/field_presenters/contact/email_presenter.rb
253
+ - lib/content_block_tools/presenters/field_presenters/pension/amount_presenter.rb
236
254
  - lib/content_block_tools/presenters/field_presenters/time_period/date_presenter.rb
237
255
  - lib/content_block_tools/presenters/field_presenters/time_period/date_range_presenter.rb
238
256
  - lib/content_block_tools/presenters/field_presenters/time_period/end_presenter.rb