本文介绍了将 ERB 模板转换为 SLIM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的许多视图都是 SLIM 模板,我希望在我的应用程序中添加一个 vote_form 部分.我如何将这个局部视图从 ERB 转换为 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 %>

谢谢:)

推荐答案

如何将 .erb 转换为 .slim :

更新!18-08-2015

您可以简单地使用 html2slim gem

gem install html2slim

这个包包含一个名为erb2slim的工具,它可以递归地将erb文件转换为slim.选项 -d 用于在转换完成后删除 erb 文件.

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>

在设计维基上查看

你必须通过HAML

在您的环境或 gemset 上安装 HAML 依赖项

Install HAML dependencies on your environment or your gemset

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

切换到 HAML 模板

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

安装SLIM工具依赖

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

切换到SLIM模板

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

清理ERBHAML 模板

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

删除依赖

gem uninstall html2haml
gem uninstall ruby_parser
gem uninstall haml2slim

就这样,玩得开心

这篇关于将 ERB 模板转换为 SLIM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 12:43