content_block_tools 1.6.2 → 1.7.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: e56c70a49537656eb82058f2e701e8b6b80adfce2f1bacaaab776ad8bc5050f5
4
- data.tar.gz: 12a8b050898d3111a33c40df40666891563bd258e827075d423f2ec13c057cc4
3
+ metadata.gz: 8bf99fd8affbea779c0cdf676527123d493ef6e52736b2ef53e037751edda3db
4
+ data.tar.gz: 00c4d22fd4f3c02a2d287cb9897ded18cdcb45d8e65c9788c11b0a1e9f783cc1
5
5
  SHA512:
6
- metadata.gz: 33d2dc4fff3d9357fcbd0d66d34e1577adfc884241e038731a248cd68866e7818da3020ae246cd3bffb71437ffaf56385cda1cff9da7f44b89dff3cd5ce4af10
7
- data.tar.gz: 565e564662e0fad52667b6e18068b049f81fa2f2d841793ca9a4f630b6f6440bf5720eeb92ede7c07417113b269f15417e00c47403d682fe1daf30fdda925304
6
+ metadata.gz: 4e69ba2bb65f19db0f5f8d5f74d958cf5e4a999c40498579d1caec2425b43dfee14e2d42597682f9f7956ecc4e25c95245ccf4e63ab96a8eb9960bbd8f8f9f0b
7
+ data.tar.gz: 40e4924121bfe450ca64b92bf8f6b4e89da077c189cb236fd09b61853e5e2a4fac63135de438413cbb791e72e84dd7ee692ba28bba1fc3dd4d19538eb5792cce
@@ -1,6 +1,8 @@
1
1
  module ContentBlockTools
2
2
  class BaseComponent < ViewComponent::Base
3
3
  include ContentBlockTools::Govspeak
4
+ include ContentBlockTools::OverrideClasses
5
+
4
6
  def render
5
7
  render_in(view_context)
6
8
  end
@@ -1,21 +1,17 @@
1
- <dl class="vcard content-block__contact-list">
2
- <dt class="content-block__contact-key fn org"><%= content_block.title %></dt>
3
-
1
+ <div class="vcard">
4
2
  <% if block_type.nil? %>
5
- <dd class="content-block__contact-value">
6
- <%= render_govspeak(content_block.details[:description]) if content_block.details[:description] %>
7
- <dl class="content-block__contact-list--nested">
8
- <% items.each do |block_type, _, item| %>
9
- <dt class="content-block__contact-key"><%= item[:title] %></dt>
10
- <dd class="content-block__contact-value">
11
- <%= component_for_block_type(block_type).new(item:).render.html_safe %>
12
- </dd>
13
- <% end %>
14
- </dl>
15
- </dd>
3
+ <%= render_govspeak(content_block.details[:description]) if content_block.details[:description] %>
4
+ <dl class="<%= margin_classes(0) %> <%= padding_classes(0) %>">
5
+ <% items.each do |block_type, _, item| %>
6
+ <dt class="<%= margin_classes(0, 0, 4, 0) %> <%= padding_classes(0) %> <%= font_classes(19, "bold") %>">
7
+ <%= item[:title] %>
8
+ </dt>
9
+ <dd class="<%= margin_classes(0) %>">
10
+ <%= component_for_block_type(block_type).new(item:).render.html_safe %>
11
+ </dd>
12
+ <% end %>
13
+ </dl>
16
14
  <% else %>
17
- <dd class="content-block__contact-value">
18
- <%= component_for_block_type(block_type).new(item: item_to_render).render.html_safe %>
19
- </dd>
15
+ <%= component_for_block_type(block_type).new(item: item_to_render).render.html_safe %>
20
16
  <% end %>
21
- </dl>
17
+ </div>
@@ -1,4 +1,4 @@
1
- <ul class="content-block__list">
1
+ <ul class="govuk-list list-no-bullets <%= margin_classes(0, 0, 6, 0) %>">
2
2
  <li>
3
3
  <a href="<%= item[:url] %>" class="url">
4
4
  <%= link_text %>
@@ -1,4 +1,4 @@
1
- <ul class="content-block__list">
1
+ <ul class="govuk-list list-no-bullets <%= margin_classes(0, 0, 6, 0) %>">
2
2
  <li>
3
3
  <a href="<%= "mailto:#{item[:email_address]}#{query_params}" %>" class="email">
4
4
  <%= link_text %>
@@ -2,7 +2,7 @@
2
2
  <%= render_govspeak(item[:description]) %>
3
3
  <% end %>
4
4
 
5
- <ul class="content-block__list govuk-!-margin-bottom-0">
5
+ <ul class="govuk-list list-no-bullets <%= margin_classes(0) %>">
6
6
  <% item[:telephone_numbers].each do |number| %>
7
7
  <li class="govuk-!-margin-bottom-1">
8
8
  <span><%= number[:label] %>: </span>
