---
url: /reference/concerns/formattable.md
---
# Trek::Formattable

Applies formatters to attributes before validation — out of the box, [`Trek::TypographyFormatter`](/reference/formatters#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), including a document submitted by the content editor as a JSON string, which comes back as a Hash.
