ditto_code 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d45d548498e69ecad8d759e8aed1e3c17df6765e
4
- data.tar.gz: 18c3ea1ca196d56fe0ccb2ad177cb0fac9bdedb3
3
+ metadata.gz: 89878b0fa06bbd81f76c75ccd999d978cd61a25b
4
+ data.tar.gz: 4e890cabd15a0063b01cc9306759707a361e7b2a
5
5
  SHA512:
6
- metadata.gz: 065e4d4bb009ff1e516dbdd193334edbd303e411501d93a7675d79e9d0ca0949cb64d9a4273e79e118c20d2a802d9c3814864920f267c082f7fb1c877658034d
7
- data.tar.gz: 35e6fc6473fee37d2bd84a0e9e34a39233bba9535bd57b8f9e6e70920244d2cccd4f84294924f9aa20d61e20c49b22d1cfeba974652fa8ca81d184e3b736b143
6
+ metadata.gz: ce6fefc7f72c9584ebce1a52208146b62ceb97f4783723dd044cadd3363768d3e0811922568aba528ba28f9a57412c2db4cddb390ddd5a566be89fb53b81e743
7
+ data.tar.gz: 54907456795f48ee4e6d523324fe9aaccb6fcc51e1a888f2284fabd5d6883365d833d30b18a471b50fc57a65299684ec5c72d85a6bb74f7b0d1623336d0c885e
data/bin/dittoc CHANGED
@@ -81,7 +81,7 @@ def iterateFolder(folder)
81
81
  end
82
82
 
83
83
  # ===============================================================
84
- # VARIAVLEs
84
+ # VARIABLES
85
85
  # ===============================================================
86
86
 
87
87
  $isFolder = false;
@@ -147,8 +147,11 @@ end
147
147
 
148
148
  unless @stop
149
149
 
150
+ # Initiate the global var for the parser
151
+ ENV["DITTOCODE_ENV"] = $environment
152
+
150
153
  # Initiate ditto
151
- @ditto = DittoCode::Parse.new($environment, $override, $verbose, $indent)
154
+ @ditto = DittoCode::Parse.new($override, $verbose, $indent)
152
155
 
153
156
  # Check if the user has introduce a folder/file
154
157
  if $folder.empty?
@@ -1,11 +1,19 @@
1
1
  require 'dittocode/parse'
2
2
  require 'dittocode/exec'
3
3
  require 'dittocode/talk'
4
+ require 'dittocode/remove_file'
5
+ require 'dittocode/hold_file'
6
+ require 'dittocode/environments'
7
+ include DittoCode::Environments
4
8
  include DittoCode::Exec
5
9
  include DittoCode::Talk
10
+ include DittoCode::RemoveFile
11
+ include DittoCode::HoldFile
6
12
 
7
13
  module DittoCode
8
- def self.symbolize_keys h
9
- h.inject({}) { |opts,(k,v)| opts[(k.to_sym rescue k) || k] = v; opts }
10
- end
14
+
15
+ #def self.symbolize_keys h
16
+ # h.inject({}) { |opts,(k,v)| opts[(k.to_sym rescue k) || k] = v; opts }
17
+ #end
18
+
11
19
  end
@@ -0,0 +1,23 @@
1
+ module DittoCode
2
+
3
+ module Environments
4
+
5
+ # Check the presence of the environment constant
6
+ def check_env
7
+ if ENV["DITTOCODE_ENV"].nil? || ENV["DITTOCODE_ENV"].empty?
8
+ puts 'Ditto say -> Environment isn\'t declared'
9
+ end
10
+ @initialize = true
11
+ end
12
+
13
+ # True if the environment is included
14
+ def isIncluded? (environment)
15
+
16
+ if environment.split(",").include? ENV["DITTOCODE_ENV"]
17
+ true
18
+ else
19
+ false
20
+ end
21
+ end
22
+ end
23
+ end
@@ -7,23 +7,13 @@ module DittoCode
7
7
 
8
8
  # check the env code
9
9
  unless @initialize
10
- check_env
10
+ DittoCode::Environments.check_env
11
11
  end
12
12
 
13
- if ENV["DITTOCODE_ENV"] == environment
13
+ if DittoCode::Environments.isIncluded? environment
14
14
  yield
15
15
  end
16
16
  end
17
17
 
18
- private
19
-
20
- # Check the presence of the environment constant
21
- def check_env
22
- if ENV["DITTOCODE_ENV"].nil? || ENV["DITTOCODE_ENV"].empty?
23
- puts 'Ditto say -> Environment isn\'t declared'
24
- end
25
- @initialize = true
26
- end
27
18
  end
28
-
29
19
  end
@@ -0,0 +1,19 @@
1
+ module DittoCode
2
+
3
+ @initialize = false
4
+
5
+ module HoldFile
6
+ def self.if (environment)
7
+
8
+ # check the env code
9
+ unless @initialize
10
+ DittoCode::Environments.check_env
11
+ end
12
+
13
+ unless DittoCode::Environments.isIncluded? environment
14
+ exit
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -7,11 +7,12 @@ module DittoCode
7
7
  require 'rainbow/ext/string'
8
8
 
9
9
  # Initialize the environment
10
- def initialize(environment, override, verbose, indent)
11
- @env = environment
10
+ def initialize(override, verbose, indent)
11
+ @env = ENV["DITTOCODE_ENV"]
12
12
  @override = override
