Skip to content

Trek::Formattable

Applies formatters to attributes before validation — out of the box, Trek::TypographyFormatter and its French typography rules.

API

ruby
class Page < ApplicationRecord
  include Trek::Formattable
  format_attributes Trek::TypographyFormatter, :title, :description
end

format_attributes(formatter_class, *attr_names) registers the attributes; a before_validation callback runs the formatter on each of them.

Usage

ruby
page = Page.new(title: "Un titre: voici...")
page.valid?
page.title # => "Un titre : voici…"

Works on plain strings and on ProseMirror documents (only text nodes are touched; the structure is preserved).

Released under the MIT License.