content_block_tools 1.5.1 → 1.6.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: c915d105c0d5c7ec20f90a8e697bdbfa6fcc1b0379eb13ff03cc1185e49e326d
4
- data.tar.gz: 4cd037fefbf68fbfff42a6149b159b8a1054b3ca1d396c291390f8b4b0b72806
3
+ metadata.gz: 90a58c8f62e62d8a410f3f55b4a9cdb2d754aa4184c1903015604764da38e9af
4
+ data.tar.gz: ee205849804c1203a1c09d92dfaf09f0c2b1251adff21a987786a947901795c4
5
5
  SHA512:
6
- metadata.gz: a590e3fbbdbe0a8d1fa23971bf6db5f6eb02fee0b7dd372df143fa2d17991612c42d5f98364c5ceb137d240c5efb23da63cc863828b47ed38c0637403890f974
7
- data.tar.gz: 97c88d5c7773b6cc8672b6f48ebf71f7acf3f9d3b79c96b0fa4a2064ed404c5ecd4b75064edc70776ad845c3a3c18bdefc5a51f95cc9a3ac9b8500d04ee9bb5e
6
+ metadata.gz: 5a44364c60ea81ea57088c0834382c679e3b30d6edc0c50123204992b6c4ab02df72fc56f1a910cf6a385d5b284b7c146d8e04864e5a5c72c2bec3ff159cc356
7
+ data.tar.gz: 682b1b92a8164c3e1ed07dbb8f3124d9b233bbcc7c1aee7f71db1e82cd0c68adb45012efc7a6305eb59cb773022b2114407c1a4c3628da226322486e940dafe8
@@ -46,6 +46,38 @@ module ContentBlockTools
46
46
 
47
47
  attr_reader :content_id, :title, :embed_code
48
48
 
49
+ # Creates a ContentBlock instance from an embed code string by fetching
50
+ # the content item data from the Content Store API.
51
+ #
52
+ # @param embed_code [String] The embed code string to parse and fetch content for
53
+ # @example
54
+ # ContentBlock.from_embed_code("{{embed:content_block_pension:2b92cade-549c-4449-9796-e7a3957f3a86}}")
55
+ #
56
+ # @return [ContentBlock] A new ContentBlock instance populated with data from the Content Store
57
+ #
58
+ # @raise [ContentBlockTools::InvalidEmbedCodeError] if the embed code format is invalid
59
+ # @raise [GdsApi::HTTPErrorResponse] if the API request fails
60
+ #
61
+ # @example Create a ContentBlock from an embed code
62
+ # embed_code = "{{embed:content_block_email:123e4567-e89b-12d3-a456-426614174000}}"
63
+ # content_block = ContentBlock.from_embed_code(embed_code)
64
+ # content_block.title #=> "Contact Email"
65
+ # content_block.document_type #=> "email"
66
+ #
67
+ # @see ContentBlockReference.from_string
68
+ # @see GdsApi.content_store
69
+ def self.from_embed_code(embed_code)
70
+ reference = ContentBlockReference.from_string(embed_code)
71
+ api_response = GdsApi.content_store.content_item(reference.content_store_identifier)
72
+ new(
73
+ content_id: api_response["content_id"],
74
+ title: api_response["title"],
75
+ document_type: api_response["document_type"],
76
+ details: api_response["details"],
77
+ embed_code:,
78
+ )
79
+ end
80
+
49
81
  def initialize(content_id:, title:, document_type:, details:, embed_code:)
50
82
  @content_id = content_id
51
83
  @title = title
@@ -45,6 +45,21 @@ module ContentBlockTools
45
45
  !identifier.match?(UUID_REGEX)
46
46
  end
47
47
 
48
+ # Returns the content store path for this content block reference
49
+ #
50
+ # Constructs a path used to identify and retrieve the content block from the content store.
51
+ # The path follows the format `/content-blocks/{document_type}/{identifier}`.
52
+ #
53
+ # @example
54
+ # reference = ContentBlockReference.new(document_type: "content_block_contact", identifier: "some-slug", embed_code: "...")
55
+ # reference.content_store_identifier
56
+ # #=> "/content-blocks/content_block_contact/some-slug"
57
+ #
58
+ # @return [String] the content store path for this content block
59
+ def content_store_identifier
60
+ "/content-blocks/#{document_type}/#{identifier}"
61
+ end
62
+
48
63
  class << self
49
64
  # Finds all content block references within a document, using `ContentBlockReference::EMBED_REGEX`
50
65
  # to scan through the document
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentBlockTools
4
- VERSION = "1.5.1"
4
+ VERSION = "1.6.0"
5
5
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "action_view"
4
4
  require "uri"
5
+ require "gds-api-adapters"
5
6
  require "govspeak"
6
7
 
7
8
  require "content_block_tools/helpers/govspeak"
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.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -99,6 +99,20 @@ dependencies:
99
99
  - - "<"
100
100
  - !ruby/object:Gem::Version
101
101
  version: 8.0.4
102
+ - !ruby/object:Gem::Dependency
103
+ name: gds-api-adapters
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: 101.0.0
109
+ type: :runtime
110
+ prerelease: false
111
+ version_requirements: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: 101.0.0
102
116
  - !ruby/object:Gem::Dependency
103
117
  name: govspeak
104
118
  requirement: !ruby/object:Gem::Requirement