Weston Ganger
Weston Ganger

Reputation: 6732

Convert slim to html for use as post content in Rails

I have a blog written in rails and I write the templates in slim. I was thinking it would be awesome to write my blog post content slim in my textarea box and convert it to html before I save it to the database

Is this possible and if so how can I accomplish it?

Upvotes: 3

Views: 1660

Answers (1)

Yan Foto
Yan Foto

Reputation: 11388

The documentation says:

Slim uses Tilt to compile the generated code. If you want to use the Slim template directly, you can use the Tilt interface.

And provides the following examples:

Tilt.new['template.slim'].render(scope)
Slim::Template.new('template.slim', optional_option_hash).render(scope)
Slim::Template.new(optional_option_hash) { source }.render(scope)

And I am pretty sure that something like the following also works:

Slim::Template.new(template_path).render

The complete gist of the aforementioned line is to be found here.

Upvotes: 4

Related Questions