kwatable 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +46 -0
- data/MIT-LICENSE +20 -0
- data/README.txt +4 -2
- data/bin/kwatable +4 -4
- data/examples/ex1/Makefile +40 -14
- data/examples/ex1/{example1.yaml → tabledef.yaml} +42 -11
- data/examples/ex2/Makefile +41 -14
- data/examples/ex2/{example2.yaml → tabledef.yaml} +45 -30
- data/examples/ex3/Makefile +52 -0
- data/examples/ex3/tabledef.yaml +136 -0
- data/kwatable.gemspec +11 -10
- data/lib/kwatable.rb +24 -18
- data/lib/kwatable/kwatable.schema.yaml +95 -5
- data/lib/kwatable/main.rb +331 -0
- data/lib/kwatable/manipulator.rb +320 -192
- data/lib/kwatable/messages.rb +59 -0
- data/lib/kwatable/template/ddl-mysql.eruby +202 -0
- data/lib/kwatable/{templates → template}/ddl-postgresql.eruby +71 -45
- data/lib/kwatable/{templates → template}/defaults.yaml +2 -2
- data/lib/kwatable/template/dictionary.en.yaml +70 -0
- data/lib/kwatable/template/dictionary.ja.yaml +165 -0
- data/lib/kwatable/template/dto-java.eruby +77 -0
- data/lib/kwatable/template/dto-java.sub.eruby +259 -0
- data/lib/kwatable/template/dto-ruby.eruby +63 -0
- data/lib/kwatable/template/dto-ruby.sub.eruby +213 -0
- data/lib/kwatable/template/helper/column.rb +70 -0
- data/lib/kwatable/template/helper/common.rb +151 -0
- data/lib/kwatable/template/helper/java.rb +83 -0
- data/lib/kwatable/template/helper/label.rb +90 -0
- data/lib/kwatable/template/helper/ruby.rb +36 -0
- data/lib/kwatable/template/helper/table.rb +62 -0
- data/lib/kwatable/template/hibernate.eruby +139 -0
- data/lib/kwatable/template/rails-controller.eruby +66 -0
- data/lib/kwatable/template/rails-controller.sub.eruby +114 -0
- data/lib/kwatable/template/rails-kwartz.eruby +164 -0
- data/lib/kwatable/template/rails-kwartz/_attr.plogic.eruby +56 -0
- data/lib/kwatable/template/rails-kwartz/_form.plogic.eruby +81 -0
- data/lib/kwatable/template/rails-kwartz/_link.plogic.eruby +36 -0
- data/lib/kwatable/template/rails-kwartz/edit.cfg.yaml.eruby +16 -0
- data/lib/kwatable/template/rails-kwartz/edit.html.eruby +46 -0
- data/lib/kwatable/template/rails-kwartz/edit.plogic.eruby +20 -0
- data/lib/kwatable/template/rails-kwartz/layout.html.eruby +39 -0
- data/lib/kwatable/template/rails-kwartz/layout.plogic.eruby +32 -0
- data/lib/kwatable/template/rails-kwartz/list.html.eruby +94 -0
- data/lib/kwatable/template/rails-kwartz/list.plogic.eruby +41 -0
- data/lib/kwatable/template/rails-kwartz/new.html.eruby +100 -0
- data/lib/kwatable/template/rails-kwartz/new.plogic.eruby +26 -0
- data/lib/kwatable/template/rails-kwartz/show.html.eruby +51 -0
- data/lib/kwatable/template/rails-kwartz/show.plogic.eruby +9 -0
- data/lib/kwatable/template/rails-model.eruby +35 -0
- data/lib/kwatable/template/rails-model.sub.eruby +136 -0
- data/lib/kwatable/{templates → template}/validator-ruby.eruby +18 -11
- data/lib/kwatable/util.rb +133 -0
- data/lib/kwatable/util/assert-text-equal.rb +47 -0
- data/lib/kwatable/util/assertion.rb +115 -0
- data/lib/kwatable/validator.rb +50 -0
- data/test/assert-diff.rb +1 -1
- data/test/test-ex.rb +306 -0
- data/test/test.rb +37 -127
- metadata +66 -17
- data/COPYING +0 -340
- data/ChangeLog.txt +0 -65
- data/lib/kwatable/error-msg.rb +0 -38
- data/lib/kwatable/main-program.rb +0 -216
- data/lib/kwatable/templates/ddl-mysql.eruby +0 -172
- data/lib/kwatable/templates/dto-java.eruby +0 -260
- data/lib/kwatable/templates/dto-ruby.eruby +0 -185
@@ -1,185 +0,0 @@
|
|
1
|
-
<%
|
2
|
-
|
3
|
-
##
|
4
|
-
## kwatable template file for Ruby DTO class
|
5
|
-
##
|
6
|
-
## copyright(c) 2005 kuwata-lab.com all rights reserved.
|
7
|
-
## $Release: 0.2.0 $
|
8
|
-
## $Rev: 17 $
|
9
|
-
##
|
10
|
-
## template properties:
|
11
|
-
## --module=name : module name
|
12
|
-
## --parent=name : parent class
|
13
|
-
## --reqpath=path : require path
|
14
|
-
## --symbolkey : use symbol as hash key
|
15
|
-
##
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
# context variables
|
20
|
-
#
|
21
|
-
table = context['table']
|
22
|
-
properties = context['properties']
|
23
|
-
raise "option '-m' is required when using 'dto-ruby.eruby'." unless table
|
24
|
-
|
25
|
-
|
26
|
-
#
|
27
|
-
# ruby keywords
|
28
|
-
#
|
29
|
-
keywords = <<-END
|
30
|
-
BEGIN END alias and begin break case
|
31
|
-
class def defined do else elsif end
|
32
|
-
ensure false for if in module next
|
33
|
-
nil not or redo rescue retry return
|
34
|
-
self super then true undef unless
|
35
|
-
until when while yield
|
36
|
-
END
|
37
|
-
@keywords = {}
|
38
|
-
keywords.split(/\s+/).each { |word| @keywords[word] = true }
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
# escape java keywords
|
43
|
-
#
|
44
|
-
def self._(word)
|
45
|
-
return @keywords[word] ? "_#{word}" : word
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
#
|
50
|
-
# convert 'aaa_bbb_ccc' into 'AaaBbbCcc'
|
51
|
-
#
|
52
|
-
def self.camel_case(name, flag_all=true)
|
53
|
-
s = ''
|
54
|
-
name.split('_').each_with_index do |word, i|
|
55
|
-
s << (!flag_all && i == 0 ? word.downcase : word.capitalize)
|
56
|
-
end
|
57
|
-
return s
|
58
|
-
#s = name.split('_').collect { |w| w.capitalize }.join()
|
59
|
-
#s[0] = s[0].to_s.upcase.chr unless flag_all
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
#
|
64
|
-
# class definition
|
65
|
-
#
|
66
|
-
klass = {
|
67
|
-
:name => table['class'] || camel_case(table['name']),
|
68
|
-
:module => table['module'] || properties[:module],
|
69
|
-
:parent => table['parent'] || properties[:parent],
|
70
|
-
:desc => table['desc'],
|
71
|
-
}
|
72
|
-
|
73
|
-
|
74
|
-
#
|
75
|
-
# output file name
|
76
|
-
#
|
77
|
-
context[:output_filename] = klass[:name] + ".rb"
|
78
|
-
|
79
|
-
|
80
|
-
#
|
81
|
-
# instance variables
|
82
|
-
#
|
83
|
-
variables = []
|
84
|
-
for column in table['columns']
|
85
|
-
var = {
|
86
|
-
:name => column['name'],
|
87
|
-
:type => column['class'] || column['type'],
|
88
|
-
:desc => column['desc'],
|
89
|
-
}
|
90
|
-
variables << var
|
91
|
-
end
|
92
|
-
|
93
|
-
%>
|
94
|
-
##
|
95
|
-
## DTO for Ruby
|
96
|
-
## generated by kwatable with template 'dto-ruby.eruby'
|
97
|
-
## at <%= Time.now.to_s %>
|
98
|
-
|
99
|
-
##
|
100
|
-
<%
|
101
|
-
#
|
102
|
-
# require other dto file
|
103
|
-
#
|
104
|
-
refclass_table = {}
|
105
|
-
for column in table['columns']
|
106
|
-
if column['ref']
|
107
|
-
refclass = column['ref']['table']['class']
|
108
|
-
refclass ||= camel_case(column['ref']['table']['name'])
|
109
|
-
reqpath = properties[:reqpath]
|
110
|
-
next if refclass_table[refclass]
|
111
|
-
refclass_table[refclass] = true
|
112
|
-
|
113
|
-
%>
|
114
|
-
require '<%= reqpath %><%= reqpath ? '/' : '' %><%= refclass %>'
|
115
|
-
<%
|
116
|
-
end
|
117
|
-
end
|
118
|
-
%>
|
119
|
-
|
120
|
-
<%
|
121
|
-
#
|
122
|
-
# class definition start
|
123
|
-
#
|
124
|
-
mod = klass[:module] ? "#{klass[:module]}::" : ""
|
125
|
-
extends = klass[:parent] ? " < #{klass[:parent]}" : ""
|
126
|
-
|
127
|
-
%>
|
128
|
-
## <%= klass[:desc] %>
|
129
|
-
|
130
|
-
class <%= mod %><%= klass[:name] %><%= extends %>
|
131
|
-
|
132
|
-
|
133
|
-
<%
|
134
|
-
#
|
135
|
-
# accessor
|
136
|
-
#
|
137
|
-
%>
|
138
|
-
<% for var in variables %>
|
139
|
-
attr_accessor :<%= '%-14s' % var[:name] %> # <%= var[:desc] %>
|
140
|
-
|
141
|
-
<% end %>
|
142
|
-
|
143
|
-
<%
|
144
|
-
#
|
145
|
-
# set all values
|
146
|
-
#
|
147
|
-
%>
|
148
|
-
def populate(_hash={})
|
149
|
-
<% flag_symbol = properties[:keytype] == 'symbol' %>
|
150
|
-
<% for var in variables %>
|
151
|
-
<% if flag_symbol %>
|
152
|
-
@<%= "%-14s" % var[:name] %> = _hash[:<%= var[:name] %>]
|
153
|
-
<% else %>
|
154
|
-
@<%= "%-14s" % var[:name] %> = _hash['<%= var[:name] %>']
|
155
|
-
<% end %>
|
156
|
-
<% end %>
|
157
|
-
end
|
158
|
-
|
159
|
-
<%
|
160
|
-
#
|
161
|
-
# foreign keys
|
162
|
-
#
|
163
|
-
table['columns'].each do |column|
|
164
|
-
if column['ref']
|
165
|
-
refcol = column['ref']['name']
|
166
|
-
refname = column['ref-name']
|
167
|
-
varname = column['name']
|
168
|
-
if refname == varname
|
169
|
-
raise "table #{table['name']}: column #{column['name']}: proper ref-name is required."
|
170
|
-
end
|
171
|
-
%>
|
172
|
-
attr_reader :<%= refname %>
|
173
|
-
|
174
|
-
def <%= refname %>=(<%=_ refname %>)
|
175
|
-
@<%= refname %> = <%=_ refname %>
|
176
|
-
|
177
|
-
@<%= varname %> = <%=_ refname %>.<%= refcol %>
|
178
|
-
|
179
|
-
end
|
180
|
-
|
181
|
-
<%
|
182
|
-
end
|
183
|
-
end
|
184
|
-
%>
|
185
|
-
end
|