ObjCGenerator 0.0.5 → 0.0.6
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/bin/objcgenerator +9 -10
- data/lib/ObjCGenerator/category_generator.rb +31 -0
- data/lib/ObjCGenerator/class_interface_generator.rb +0 -1
- data/lib/ObjCGenerator/command.rb +29 -35
- data/lib/ObjCGenerator/json_parser.rb +36 -0
- data/lib/ObjCGenerator/types.rb +3 -0
- data/lib/ObjCGenerator/version.rb +1 -1
- data/lib/ObjCGenerator.rb +2 -0
- data/templates/category_header.erb +5 -0
- data/templates/category_implementation.erb +5 -0
- data/templates/class_header.erb +9 -0
- data/templates/class_implementation.erb +23 -0
- data/templates/incipit.erb +5 -0
- data/templates/method_class_init_with_dict.erb +3 -0
- data/templates/method_copy.erb +5 -0
- data/templates/method_description.erb +7 -0
- data/templates/method_hash.erb +6 -0
- data/templates/method_init.erb +7 -0
- data/templates/method_init_with_dictionary.erb +8 -0
- data/templates/method_is_equal.erb +7 -0
- data/templates/method_is_equal_to.erb +5 -0
- data/templates/method_to_dict.erb +5 -0
- data/templates/methods_definition.erb +10 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99a5a896777c606d06a79dfaaed6c290d62b4cf8
|
4
|
+
data.tar.gz: 2c4dbfacda9f5e823bebaadd0b8ba4864e7cf450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2aebc58d88362c096cd5a70f8ed0e82fe4444d019557a80fcadf00bd43e3e9fe5658ccb89fbae7fbaf7130b1c1d3a99a2267d4d9bac6184b6c144b9dfe210a5b
|
7
|
+
data.tar.gz: 9278bae480f767287746a6b79b8700b97029fdc434a450c377dbd592eab5ea2fd7559a1cc3a520a8b99772afb142b92b58f0490ab7a747744e63db744c79614c
|
data/bin/objcgenerator
CHANGED
@@ -13,23 +13,22 @@ command :generate do |c|
|
|
13
13
|
c.syntax = 'objgenerator generate [options]'
|
14
14
|
c.summary = 'Generate the Objective-C code'
|
15
15
|
c.description = 'Generate the Objective-C code. Provide a valid json description with the --input <string> parameter.'
|
16
|
-
c.example 'Use the "api.json" definition file and generate the classes in the current directory', 'objcgenerator generate --input "api.json" --output .'
|
16
|
+
c.example 'Use the "api.json" definition file and generate the classes in the current directory', 'objcgenerator generate --input "api.json" --output . --generate-categories'
|
17
17
|
c.option '--input STRING', String, 'The path oth the JSON desctription'
|
18
18
|
c.option '--output STRING', String, 'The output path where the obj-c code will be generated'
|
19
|
+
c.option '--generate-categories', 'For each class, a category is also created'
|
19
20
|
|
20
21
|
c.action do |args, options|
|
21
22
|
options.default :output => '.'
|
22
23
|
|
23
|
-
|
24
|
-
puts "Inavalid format:"
|
25
|
-
puts "objgenerator generate --input <file> --output <path>"
|
26
|
-
else
|
27
|
-
input=File.new(options.input,"r");
|
28
|
-
json = input.read
|
29
|
-
command = ObjCGenerator::Command.new
|
24
|
+
raise ArgumentError.new("Input parameter is required!") unless options.input
|
30
25
|
|
31
|
-
|
32
|
-
|
26
|
+
input=File.new(options.input,"r");
|
27
|
+
json = input.read
|
28
|
+
command = ObjCGenerator::Command.new
|
29
|
+
command.run json, options.output
|
30
|
+
|
31
|
+
command.generate_categories(json, options.output) if options.generate_categories
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ObjCGenerator
|
2
|
+
class CategoryGenerator
|
3
|
+
def template_path filename
|
4
|
+
File.join(File.expand_path("../..", File.dirname(__FILE__)), "templates/#{filename}.erb")
|
5
|
+
end
|
6
|
+
|
7
|
+
def generate_incipit()
|
8
|
+
author = "Ignazioc"
|
9
|
+
|
10
|
+
incipit_template = File.read(template_path('incipit'))
|
11
|
+
ERB.new(incipit_template).result(binding)
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_category_header(class_name)
|
15
|
+
incipit = generate_incipit()
|
16
|
+
|
17
|
+
header_template = File.read(template_path('category_header'))
|
18
|
+
category_header = ERB.new(header_template).result(binding)
|
19
|
+
return incipit + category_header
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_category_implementation(class_name)
|
23
|
+
incipit = generate_incipit()
|
24
|
+
|
25
|
+
template = File.read(template_path('category_implementation'))
|
26
|
+
category_implementation = ERB.new(template).result(binding)
|
27
|
+
return incipit + category_implementation
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -14,7 +14,6 @@ module ObjCGenerator
|
|
14
14
|
|
15
15
|
def generate_class_header (class_name, variables)
|
16
16
|
incipit = generate_incipit()
|
17
|
-
|
18
17
|
@class_predefinitions = generate_import_classes(variables)
|
19
18
|
@class_name = "@interface #{class_name} : NSObject <NSCopying>"
|
20
19
|
@class_properties = generate_class_properties(variables)
|
@@ -2,42 +2,36 @@ module ObjCGenerator
|
|
2
2
|
class Command
|
3
3
|
|
4
4
|
def run input_file, output_dir
|
5
|
+
parser = JSONParser.new()
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
header = g.generate_class_header var["name"], vars
|
35
|
-
File.open( output_dir + "/#{var["name"]}.h", 'w') { |file| file.write(header) }
|
36
|
-
|
37
|
-
implementation = gc.class_implementation var["name"], vars
|
38
|
-
File.open( output_dir + "/#{var["name"]}.m", 'w') { |file| file.write(implementation) }
|
39
|
-
|
40
|
-
end
|
7
|
+
result = parser.parse(input_file)
|
8
|
+
result.each do |klass|
|
9
|
+
|
10
|
+
g = ClassInterfaceGenerator.new()
|
11
|
+
gc = ClassInterfaceGenerator.new()
|
12
|
+
|
13
|
+
header = g.generate_class_header klass[:name], klass[:var_list]
|
14
|
+
File.open( output_dir + "/#{klass[:name]}.h", 'w') { |file| file.write(header) }
|
15
|
+
|
16
|
+
implementation = gc.class_implementation klass[:name], klass[:var_list]
|
17
|
+
File.open( output_dir + "/#{klass[:name]}.m", 'w') { |file| file.write(implementation) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_categories(input_file, output_dir)
|
22
|
+
parser = JSONParser.new()
|
23
|
+
result = parser.parse(input_file)
|
24
|
+
|
25
|
+
categoryGenerator = CategoryGenerator.new()
|
26
|
+
|
27
|
+
result.each do |klass|
|
28
|
+
class_name = klass[:name]
|
29
|
+
|
30
|
+
header = categoryGenerator.generate_category_header(class_name)
|
31
|
+
File.open( output_dir + "/#{klass[:name]}+CustomCode.h", 'w') { |file| file.write(header) }
|
32
|
+
|
33
|
+
implementation = categoryGenerator.generate_category_implementation(class_name)
|
34
|
+
File.open( output_dir + "/#{klass[:name]}+CustomCode.m", 'w') { |file| file.write(implementation) }
|
41
35
|
end
|
42
36
|
end
|
43
37
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ObjCGenerator
|
2
|
+
class JSONParser
|
3
|
+
|
4
|
+
|
5
|
+
#return an array of maps
|
6
|
+
#in this format {:name => 'SampleClass', :var_list => [....]}
|
7
|
+
def parse(input_file)
|
8
|
+
parsed = JSON.parse(input_file)
|
9
|
+
result = []
|
10
|
+
parsed.each do |klass|
|
11
|
+
if klass["type"] == "Class"
|
12
|
+
var_list = klass["vars"].map { |hash|
|
13
|
+
case hash["type"]
|
14
|
+
when "Bool"
|
15
|
+
TypeBool.new(hash["name"])
|
16
|
+
when "Int"
|
17
|
+
TypeInt.new(hash["name"])
|
18
|
+
when "Float"
|
19
|
+
TypeFloat.new(hash["name"])
|
20
|
+
when "String"
|
21
|
+
TypeString.new(hash["name"])
|
22
|
+
when "Date"
|
23
|
+
TypeDate.new(hash["name"])
|
24
|
+
when "Array"
|
25
|
+
TypeArray.new(hash["name"], hash["subType"])
|
26
|
+
else
|
27
|
+
TypeCustomObject.new(hash["name"], hash["type"])
|
28
|
+
end
|
29
|
+
}
|
30
|
+
end #end if
|
31
|
+
result << {name: klass["name"], var_list: var_list }
|
32
|
+
end #end each
|
33
|
+
result
|
34
|
+
end #end parse
|
35
|
+
end
|
36
|
+
end
|
data/lib/ObjCGenerator/types.rb
CHANGED
data/lib/ObjCGenerator.rb
CHANGED
@@ -4,6 +4,8 @@ require 'erb'
|
|
4
4
|
require "ObjCGenerator/version"
|
5
5
|
require "ObjCGenerator/class_interface_generator"
|
6
6
|
require "ObjCGenerator/class_implementation_generator"
|
7
|
+
require "ObjCGenerator/category_generator"
|
8
|
+
require "ObjCGenerator/json_parser"
|
7
9
|
require "ObjCGenerator/command"
|
8
10
|
require "ObjCGenerator/types"
|
9
11
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#import "<%= class_name %>.h"
|
2
|
+
<%= @import_other_classes %>
|
3
|
+
@implementation <%= class_name %>
|
4
|
+
|
5
|
+
<%= @init_method %>
|
6
|
+
|
7
|
+
<%= @init_with_dict_method %>
|
8
|
+
|
9
|
+
<%= @class_init_with_dict %>
|
10
|
+
|
11
|
+
<%= @to_dict_method %>
|
12
|
+
|
13
|
+
<%= @is_equals_method%>
|
14
|
+
|
15
|
+
<%= @is_equals_to_Object_method %>
|
16
|
+
|
17
|
+
<%= @description_method %>
|
18
|
+
|
19
|
+
<%= @copy_method %>
|
20
|
+
|
21
|
+
<%= @hash_method %>
|
22
|
+
|
23
|
+
@end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
- (instancetype)init;
|
2
|
+
- (instancetype)initWithDict:(NSDictionary *)dict;
|
3
|
+
+ (instancetype)<%= lowercase_class_name %>WithDict:(NSDictionary *)dict;
|
4
|
+
- (NSDictionary *)toDict;
|
5
|
+
|
6
|
+
- (BOOL)isEqual:(id)object;
|
7
|
+
- (BOOL)isEqualTo<%= class_name %>:(<%= class_name %> *)other;
|
8
|
+
- (NSUInteger)hash;
|
9
|
+
- (NSString *)description;
|
10
|
+
- (instancetype)copyWithZone:(NSZone *)zone;
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ObjCGenerator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignazio Calò
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -62,11 +62,28 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- bin/objcgenerator
|
64
64
|
- lib/ObjCGenerator.rb
|
65
|
+
- lib/ObjCGenerator/category_generator.rb
|
65
66
|
- lib/ObjCGenerator/class_implementation_generator.rb
|
66
67
|
- lib/ObjCGenerator/class_interface_generator.rb
|
67
68
|
- lib/ObjCGenerator/command.rb
|
69
|
+
- lib/ObjCGenerator/json_parser.rb
|
68
70
|
- lib/ObjCGenerator/types.rb
|
69
71
|
- lib/ObjCGenerator/version.rb
|
72
|
+
- templates/category_header.erb
|
73
|
+
- templates/category_implementation.erb
|
74
|
+
- templates/class_header.erb
|
75
|
+
- templates/class_implementation.erb
|
76
|
+
- templates/incipit.erb
|
77
|
+
- templates/method_class_init_with_dict.erb
|
78
|
+
- templates/method_copy.erb
|
79
|
+
- templates/method_description.erb
|
80
|
+
- templates/method_hash.erb
|
81
|
+
- templates/method_init.erb
|
82
|
+
- templates/method_init_with_dictionary.erb
|
83
|
+
- templates/method_is_equal.erb
|
84
|
+
- templates/method_is_equal_to.erb
|
85
|
+
- templates/method_to_dict.erb
|
86
|
+
- templates/methods_definition.erb
|
70
87
|
homepage: ''
|
71
88
|
licenses:
|
72
89
|
- MIT
|