sawa 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c47bbe5403c7588283749222d8c9a28f2d47b4df
4
- data.tar.gz: e91c8364730c5a6defb4a37ac9b8a9062ed18976
3
+ metadata.gz: c9a8407ae0c6fad4e626c1f01b20cd5b13434cd9
4
+ data.tar.gz: e9a44f7aa4e80dc5fc99b1c6a3903f19fb7bf6e0
5
5
  SHA512:
6
- metadata.gz: 3a08f62d6d1cb7ad63eca276adae1162d5b79cbb3ef3d2df1f03d97fec25fea98a0ea4d86efe6a65e4510eaa7a3ae6c4082467f3faa71288751eb50baa54072a
7
- data.tar.gz: eb89e5761f4c21dc3b4495eeaba9ae29b73ecabbd1647b78b602e653dd4841dcb0dd9ae1ecab3046140b713bec11d1ab668522a6f337841e620d3566144908d7
6
+ metadata.gz: 1b5b90d2056dd3acffa499254bcad2b5ad3ac03d12eafb34d80774d53b6e907dd21f3349d4693208988cbbed25af8512fbb7ad53f94d33cb825ac79fffa1269a
7
+ data.tar.gz: 9b9b1fe68e16f7d778f75658321b2b60d7eb1f82e4b03370c99985ae50dec5eec2559158cdf9778ce505a851616ecf11b10c46be4f110b513eee3f54a765f621
data/.project ADDED
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>sawagem</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ </buildSpec>
9
+ <natures>
10
+ </natures>
11
+ </projectDescription>
data/README.md CHANGED
@@ -1,36 +1,59 @@
1
- # Sawa
2
-
3
- install it yourself as:
4
-
5
- $ gem install sawa
6
-
7
- ## Usage
8
-
9
- create new crud project:
10
-
11
- $ sawa -n demo
12
-
13
- create new crud project:
14
-
15
- $ cd demo
16
- $ sawa -g model.xls
17
- $ ant compile
18
-
19
- run api server (*before run api you must fix db config in mini.yml)
20
-
21
- $ sawa -s
22
-
23
- [http://localhost:9000/](http://localhost:9000)
24
-
25
- run client
26
-
27
- $ cd www
28
- $ npm install
29
- $ npm start
30
-
31
- [http://localhost:3000/](http://localhost:3000)
32
-
33
- ## License
34
-
35
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
36
-
1
+
2
+ ![](https://s3-ap-northeast-1.amazonaws.com/ms17222/step/Original_without_effects_204x75.png)
3
+
4
+ # SawaGem : auto generate code tools for sawa rest api
5
+
6
+ install it yourself as:
7
+
8
+ $ gem install sawa
9
+
10
+ ## Usage
11
+
12
+ create new crud project:
13
+
14
+ $ sawa -n demo
15
+
16
+ create new crud project:
17
+
18
+ $ cd demo
19
+
20
+ fill model.xls and it will create tables、resources、models、pages
21
+
22
+ ![](https://s3-ap-northeast-1.amazonaws.com/ms17222/step/step1.JPG)
23
+
24
+ $ sawa -g model.xls
25
+ $ ant compile
26
+
27
+ run api server (*before run api you must fix db config in mini.yml)
28
+
29
+ $ sawa -s
30
+
31
+ [http://localhost:9000/](http://localhost:9000)
32
+
33
+ run client
34
+
35
+ $ cd www
36
+ $ npm install
37
+ $ npm start
38
+
39
+ [http://localhost:3000/](http://localhost:3000)
40
+
41
+ login(*before login must be regist, debug model password is 0000)
42
+
43
+ ![](https://s3-ap-northeast-1.amazonaws.com/ms17222/step/step5.JPG)
44
+
45
+ after login
46
+
47
+ ![](https://s3-ap-northeast-1.amazonaws.com/ms17222/step/step6.JPG)
48
+
49
+ ## dependencies
50
+
51
+ Ruby2.3
52
+ JDK1.8
53
+ Apache Ant
54
+ npm
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
59
+
data/bin/sawa CHANGED
@@ -1,83 +1,83 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'sawa'
4
- require 'sawa/version'
5
- require 'optparse'
6
- require 'fileutils'
7
-
8
- class Sawa
9
- class CLI
10
- # Return a structure describing the options.
11
- def self.parse_options(args)
12
- opts = OptionParser.new do |opts|
13
- opts.banner = "Usage: sawa [-c] [-t] [-e] [-r library] FILE ..."
14
-
15
- opts.separator " "
16
-
17
- opts.separator "Examples:"
18
- opts.separator " $ mustache data.yml template.mustache"
19
- opts.separator " $ cat data.yml | mustache - template.mustache"
20
- opts.separator " $ mustache -c template.mustache"
21
-
22
- opts.separator " "
23
-
24
- opts.separator "See https://github.com/shouaya/sawagem"
25
- opts.separator " for more details."
26
-
27
- opts.separator " "
28
- opts.separator "Options:"
29
-
30
- opts.on("-n", "--new FILE", "create sawa project") do |file|
31
- puts exec('git clone https://github.com/shouaya/sawaapp.git ' + file)
32
- exit
33
- end
34
-
35
- opts.on("-g", "--generate FILE", "generate source from file") do |file|
36
- puts Sawa.new(file).generate_code
37
- exit
38
- end
39
-
40
- opts.on("-s", "--server", "run rest api server") do
41
- puts "start rest api server"
42
- system('start java -cp bin;lib\sawa.jar;. com.jialu.sawa.MiniApp server mini.yml')
43
- exit
44
- end
45
-
46
- opts.on("-d", "--dropdb", "drop db") do
47
- puts "drop db"
48
- system('start java -cp bin;lib\sawa.jar;. com.jialu.sawa.MiniApp db drop-all --confirm-delete-everything mini.yml')
49
- exit
50
- end
51
-
52
- #TODO
53
- # opts.on("-ac", "--antcompile", "ant compile java file to class") do
54
- # exit
55
- # end
56
- # opts.on("-r", "--replace", "replace domian in build js") do
57
- # exit
58
- # end
59
- # npm start / npm run /npm build
60
-
61
- opts.on("-v", "--version", "Print the version") do |v|
62
- puts "Sawa v#{Sawa::VERSION}"
63
- exit
64
- end
65
-
66
- opts.on_tail("-h", "--help", "Show this message") do
67
- puts opts
68
- exit
69
- end
70
- end
71
-
72
- opts.separator ""
73
-
74
- opts.parse!(args)
75
- end
76
- end
77
- end
78
-
79
- # Help is the default.
80
- ARGV << '-h' if ARGV.empty? && $stdin.tty?
81
-
82
- # Process options
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sawa'
4
+ require 'sawa/version'
5
+ require 'optparse'
6
+ require 'fileutils'
7
+
8
+ class Sawa
9
+ class CLI
10
+ # Return a structure describing the options.
11
+ def self.parse_options(args)
12
+ opts = OptionParser.new do |opts|
13
+ opts.banner = "Usage: sawa [-c] [-t] [-e] [-r library] FILE ..."
14
+
15
+ opts.separator " "
16
+
17
+ opts.separator "Examples:"
18
+ opts.separator " $ mustache data.yml template.mustache"
19
+ opts.separator " $ cat data.yml | mustache - template.mustache"
20
+ opts.separator " $ mustache -c template.mustache"
21
+
22
+ opts.separator " "
23
+
24
+ opts.separator "See https://github.com/shouaya/sawagem"
25
+ opts.separator " for more details."
26
+
27
+ opts.separator " "
28
+ opts.separator "Options:"
29
+
30
+ opts.on("-n", "--new FILE", "create sawa project") do |file|
31
+ puts exec('git clone https://github.com/shouaya/sawaapp.git ' + file)
32
+ exit
33
+ end
34
+
35
+ opts.on("-g", "--generate FILE", "generate source from file") do |file|
36
+ puts Sawa.new(file).generate_code
37
+ exit
38
+ end
39
+
40
+ opts.on("-s", "--server", "run rest api server") do
41
+ puts "start rest api server"
42
+ system('start java -cp bin;lib\sawa.jar;. com.jialu.sawa.MiniApp server mini.yml')
43
+ exit
44
+ end
45
+
46
+ opts.on("-d", "--dropdb", "drop db") do
47
+ puts "drop db"
48
+ system('start java -cp bin;lib\sawa.jar;. com.jialu.sawa.MiniApp db drop-all --confirm-delete-everything mini.yml')
49
+ exit
50
+ end
51
+
52
+ #TODO
53
+ # opts.on("-ac", "--antcompile", "ant compile java file to class") do
54
+ # exit
55
+ # end
56
+ # opts.on("-r", "--replace", "replace domian in build js") do
57
+ # exit
58
+ # end
59
+ # npm start / npm run /npm build
60
+
61
+ opts.on("-v", "--version", "Print the version") do |v|
62
+ puts "Sawa v#{Sawa::VERSION}"
63
+ exit
64
+ end
65
+
66
+ opts.on_tail("-h", "--help", "Show this message") do
67
+ puts opts
68
+ exit
69
+ end
70
+ end
71
+
72
+ opts.separator ""
73
+
74
+ opts.parse!(args)
75
+ end
76
+ end
77
+ end
78
+
79
+ # Help is the default.
80
+ ARGV << '-h' if ARGV.empty? && $stdin.tty?
81
+
82
+ # Process options
83
83
  Sawa::CLI.parse_options(ARGV) if $stdin.tty?
@@ -1,79 +1,79 @@
1
- class MiniProperty
2
- def initialize(row, sheet)
3
- @row = row
4
- @sheet = sheet
5
- @idx_type = 1
6
- @idx_name = 2
7
- @idx_unique = 3
8
- @idx_nullable = 4
9
- @idx_jsonignore = 5
10
- @idx_title = 6
11
- @idx_mappedBy = 7
12
- @idx_refColumn = 8
13
- end
14
-
15
- def resource_name
16
- @sheet.resource_path
17
- end
18
-
19
- def name
20
- @row[@idx_name]
21
- end
22
-
23
- def type
24
- @row[@idx_type]
25
- end
26
-
27
- def type_js
28
- if @row[@idx_type] == "java.lang.String"
29
- return "txt"
30
- end
31
- if @row[@idx_type] == "java.lang.Integer" or @row[@idx_type] == "java.lang.Short" or @row[@idx_type] == "java.lang.Long" or @row[@idx_type] == "java.lang.Float" or @row[@idx_type] == "java.lang.Double"
32
- return "num"
33
- end
34
- if @row[@idx_type].start_with?("java.util.List")
35
- return "list"
36
- end
37
- return "obj"
38
- end
39
-
40
- def unique
41
- @row[@idx_unique] == "1"
42
- end
43
-
44
- def nullable
45
- @row[@idx_nullable] == "1"
46
- end
47
-
48
- def jsonignore
49
- @row[@idx_jsonignore] == "1"
50
- end
51
-
52
- def title
53
- @row[@idx_title]
54
- end
55
-
56
- def is_column
57
- @row[@idx_unique] != "-"
58
- end
59
-
60
- def has_mapped
61
- @row[@idx_mappedBy] == "1:1" or @row[@idx_mappedBy] == "1:n" or @row[@idx_mappedBy] == "n:1"
62
- end
63
-
64
- def join_column
65
- @row[@idx_refColumn]
66
- end
67
-
68
- def is_onetomany
69
- @row[@idx_mappedBy] == "1:n"
70
- end
71
-
72
- def is_manytoone
73
- @row[@idx_mappedBy] == "n:1"
74
- end
75
-
76
- def is_onetoone
77
- @row[@idx_mappedBy] == "1:1"
78
- end
1
+ class MiniProperty
2
+ def initialize(row, sheet)
3
+ @row = row
4
+ @sheet = sheet
5
+ @idx_type = 1
6
+ @idx_name = 2
7
+ @idx_unique = 3
8
+ @idx_nullable = 4
9
+ @idx_jsonignore = 5
10
+ @idx_title = 6
11
+ @idx_mappedBy = 7
12
+ @idx_refColumn = 8
13
+ end
14
+
15
+ def resource_name
16
+ @sheet.resource_path
17
+ end
18
+
19
+ def name
20
+ @row[@idx_name]
21
+ end
22
+
23
+ def type
24
+ @row[@idx_type]
25
+ end
26
+
27
+ def type_js
28
+ if @row[@idx_type] == "java.lang.String"
29
+ return "txt"
30
+ end
31
+ if @row[@idx_type] == "java.lang.Integer" or @row[@idx_type] == "java.lang.Short" or @row[@idx_type] == "java.lang.Long" or @row[@idx_type] == "java.lang.Float" or @row[@idx_type] == "java.lang.Double"
32
+ return "num"
33
+ end
34
+ if @row[@idx_type].start_with?("java.util.List")
35
+ return "list"
36
+ end
37
+ return "obj"
38
+ end
39
+
40
+ def unique
41
+ @row[@idx_unique] == "1"
42
+ end
43
+
44
+ def nullable
45
+ @row[@idx_nullable] == "1"
46
+ end
47
+
48
+ def jsonignore
49
+ @row[@idx_jsonignore] == "1"
50
+ end
51
+
52
+ def title
53
+ @row[@idx_title]
54
+ end
55
+
56
+ def is_column
57
+ @row[@idx_unique] != "-"
58
+ end
59
+
60
+ def has_mapped
61
+ @row[@idx_mappedBy] == "1:1" or @row[@idx_mappedBy] == "1:n" or @row[@idx_mappedBy] == "n:1"
62
+ end
63
+
64
+ def join_column
65
+ @row[@idx_refColumn]
66
+ end
67
+
68
+ def is_onetomany
69
+ @row[@idx_mappedBy] == "1:n"
70
+ end
71
+
72
+ def is_manytoone
73
+ @row[@idx_mappedBy] == "n:1"
74
+ end
75
+
76
+ def is_onetoone
77
+ @row[@idx_mappedBy] == "1:1"
78
+ end
79
79
  end
@@ -1,101 +1,101 @@
1
- class MiniResource
2
-
3
- def initialize(row, sheet)
4
- @row = row
5
- @sheet = sheet
6
- @idx_method = 1
7
- @idx_process = 2
8
- @idx_role = 3
9
- @idx_desc = 4
10
- @idx_islist = 5
11
- @idx_param = 6
12
- @idx_path = 7
13
- @idx_httpM = 8
14
- end
15
-
16
- def resource_method
17
- @row[@idx_method]
18
- end
19
-
20
- def resource_process
21
- @row[@idx_process]
22
- end
23
-
24
- def resource_role
25
- if @row[@idx_role] == nil or @row[@idx_role] == ""
26
- nil
27
- else
28
- "\"" + @row[@idx_role].split(",").join(",") + "\""
29
- end
30
- end
31
-
32
- def resource_desc
33
- @row[@idx_desc]
34
- end
35
-
36
- def resource_islist
37
- @row[@idx_islist] == "1"
38
- end
39
-
40
- def resource_param_type
41
- vals = []
42
- prms = @row[@idx_param].split(",")
43
- prms.map do |prm|
44
- if prm.strip == "@query"
45
- vals.push("MiniQuery query")
46
- elsif prm.strip == "@role"
47
- vals.push("OperatorRole role")
48
- elsif prm.strip == "@obj"
49
- vals.push("#{@sheet.model_name} obj")
50
- else
51
- vals.push(prm)
52
- end
53
- end
54
- vals.join(",")
55
- end
56
-
57
- def resource_param_value
58
- vals = []
59
- prms = @row[@idx_param].split(",")
60
- prms.map do |prm|
61
- tmp = prm.split(" ")
62
- vals.push(tmp[tmp.length - 1].gsub(/@/, ''))
63
- end
64
- if !@row[@idx_process].start_with?("super.")
65
- vals.push("this")
66
- end
67
- vals.join(",")
68
- end
69
-
70
- def resource_param_full
71
- vals = []
72
- prms = @row[@idx_param].split(",")
73
- prms.map do |prm|
74
- if prm.strip == "@query"
75
- vals.push("MiniQuery query")
76
- elsif prm.strip == "@role"
77
- vals.push("@Auth OperatorRole role")
78
- elsif prm.strip == "@obj"
79
- vals.push("#{@sheet.model_name} obj")
80
- else
81
- arr = prm.split(" ")
82
- s = arr[arr.length - 1]
83
- if @row[@idx_path].include?("#{s}")
84
- vals.push("@PathParam(\"#{s}\") #{prm.strip}")
85
- else
86
- vals.push("@QueryParam(\"#{s}\") #{prm.strip}")
87
- end
88
- end
89
- end
90
- vals.join(",")
91
- end
92
-
93
- def resource_path
94
- @row[@idx_path]
95
- end
96
-
97
- def resource_httpM
98
- @row[@idx_httpM]
99
- end
100
-
1
+ class MiniResource
2
+
3
+ def initialize(row, sheet)
4
+ @row = row
5
+ @sheet = sheet
6
+ @idx_method = 1
7
+ @idx_process = 2
8
+ @idx_role = 3
9
+ @idx_desc = 4
10
+ @idx_islist = 5
11
+ @idx_param = 6
12
+ @idx_path = 7
13
+ @idx_httpM = 8
14
+ end
15
+
16
+ def resource_method
17
+ @row[@idx_method]
18
+ end
19
+
20
+ def resource_process
21
+ @row[@idx_process]
22
+ end
23
+
24
+ def resource_role
25
+ if @row[@idx_role] == nil or @row[@idx_role] == ""
26
+ nil
27
+ else
28
+ "\"" + @row[@idx_role].split(",").join(",") + "\""
29
+ end
30
+ end
31
+
32
+ def resource_desc
33
+ @row[@idx_desc]
34
+ end
35
+
36
+ def resource_islist
37
+ @row[@idx_islist] == "1"
38
+ end
39
+
40
+ def resource_param_type
41
+ vals = []
42
+ prms = @row[@idx_param].split(",")
43
+ prms.map do |prm|
44
+ if prm.strip == "@query"
45
+ vals.push("MiniQuery query")
46
+ elsif prm.strip == "@role"
47
+ vals.push("OperatorRole role")
48
+ elsif prm.strip == "@obj"
49
+ vals.push("#{@sheet.model_name} obj")
50
+ else
51
+ vals.push(prm)
52
+ end
53
+ end
54
+ vals.join(",")
55
+ end
56
+
57
+ def resource_param_value
58
+ vals = []
59
+ prms = @row[@idx_param].split(",")
60
+ prms.map do |prm|
61
+ tmp = prm.split(" ")
62
+ vals.push(tmp[tmp.length - 1].gsub(/@/, ''))
63
+ end
64
+ if !@row[@idx_process].start_with?("super.")
65
+ vals.push("this")
66
+ end
67
+ vals.join(",")
68
+ end
69
+
70
+ def resource_param_full
71
+ vals = []
72
+ prms = @row[@idx_param].split(",")
73
+ prms.map do |prm|
74
+ if prm.strip == "@query"
75
+ vals.push("MiniQuery query")
76
+ elsif prm.strip == "@role"
77
+ vals.push("@Auth OperatorRole role")
78
+ elsif prm.strip == "@obj"
79
+ vals.push("#{@sheet.model_name} obj")
80
+ else
81
+ arr = prm.split(" ")
82
+ s = arr[arr.length - 1]
83
+ if @row[@idx_path].include?("#{s}")
84
+ vals.push("@PathParam(\"#{s}\") #{prm.strip}")
85
+ else
86
+ vals.push("@QueryParam(\"#{s}\") #{prm.strip}")
87
+ end
88
+ end
89
+ end
90
+ vals.join(",")
91
+ end
92
+
93
+ def resource_path
94
+ @row[@idx_path]
95
+ end
96
+
97
+ def resource_httpM
98
+ @row[@idx_httpM]
99
+ end
100
+
101
101
  end