English 中文(简体)
Convert existing html.erb to Haml [closed]
原标题:

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 6 years ago.

I have a rails project, the views only consist with HTML.ERB files, my client wants to convert ERB to HAML. I have too many views file. It s taking a huge amount of time to convert file by file. So that any simply way I can convert HTML to haml? I installed haml plugin under my project.

最佳回答
问题回答

You can use from the command line html2haml

html2haml your_erb_file new_haml_file

If you want to convert all your files in one go, look at this article : http://shifteleven.com/articles/2008/06/08/converting-erb-to-haml-snippet

http://www.htmltohaml.com

A more user-friendly alternative to the selected answer.

David Leung provides this gem on github that installs two rake tasks.

With erb2haml, you can easily convert an entire project from erb to haml with either rake haml:convert_erbs or rake haml:replace_erbs.

On the haml-rails git page, it provides the cli command to do convert all erb to haml right in your project.

add gem "haml-rails" to your Gemfile

run: rake haml:erb2haml

very simple

in your Gemfile add

gem "erb2haml", :group => :development

then run bundle install

for Converting *.erb to *.haml keeping original files do:

rake haml:convert_erbs

for Converting *.erb to *.haml replacing original files do:

rake haml:replace_erbs

it ll search all the erb files in project and convert to haml.

For shorthand: use on-line converter

http://www.htmltohaml.com

EDIT: html2haml does work as advertised, however you must use version obtained from the current master branch of the haml github repoistory.

The version of html2haml included with the haml gem currently available from rubygems is no good. This is the version you will get if you were to do gem install haml right now. Using the version supplied with the gem will result in invalid haml, as it cannot process ruby properly.

html2haml is now in the html2haml gem, so you can use:

$ gem install html2haml
$ html2haml path/to/yourfile.html path/to/yourfile.haml

Way late to the game here, but this post still flies high in the Google when searching for similar solutions.

Install the html2haml gem, pop into your app/views directory and give this a try:

find ./ -name  *.erb  -exec html2haml -e {} {}.haml ;
find ./ -name "*.erb.haml" -exec sh -c  mv "$1" "${1%.erb.haml}.haml"  _ {} ;
find ./ -name  *.erb  -exec rm {} ;

The flaw in this solution is that it doesn t retain revision history from your old .erb files to your new .haml files. But at times where that revision history of those view files isn t a big deal, this solution has served me pretty well.

Also, be sure to watch for any errors in the html2haml line before you delete the old .erb files.





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签