ditto_code 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/bin/dittoc +13 -3
- data/lib/dittocode/parse.rb +14 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ea196dce723d0ac359698050ce90f82f8f0e881
|
4
|
+
data.tar.gz: 49835ff70f702190110698aec6b36d574194a949
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7076a4c538c10972d81f43f625d87cfeea2dcc3b97c29ef253f69dc875dd00b6a61d85c3209f2f62365f4780efa9f3368a41e0d4bdb0e389c73c4b0803bff39d
|
7
|
+
data.tar.gz: b137220d26735421ac0a6955e976a982cb2bdd8a6dae9131c5617fc9eed82a1015e176cd2ad30f6eb00322f2d814cf16b43969bd7b1cc0ca5307a81a52d668df
|
data/bin/dittoc
CHANGED
@@ -7,7 +7,7 @@ require 'ditto_code'
|
|
7
7
|
|
8
8
|
def usage(s)
|
9
9
|
$stderr.puts("Ditto say -> [Err] " + s)
|
10
|
-
$stderr.puts("Ditto say -> [Usage] #{File.basename($0)}: [-v <verbose>] [-f <folder>] [-r <recursive>] [-o <override files>] ENVIRONMENT file|folder")
|
10
|
+
$stderr.puts("Ditto say -> [Usage] #{File.basename($0)}: [-v <verbose>] [-f <folder>] [-r <recursive>] [-o <override files>] [--allow-views <search in views>] ENVIRONMENT file|folder")
|
11
11
|
exit(1)
|
12
12
|
end
|
13
13
|
|
@@ -37,8 +37,14 @@ def iterateFolder(folder)
|
|
37
37
|
|
38
38
|
filepath = "#{folder}#{rb_file}"
|
39
39
|
|
40
|
-
if isFile?(filepath)
|
41
|
-
|
40
|
+
if isFile?(filepath)
|
41
|
+
|
42
|
+
if rb_file.end_with?('.rb')
|
43
|
+
@ditto.transformation(filepath, false)
|
44
|
+
elsif rb_file.end_with?('.erb') && @allow_views
|
45
|
+
@ditto.transformation(filepath, true)
|
46
|
+
end
|
47
|
+
|
42
48
|
elsif isDirectory?(filepath) && @recursive
|
43
49
|
# Recursive
|
44
50
|
iterateFolder("#{filepath}/")
|
@@ -57,6 +63,7 @@ $environment = "";
|
|
57
63
|
$verbose = false;
|
58
64
|
$override = false;
|
59
65
|
@recursive = false
|
66
|
+
@allow_views = false
|
60
67
|
|
61
68
|
# ===============================================================
|
62
69
|
# INITIATION
|
@@ -76,6 +83,9 @@ while ARGV[0]
|
|
76
83
|
when '-r'
|
77
84
|
ARGV.shift
|
78
85
|
@recursive = true
|
86
|
+
when '--allow-views'
|
87
|
+
ARGV.shift
|
88
|
+
@allow_views = true
|
79
89
|
when /^-/
|
80
90
|
usage("Unknown option: #{ARGV[0].inspect}");
|
81
91
|
else
|
data/lib/dittocode/parse.rb
CHANGED
@@ -16,7 +16,7 @@ module DittoCode
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# Transform the file based in the environment
|
19
|
-
def transformation(file_path)
|
19
|
+
def transformation(file_path, @isView)
|
20
20
|
|
21
21
|
# Start to read the file
|
22
22
|
file = File.open(file_path)
|
@@ -37,7 +37,11 @@ module DittoCode
|
|
37
37
|
# Each line........
|
38
38
|
text.each_line do | line |
|
39
39
|
|
40
|
-
|
40
|
+
if @isView
|
41
|
+
m = /[\s]*<%[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z]+)['|"][\s]+do[\s]*%>/.match(line)
|
42
|
+
else
|
43
|
+
m = /[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z]+)['|"] do/.match(line)
|
44
|
+
end
|
41
45
|
|
42
46
|
if m
|
43
47
|
actions[:env] = m[:environment]
|
@@ -113,10 +117,14 @@ module DittoCode
|
|
113
117
|
# Detect if we need to add a new end
|
114
118
|
def moreEnds?(line)
|
115
119
|
|
116
|
-
# Get the initializers of blocks
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
+
# Get the initializers and the ends of the blocks
|
121
|
+
if @isView
|
122
|
+
initializers = line.scan(/<%[\s]*(if|do|def)[\s]+/).size + line.scan(/<%[@=;\s\w\d]*(if|do|def)[\s]+/).size
|
123
|
+
finals = line.scan(/[\s]+(end)[\s]*%>/).size + line.scan(/<%[\s]*(end)[\s]*%>/).size
|
124
|
+
else
|
125
|
+
initializers = line.scan(/^(if|do|def)[\s]+/).size + line.scan(/[\s]+(if|do|def)[\s]+/).size + line.scan(/[\s]+(if|do|def)$/).size
|
126
|
+
finals = line.scan(/[\s]+(end)[\s]+/).size + line.scan(/^(end)[\s]+/).size + line.scan(/[\s]+(end)$/).size
|
127
|
+
end
|
120
128
|
|
121
129
|
# Return the difference
|
122
130
|
initializers - finals
|