Skip to content

Instantly share code, notes, and snippets.

@yalab
Last active March 4, 2018 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yalab/c51260a89d0b0544e7b8d4efb04bffdc to your computer and use it in GitHub Desktop.
Save yalab/c51260a89d0b0544e7b8d4efb04bffdc to your computer and use it in GitHub Desktop.
(defun rb-strkeytosym (start end)
"ruby Hash key string to symbol"
(interactive "r")
(replace-regexp "\"\\([a-z_]+\\)\"=>" "\\1: " nil start end))
(defun rb-htmlopttoerb (start end)
"html attreibute to erb option"
(interactive "r")
(replace-regexp " \\([a-z_]+\\)=" ", \\1: " nil start end))
(defun strip-unused-html-attributes (start end)
"remove unused html attributes"
(interactive "r")
(replace-regexp "\\(value\\|style\\|type\\): \"[^\"]*\",?" "" nil start end))
(defun rb-inputtoerb (start end)
"input tag to erb"
(interactive "r")
(funcall (lambda ()
(replace-regexp
"<input\\([^>]+\\) ?name=\"\\([0-9a-z_]+\\)\"\\([^>]+\\)>"
"<%= f.text_field :\\2\\1\\3 %>" nil start end)
(call-interactively 'rb-htmlopttoerb)
(call-interactively 'strip-unused-html-attributes))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment