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 CHANGED
@@ -1,13 +1,5 @@
1
- #!/bin/bash
2
- dir=$@
3
- [ -z ${dir} ] && dir="."
4
- for fn in $(find ${dir} -name '*.erb'); do
5
- src=${fn}
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
@@ -1,3 +1,3 @@
1
1
  module Erb2hamlCli
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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
- # Your code goes here...
5
- end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb2haml_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: