erb2haml_cli 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/erb2haml +5 -13
- data/lib/erb2haml_cli/version.rb +1 -1
- data/lib/erb2haml_cli.rb +53 -2
- metadata +1 -1
data/bin/erb2haml
CHANGED
@@ -1,13 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
dst=${fn/%erb/haml}
|
7
|
-
echo -n "Converting ${src} to ${dst} ... "
|
8
|
-
if html2haml --erb --unix-newlines ${src} ${dst}; then
|
9
|
-
echo "OK"
|
10
|
-
else
|
11
|
-
echo "ERROR"
|
12
|
-
fi
|
13
|
-
done
|
1
|
+
#/usr/bin/env ruby -w
|
2
|
+
# -*- encoding: utf-8 -*-
|
3
|
+
|
4
|
+
require File.expand_path('../../lib/erb2haml_cli', __FILE__)
|
5
|
+
Erb2hamlCli.run ARGV
|
data/lib/erb2haml_cli/version.rb
CHANGED
data/lib/erb2haml_cli.rb
CHANGED
@@ -1,5 +1,56 @@
|
|
1
1
|
require "erb2haml_cli/version"
|
2
|
+
# Taken and modified from https://github.com/dhl/erb2haml
|
2
3
|
|
3
4
|
module Erb2hamlCli
|
4
|
-
|
5
|
-
|
5
|
+
require 'find'
|
6
|
+
|
7
|
+
RED_FG ="\033[31m"
|
8
|
+
GREEN_FG = "\033[32m"
|
9
|
+
END_TEXT_STYLE = "\033[0m"
|
10
|
+
|
11
|
+
# Helper method to inject ASCII escape sequences for colorized output
|
12
|
+
def self.color(text, begin_text_style)
|
13
|
+
begin_text_style + text + END_TEXT_STYLE
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.run(argv)
|
17
|
+
return usage if argv.grep(/--help/)
|
18
|
+
|
19
|
+
if `which html2haml`.empty?
|
20
|
+
puts "#{color "ERROR: ", RED_FG} Could not find " +
|
21
|
+
"#{color "html2haml", GREEN_FG} in your PATH. Aborting."
|
22
|
+
end
|
23
|
+
|
24
|
+
dir = argv.first || "."
|
25
|
+
unless FileTest.directory?(dir)
|
26
|
+
$stderr.puts "#{dir} is not a directory"
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
puts "Looking for #{color "ERB", GREEN_FG} files to convert to " +
|
31
|
+
"#{color("Haml", RED_FG)}..."
|
32
|
+
|
33
|
+
Find.find(dir) do |path|
|
34
|
+
if FileTest.file?(path) and path.downcase.match(/\.erb$/i)
|
35
|
+
haml_path = path.gsub("erb", "haml")
|
36
|
+
|
37
|
+
unless FileTest.exists?(haml_path)
|
38
|
+
print "Converting: #{path}... "
|
39
|
+
|
40
|
+
if system("html2haml", "--erb", "--unix-newlines", path, haml_path)
|
41
|
+
puts color("Done!", GREEN_FG)
|
42
|
+
else
|
43
|
+
puts color("Failed!", RED_FG)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end # self.run
|
49
|
+
|
50
|
+
def self.usage
|
51
|
+
puts <<-DOC
|
52
|
+
#{$0} [PATH]
|
53
|
+
Convert all *.erb files in directory PATH. Using current working directory if not set.
|
54
|
+
DOC
|
55
|
+
end
|
56
|
+
end # Erb2hamlCli
|