haml2slim 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/haml2slim/command.rb +18 -9
- data/lib/haml2slim/converter.rb +5 -5
- data/lib/haml2slim/version.rb +1 -1
- metadata +3 -3
data/lib/haml2slim/command.rb
CHANGED
@@ -11,7 +11,7 @@ module Haml2Slim
|
|
11
11
|
def run
|
12
12
|
@opts = OptionParser.new(&method(:set_opts))
|
13
13
|
@opts.parse!(@args)
|
14
|
-
process
|
14
|
+
process!
|
15
15
|
exit 0
|
16
16
|
rescue Exception => ex
|
17
17
|
raise ex if @options[:trace] || SystemExit === ex
|
@@ -47,25 +47,34 @@ module Haml2Slim
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def process
|
51
|
-
|
50
|
+
def process!
|
51
|
+
@files = @args.dup
|
52
|
+
|
52
53
|
unless @options[:input]
|
53
|
-
file =
|
54
|
+
file = @files.shift
|
54
55
|
if file
|
55
56
|
@options[:file] = file
|
56
|
-
@options[:input] =
|
57
|
+
@options[:input] = file
|
57
58
|
else
|
58
59
|
@options[:file] = 'STDIN'
|
59
60
|
@options[:input] = $stdin
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
|
-
|
64
|
-
file
|
65
|
-
|
64
|
+
if File.directory?(@options[:file])
|
65
|
+
Dir.glob(File.join(@options[:file], "**", "*.haml")).each { |file| _process(file) }
|
66
|
+
else
|
67
|
+
_process(file)
|
66
68
|
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
67
72
|
|
68
|
-
|
73
|
+
def _process(file)
|
74
|
+
slim_file = (File.file?(@options[:file]) ? @options[:output] : false) || file.sub(/\.haml$/, '.slim')
|
75
|
+
@options[:output] = file ? File.open(slim_file, 'w') : $stdout
|
76
|
+
@options[:output].puts Haml2Slim.convert!(File.open(file, 'r'))
|
77
|
+
@options[:output].close
|
69
78
|
end
|
70
79
|
end
|
71
80
|
end
|
data/lib/haml2slim/converter.rb
CHANGED
@@ -37,11 +37,11 @@ module Haml2Slim
|
|
37
37
|
def parse_tag(tag_line)
|
38
38
|
tag_line.sub!(/^%/, "")
|
39
39
|
|
40
|
-
if
|
41
|
-
tag
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
if tag_line_contains_attr = tag_line.match(/(.+)\{(.+)\}/)
|
41
|
+
tag, attrs = *tag_line_contains_attr[1..2]
|
42
|
+
|
43
|
+
attrs.gsub!(/,?( ?):?"?([^"'{ ]+)"? ?=> ?/, '\1\2=')
|
44
|
+
attrs.gsub!(/=([^"']+)(?: |$)/, '=(\1)')
|
45
45
|
|
46
46
|
"#{tag} #{attrs}"
|
47
47
|
else
|
data/lib/haml2slim/version.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Fred Wu
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-22 00:00:00 +11:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|