kilza 1.0.1 → 1.0.2

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: 1399ff570feae81c6563af28176cf00c299b457f
4
- data.tar.gz: e800dd1435fc52614ea820b2e328925d0115bd88
3
+ metadata.gz: 19afa4576243d4b81618c7a96e3fcfc171d1e40c
4
+ data.tar.gz: 5ebd96dd828845962476cd04e9d9b1c5f2c581e4
5
5
  SHA512:
6
- metadata.gz: 63d33a06e41782c5e2d7d77d3141e2d58fa5e246616e0b91021b89cd5470991aa0483ec15fa2e031c4e9e4da159bb70d57cfa45d45f1a54ff5dcc8abcd838124
7
- data.tar.gz: ecc51bd08e3a2b6803f9827870e2e1ecf41cf233269f742249211e1b39202211312038ac91f9c5b32e5ba08f01e5f6aa9180ba01ed1b8ae3322f542b7a9172b3
6
+ metadata.gz: 7359efe86778e41c19a07fbd9b2e7719d73db4626c4630f1944d9ba4ab4c4576efd9c4155f5d88cdb3f720012617b4bb3a8d0ad9b88f8db6178fc131a931a2e5
7
+ data.tar.gz: 08bbb522b1b72075a981a2accd3ea2d4db85629cf417d0c22eb4f871bbb5d14428322f99297e78b0941788ce467d2a8610b894ba42efd7c54bf4f8e67e54c09e
data/bin/kilza CHANGED
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubygems'
4
- require 'highline'
5
4
  require 'kilza'
5
+ require 'pastel'
6
+ require 'tty'
7
+ require 'tty-prompt'
8
+ require 'tty-spinner'
6
9
  require 'net/http'
7
10
  require 'uri'
8
11
 
@@ -10,101 +13,118 @@ def read_url(url)
10
13
  Net::HTTP.get(URI.parse(url))
11
14
  end
12
15
 
13
- cli = HighLine.new
14
- cli.say "Hi <%= color('master', BOLD) %>. I can convert your JSON string to Object files.\n\n"
15
-
16
- loop do
17
- begin
18
- cli.say "<%= color('What can I do for you?', BOLD) %>"
19
- cli.choose do |menu|
20
- menu.prompt = ""
21
- menu.choice("I want some JSON objects.") {
22
- }
23
- menu.choice("Nothing.") {
24
- break
25
- }
16
+ module TTY
17
+ class Prompt
18
+ class List
19
+ def numpad(value)
20
+ @numpad = value
21
+ end
26
22
  end
23
+ end
24
+ end
27
25
 
28
- json_is_url = false
29
- cli.say "<%= color('\nWhere is your JSON string content?', BOLD) %>"
30
- cli.choose do |menu|
31
- menu.prompt = ""
32
- menu.choice("It's online. I have an URL.") {
33
- json_is_url = true
34
- }
35
- menu.choice("It's offline. I have the file path.") { cli.say("Ok.") }
36
- end
26
+ class KilzaApplication
37
27
 
38
- json_string = ''
39
- if (json_is_url)
40
- url = cli.ask ("<%= color('\nPlease, what is the URL?', BOLD) %>")
41
- cli.say("<%= color('\nOk. I\\'ll try to get the content right now.', BOLD) %>")
42
- json_string = read_url(url)
43
- else
44
- file_path = cli.ask ("<%= color('\nPlease, what is the file path?', BOLD) %>")
45
- json_string = File.read(file_path)
46
- end
28
+ def initialize
29
+ @pastel = Pastel.new
30
+ @prompt = TTY::Prompt.new
31
+ @spinner = TTY::Spinner.new
47
32
 
48
- target_path = cli.ask "<%= color('\nMaster, where would you like to save?', BOLD) %>"
49
- target_path = File.expand_path(target_path)
50
-
51
- class_basename = cli.ask "<%= color('\nMaster, which name would like to call the first class?', BOLD) %>"
52
-
53
- target_lang = ''
54
- cli.say("<%= color('\nPlease choose your target programming language?', BOLD) %>")
55
- cli.choose do |menu|
56
- menu.prompt = ""
57
- menu.choice("Objective-C") {
58
- target_lang = "objc"
59
- }
60
- menu.choice("Java") {
61
- target_lang = "java"
62
- }
63
- end
33
+ @done = false
34
+ end
64
35
 
