Created
March 11, 2011 04:32
-
-
Save jugyo/865454 to your computer and use it in GitHub Desktop.
TextMate command to convert haml to html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Input: Selected Text or Nothing | |
# Output: Replace Selected Text | |
require 'tempfile' | |
def unindent(text) | |
lines = text.split(/\n/) | |
level = lines.map{|l| l[/^\s*/].size}.min | |
[lines.map{|l| l[level..-1]}.join("\n"), level] | |
end | |
text, level = unindent(STDIN.read) | |
Tempfile.open('haml2html') do |t| | |
t << text | |
t.flush | |
output = `#{File.join(ENV['TM_GEM_BIN'], 'haml')} #{t.path}` | |
puts output.split("\n").map{|l| ' ' * level + l}.join("\n") | |
end |
michaeldv
commented
Mar 11, 2011
cool!
Hope you and your family are staying safe. The pictures shown are pretty horrifying.
We are safe, and I can go home soon :)
Thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment