erb2slim
658 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env ruby
require 'html2haml'
require 'haml2slim'
def run cmd
puts cmd
system cmd
end
def convert erb
run <<-CMD
html2haml --erb #{erb} | haml2slim | sed 's/ *\\\\$//g' > $(echo #{erb} | sed 's/erb/slim/') && rm #{erb}
CMD
end
erb = ARGV[0]
if erb and not erb.empty?
if File.file? erb
convert erb
else
STDERR.puts "file '#{erb}' not found"
end
else
GLOB_ALL = '**/*.erb'
GLOB_HTML = '**/*.html.erb'
GLOB = GLOB_HTML
Dir.glob(GLOB).each do |erb|
if File.file? erb
convert erb
elsif File.symlink? erb
run <<-CMD
mv #{erb} $(echo #{erb} | sed 's/erb/slim/')
CMD
end
end
end