Contributions are welcome — as README.md puts it, feel free to improve this
tool by submitting a Pull Request. This file records how to do that so CI
passes on the first try.
You need a Ruby that CI also covers: 3.2, 3.3 or 3.4, per the matrix in
.circleci/config.yml. Then:
git clone https://github.com/contentful/rich-text-renderer.rb.git
cd rich-text-renderer.rb
bundle installGemfile.lock is intentionally gitignored, so the resolve is fresh each time.
Nothing here needs Contentful credentials or network access at test time.
bundle exec rspec # the suite
bundle exec rubocop # lint
bundle exec rake rspec_rubocop # both, in the order CI runs them
bundle exec guard # watch mode while you workbundle exec rake rspec_rubocop is the command CI runs. If it is green
locally on one of the supported Rubies, CI is very likely green too.
The default branch is master. Branch from it, and open the Pull Request
against it.
Adding support for a new node type takes four edits:
- A renderer class in
lib/rich_text_renderer/block_renderers/orlib/rich_text_renderer/text_renderers/, subclassingBaseBlockRenderer,BaseInlineRendererorBaseNodeRenderer. If the only difference from the base is the HTML tag, override the protected#render_tagand nothing else. - A
require_relativeline in the matching aggregator —lib/rich_text_renderer/block_renderers.rborlib/rich_text_renderer/text_renderers.rb. Loading is explicit; a file that is not required is not loaded. - An entry in
DEFAULT_MAPPINGSinlib/rich_text_renderer/renderer.rb, keyed by the ContentfulnodeTypestring exactly as it appears in the API response. - A spec at the mirrored path under
spec/lib/, named*_spec.rb. The suffix matters — RSpec's default pattern is what discovers the file.
e4af1c1 (superscript and subscript) is a good example of the full shape of
such a change.
RuboCop is enforced in CI, so run it. .rubocop.yml inherits
.rubocop_todo.yml; the todo file is generated output, so prefer fixing an
offence over adding an exclusion. Two things that surprise people:
Style/SignalExceptionis set toonly_fail. Raise withfail, notraise.spec/**/*,Gemfile,RakefileandGuardfileare excluded from linting entirely.
Otherwise, follow what the surrounding files already do: two-space indent,
require_relative for internal requires, one class per file, a short comment
above each class (YARD is configured with --no-private in .yardopts).
CHANGELOG.md is maintained by hand and has an ## Unreleased heading at the
top. Add your entry there as part of the same Pull Request. Do not bump
lib/rich_text_renderer/version.rb — that happens at release time.
.github/CODEOWNERS routes every path to @contentful/team-developer-experience,
so a review from that team is required. CI must be green. Squash or merge as the
reviewer prefers; the history contains both styles.
Maintainers only, and manual:
- Bump
VERSIONinlib/rich_text_renderer/version.rb. - Move the
## Unreleasedentries inCHANGELOG.mdunder the new version heading. - Commit (the history uses
Bump to version X.Y.Z, e.g. 0300473). - Publish with the tasks
rubygems-tasksregisters viaGem::Tasks.newin theRakefile—rake buildandrake release. Tags arev-prefixed, e.g.v0.3.3.
There is no CI publish job; nothing is released by merging to master.
Open a GitHub issue on
contentful/rich-text-renderer.rb.
A minimal RichText document hash that reproduces the wrong output is the most
useful thing you can include, since every renderer is a pure function of that
hash.