/ Published in: Emacs Lisp
URL: http://github.com/nex3/haml/tree/master/bin/html2haml
Some utility functions I was working on just before I discovered html2haml.
Expand |
Embed | Plain Text
;;;; HAML conversion macros ;;;;; When the point is at the start of an attribute foo="bar" haml-ize it (or ruby-ize it, really) by changing that to ;;;;; :foo => "bar", (fset 'ygritte-haml-ize-html-attributes [?: ?\C-s ?= left ? right ?> ? ?\C-s ?\" ?\C-s right left ?, right]) ;;;;; Replace <td>foo</td> with %td foo (fset 'ygritte-haml-ize-table-row [?\C-s ?< ?t ?d left left backspace ?% right right right backspace ? ?\C-s ?< left ?\C-k ?\C-a tab down ?\C-a]) ;;;;; RHTML-to-HAML converter (defun ygritte-haml-from-rhtml () "Convert simple RHTML markup to HAML." (interactive) (save-excursion ;get rid of HTML terminators (beginning-of-buffer) (replace-regexp "</[^>]+>" "") ;get rid of RHTML terminators (beginning-of-buffer) (replace-regexp "%>" "") ;convert opening RHTML tags (beginning-of-buffer) (replace-regexp "<%" "") ;convert opening HTML tags (beginning-of-buffer) (replace-regexp "\\(^\s-*\\)<\\([^>]+\\)>" "\\1%\\2 ") ;clean up RHTML declarations that are on the same line as a HAML tag (beginning-of-buffer) (replace-regexp "\\(%\\w+\\) =" "\\1=") ) )
You need to login to post a comment.