13
13
  @verbose = verbose
14
14
  @indent = indent
15
+ @remove = false
15
16
  end
16
17
 
17
18
  # Transform the file based in the environment
@@ -43,17 +44,45 @@ module DittoCode
43
44
  if /[\s]*require[\s]*['|"](ditto_code)['|"]/.match(line).nil?
44
45
 
45
46
  if @isView
46
- m = /[\s]*<%[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z]+)['|"][\s]+do[\s]*%>/.match(line)
47
+ # rem can stop the execution of this file
48
+ rem = /[\s]*<%[\s]*DittoCode::(?<action>Remove|Hold)File.if[\s]+['|"](?<environment>[a-zA-Z,]+)['|"][\s]*%>/.match(line)
49
+ # m catch a block of dittoCode::Exec
50
+ m = /[\s]*<%[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z,]+)['|"][\s]+do[\s]*%>/.match(line)
47
51
  else
48
- m = /[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z]+)['|"] do/.match(line)
52
+ rem = /[\s]*DittoCode::(?<action>Remove|Hold)File.if[\s]+['|"](?<environment>[a-zA-Z,]+)['|"][\s]*/.match(line)
53
+ m = /[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z,]+)['|"] do/.match(line)
49
54
  end
50
55
 
51
- if m
56
+ if rem
57
+
58
+ # Remove the files and stop the execution of this script
59
+ if rem[:action] == 'Remove'
60
+ # Remove action
61
+ if DittoCode::Environments.isIncluded? rem[:environment]
62
+ @removed = true
63
+ break
64
+ end
65
+
66
+ else
67
+
68
+ # Hold action
69
+ unless DittoCode::Environments.isIncluded? rem[:environment]
70
+ @removed = true
71
+ break
72
+ end
73
+
74
+ end
75
+
76
+ dittos += 1
77
+
78
+ elsif m
79
+ # A block as been detected
52
80
  actions[:env] = m[:environment]
53
81
  actions[:atack] = true;
54
82
  actions[:ends] = 1;
55
83
  else
56
84
 
85
+ # Ditto is atacking?
57
86
  if !actions[:atack]
58
87
  if file.eof?
59
88
  # Don't print a \n in the last line
@@ -77,6 +106,7 @@ module DittoCode
77
106
  check_with_indent(out_file, line)
78
107
  end
79
108
 
109
+ # -1 end
80
110
  actions[:ends] -= 1
81
111
 
82
112
  else
@@ -96,15 +126,22 @@ module DittoCode
96
126
 
97
127
  end
98
128
 
129
+ else
130
+ # We delete the line require 'ditto_code'
131
+ dittos += 1
99
132
  end
100
133
 
101
134
  end
102
135
 
103
- if @verbose || dittos != 0
104
- say "[ "+"OK".color("64d67f")+" ] #{dittos} lines ditted on #{@dir_name}#{@file_name}!"
136
+ # Check if the file is removed
137
+ if @removed
138
+ say "[ "+"OK".color("64d67f")+" ] file #{@dir_name}#{@file_name} as been removed"
139
+ elsif @verbose || dittos != 0
140
+ say "[ "+"OK".color("64d67f")+" ] #{dittos} lines ditted on #{@dir_name}#{@file_name}"
105
141
  end
106
142
 
107
- closeFile(out_file)
143
+ # Close and save the file
144
+ closeAndSaveFile(out_file)
108
145
 
109
146
  rescue => e
110
147
 
@@ -193,12 +230,30 @@ module DittoCode
193
230
  # file => file to close
194
231
  # file_name => name of the file
195
232
  # file_path => path of the original file
196
- def closeFile(file)
233
+ def closeAndSaveFile(file)
197
234
 
198
235
  # Close the file
199
236
  file.close;
200
237
 
201
- if(@override)
238
+ # Check if we must to remove the file
239
+ if @removed
240
+
241
+ # We need to remove
242
+ if @override
243
+
244
+ if @isView
245
+ File.delete("#{@dir_name}#{@file_name}.erb")
246
+ else
247
+ File.delete("#{@dir_name}#{@file_name}.rb")
248
+ end
249
+
250
+ File.delete(file)
251
+ else
252
+ File.delete(file)
253
+ end
254
+
255
+ elsif @override
256
+ # No delete, but override?
202
257
  if @isView
203
258
  File.delete("#{@dir_name}#{@file_name}.erb")
204
259
  File.rename(file, "#{@dir_name}#{@file_name}.erb")
@@ -0,0 +1,19 @@
1
+ module DittoCode
2
+
3
+ @initialize = false
4
+
5
+ module RemoveFile
6
+ def self.if (environment)
7
+
8
+ # check the env code
9
+ unless @initialize
10
+ DittoCode::Environments.check_env
11
+ end
12
+
13
+ if DittoCode::Environments.isIncluded? environment
14
+ exit
15
+ end
16
+ end
17
+
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ditto_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Angel M Miguel
@@ -47,8 +47,11 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - bin/dittoc
49
49
  - lib/ditto_code.rb
50
+ - lib/dittocode/environments.rb
50
51
  - lib/dittocode/exec.rb
52
+ - lib/dittocode/hold_file.rb
51
53
  - lib/dittocode/parse.rb
54
+ - lib/dittocode/remove_file.rb
52
55
  - lib/dittocode/talk.rb
53
56
  homepage: https://github.com/Angelmmiguel/ditto_code
54
57
  licenses: