ditto_code 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dittocode/parse.rb +52 -41
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af74379b473320c2e99ed19b96ae0e96be912ef8
4
- data.tar.gz: 6a35b34be56aa6b3d06dae11fc466b9411aa8ae9
3
+ metadata.gz: 5fed41ea34a21cd5ca04e6e1e49170f86c22d196
4
+ data.tar.gz: cee727cacd7234595c33cd6e716d392842ffa896
5
5
  SHA512:
6
- metadata.gz: e2910a3048a9ab65e993252e74e24e622b70fcd6c8b1e21432a7989fab05a6f7f3156414aabdfdd803c5c00a1021259a90c85ccc36ba37bceabd36f320cee6ff
7
- data.tar.gz: 69b1e8955e98194d41882650fd30015dc6bd225ef259d3d547e4c14e19efc197ba2ff8e07ad476af92b9840b66d8615a63211aaecda5bcc0fc1b0aaaccd1191e
6
+ metadata.gz: 7138f2589367b8d2c8526bbc4ef4db56226cb804a842610b5f5df878d358e121fd39098def71a255a21c5a7d74e309a23f44abca774ae65becf7f632dbb52175
7
+ data.tar.gz: a775da4d2ad86fe823d76b72e9d987ca30263cd1321ec047b8ec4bfa8a9218b91f72687e054a40c102fee5f1ecada3c5942a716d9aa3ec5c3beb4e9544ef449e
@@ -42,54 +42,59 @@ module DittoCode
42
42
  # Each line........
43
43
  file.each_line do | line |
44
44
 
45
- if @isView
46
- m = /[\s]*<%[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z]+)['|"][\s]+do[\s]*%>/.match(line)
47
- else
48
- m = /[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z]+)['|"] do/.match(line)
49
- end
45
+ # Ignore the line require ditto_code to delete it on final releases
46
+ if /[\s]*require[\s]*['|"](ditto_code)['|"]/.match(line).nil?
50
47
 
51
- if m
52
- actions[:env] = m[:environment]
53
- actions[:atack] = true;
54
- actions[:ends] = 1;
55
- else
48
+ if @isView
49
+ m = /[\s]*<%[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z]+)['|"][\s]+do[\s]*%>/.match(line)
50
+ else
51
+ m = /[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z]+)['|"] do/.match(line)
52
+ end
56
53
 
57
- if !actions[:atack]
58
- if file.eof?
59
- # Don't print a \n in the last line
60
- out_file.print(line)
61
- else
62
- out_file.puts(line)
63
- end
54
+ if m
55
+ actions[:env] = m[:environment]
56
+ actions[:atack] = true;
57
+ actions[:ends] = 1;
58
+ else
59
+
60
+ if !actions[:atack]
61
+ if file.eof?
62
+ # Don't print a \n in the last line
63
+ out_file.print(line)
64
+ else
65
+ out_file.puts(line)
66
+ end
64
67
 
65
- else
66
- # He is transforming
67
- dittos += 1
68
+ else
69
+ # He is transforming
70
+ dittos += 1
68
71
 
69
- # Check if the line is end
70
- if isEnd? line
72
+ # Check if the line is end
73
+ if isEnd? line
71
74
 
72
- # If is the last end, it's coincide with the end of the block
73
- if actions[:ends] == 1
74
- actions[:atack] = false
75
- elsif actions[:env] == @env
76
- # Only how if we must mantain it
77
- check_with_indent(out_file, line)
78
- end
75
+ # If is the last end, it's coincide with the end of the block
76
+ if actions[:ends] == 1
77
+ actions[:atack] = false
78
+ elsif actions[:env] == @env
79
+ # Only how if we must mantain it
80
+ check_with_indent(out_file, line)
81
+ end
79
82
 
80
- actions[:ends] -= 1
83
+ actions[:ends] -= 1
81
84
 
82
- else
85
+ else
83
86
 
84
- # prints of coincide with the environment
85
- if actions[:env] == @env
86
- check_with_indent(out_file, line)
87
+ # prints of coincide with the environment
88
+ if actions[:env] == @env
89
+ check_with_indent(out_file, line)
90
+ end
91
+
92
+ # Check if we need to add a new end
93
+ new_ends = moreEnds? line
94
+ actions[:ends] += new_ends
95
+ dittos += new_ends
87
96
  end
88
97
 
89
- # Check if we need to add a new end
90
- new_ends = moreEnds? line
91
- actions[:ends] += new_ends
92
- dittos += new_ends
93
98
  end
94
99
 
95
100
  end
@@ -149,11 +154,17 @@ module DittoCode
149
154
 
150
155
  # Get the initializers and the ends of the blocks
151
156
  if @isView
152
- initializers = line.scan(/<%[\s]*(case|unless|if|do|def)[\s]+/).size + line.scan(/<%[@=;\s\w\d]*(case|unless|if|do|def)[\s]+/).size
157
+ initializers = line.scan(/<%[\s]*(case|unless|if|do|def)[\s]+/).size
158
+ initializers += line.scan(/<%[@=;\s\w\d]*(case|unless|if|do|def)[\s]+/).size
159
+
153
160
  finals = line.scan(/[\s]+(end)[\s]*%>/).size
154
161
  else
155
- initializers = line.scan(/^(case|unless|if|do|def)[\s]+/).size + line.scan(/[\s]+(case|unless|if|do|def)[\s]+/).size + line.scan(/[\s]+(case|unless|if|do|def)$/).size
156
- finals = line.scan(/[\s]+(end)[\s]+/).size + line.scan(/^(end)[\s]+/).size + line.scan(/[\s]+(end)$/).size
162
+ initializers = line.scan(/^[\s\t]*(case|unless|if|do|def)[\s]+/).size # If, def, unless... of a start line
163
+ initializers += line.scan(/[\s\t]+(case|do)[\s]+[|]+/).size # Case or do inside a line
164
+ initializers += line.scan(/[\s\t]+(do)[\s]*$/).size # Finals do
165
+ initializers += line.scan(/[\s\t]+(if|unless)[\s]+[@=\d\w\s]+(?:then){1}/).size # Only if|unless + then, this line disable error by: unless|if var
166
+
167
+ finals = line.scan(/[\s\t]*(end)[\s]*$/).size
157
168
  end
158
169
 
159
170
  # Return the difference
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.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Angel M Miguel