Skip to content

Generate a Custom Renderer

rzig edited this page Feb 25, 2017 · 3 revisions

With Redcarpet, you can roll your own renderer. To simplify managing custom renderers in your Rails app, Carpet provides a generator for you to use.


Generate a new renderer

Excecute:

    rails g carpet your_renderer_name

This will generate a file at app/redcarpet_renderers/your_renderer_name.rb. This will be a simple file with a single class called YourRendererName. The class name in this file should not be changed - it needs to be the camel case version of the file name. Once you've generated the file, add rendering methods as described in the Redcarpet Docs. To use this renderer for a field in your model, see this example.

Clone this wiki locally