content_block_tools 0.4.4 → 0.4.5

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: 590deefd4541eee270592e6490d44140ede0fc10ed6333d348052afebd949a68
4
- data.tar.gz: 94e1064ffaef327f90a48c1f06d45e6bb95718325ba9cbdaf0d535bb82d8e1e3
3
+ metadata.gz: 8dcdb3b81c3bba801688a197e2f9208ed17e8432f1d4c96215d3591bca746708
4
+ data.tar.gz: 81b3aab74207c5d64a687f4c7cff7e309b8fca6a8da68b19a74e183a09f809c3
5
5
  SHA512:
6
- metadata.gz: 890262fb9673b49caec318e0fe55ea30a723a0433ba5fb94166a97bf0ef3692c0cc483d5a3749fe3b250b42234ae7e0fe65bb472b203c3ca109aeae7655321f1
7
- data.tar.gz: 0e6c72ecf5c5a7adfb587388f3c065e6b35bdcf7226807a79c99eb339cc06f231396610be3fe5ac1fd6957127fcd1a2e2f2145a3c53444d6e1c55bee0c46fcf2
6
+ metadata.gz: 8f0169d5727462ad30dd9888a9bfc8421dac428e8c9203e7d4b00c5f3dcc093751addb500d6b1fa4d5b334e5cf3fcb118366e9615b0c1b57c95c998a082d85bf
7
+ data.tar.gz: d64fdbcef11a2de0279f01d4aca052b7aaed794669cbc24a2d8d3f8cef21e5855c3523f9e363d9db9f4376190f655fc2370debfafadb272904d83f15d51eeb10
@@ -0,0 +1,12 @@
1
+ name: Lint GitHub Actions
2
+ on:
3
+ push:
4
+ paths: ['.github/**']
5
+ jobs:
6
+ actionlint:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v4
10
+ with:
11
+ show-progress: false
12
+ - uses: alphagov/govuk-infrastructure/.github/actions/actionlint@main
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@
7
7
  useful summary for people upgrading their application, not a replication
8
8
  of the commit log.
9
9
 
10
+ ## 0.4.5
11
+
12
+ - Add handling for incorrect field names and some logging ([24](https://github.com/alphagov/govuk_content_block_tools/pull/24))
13
+
10
14
  ## 0.4.4
11
15
 
12
16
  - symbolize keys in block details blob, in order to find embedded nested fields ([22](https://github.com/alphagov/govuk_content_block_tools/pull/22))
@@ -40,7 +40,9 @@ module ContentBlockTools
40
40
  #
41
41
  # @return [Array<ContentBlockReference>] An array of content block references
42
42
  def find_all_in_document(document)
43
+ ContentBlockTools.logger.info("Finding embedded content")
43
44
  document.scan(ContentBlockReference::EMBED_REGEX).map do |match|
45
+ ContentBlockTools.logger.info("Found Content Block Reference: #{match}")
44
46
  ContentBlockReference.new(document_type: match[1], content_id: match[2], embed_code: match[0])
45
47
  end
46
48
  end
@@ -44,6 +44,7 @@ module ContentBlockTools
44
44
  # @return [string] A representation of the content block to be wrapped in the base_tag in
45
45
  # {#content}
46
46
  def content
47
+ ContentBlockTools.logger.info("Getting content for content block #{content_block.content_id}")
47
48
  if field_names.present?
48
49
  content_for_fields
49
50
  else
@@ -56,7 +57,13 @@ module ContentBlockTools
56
57
  end
57
58
 
58
59
  def content_for_fields
59
- content_block.details.deep_symbolize_keys.dig(*field_names)
60
+ content = content_block.details.deep_symbolize_keys.dig(*field_names)
61
+ if content.blank?
62
+ ContentBlockTools.logger.warn("Content not found for content block #{content_block.content_id} and fields #{field_names}")
63
+ content_block.embed_code
64
+ else
65
+ content
66
+ end
60
67
  end
61
68
 
62
69
  def field_names
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentBlockTools
4
- VERSION = "0.4.4"
4
+ VERSION = "0.4.5"
5
5
  end
@@ -16,4 +16,20 @@ require "content_block_tools/version"
16
16
  module ContentBlockTools
17
17
  class Error < StandardError; end
18
18
  module Presenters; end
19
+
20
+ class << self
21
+ attr_writer :logger
22
+
23
+ def logger
24
+ @logger ||= Logger.new($stdout)
25
+ end
26
+ end
27
+
28
+ if defined?(Rails::Railtie)
29
+ class Railtie < Rails::Railtie
30
+ initializer "content_block_tools.initialize_logger" do
31
+ ContentBlockTools.logger = Rails.logger
32
+ end
33
+ end
34
+ end
19
35
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content_block_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-17 00:00:00.000000000 Z
10
+ date: 2025-03-05 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake
@@ -73,6 +73,7 @@ extra_rdoc_files: []
73
73
  files:
74
74
  - ".github/dependabot.yml"
75
75
  - ".github/pull_request_template.md"
76
+ - ".github/workflows/actionlint.yml"
76
77
  - ".github/workflows/autorelease.yml"
77
78
  - ".github/workflows/ci.yml"
78
79
  - ".gitignore"
@@ -113,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  - !ruby/object:Gem::Version
114
115
  version: '0'
115
116
  requirements: []
116
- rubygems_version: 3.6.3
117
+ rubygems_version: 3.6.5
117
118
  specification_version: 4
118
119
  summary: A suite of tools for working with GOV.UK Content Blocks
119
120
  test_files: []