65
- cli.say "<%= color('\nIs that correct?', BOLD) %>"
66
- cli.say("Target: " + target_path)
67
- cli.say("Base class name:" + class_basename)
68
- cli.say("Target language:" + target_lang)
69
-
70
- cli.choose do |menu|
71
- menu.prompt = ""
72
- menu.choice("Yes.") {
73
- }
74
- menu.choice("No.") {
75
- break
76
- }
36
+ def get_lang
37
+ action = @prompt.select(@pastel.bold("Target programming language?")) do |menu|
38
+ menu.default 1
39
+ menu.numpad true
40
+
41
+ menu.choice "Objective-C", 1
42
+ menu.choice "Java", 2
77
43
  end
44
+ action
45
+ end
78
46
 
79
- cli.say("<%= color('\nYes master. Now I\\'m going to generate all files.', BOLD) %>")
80
- cli.say("<%= color('Berebekan Katabamba Berebekan Katabamba Berebekan Katabamba', BOLD) %>")
47
+ def get_json
48
+ action = @prompt.select(@pastel.bold("Where is your JSON string content?")) do |menu|
49
+ menu.default 1
50
+ menu.numpad true
81
51
 
82
- if (target_lang == "objc")
83
- objc = Kilza::Objc.new(json_string)
84
- objc.classes(class_basename).each { |c|
85
- c.sources.each{ |s|
86
- File.write(File.join(target_path, s.file_name), s.source)
87
- }
88
- }
89
- else
90
- java = Kilza::Java.new(json_string)
91
- java.classes(class_basename).each { |c|
92
- c.sources.each{ |s|
93
- File.write(File.join(target_path, s.file_name), s.source)
94
- }
95
- }
52
+ menu.choice "It's online. I have an URL.", 1
53
+ menu.choice "It's offline. I have the file path.", 2
96
54
  end
97
55
 
98
- cli.say("<%= color('\nKikera!', BOLD) %>")
56
+ json_string = ''
57
+ if (action == 1)
58
+ url = @prompt.ask(@pastel.bold("Please, what is the URL?")) do |q|
59
+ q.required true
60
+ end
61
+ @prompt.say(@pastel.bold("Ok. I'll try to get the content right now."))
62
+ json_string = read_url(url)
63
+ else
64
+ file_path = File.expand_path(@prompt.ask(@pastel.bold("Please, what is the file path? "))) do |q|
65
+ q.required true
66
+ end
67
+ json_string = File.read(file_path.chomp)
68
+ end
69
+ json_string
70
+ end
99
71
 
100
- rescue EOFError # HighLine throws this if @input.eof?
101
- break
102
- rescue => e
103
- cli.say("<%= color('\nOh master. Sorry, but I\\'ve encountered an error:', BOLD) %>")
104
- puts e
105
- puts "\n"
72
+ def run
73
+ while (not @done)
74
+ action = @prompt.select(@pastel.bold("Choose your destiny?")) do |menu|
75
+ menu.default 1
76
+ menu.numpad true
77
+
78
+ menu.choice 'I want some JSON objects.', 1
79
+ menu.choice 'Nothing.', 2
80
+ end
81
+ if action == 1
82
+ json_string = get_json
83
+ target_path = @prompt.ask(@pastel.bold("Master, where would you like to save? ")).chomp
84
+ target_path = File.expand_path(target_path)
85
+ class_basename = @prompt.ask(@pastel.bold("Master, which name would like to call the first class? ")).chomp
86
+ lang = get_lang
87
+
88
+ class_package = nil
89
+ if (lang == 2)
90
+ class_package = @prompt.ask(@pastel.bold("What is the target Java package? ")).chomp
91
+ end
92
+
93
+ @prompt.say(@pastel.bold("Target: ") + target_path)
94
+ @prompt.say(@pastel.bold("Base class name: ") + class_basename)
95
+ @prompt.say(@pastel.bold("Target language: ") + (lang == 1 ? 'Objective-C' : 'Java'))
96
+ if (not class_package.nil?)
97
+ @prompt.say(@pastel.bold("Target package: ") + class_package)
98
+ end
99
+ ok = @prompt.yes?('Is that correct?')
100
+ if (ok.nil? or ok)
101
+ @prompt.say(@pastel.bold("Yes master. Now I'm going to generate all files."))
102
+ @prompt.say(@pastel.bold("Berebekan Katabamba Berebekan Katabamba Berebekan Katabamba"))
103
+
104
+ if (lang == 1)
105
+ objc = Kilza::Objc.new(json_string)
106
+ objc.classes(class_basename).each { |c|
107
+ c.sources.each{ |s|
108
+ File.write(File.join(target_path, s.file_name), s.source)
109
+ }
110
+ }
111
+ else
112
+ java = Kilza::Java.new(json_string)
113
+ java.classes(class_basename).each { |c|
114
+ c.package = class_package
115
+ c.sources.each{ |s|
116
+ File.write(File.join(target_path, s.file_name), s.source)
117
+ }
118
+ }
119
+ end
120
+
121
+ @prompt.say(@pastel.bold("Kikera!"))
122
+ end
123
+ else
124
+ @done = true
125
+ end
126
+ end
106
127
  end
