Convertir html existente.erb a Haml [cerrado]


Tengo un proyecto rails, las vistas solo consisten en HTML.Archivos ERB, mi cliente quiere convertir ERB a HAML. Tengo demasiados archivos de vistas. Está tomando una gran cantidad de tiempo convertir archivo por archivo. Por lo que cualquier manera simplemente puedo convertir HTML a haml? He instalado haml plugin bajo mi proyecto.

Author: Islam Azab, 2010-02-11

9 answers

 27
Author: mikewilliamson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-02-11 07:47:53

Puede usar desde la línea de comandos html2haml

html2haml your_erb_file new_haml_file

Si quieres convertir todos tus archivos de una sola vez, mira este artículo: http://shifteleven.com/articles/2008/06/08/converting-erb-to-haml-snippet

 97
Author: Mike,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-26 04:04:16

Http://www.htmltohaml.com

Una alternativa más fácil de usar a la respuesta seleccionada.

 16
Author: bevanb,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-07-13 16:15:09

David Leung proporciona esta gema en github que instala dos tareas de rake.

Con erb2haml, puede convertir fácilmente un proyecto completo de erb a haml con rake haml:convert_erbs o rake haml:replace_erbs.

 13
Author: IAmNaN,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-29 06:30:22

En la página git de haml-rails, proporciona el comando cli para convertir todo erb a haml directamente en su proyecto.

Añade gem "haml-rails" a tu Gemfile

Ejecutar: rake haml:erb2haml

 10
Author: aviemet,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-20 03:51:52

Muy simple

En su Gemfile añadir

gem "erb2haml", :group => :development

Luego corre bundle install

Para Convertir *.erb a *.haml mantener los archivos originales haga:

rake haml:convert_erbs

Para Convertir *.erb a *.haml reemplazar los archivos originales haga:

rake haml:replace_erbs

Buscará todos los archivos erb en project y los convertirá a haml.

Para abreviar: utilice el convertidor en línea

Http://www.htmltohaml.com

 8
Author: Kaleem Ullah,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-17 07:58:14

EDITAR: html2haml funciona como se anuncia, sin embargo, debe usar la versión obtenida de la rama maestra actual de la repositorio github de haml .

La versión de html2haml incluida con la gema haml actualmente disponible en rubygems no es buena. Esta es la versión que obtendrá si tuviera que hacer gem install haml ahora mismo. El uso de la versión suministrada con la gema resultará en haml inválido, ya que no puede procesar ruby correctamente.

 4
Author: EmFi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-02-11 22:55:11

Html2haml ahora está en la gema html2haml, por lo que puede usar:

$ gem install html2haml
$ html2haml path/to/yourfile.html path/to/yourfile.haml
 1
Author: JobJob,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-26 00:37:39

Muy tarde para el juego aquí, pero este post todavía vuela alto en el Google al buscar soluciones similares.

Instala la gema html2haml, entra en tu directorio app / views y pruébalo:

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 {} \;

El defecto en esta solución es que no conserva el historial de revisiones de su antiguo .erb archivos a su nuevo .archivos haml. Pero a veces donde ese historial de revisiones de esos archivos de vista no es un gran problema, esta solución me ha servido bastante bien.

También, asegúrese de esté atento a cualquier error en la línea html2haml antes de eliminar la antigua .archivos erb.

 1
Author: joealba,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-13 12:22:45