ditto_code 0.2.1 → 0.2.3
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/lib/dittocode/environments.rb +6 -4
- data/lib/dittocode/parse.rb +48 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 503c17acc1713d8a18bc7743cab5cba0a35ec507
|
4
|
+
data.tar.gz: 0fcbdb3bca3cad8b1a60996b5cac220d894ab780
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3611652d8c7af10f15d5bb44031c28332954e279ece9469a8564c67d874afe008e8ea33163a57e0fabf77b4f7c6d6ef518f768a07577d8788e1fb1ac5dc2c529
|
7
|
+
data.tar.gz: 16890f66f6024e7afa4e1a5355ee260bc4cfbfcf4a702524484017ee4129bee9f38f0ca5e94e69bf3e06bbe3fc54d9c552683a2ecfd5cdfa1921de9689dc076a
|
@@ -13,10 +13,12 @@ module DittoCode
|
|
13
13
|
# True if the environment is included
|
14
14
|
def isIncluded? (environment)
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
ENV["DITTOCODE_ENV"].split(',').each do |env|
|
17
|
+
if environment.split(",").include? env
|
18
|
+
return true
|
19
|
+
else
|
20
|
+
return false
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/dittocode/parse.rb
CHANGED
@@ -21,7 +21,7 @@ module DittoCode
|
|
21
21
|
@removed = false
|
22
22
|
|
23
23
|
# Start to read the file
|
24
|
-
file = File.open(file_path)
|
24
|
+
file = File.open(file_path, "r")
|
25
25
|
if isView
|
26
26
|
@file_name = File.basename(file_path, ".erb")
|
27
27
|
else
|
@@ -29,6 +29,7 @@ module DittoCode
|
|
29
29
|
end
|
30
30
|
@dir_name = File.dirname(file_path) + "/"
|
31
31
|
@isView = isView
|
32
|
+
@first_line = true
|
32
33
|
|
33
34
|
# Generate the new archive
|
34
35
|
out_file = initiateFile(file_path)
|
@@ -48,13 +49,17 @@ module DittoCode
|
|
48
49
|
if @isView
|
49
50
|
# rem can stop the execution of this file
|
50
51
|
rem = /[\s]*<%[\s]*DittoCode::(?<action>Remove|Hold)File.if[\s]+['|"](?<environment>[a-zA-Z,]+)['|"][\s]*%>/.match(line)
|
51
|
-
#
|
52
|
-
|
52
|
+
# is catch a block of DittoCode::Exec.is (Inline conditionals)
|
53
|
+
is = /[\s]*(?<action>if|unless)[\s]+DittoCode::Exec.is[\s]+['|"](?<environment>[a-zA-Z,]+)['|"][\s]*/.match(line)
|
54
|
+
# m catch a block of dittoCode::Exec.if (Block conditionals)
|
55
|
+
m = /[\s]*<%[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z,]+)['|"][\s]+do[\s]*%>/.match(line)
|
53
56
|
else
|
54
57
|
rem = /[\s]*DittoCode::(?<action>Remove|Hold)File.if[\s]+['|"](?<environment>[a-zA-Z,]+)['|"][\s]*/.match(line)
|
55
|
-
|
58
|
+
is = /[\s]*(?<action>if|unless)[\s]+DittoCode::Exec.is[\s]+['|"](?<environment>[a-zA-Z,]+)['|"]/.match(line)
|
59
|
+
m = /[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z,]+)['|"] do/.match(line)
|
56
60
|
end
|
57
61
|
|
62
|
+
# Remove files
|
58
63
|
if rem
|
59
64
|
|
60
65
|
# Remove the files and stop the execution of this script
|
@@ -77,6 +82,22 @@ module DittoCode
|
|
77
82
|
|
78
83
|
dittos += 1
|
79
84
|
|
85
|
+
# Inline conditionals
|
86
|
+
elsif is
|
87
|
+
|
88
|
+
# Check the action (unless or if)
|
89
|
+
if (is[:action] == 'unless' && !DittoCode::Environments.isIncluded?(is[:environment])) || (is[:action] == 'if' && DittoCode::Environments.isIncluded?(is[:environment]))
|
90
|
+
# We must hold the line
|
91
|
+
|
92
|
+
# Delete the inline conditional from the line
|
93
|
+
line.slice! is[0]
|
94
|
+
|
95
|
+
# Write on the file
|
96
|
+
check_with_indent(out_file, line)
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
# Block conditionals
|
80
101
|
elsif m
|
81
102
|
# A block as been detected
|
82
103
|
actions[:env] = m[:environment]
|
@@ -86,13 +107,7 @@ module DittoCode
|
|
86
107
|
|
87
108
|
# Ditto is atacking?
|
88
109
|
if !actions[:atack]
|
89
|
-
|
90
|
-
# Don't print a \n in the last line
|
91
|
-
out_file.print(line)
|
92
|
-
else
|
93
|
-
out_file.puts(line)
|
94
|
-
end
|
95
|
-
|
110
|
+
check_with_indent(out_file, line)
|
96
111
|
else
|
97
112
|
# He is transforming
|
98
113
|
dittos += 1
|
@@ -136,7 +151,7 @@ module DittoCode
|
|
136
151
|
|
137
152
|
# Check if the file is removed
|
138
153
|
if @removed
|
139
|
-
say "[ "+"OK".color("64d67f")+" ] file #{@dir_name}#{@file_name}
|
154
|
+
say "[ "+"OK".color("64d67f")+" ] file #{@dir_name}#{@file_name} has been removed"
|
140
155
|
elsif @verbose || dittos != 0
|
141
156
|
printf("Ditto say -> [ "+"OK".color("64d67f")+" ] %5s lines ditted on #{@dir_name}#{@file_name}\n", dittos)
|
142
157
|
end
|
@@ -164,10 +179,27 @@ module DittoCode
|
|
164
179
|
# Send the line into the file. If indent is true
|
165
180
|
# The line will be indented
|
166
181
|
def check_with_indent(out_file, line)
|
167
|
-
|
168
|
-
|
182
|
+
|
183
|
+
line.chomp!
|
184
|
+
|
185
|
+
if @first_line
|
186
|
+
|
187
|
+
if @indent
|
188
|
+
out_file.print("#{line.indent(-1)}")
|
189
|
+
else
|
190
|
+
out_file.print("#{line}")
|
191
|
+
end
|
192
|
+
|
193
|
+
@first_line = false
|
194
|
+
|
169
195
|
else
|
170
|
-
|
196
|
+
|
197
|
+
if @indent
|
198
|
+
out_file.print("\n#{line.indent(-1)}")
|
199
|
+
else
|
200
|
+
out_file.print("\n#{line}")
|
201
|
+
end
|
202
|
+
|
171
203
|
end
|
172
204
|
end
|
173
205
|
|
@@ -234,7 +266,7 @@ module DittoCode
|
|
234
266
|
def closeAndSaveFile(file)
|
235
267
|
|
236
268
|
# Close the file
|
237
|
-
file.close
|
269
|
+
file.close
|
238
270
|
|
239
271
|
# Check if we must to remove the file
|
240
272
|
if @removed
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ditto_code
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angel M Miguel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: indentation
|