107
128
  end
108
129
 
109
- puts "Goodbye."
110
- exit
130
+ KilzaApplication.new.run
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Toshiro Sugii"]
10
10
  spec.email = ["rtoshiro@printwtf.com"]
11
11
 
12
- spec.summary = %q{Parses JSON objects and generates objects in other languages}
13
- spec.description = %q{Parses JSON objects and generates objects in other languages}
12
+ spec.summary = %q{Parses JSON objects and generates objects into other languages}
13
+ spec.description = %q{Parses JSON objects and generates objects into other languages}
14
14
  spec.homepage = "https://github.com/Jaspion/Kilza"
15
15
  spec.license = "MIT"
16
16
 
@@ -33,5 +33,6 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  spec.add_dependency "json"
35
35
  spec.add_dependency "erubis"
36
- spec.add_dependency "highline"
36
+ spec.add_dependency "tty"
37
+ spec.add_dependency "pastel"
37
38
  end
@@ -8,6 +8,11 @@ module Kilza
8
8
 
9
9
  attr_accessor :package
10
10
 
11
+ def initialize(name, package = nil)
12
+ super(name)
13
+ @package = package
14
+ end
15
+
11
16
  def sources
12
17
  cur_path = File.expand_path(__FILE__)
13
18
  java_path = File.join(File.dirname(cur_path), File.basename(cur_path, '.rb'), "java.erb")
@@ -80,14 +80,14 @@ public class <%= @name %> implements Serializable
80
80
  }
81
81
 
82
82
  <% for @property in @properties %>
83
- public void set<%= @property.name.capitalize %>(<%= @property.type %> value) {
83
+ public void set<%= @property.name.capitalize %>(<%= @property.is_array? ? "ArrayList<" + @property.type + ">" : @property.type %> value) {
84
84
  this.<%= @property.name %> = value;
85
85
  }
86
86
 
87
87
  <% if @property.is_boolean? %>
88
88
  public <%= @property.type %> is<%= @property.name.capitalize %>() {
89
89
  <% else %>
90
- public <%= @property.type %> get<%= @property.name.capitalize %>() {
90
+ public <%= @property.is_array? ? "ArrayList<" + @property.type + ">" : @property.type %> get<%= @property.name.capitalize %>() {
91
91
  <% end %>
92
92
  return this.<%= @property.name %>;
93
93
  }
@@ -98,7 +98,7 @@ public class <%= @name %> implements Serializable
98
98
  @hs = []
99
99
  for @property in @properties
100
100
  @eq.push("((#{@name}) obj).get#{@property.name.capitalize}().equals(#{@property.name})") if (@property.is_key)
101
- @hs.push("((#{@property.type})#{@property.name}).hashCode()") if (@property.is_key)
101
+ @hs.push("(#{@property.name}).hashCode()") if (@property.is_key)
102
102
  end
103
103
  %>
104
104
  <% if @eq.length > 0 %>
@@ -20,7 +20,7 @@ module Kilza
20
20
  end
21
21
 
22
22
  def is_object?
23
- @type == 'object'
23
+ @type == 'object' or @type == @name.capitalize
24
24
  end
25
25
 
26
26
  def is_fixnum?
@@ -1,3 +1,3 @@
1
1
  module Kilza
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kilza
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshiro Sugii
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-08 00:00:00.000000000 Z
11
+ date: 2016-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: highline
84
+ name: tty
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '>='
@@ -94,7 +94,21 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: Parses JSON objects and generates objects in other languages
97
+ - !ruby/object:Gem::Dependency
98
+ name: pastel
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Parses JSON objects and generates objects into other languages
98
112
  email:
99
113
  - rtoshiro@printwtf.com
100
114
  executables:
@@ -148,5 +162,5 @@ rubyforge_project:
148
162
  rubygems_version: 2.0.14
149
163
  signing_key:
150
164
  specification_version: 4
151
- summary: Parses JSON objects and generates objects in other languages
165
+ summary: Parses JSON objects and generates objects into other languages
152
166
  test_files: []