# Haml to erb

**URL:** <https://www.ruby-forum.com/t/haml-to-erb/156177>\
**Category:** Ruby\
**Created:** [December 22, 2008, 6:01am UTC](https://www.ruby-forum.com/t/haml-to-erb/156177 "2008-12-22T06:01:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thaniyarasu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@thaniyarasu](https://www.ruby-forum.com/u/thaniyarasu)\
**Post date:** [December 22, 2008, 6:01am UTC](https://www.ruby-forum.com/t/haml-to-erb/156177/1 "2008-12-22T06:01:16Z")

</div>

i have lot of haml file  
i want to convert all files to erb files

any idea ?

---

<div class="post-metadata">

**Author:** ![thaniyarasu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@thaniyarasu](https://www.ruby-forum.com/u/thaniyarasu)\
**Post date:** [December 22, 2008, 7:12am UTC](https://www.ruby-forum.com/t/haml-to-erb/156177/2 "2008-12-22T07:12:55Z")

</div>

Thani A. wrote:

> i have lot of haml file  
> i want to convert all files to erb files
> 
> any idea ?

Write a script to replace the ruby commands in each haml file with a  
unique identifier while storing the ruby commands and identifiers in a  
hash. Then generate html from the modified haml. Then replace the  
unique identifiers with the ruby commands in the hash suitably wrapped  
in erb syntax.

orignal haml:

#example  
.name= foo.name

becomes:

#example  
.name ERB00001

and hash would look like:

‘ERB00001’ =\> ‘foo.name’

changed haml should generate:

ERB00001

Substituting from the hash with erb syntax should then yield:

\<%= foo.name %\>

BTW, just curious why are you going from haml to erb?

Have fun,  
Roy
