zan_tools 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/zan_tools/command.rb +6 -1
- data/lib/zan_tools/generatable.rb +4 -0
- data/lib/zan_tools/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e870996ef60beb65a1f65303e557a192eca74e9118c5fc9d5e2a501b7813a89d
|
4
|
+
data.tar.gz: 382376d090cd27f457b488b5ed8779f4e42eac0084294366926f8b9797712f8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f95bc1544d8c565762f573970a4e1fd0b90ba25672f008fe2cd4c8f6b9ec64209ecfe0c4ab7b3c8183833af43fc2c8dffbd10a3c0f5ff8fe7f0881a5136e97f
|
7
|
+
data.tar.gz: 1ca110d0fa95fbb162158cf1c9b205aa6908c3cffa1c5230682c802a477949a57ec60677aa2732e550ff2ce8819f2c8859b13d3b6e84007883412d7ae08f9ff7
|
data/README.md
CHANGED
@@ -18,8 +18,17 @@ Or install it yourself as:
|
|
18
18
|
$ gem install zan_tools
|
19
19
|
|
20
20
|
## Usage
|
21
|
-
|
22
|
-
|
21
|
+
```
|
22
|
+
$ zan_tools -h
|
23
|
+
Usage zan_tools COMMAND [options]
|
24
|
+
COMMAND
|
25
|
+
g/generate: 根据指定模板生成代码
|
26
|
+
generate options
|
27
|
+
-n, --name NAME 表名或者类名
|
28
|
+
-f, --fields FIELDS 字段列表,格式:字段1:类型2,字段2:类型2
|
29
|
+
-t, --template TEMPLATE 模板文件
|
30
|
+
-o, --output FILE 输出到指定文件
|
31
|
+
```
|
23
32
|
|
24
33
|
## Development
|
25
34
|
|
data/lib/zan_tools/command.rb
CHANGED
@@ -14,7 +14,6 @@ module ZanTools
|
|
14
14
|
opts.banner = "Usage zan_tools COMMAND [options]"
|
15
15
|
opts.separator "COMMAND"
|
16
16
|
opts.separator " g/generate: 根据指定模板生成代码"
|
17
|
-
|
18
17
|
opts.separator "generate options"
|
19
18
|
# generate命令参数
|
20
19
|
opts.on("-n", "--name NAME", "表名或者类名") do |value|
|
@@ -30,16 +29,22 @@ module ZanTools
|
|
30
29
|
raise "template file not exists"
|
31
30
|
end
|
32
31
|
end
|
32
|
+
opts.separator "common options"
|
33
33
|
# 其他参数
|
34
34
|
opts.on("-o", "--output FILE", "输出到指定文件") do |value|
|
35
35
|
options[:output] = value
|
36
36
|
end
|
37
|
+
opts.on("-v", "--version", "zan_tools版本") do |value|
|
38
|
+
options[:version] = ZanTools::VERSION
|
39
|
+
end
|
37
40
|
end
|
38
41
|
parser.parse!
|
39
42
|
|
40
43
|
case ARGV[0]
|
41
44
|
when 'g', 'generate'
|
42
45
|
generate
|
46
|
+
else
|
47
|
+
puts options[:version] if options[:version]
|
43
48
|
end
|
44
49
|
rescue StandardError => e
|
45
50
|
puts [e.class, e.message].join(': ')
|
@@ -2,6 +2,8 @@ require 'erb'
|
|
2
2
|
require 'zan_tools/string'
|
3
3
|
|
4
4
|
module ZanTools
|
5
|
+
class TemplateError < StandardError; end
|
6
|
+
|
5
7
|
module Generatable
|
6
8
|
def self.included(host_class)
|
7
9
|
host_class.extend ClassMethods
|
@@ -32,6 +34,8 @@ module ZanTools
|
|
32
34
|
def compile(tmpl)
|
33
35
|
template = ERB.new(tmpl, nil, '-')
|
34
36
|
template.result(binding)
|
37
|
+
rescue StandardError => e
|
38
|
+
raise TemplateError.new("#{e.class} - #{e.message}")
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
data/lib/zan_tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zan_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zigu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|