Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ERB template to SLIM

Many of my views are SLIM templates and I wish to add a vote_form partial to my app. How would I convert this partial view from ERB to SLIM?

<strong class="result">Votes: <%= voteable.votes_for - voteable.votes_against %></strong>
<%= form_tag user_votes_path(current_user) do |f| %>
  <%= radio_button_tag :thumb_direction, :up %>
  <%= radio_button_tag :thumb_direction, :down %>
  <%= hidden_field_tag :voteable, @voteable %>
  <%= submit_tag :vote %>
<% end %>

Thanks :)

like image 408
Khmaies Guesmi Avatar asked Apr 27 '12 08:04

Khmaies Guesmi


1 Answers

How convert your .erb to .slim :

Update (18-08-2015)

You can simply use html2slim gem

gem install html2slim

This package include a tool called erb2slim which can convert erb file to slim recursively. Option -d for delete the erb file after the convert finished.

erb2slim -d <dir of your views>

View on devise wiki

Original answer

You must pass through HAML !

Install HAML dependencies on your environment or your gemset

gem install html2haml # This was moved out of haml gem
gem install ruby_parser

Switch to HAML templating

find . -name '*erb' | \
xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | \
bash

Install SLIM tool dependency

gem install haml2slim # https://github.com/fredwu/haml2slim

Switch to SLIM templating

find . -name '*haml' | \
xargs ruby -e 'ARGV.each { |i| puts "haml2slim #{i} #{i.sub(/haml$/,"slim")}"}' | \
bash

Clean ERB and HAML templates

find . -name '*erb' -exec rm -f {} \;
find . -name '*haml' -exec rm -f {} \;

Remove dependencies

gem uninstall html2haml
gem uninstall ruby_parser
gem uninstall haml2slim

That all, have fun

like image 50
Joel AZEMAR Avatar answered Sep 22 '22 13:09

Joel AZEMAR