ditto_code 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dittoc +13 -3
  3. data/lib/dittocode/parse.rb +14 -6
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94116e826c5c80e1677bb93fa0995931aa91a846
4
- data.tar.gz: a7bb58d325d8ba77a5397e9bf46939ed8d6c73e8
3
+ metadata.gz: 0ea196dce723d0ac359698050ce90f82f8f0e881
4
+ data.tar.gz: 49835ff70f702190110698aec6b36d574194a949
5
5
  SHA512:
6
- metadata.gz: ffc4edeb0b21be03a544bde6efb05653554cc510f719b52506f7b39b1af62f0e02ca88cc9758cffc9ffc9f91a8ffdb6e4803ce5d7f8706079a045e8ac46839bb
7
- data.tar.gz: e3d830ff566898824715a0728e61ec574a19c883f873c054ccdb19d0e29baa3f4a1c34071dbf07470766cba2edd547bcaf01f4729b500272c4523eaee43613de
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) && rb_file.end_with?('.rb')
41
- @ditto.transformation(filepath)
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
@@ -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
- m = /[\s]*DittoCode::Exec.if[\s]+['|"](?<environment>[a-zA-Z]+)['|"] do/.match(line)
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
- initializers = line.scan(/^(if|do|def)[\s]+/).size + line.scan(/[\s]+(if|do|def)[\s]+/).size + line.scan(/[\s]+(if|do|def)$/).size
118
- # Get the ends blocks
119
- finals = line.scan(/[\s]+(end)[\s]+/).size + line.scan(/^(end)[\s]+/).size + line.scan(/[\s]+(end)$/).size
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
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Angel M Miguel