A long-lived project that still receives updates
A suite of tools for working with GOV.UK Content Blocks
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

= 13.3.0
= 3.13.1

Runtime

= 10.6.1
 Project Readme

Content Block Tools

A suite of tools for working with GOV.UK Content Blocks

Installation

Install the gem

gem install content_block_tools

or add it to your Gemfile

gem "content_block_tools"

Usage

Finding embed code

To find embed code in a block of text, use ContentBlockReference.find_all_in_document:

content = "Hello - here is a embed code {{embed:content_block_pension:be24ee44-b636-4a3e-b979-0da27b4a8e62}}"
ContentBlockReference.find_all_in_document(content)
# =>
#[#<data ContentBlockTools::ContentBlockReference
#  document_type="content_block_pension",
#  content_id="be24ee44-b636-4a3e-b979-0da27b4a8e62",
#  embed_code="{{embed:content_block_pension:be24ee44-b636-4a3e-b979-0da27b4a8e62}}">]

Rendering a content block

To render a content block, you can initialize the content block like so:

content_block = ContentBlockTools::ContentBlock.new(
  document_type: "something",
  content_id: "some uuid",
  title: "Title",
  details: { some: "hash"},
)

Then call render:

content_block.render
#=> {HTML representation of content block}

For more information, see the Documentation

License

The gem is available as open source under the terms of the MIT License.