A set of Liquid filters and tags used to render custom plugins for TRMNL.
Functionality is achieved by parsing a template with the option { environment: TRMNL::Liquid.build_environment }.
The environment concept was introduced in v5.6.0 of the liquid gem as a safer alternative to global registration of tags, filters, and so on.
See lib/trmnl/liquid/filters.rb for the currently-supported filters.
require 'trmnl/liquid'
markup = "Hello {{ count | number_with_delimiter }} people!"
environment = TRMNL::Liquid.build_environment # same arguments as Liquid::Environment.build
template = Liquid::Template.parse(markup, environment: environment)
rendered = template.render(count: 1337)
# => "Hello 1,337 people!"Additionally, the {% template %} tag defines reusable chunks of markup:
{% template say_hello %}
<h1>Why hello there, {{ name }}!</h1>
{% endtemplate %}
{% render "say_hello", name: "General Kenobi" %}Install the gem and add to the application's Gemfile by executing:
bundle add trmnl-liquidIf bundler is not being used to manage dependencies, install the gem by executing:
gem install trmnl-liquidSome filter functions (e.g. number_to_currency, l_word, and l_date) require translations provided by the rails-i18n and trmnl-i18n gems.
These dependencies are optional, and if missing will fall back to default behavior. If you want to internationalize, also include these gems:
# optional peer dependencies
gem "rails-i18n", "~> 8.0"
gem "trmnl-i18n", github: "usetrmnl/trmnl-i18n", branch: "main" # recommended for the latest changesAfter checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/usetrmnl/trmnl-liquid.
The gem is available as open source under the terms of the MIT License.