codgen 0.0.2 → 0.0.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/.idea/codgen.iml +3 -5
- data/.idea/workspace.xml +260 -188
- data/README.md +2 -0
- data/codgen.gemspec +2 -0
- data/lib/codgen.rb +10 -1
- data/lib/codgen/package.rb +54 -0
- data/lib/codgen/version.rb +1 -1
- data/test/data/Input/example-data.json +2 -1
- data/test/data/Input/package_test_dir/config.json +8 -0
- data/test/data/Input/package_test_dir/templates/package_hello_world.txt.mustache +1 -0
- data/test/data/Input/package_test_zip.zip +0 -0
- data/test/data/Output/package_hello_world.txt +1 -0
- data/test/data/Output/package_zip_hello_world.txt +1 -0
- data/test/data/__MACOSX/package_test_zip/._.DS_Store +0 -0
- data/test/data/config.json +5 -0
- data/test/data/expected_output/package_hello_world.txt +1 -0
- data/test/data/expected_output/package_zip_hello_world.txt +1 -0
- data/test/data/package_test_zip/config.json +8 -0
- data/test/data/package_test_zip/templates/config.json +8 -0
- data/test/data/package_test_zip/templates/package_zip_hello_world.txt.mustache +1 -0
- data/test/unit/package_spec.rb +95 -0
- metadata +54 -1
data/README.md
CHANGED
|
@@ -7,6 +7,8 @@ Right now it uses mustache for it's template files and JSON for it's config and
|
|
|
7
7
|
If you find bugs or bad error messages be sure to log an issue.
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
[](http://badge.fury.io/rb/codgen)
|
|
11
|
+
|
|
10
12
|
## Installation
|
|
11
13
|
|
|
12
14
|
$ gem install codgen
|
data/codgen.gemspec
CHANGED
|
@@ -26,7 +26,9 @@ If you find bugs or bad error messages be sure to log an issue on GitHub."
|
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.7"
|
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
28
28
|
spec.add_development_dependency "rspec"
|
|
29
|
+
spec.add_development_dependency "given_when_then"
|
|
29
30
|
spec.add_runtime_dependency "mustache"
|
|
30
31
|
spec.add_runtime_dependency "json"
|
|
31
32
|
spec.add_runtime_dependency "activerecord"
|
|
33
|
+
spec.add_runtime_dependency 'rubyzip'
|
|
32
34
|
end
|
data/lib/codgen.rb
CHANGED
|
@@ -3,6 +3,7 @@ require_relative 'codgen/auto_style'
|
|
|
3
3
|
require_relative 'codgen/mapping'
|
|
4
4
|
require_relative 'codgen/logger'
|
|
5
5
|
require_relative 'codgen/template'
|
|
6
|
+
require_relative 'codgen/package'
|
|
6
7
|
|
|
7
8
|
module Codgen
|
|
8
9
|
def self.run(json_config)
|
|
@@ -18,8 +19,16 @@ module Codgen
|
|
|
18
19
|
filled_templates = Array.new
|
|
19
20
|
|
|
20
21
|
templates = json_config['templates']
|
|
21
|
-
|
|
22
|
+
packages = json_config['packages']
|
|
22
23
|
|
|
24
|
+
if packages != nil
|
|
25
|
+
packages.each do |packageInfo|
|
|
26
|
+
package = Package.new(packageInfo)
|
|
27
|
+
templates.concat(package.templates)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
templates.each do |template_info|
|
|
23
32
|
template = Template.new(template_info, json_data)
|
|
24
33
|
template.fill_template.each {|filled_template| filled_templates.push(filled_template)}
|
|
25
34
|
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require_relative 'logger'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'zip'
|
|
5
|
+
|
|
6
|
+
module Codgen
|
|
7
|
+
class Package
|
|
8
|
+
def initialize(package_info)
|
|
9
|
+
if package_info.is_a?(String)
|
|
10
|
+
@input_path = package_info
|
|
11
|
+
elsif package_info.is_a?(Hash)
|
|
12
|
+
@input_path = package_info['path']
|
|
13
|
+
if @input_path == nil
|
|
14
|
+
Logger.error 'Required property of package "path" was not found'
|
|
15
|
+
end
|
|
16
|
+
else
|
|
17
|
+
Logger.error 'Invalid package path format'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
@unpacked_path = ''
|
|
21
|
+
|
|
22
|
+
if File.directory?(@input_path)
|
|
23
|
+
@unpacked_path = @input_path
|
|
24
|
+
elsif File.extname(@input_path) == '.zip'
|
|
25
|
+
@unpacked_path = File.basename(@input_path, '.zip')
|
|
26
|
+
unzip_file(@input_path)
|
|
27
|
+
else
|
|
28
|
+
Logger.error 'Invalid package file format: should be a zip or a directory'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
config_path = "#{@unpacked_path}/config.json"
|
|
32
|
+
config_file = File.read(config_path)
|
|
33
|
+
@config = JSON.parse(config_file)
|
|
34
|
+
@templates = @config['templates']
|
|
35
|
+
@templates.each { |t| t['in'] = "#{@unpacked_path}/templates/#{t['in']}"}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
attr_reader :config, :templates, :unpacked_path
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
def unzip_file (file)
|
|
42
|
+
Zip::File.open(file) do |zip_file|
|
|
43
|
+
zip_file.each do |f|
|
|
44
|
+
f_path = f.name
|
|
45
|
+
if File.directory?(f_path)
|
|
46
|
+
FileUtils.rm_rf(f_path)
|
|
47
|
+
end
|
|
48
|
+
FileUtils.mkdir_p(File.dirname(f_path))
|
|
49
|
+
f.extract(f_path)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
data/lib/codgen/version.rb
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Hello {{name}}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Hello World
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Hello World
|
|
Binary file
|
data/test/data/config.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Hello World
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Hello World
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Hello {{name}}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require 'rspec'
|
|
2
|
+
require 'given_when_then'
|
|
3
|
+
require_relative '../../lib/codgen/package'
|
|
4
|
+
|
|
5
|
+
describe 'Package' do
|
|
6
|
+
Given 'A unpacked package with a string input' do
|
|
7
|
+
path = 'Input/package_test_dir'
|
|
8
|
+
When 'the package object is initialized' do
|
|
9
|
+
package = Codgen::Package.new(path)
|
|
10
|
+
Then 'the path to the templates pointed at package path' do
|
|
11
|
+
expect(package.unpacked_path).to eq 'Input/package_test_dir'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
Then 'templates should be an array' do
|
|
15
|
+
expect(package.templates.is_a?(Array)).to eq true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
Then 'templates should have one element' do
|
|
19
|
+
expect(package.templates.length).to eq 1
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
Then 'the first template should have an "in" value of "Input/package_test_dir/templates/package_hello_world.txt.mustache"' do
|
|
23
|
+
expect(package.templates[0]['in']).to eq 'Input/package_test_dir/templates/package_hello_world.txt.mustache'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Then 'the first template should have an "out" value of "Output/package_hello_world.txt"' do
|
|
27
|
+
expect(package.templates[0]['out']).to eq 'Output/package_hello_world.txt'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Then 'config should be a hash' do
|
|
31
|
+
expect(package.config.is_a?(Hash)).to eq true
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
Given 'A compressed package with a string path input' do
|
|
37
|
+
path = 'Input/package_test_zip.zip'
|
|
38
|
+
When 'the package object is initialized' do
|
|
39
|
+
package = Codgen::Package.new(path)
|
|
40
|
+
Then 'the path to the templates pointed at the unpacked directory' do
|
|
41
|
+
expect(package.unpacked_path).to eq 'package_test_zip'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
Then 'templates should be an array' do
|
|
45
|
+
expect(package.templates.is_a?(Array)).to eq true
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
Then 'templates should have one element' do
|
|
49
|
+
expect(package.templates.length).to eq 1
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
Then 'the first template should have an "in" value of "package_test_zip/templates/package_zip_hello_world.txt.mustache"' do
|
|
53
|
+
expect(package.templates[0]['in']).to eq 'package_test_zip/templates/package_zip_hello_world.txt.mustache'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
Then 'the first template should have an "out" value of "Output/package_zip_hello_world.txt"' do
|
|
57
|
+
expect(package.templates[0]['out']).to eq 'Output/package_zip_hello_world.txt'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
Then 'config should be a hash' do
|
|
61
|
+
expect(package.config.is_a?(Hash)).to eq true
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
Given 'A unpacked package with a json object with path property' do
|
|
67
|
+
package_info = { 'path' => 'Input/package_test_dir' }
|
|
68
|
+
When 'the package object is initialized' do
|
|
69
|
+
package = Codgen::Package.new(package_info)
|
|
70
|
+
Then 'the path to the templates pointed at package path' do
|
|
71
|
+
expect(package.unpacked_path).to eq 'Input/package_test_dir'
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
Then 'templates should be an array' do
|
|
75
|
+
expect(package.templates.is_a?(Array)).to eq true
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
Then 'templates should have one element' do
|
|
79
|
+
expect(package.templates.length).to eq 1
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
Then 'the first template should have an "in" value of "Input/package_test_dir/templates/package_hello_world.txt.mustache"' do
|
|
83
|
+
expect(package.templates[0]['in']).to eq 'Input/package_test_dir/templates/package_hello_world.txt.mustache'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
Then 'the first template should have an "out" value of "Output/package_hello_world.txt"' do
|
|
87
|
+
expect(package.templates[0]['out']).to eq 'Output/package_hello_world.txt'
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
Then 'config should be a hash' do
|
|
91
|
+
expect(package.config.is_a?(Hash)).to eq true
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: codgen
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matthew Beatty
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - '>='
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: given_when_then
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '>='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: mustache
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -94,6 +108,20 @@ dependencies:
|
|
|
94
108
|
- - '>='
|
|
95
109
|
- !ruby/object:Gem::Version
|
|
96
110
|
version: '0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: rubyzip
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - '>='
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :runtime
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - '>='
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
97
125
|
description: |-
|
|
98
126
|
A cross language, template based, code generator, capable of generating multiple applications from a common model.
|
|
99
127
|
|
|
@@ -144,6 +172,7 @@ files:
|
|
|
144
172
|
- lib/codgen/flattener.rb
|
|
145
173
|
- lib/codgen/logger.rb
|
|
146
174
|
- lib/codgen/mapping.rb
|
|
175
|
+
- lib/codgen/package.rb
|
|
147
176
|
- lib/codgen/statement.rb
|
|
148
177
|
- lib/codgen/template.rb
|
|
149
178
|
- lib/codgen/version.rb
|
|
@@ -156,6 +185,9 @@ files:
|
|
|
156
185
|
- test/data/Input/example-data.json
|
|
157
186
|
- test/data/Input/hello_world.txt.mustache
|
|
158
187
|
- test/data/Input/model_template.rb.ctemp
|
|
188
|
+
- test/data/Input/package_test_dir/config.json
|
|
189
|
+
- test/data/Input/package_test_dir/templates/package_hello_world.txt.mustache
|
|
190
|
+
- test/data/Input/package_test_zip.zip
|
|
159
191
|
- test/data/Input/test_conditionals
|
|
160
192
|
- test/data/Input/test_escapes
|
|
161
193
|
- test/data/Map.json
|
|
@@ -165,15 +197,24 @@ files:
|
|
|
165
197
|
- test/data/Output/MsMvc/MyBlog/Models/Post.cs
|
|
166
198
|
- test/data/Output/Ruby/my_blog/Models/comment.rb
|
|
167
199
|
- test/data/Output/Ruby/my_blog/Models/post.rb
|
|
200
|
+
- test/data/Output/package_hello_world.txt
|
|
201
|
+
- test/data/Output/package_zip_hello_world.txt
|
|
202
|
+
- test/data/__MACOSX/package_test_zip/._.DS_Store
|
|
168
203
|
- test/data/config.json
|
|
169
204
|
- test/data/expected_output/MsMvc/MyBlog/DAL/MyBlogContext.cs
|
|
170
205
|
- test/data/expected_output/MsMvc/MyBlog/Models/Comment.cs
|
|
171
206
|
- test/data/expected_output/MsMvc/MyBlog/Models/Post.cs
|
|
172
207
|
- test/data/expected_output/Ruby/my_blog/Models/comment.rb
|
|
173
208
|
- test/data/expected_output/Ruby/my_blog/Models/post.rb
|
|
209
|
+
- test/data/expected_output/package_hello_world.txt
|
|
210
|
+
- test/data/expected_output/package_zip_hello_world.txt
|
|
211
|
+
- test/data/package_test_zip/config.json
|
|
212
|
+
- test/data/package_test_zip/templates/config.json
|
|
213
|
+
- test/data/package_test_zip/templates/package_zip_hello_world.txt.mustache
|
|
174
214
|
- test/data/test.mustache
|
|
175
215
|
- test/unit/codgen_engine_spec.rb
|
|
176
216
|
- test/unit/flattener_spec.rb
|
|
217
|
+
- test/unit/package_spec.rb
|
|
177
218
|
- test/unit/template_spec.rb
|
|
178
219
|
homepage: https://github.com/beattyml1/codgen
|
|
179
220
|
licenses:
|
|
@@ -210,6 +251,9 @@ test_files:
|
|
|
210
251
|
- test/data/Input/example-data.json
|
|
211
252
|
- test/data/Input/hello_world.txt.mustache
|
|
212
253
|
- test/data/Input/model_template.rb.ctemp
|
|
254
|
+
- test/data/Input/package_test_dir/config.json
|
|
255
|
+
- test/data/Input/package_test_dir/templates/package_hello_world.txt.mustache
|
|
256
|
+
- test/data/Input/package_test_zip.zip
|
|
213
257
|
- test/data/Input/test_conditionals
|
|
214
258
|
- test/data/Input/test_escapes
|
|
215
259
|
- test/data/Map.json
|
|
@@ -219,13 +263,22 @@ test_files:
|
|
|
219
263
|
- test/data/Output/MsMvc/MyBlog/Models/Post.cs
|
|
220
264
|
- test/data/Output/Ruby/my_blog/Models/comment.rb
|
|
221
265
|
- test/data/Output/Ruby/my_blog/Models/post.rb
|
|
266
|
+
- test/data/Output/package_hello_world.txt
|
|
267
|
+
- test/data/Output/package_zip_hello_world.txt
|
|
268
|
+
- test/data/__MACOSX/package_test_zip/._.DS_Store
|
|
222
269
|
- test/data/config.json
|
|
223
270
|
- test/data/expected_output/MsMvc/MyBlog/DAL/MyBlogContext.cs
|
|
224
271
|
- test/data/expected_output/MsMvc/MyBlog/Models/Comment.cs
|
|
225
272
|
- test/data/expected_output/MsMvc/MyBlog/Models/Post.cs
|
|
226
273
|
- test/data/expected_output/Ruby/my_blog/Models/comment.rb
|
|
227
274
|
- test/data/expected_output/Ruby/my_blog/Models/post.rb
|
|
275
|
+
- test/data/expected_output/package_hello_world.txt
|
|
276
|
+
- test/data/expected_output/package_zip_hello_world.txt
|
|
277
|
+
- test/data/package_test_zip/config.json
|
|
278
|
+
- test/data/package_test_zip/templates/config.json
|
|
279
|
+
- test/data/package_test_zip/templates/package_zip_hello_world.txt.mustache
|
|
228
280
|
- test/data/test.mustache
|
|
229
281
|
- test/unit/codgen_engine_spec.rb
|
|
230
282
|
- test/unit/flattener_spec.rb
|
|
283
|
+
- test/unit/package_spec.rb
|
|
231
284
|
- test/unit/template_spec.rb
|