Orientation for coding agents and new contributors working in
contentful/rich-text-renderer.rb.
The rich_text_renderer gem. It serializes a Contentful RichText field
document — a nested Ruby hash decoded from JSON — into HTML, and every part of
that serialization is overridable. It is meant to be used alongside the
Contentful Delivery SDK but does
not depend on it: rich_text_renderer.gemspec declares development
dependencies only, no runtime dependencies.
Public entry point is lib/rich_text_renderer.rb, which requires
lib/rich_text_renderer/renderer.rb and lib/rich_text_renderer/version.rb.
The only class most callers touch is RichTextRenderer::Renderer. See
ARCHITECTURE.md for the rendering pipeline.
bundle install
bundle exec rspec # run the suite
bundle exec rubocop # lint
bundle exec rake rspec_rubocop # both, exactly what CI runs
bundle exec rake # defaults to :spec
bundle exec guard # watch mode: rspec, yard, rubocop
bundle exec yard doc # generate documentation.rspec passes --color --format documentation. .yardopts passes
--no-private and includes CHANGELOG.md and LICENSE.txt.
No credentials are needed to run anything in this repository. There is no
network access and no fixture download step — specs build their input hashes
inline and use the hand-rolled MockAsset / MockFile doubles in
spec/spec_helper.rb.
.circleci/config.yml defines one job, test_and_lint, run as a matrix over
Ruby 3.2, 3.3 and 3.4 on the cimg/ruby:<version> images. Each run does
gem install bundler:2.3.26, bundle install, then
bundle exec rake rspec_rubocop. There is no publish job.
.github/workflows/codeql.yml runs CodeQL, but only over
.github/workflows/** — it analyses the workflow definitions, not the Ruby
source.
- Every renderer subclasses
RichTextRenderer::BaseNodeRendererand exposes#render(node)returning aString. - Most block and inline renderers override nothing but the protected
#render_tag. Prefer that over reimplementing#render. Seelib/rich_text_renderer/block_renderers/paragraph_renderer.rbfor the minimal shape. - Loading is explicit
require_relative, no autoloading. A new renderer must be added in three places: its own file, the matching aggregator (lib/rich_text_renderer/block_renderers.rb,lib/rich_text_renderer/text_renderers.rb, orlib/rich_text_renderer/document_renderers.rb), andDEFAULT_MAPPINGSinlib/rich_text_renderer/renderer.rb, keyed by the ContentfulnodeTypestring. .rubocop.ymlinherits.rubocop_todo.yml, which was generated 2024-04-01 with RuboCop 1.62.1.Style/SignalExceptionis set toonly_fail, so raise errors withfail, notraise.spec/**/*,Gemfile,RakefileandGuardfileare excluded from linting.- Specs mirror
lib/underspec/lib/, one*_spec.rbper renderer. CHANGELOG.mdis hand-maintained and has an## Unreleasedheading at the top. Add entries there.
- The default branch is
master, notmain. spec/lib/rich_text_renderer/text_renderers/subscript_renderer.rbis a spec file that is missing the_specsuffix, so neitherbundle exec rspecnor the Rake task loads it. It arrived that way in e4af1c1. Renaming it may surface assertions that have never actually run..rubocop.ymlstill excludesstructured_text_renderer.gemspec, a filename that has not existed since the rename in 97c6913. It is inert, not a live rule.README.mdlinks to./LICENSE; the file on disk isLICENSE.txt.TextRendererdeep-copies its node withMarshal.load(Marshal.dump(node))before mutatingvalue. That is deliberate — callers own the document they pass in.AssetHyperlinkRendereridentifies assets by scanningclass.ancestorsfor a name containingAssetrather than by class equality, and handles raw hashes on a separate code path. The reasoning is recorded in docs/ADRs.
Manual, with no automation. Bump VERSION in
lib/rich_text_renderer/version.rb, move the ## Unreleased entries in
CHANGELOG.md under the new version heading, commit, then use the tasks that
rubygems-tasks registers through Gem::Tasks.new in the Rakefile
(rake build, rake release). The history shows this as explicit
"Bump to version X" commits — 0300473 for 0.3.3, 465846a for 0.3.2 — and
v-prefixed tags such as v0.3.3.
.github/CODEOWNERS and catalog-info.yaml both assign this repository to
team-developer-experience. It is a tier-4 library; CI alerts go to the
sdk-bots Slack channel. Dependency bumps arrive from Renovate, configured in
renovate.json extending local>contentful/renovate-config (set up in
b40e79b).