Convert slim to html for use as post content in Rails - ruby-on-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?

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.

Related

Use HTML instead of HAML with Ruby on Rails Happy Seed

How can I use html.erb instead of haml when using a rails application that is generated using happy seed?
You dont have to do anything special.
You could convert your haml code to erb using https://haml2erb.org and then create an erb file pasting the code. Also delete the haml file. This should work.

Configure ckeditor in rails to write in Markdown syntax as opposed to HTML

In one part of my application I am successfully using creditor. It properly takes the text typed in and converts it into html format.
User Types in the content:
And it properly saves the content in html syntax:
In another place in my application I want to again use ckeditor. However: this time I want the content to be converted into Markdown syntax as opposed to HTML syntax. Is this possible? If so, how do you specify that configuration for this one place in the application (as opposed to globally specifying this rule because everywhere else I want ckeditor to continue converting the content into html).
I did look within the ruby gems ckeditor docs. I also looked through the ckeditor documentation on options, however looking through that was a bit overwhelming to me.
Seems like you have to add the markdown addon as it is not part of ckeditor, then follow the documentation.
What I ended up doing was creating a script that converted the database fields in my application that were in markdown syntax into html syntax. I did this with the redcarpet Gem and the rdiscount Gem. With those fields now saved in html syntax instead of markdown syntax, I rendered the text just like I do everywhere else where ckeditor is used.

html.haml to html.erb converter for Rails

I inherited a bunch of html.haml views in Rails project and want them to be html.erb.
Could you suggest some automatic Rails-aware converter?
Everything I've found is a set of HTML to HAML converters that additionally do not understand Rails.
You can use this converter to convert manually, link below
https://haml2erb.org/
I don't think any automatic html to erb converter is available as of now!

How to register rb as a template handler in rails

Well since I am using a lot of helper methods in my view files and I avoid using html in most of my view files.
Example
myview.html.erb
<%=myhelper #myobject%>
so I end up using,the erb processing tags each time for each file.
<%=%>
I want to register .rb as a template handler or any other extention for that matter.
So my templates look like
myview.html.rb
myhelper #myobject
I am clueless on how to go ahead.
I found it,it seems railscasts already covered that part.
Its show notes,worth checking out.
https://github.com/railscasts/379-template-handlers/blob/master/store-after/config/initializers/ruby_template_handler.rb
Things without ruby are easy to read and render without those erb tags.

Convert html to rails helpers

I am a RoR developer. I work with a graphic designer who prepares static html/css files and forward them to me.
Then I covert those html code to haml and include them in my views.
I use http://html2haml.heroku.com/ to covert html to haml. But it doesn't covert to haml using Rails helpers.
Example:
It converts
<img src="abc.png" />
To
%img{:src => "abc.png"}/
But I need it to be converted to
=image_tag "abc.png"
The same for other Rails helpers (link_to, text_field, ...etc)
Is there anything can make my work easier and converts using helpers?
I think, there's only one solution to this: your views should be built with Rails helpers from its beginning. There's many tools that can help create static views (which become your project views then), such as Serve or Middleman. The downside is that your designer should know about Rails helpers, haml etc, but this is a classical tradeoff.

Resources