@@ -0,0 +1,99 @@
1
+ # Module for generating GOV.UK Design System CSS utility classes
2
+ module ContentBlockTools
3
+ # Helper methods for generating override CSS classes
4
+ # These methods generate CSS class names for spacing and typography utilities
5
+ # from the GOV.UK Design System.
6
+ module OverrideClasses
7
+ # Generates margin CSS classes
8
+ #
9
+ # @param top [Integer, String] the margin value for all sides (if used alone) or top margin
10
+ # @param right [Integer, String, nil] the right margin value (optional)
11
+ # @param bottom [Integer, String, nil] the bottom margin value (optional)
12
+ # @param left [Integer, String, nil] the left margin value (optional)
13
+ # @return [String] the generated margin class(es)
14
+ #
15
+ # @example Generate uniform margin
16
+ # margin_classes(4)
17
+ # # => "govuk-!-margin-4"
18
+ #
19
+ # @example Generate individual side margins
20
+ # margin_classes(4, 3, 2, 1)
21
+ # # => "govuk-!-margin-top-4 govuk-!-margin-right-3 govuk-!-margin-bottom-2 govuk-!-margin-left-1"
22
+ def margin_classes(top, right = nil, bottom = nil, left = nil)
23
+ spacing_classes("margin", top, right, bottom, left)
24
+ end
25
+
26
+ # Generates padding CSS classes
27
+ #
28
+ # @param top [Integer, String] the padding value for all sides (if used alone) or top padding
29
+ # @param right [Integer, String, nil] the right padding value (optional)
30
+ # @param bottom [Integer, String, nil] the bottom padding value (optional)
31
+ # @param left [Integer, String, nil] the left padding value (optional)
32
+ # @return [String] the generated padding class(es)
33
+ #
34
+ # @example Generate uniform padding
35
+ # padding_classes(4)
36
+ # # => "govuk-!-padding-4"
37
+ #
38
+ # @example Generate individual side paddings
39
+ # padding_classes(4, 3, 2, 1)
40
+ # # => "govuk-!-padding-top-4 govuk-!-padding-right-3 govuk-!-padding-bottom-2 govuk-!-padding-left-1"
41
+ def padding_classes(top, right = nil, bottom = nil, left = nil)
42
+ spacing_classes("padding", top, right, bottom, left)
43
+ end
44
+
45
+ # Generates combined font size and weight CSS classes
46
+ #
47
+ # @param size [Integer, String] the font size value (e.g., 16, 19, 24)
48
+ # @param weight [String, Symbol] the font weight value (e.g., "bold", "regular")
49
+ # @return [String] the generated font size and weight classes separated by a space
50
+ #
51
+ # @example Generate font classes with size and weight
52
+ # font_classes(19, "bold")
53
+ # # => "govuk-!-font-size-19 govuk-!-font-weight-bold"
54
+ #
55
+ # @example Generate font classes with different values
56
+ # font_classes(24, "regular")
57
+ # # => "govuk-!-font-size-24 govuk-!-font-weight-regular"
58
+ def font_classes(size, weight)
59
+ [
60
+ font_size_class(size),
61
+ font_weight_class(weight),
62
+ ].join(" ")
63
+ end
64
+
65
+ # Generates a font size CSS class
66
+ #
67
+ # @param size [Integer, String] the font size value (e.g., 16, 19, 24)
68
+ # @return [String] the generated font size class
69
+ #
70
+ # @example
71
+ # font_size_class(19)
72
+ # # => "govuk-!-font-size-19"
73
+ def font_size_class(size)
74
+ "govuk-!-font-size-#{size}"
75
+ end
76
+
77
+ # Generates a font weight CSS class
78
+ #
79
+ # @param weight [String, Symbol] the font weight value (e.g., "bold", "regular")
80
+ # @return [String] the generated font weight class
81
+ #
82
+ # @example
83
+ # font_weight_class("bold")
84
+ # # => "govuk-!-font-weight-bold"
85
+ def font_weight_class(weight)
86
+ "govuk-!-font-weight-#{weight}"
87
+ end
88
+
89
+ private
90
+
91
+ def spacing_classes(type, top, right = nil, bottom = nil, left = nil)
92
+ if right.nil? && bottom.nil? && left.nil?
93
+ "govuk-!-#{type}-#{top}"
94
+ else
95
+ %W[govuk-!-#{type}-top-#{top} govuk-!-#{type}-right-#{right} govuk-!-#{type}-bottom-#{bottom} govuk-!-#{type}-left-#{left}].join(" ")
96
+ end
97
+ end
98
+ end
99
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentBlockTools
4
- VERSION = "1.6.2"
4
+ VERSION = "1.7.0"
5
5
  end
@@ -6,6 +6,7 @@ require "gds-api-adapters"
6
6
  require "govspeak"
7
7
 
8
8
  require "content_block_tools/helpers/govspeak"
9
+ require "content_block_tools/helpers/override_classes"
9
10
 
10
11
  require "content_block_tools/presenters/field_presenters/base_presenter"
11
12
  require "content_block_tools/presenters/field_presenters/contact/email_presenter"
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.6.2
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -185,6 +185,7 @@ files:
185
185
  - lib/content_block_tools/content_block_reference.rb
186
186
  - lib/content_block_tools/engine.rb
187
187
  - lib/content_block_tools/helpers/govspeak.rb
188
+ - lib/content_block_tools/helpers/override_classes.rb
188
189
  - lib/content_block_tools/presenters/field_presenters/base_presenter.rb
189
190
  - lib/content_block_tools/presenters/field_presenters/contact/email_presenter.rb
190
191
  - lib/content_block_tools/version.rb