Skip to content

Commit

Permalink
Make Tilt renderer configurable
Browse files Browse the repository at this point in the history
Nesta uses the Tilt gem to render Markdown, Haml, and Textile into HTML.
It uses the default options for each rendering library.

This patch allows a site's developers to configure whichever rendering
library they happen to be using, by passing those options through to a
particular renderer when it's instantiated.

To use this feature, override the `#render_config` method in your app.rb
file.

Closes #146.
  • Loading branch information
gma committed Jan 2, 2024
1 parent ec38988 commit c085d17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* Upgrade to Sinatra 3.1. (なつき)

* Tilt renderers (e.g. for Markdown, Haml, or Textile) are now configurable.
See #146 for details.
(Graham Ashton)

## 0.15.0 (11 July 2023)

* Upgrade to Sinatra 3. (Graham Ashton)
Expand Down
6 changes: 5 additions & 1 deletion lib/nesta/models/file_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,12 @@ def add_p_tags_to_haml(text)

def convert_to_html(format, scope, text)
text = add_p_tags_to_haml(text) if @format == :haml
template = Tilt[format].new { text }
template = Tilt[format].new(renderer_config(@format)) { text }
template.render(scope)
end

def renderer_config(format)
{}
end
end
end

0 comments on commit c085d17

Please sign in to comment.