• R/O
  • SSH
  • HTTPS

tenarai: 提交


Commit MetaInfo

修訂55 (tree)
時間2008-03-10 19:13:11
作者junkikuchi

Log Message

updated.

Change Summary

差異

--- trunk/Rakefile (revision 54)
+++ trunk/Rakefile (revision 55)
@@ -2,53 +2,8 @@
22 # Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com>
33 #
44
5-base_dir = File.dirname(__FILE__)
6-$LOAD_PATH.push("#{base_dir}/lib")
5+require 'main'
76
8-require 'tenarai/server'
9-require 'tenarai/classloader'
10-require 'tenarai/db/container'
11-
12-Tenarai::ClassLoader.dir = "#{base_dir}/webapp"
13-
14-config = {
15- :db => {
16- :engine => :mysql,
17- :db => 'test',
18- :host => 'localhost',
19- :user => 'root',
20- :password => 'root',
21- #:echo => true,
22- },
23-
24- :server => {
25- :address => '0.0.0.0',
26- :port => 8080,
27- },
28-
29- :model => {
30- :table => {
31- 'service' => {:row => 'Service', :class => 'ServiceTable'},
32- 'user' => {:row => 'User', :class => 'UserTable' },
33- 'session' => {:row => 'Session', :class => 'SessionTable'},
34- 'content' => {:row => 'Content' },
35- 'view' => {:row => 'View' },
36- 'widget' => {:row => 'Widget' },
37- },
38-
39- :relation => [
40- ['service.widget', 'widget' ],
41- ['user.content', 'content' ],
42- ['user.session', 'session.user' ],
43- ['content.parent', 'content.node' ],
44- ['content.view', 'view' ],
45- ['view.parent', 'view.node' ],
46- ['widget.parent', 'widget.node' ],
47- ['widget.view', 'view.widget' ],
48- ],
49- },
50-}
51-
527 init_model = {
538 'service' => [
549 {
@@ -85,6 +40,18 @@
8540 'content' => 'content:admin',
8641 },
8742 },
43+
44+ {
45+ :name => 'skelton',
46+ :class => 'User',
47+ :row => {
48+ 'name' => 'skelton',
49+ '_password' => Tenarai::ClassLoader['User'].digest('')
50+ },
51+ :relation => {
52+ 'content' => 'content:skelton',
53+ },
54+ },
8855 ],
8956
9057 'content' => [
@@ -105,66 +72,18 @@
10572 'title' => 'admin',
10673 'body' => 'admin',
10774 },
108- :relation => {'view' => 'view:resource.admin'},
75+ :relation => {'view' => 'view:resource.admin.user'},
10976 },
11077
11178 {
112- :name => 'admin.content',
79+ :name => 'skelton',
11380 :class => 'Content',
11481 :row => {
115- 'title' => 'content',
116- 'body' => 'content',
82+ 'title' => 'skelton',
83+ 'body' => 'skelton',
11784 },
118- :relation => {'view' => 'view:resource.admin'},
85+ :relation => {'view' => 'view:resource.skelton'},
11986 },
120-
121- {
122- :name => 'admin.content.c1',
123- :class => 'Content',
124- :row => { 'title' => 'c1', 'body' => 'c1', },
125- :relation => {'view' => 'view:resource.admin'},
126- },
127- {
128- :name => 'admin.content.c2',
129- :class => 'Content',
130- :row => { 'title' => 'c2', 'body' => 'c2', },
131- :relation => {'view' => 'view:resource.admin'},
132- },
133- {
134- :name => 'admin.content.c3',
135- :class => 'Content',
136- :row => { 'title' => 'c3', 'body' => 'c3', },
137- :relation => {'view' => 'view:resource.admin'},
138- },
139-
140- {
141- :name => 'admin.view',
142- :class => 'Content',
143- :row => {
144- 'title' => 'view',
145- 'body' => 'view',
146- },
147- :relation => {'view' => 'view:resource.admin'},
148- },
149-
150- {
151- :name => 'admin.view.v1',
152- :class => 'Content',
153- :row => { 'title' => 'v1', 'body' => 'v1', },
154- :relation => {'view' => 'view:resource.admin'},
155- },
156- {
157- :name => 'admin.view.v2',
158- :class => 'Content',
159- :row => { 'title' => 'v2', 'body' => 'v2', },
160- :relation => {'view' => 'view:resource.admin'},
161- },
162- {
163- :name => 'admin.view.v3',
164- :class => 'Content',
165- :row => { 'title' => 'v3', 'body' => 'v3', },
166- :relation => {'view' => 'view:resource.admin'},
167- },
16887 ],
16988
17089 'view' => [
@@ -185,6 +104,18 @@
185104 :class => 'View',
186105 :row => {'name' => 'admin'},
187106 },
107+
108+ {
109+ :name => 'resource.admin.user',
110+ :class => 'View',
111+ :row => {'name' => 'user'},
112+ },
113+
114+ {
115+ :name => 'resource.skelton',
116+ :class => 'View',
117+ :row => {'name' => 'skelton'},
118+ },
188119 ],
189120
190121 'widget' => [
@@ -237,7 +168,6 @@
237168 :relation => {'view' => 'view:resource.login'},
238169 :preference => {}
239170 },
240-
241171 {
242172 :name => 'session.user.content.view.html.login.title',
243173 :class => 'Widget::Content::Title',
@@ -250,16 +180,15 @@
250180 :row => {},
251181 :relation => {'view' => 'view:resource.login'},
252182 :preference => {
253- #'yui.reset_fonts_grids.url' => 'http://localhost/pub/yui-2.4.1/build/reset-fonts-grids/reset-fonts-grids.css',
183+ 'yui.reset_fonts_grids.url' => 'http://localhost/pub/yui-2.4.1/build/reset-fonts-grids/reset-fonts-grids.css',
254184 }
255185 },
256186 {
257- :name => 'session.user.content.view.html.login.header',
258- :class => 'Widget::Content::Header',
187+ :name => 'session.user.content.view.html.login.hd',
188+ :class => 'Widget::Panel',
259189 :row => {},
260190 :relation => {'view' => 'view:resource.login'},
261191 :preference => {
262- 'box.font.font_size' => '197%',
263192 'box.margin.margin_top' => '10px',
264193 'box.margin.margin_right' => '10px',
265194 'box.margin.margin_bottom' => '10px',
@@ -271,9 +200,23 @@
271200 'box.border.border_bottom' => 'solid 3px blue',
272201 }
273202 },
274-
275203 {
276- :name => 'session.user.content.view.html.login.login_form',
204+ :name => 'session.user.content.view.html.login.hd.header',
205+ :class => 'Widget::Content::Header',
206+ :row => {},
207+ :relation => {'view' => 'view:resource.login'},
208+ :preference => {
209+ 'box.font.font_size' => '197%',
210+ }
211+ },
212+ {
213+ :name => 'session.user.content.view.html.login.bd',
214+ :class => 'Widget::Panel',
215+ :row => {},
216+ :relation => {'view' => 'view:resource.login'},
217+ },
218+ {
219+ :name => 'session.user.content.view.html.login.bd.form',
277220 :class => 'Widget::User::Login',
278221 :row => {},
279222 :relation => {'view' => 'view:resource.login'},
@@ -285,6 +228,12 @@
285228 'box.size.width' => '500px',
286229 }
287230 },
231+ {
232+ :name => 'session.user.content.view.html.login.ft',
233+ :class => 'Widget::Panel',
234+ :row => {},
235+ :relation => {'view' => 'view:resource.login'},
236+ },
288237
289238 {
290239 :name => 'session.user.content.view.html.admin',
@@ -293,22 +242,74 @@
293242 :relation => {'view' => 'view:resource.admin'},
294243 :preference => {}
295244 },
296-
297245 {
298- :name => 'session.user.content.view.html.admin.logout',
246+ :name => 'session.user.content.view.html.admin.reset_style',
247+ :class => 'Widget::YUI::ResetFontsGrids',
248+ :row => {},
249+ :relation => {'view' => 'view:resource.admin'},
250+ :preference => {
251+ 'yui.reset_fonts_grids.url' => 'http://localhost/pub/yui-2.4.1/build/reset-fonts-grids/reset-fonts-grids.css',
252+ }
253+ },
254+ {
255+ :name => 'session.user.content.view.html.admin.hd',
256+ :class => 'Widget::Panel',
257+ :row => {},
258+ :relation => {'view' => 'view:resource.admin'},
259+ :preference => {
260+ 'box.margin.margin_top' => '10px',
261+ 'box.margin.margin_right' => '10px',
262+ 'box.margin.margin_bottom' => '10px',
263+ 'box.margin.margin_left' => '10px',
264+ 'box.padding.padding_top' => '10px',
265+ 'box.padding.padding_right' => '10px',
266+ 'box.padding.padding_bottom' => '10px',
267+ 'box.padding.padding_left' => '10px',
268+ 'box.border.border_bottom' => 'solid 3px blue',
269+ }
270+ },
271+ {
272+ :name => 'session.user.content.view.html.admin.hd.logout',
299273 :class => 'Widget::User::Logout',
300274 :row => {},
301275 :relation => {'view' => 'view:resource.admin'},
302276 },
303-
304277 {
305- :name => 'session.user.content.view.html.admin.user_list',
278+ :name => 'session.user.content.view.html.admin.hd.header',
279+ :class => 'Widget::Content::Header',
280+ :row => {},
281+ :relation => {'view' => 'view:resource.admin'},
282+ :preference => {
283+ 'box.font.font_size' => '197%',
284+ }
285+ },
286+ {
287+ :name => 'session.user.content.view.html.admin.bd',
288+ :class => 'Widget::Panel',
289+ :row => {},
290+ :relation => {'view' => 'view:resource.admin'},
291+ },
292+ {
293+ :name => 'session.user.content.view.html.admin.ft',
294+ :class => 'Widget::Panel',
295+ :row => {},
296+ :relation => {'view' => 'view:resource.admin'},
297+ },
298+ {
299+ :name => 'session.user.content.view.html.admin.bd.user',
300+ :class => 'Widget::User',
301+ :row => {},
302+ :relation => {'view' => 'view:resource.admin.user'},
303+ },
304+ {
305+ :name => 'session.user.content.view.html.admin.bd.list',
306306 :class => 'Widget::User::List',
307307 :row => {},
308- :relation => {'view' => 'view:resource.admin'},
308+ :relation => {'view' => 'view:resource.admin.user'},
309309 :preference => {}
310310 },
311311
312+=begin
312313 {
313314 :name => 'session.user.content.view.html.admin.new_user',
314315 :class => 'Widget::User::Form',
@@ -331,6 +332,7 @@
331332 :row => {},
332333 :relation => {'view' => 'view:resource.admin'},
333334 },
335+=end
334336 =begin
335337 {
336338 :name => 'session.user.content.view.html.admin.reset_style',
@@ -342,6 +344,7 @@
342344 }
343345 },
344346 =end
347+=begin
345348 {
346349 :name => 'session.user.content.view.html.admin.header',
347350 :class => 'Widget::Content::Header',
@@ -439,6 +442,7 @@
439442 'box.background.background_color' => 'green',
440443 }
441444 },
445+=end
442446 =begin
443447 {
444448 :name => 'session.user.content.view.html.admin.jquery',
@@ -462,137 +466,11 @@
462466 ],
463467 }
464468
465-class Main
466- def initialize(config)
467- @config = config
468- end
469-
470- def server(name)
471- model do |m|
472- m['service'].pub_dir = File.dirname(__FILE__) + '/pub'
473- Tenarai::Server.new(@config[:server]) do |request, response|
474- m['service'].dispatch(m, request, response)
475- m.refresh
476- end.__send__(name)
477- end
478- end
479-
480- def cgi
481- server('cgi')
482- end
483-
484- def webrick
485- server('webrick')
486- end
487-
488- def mongrel
489- server('mongrel')
490- end
491-
492- def error
493- p $!
494- $!.backtrace.each do |val|
495- puts ' ' + val
496- end
497- end
498-
499- def database(&block)
500- begin
501- Tenarai::DB.new(@config[:db]) do |db|
502- block.call(db)
503- end
504- rescue
505- error
506- end
507- end
508-
509- def model(&block)
510- database do |db|
511- block.call(Tenarai::DB::Container.new(db, @config[:model]))
512- end
513- end
514-
515- def install
516- model do |m|
517- m.create
518- end
519- end
520-
521- def uninstall
522- model do |m|
523- m.drop
524- end
525- end
526-
527- def load_model(init_model)
528- model do |m|
529- map = {}
530- create_row(m, map, init_model)
531- update_preference(m, map, init_model)
532- end
533- end
534-
535- def create_row(model, map, init_model)
536- init_model.each do |key, val|
537- val.each do |v|
538- obj = Tenarai::ClassLoader[v[:class]].new(model[key], v[:row])
539-
540- map[key] ||= {}
541- map[key][v[:name]] = obj
542-
543- n = v[:name].split('.')
544- n.pop
545-
546- unless n.empty?
547- parent = map[key][n.join('.')]
548- p [obj.class.name, parent.class.name, key, n.join('.')]
549- parent.node << obj
550- parent.save
551- end
552-
553- obj.save
554- end
555- end
556- end
557- private :create_row
558-
559- def update_preference(model, map, init_model)
560- init_model.each do |key, val|
561- val.each do |v|
562- v[:relation].each do |col, rel|
563- table, name = rel.split(':')
564-
565- a = map[key][v[:name]]
566- a.row[col] = map[table][name]
567- a.save
568- end if v[:relation]
569-
570- v[:preference].each do |pk, pv|
571- if pv.is_a? Symbol
572- mk, mv = pv.to_s.split(':')
573- pv = map[mk][mv].primary_key.to_s
574- end
575-
576- a = map[key][v[:name]]
577- if pref = a.preference.find(pk)
578- pref.value = pv
579- a.save
580- end
581- end if v[:preference]
582- end
583- end
584- end
585- private :update_preference
586-end
587-
588469 task :default do
589470 require 'test/unit'
590- Test::Unit::AutoRunner.run(true, "#{base_dir}/test")
471+ Test::Unit::AutoRunner.run(true, "#{BASE_DIR}/test")
591472 end
592473
593-task :install do Main.new(config).install end
594-task :init do Main.new(config).load_model(init_model) end
595-task :uninstall do Main.new(config).uninstall end
596-task :cgi do Main.new(config).cgi end
597-task :webrick do Main.new(config).webrick end
598-task :mongrel do Main.new(config).mongrel end
474+task :install do Main.new.install end
475+task :init do Main.new.load_model(init_model) end
476+task :uninstall do Main.new.uninstall end
--- trunk/main.rb (nonexistent)
+++ trunk/main.rb (revision 55)
@@ -0,0 +1,146 @@
1+#!/usr/bin/ruby -Ku
2+#
3+# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
4+#
5+
6+require 'config'
7+
8+$LOAD_PATH.push("#{BASE_DIR}/lib")
9+
10+require 'tenarai/server'
11+require 'tenarai/classloader'
12+require 'tenarai/db/container'
13+
14+Tenarai::ClassLoader.dir = CONFIG[:server][:app_dir]
15+
16+class Main
17+ def initialize(config)
18+ @config = config
19+ end
20+
21+ def server(name)
22+ model do |m|
23+ m['service'].pub_dir = @config[:server][:pub_dir]
24+ Tenarai::Server.new(@config[:server]) do |request, response|
25+ m['service'].dispatch(m, request, response)
26+ m.refresh
27+ end.__send__(name)
28+ end
29+ end
30+
31+ def cgi
32+ server('cgi')
33+ end
34+
35+ def webrick
36+ server('webrick')
37+ end
38+
39+ def mongrel
40+ server('mongrel')
41+ end
42+
43+ def error
44+ p $!
45+ $!.backtrace.each do |val|
46+ puts ' ' + val
47+ end
48+ end
49+
50+ def database(&block)
51+ begin
52+ Tenarai::DB.new(@config[:db]) do |db|
53+ block.call(db)
54+ end
55+ rescue
56+ error
57+ end
58+ end
59+
60+ def model(&block)
61+ database do |db|
62+ block.call(Tenarai::DB::Container.new(db, @config[:model]))
63+ end
64+ end
65+
66+ def install
67+ model do |m|
68+ m.create
69+ end
70+ end
71+
72+ def uninstall
73+ model do |m|
74+ m.drop
75+ end
76+ end
77+
78+ def load_model(init_model)
79+ model do |m|
80+ map = {}
81+ create_row(m, map, init_model)
82+ update_preference(m, map, init_model)
83+ end
84+ end
85+
86+ def create_row(model, map, init_model)
87+ init_model.each do |key, val|
88+ val.each do |v|
89+ obj = Tenarai::ClassLoader[v[:class]].new(model[key], v[:row])
90+
91+ map[key] ||= {}
92+ map[key][v[:name]] = obj
93+
94+ n = v[:name].split('.')
95+ n.pop
96+
97+ unless n.empty?
98+ parent = map[key][n.join('.')]
99+ p [obj.class.name, parent.class.name, key, n.join('.')]
100+ parent.node << obj
101+ parent.save
102+ end
103+
104+ obj.save
105+ end
106+ end
107+ end
108+ private :create_row
109+
110+ def update_preference(model, map, init_model)
111+ init_model.each do |key, val|
112+ val.each do |v|
113+ v[:relation].each do |col, rel|
114+ table, name = rel.split(':')
115+
116+ a = map[key][v[:name]]
117+ a.row[col] = map[table][name]
118+ a.save
119+ end if v[:relation]
120+
121+ v[:preference].each do |pk, pv|
122+ if pv.is_a? Symbol
123+ mk, mv = pv.to_s.split(':')
124+ pv = map[mk][mv].primary_key.to_s
125+ end
126+
127+ a = map[key][v[:name]]
128+ if pref = a.preference.find(pk)
129+ pref.value = pv
130+ a.save
131+ end
132+ end if v[:preference]
133+ end
134+ end
135+ end
136+ private :update_preference
137+end
138+
139+case ARGV.shift
140+when 'cgi'
141+ Main.new(CONFIG).cgi
142+when 'mongrel'
143+ Main.new(CONFIG).mongrel
144+when 'webrick'
145+ Main.new(CONFIG).webrick
146+end
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
--- trunk/config.rb (nonexistent)
+++ trunk/config.rb (revision 55)
@@ -0,0 +1,42 @@
1+
2+BASE_DIR = File.dirname(__FILE__)
3+
4+CONFIG = {
5+ :db => {
6+ :engine => :mysql,
7+ :db => 'test',
8+ :host => 'localhost',
9+ :user => 'root',
10+ :password => 'root',
11+ #:echo => true,
12+ },
13+
14+ :server => {
15+ :address => '0.0.0.0',
16+ :port => 8080,
17+ :pub_dir => "#{BASE_DIR}/pub",
18+ :app_dir => "#{BASE_DIR}/webapp",
19+ },
20+
21+ :model => {
22+ :table => {
23+ 'service' => {:row => 'Service', :class => 'ServiceTable'},
24+ 'user' => {:row => 'User', :class => 'UserTable' },
25+ 'session' => {:row => 'Session', :class => 'SessionTable'},
26+ 'content' => {:row => 'Content' },
27+ 'view' => {:row => 'View' },
28+ 'widget' => {:row => 'Widget' },
29+ },
30+
31+ :relation => [
32+ ['service.widget', 'widget' ],
33+ ['user.content', 'content' ],
34+ ['user.session', 'session.user' ],
35+ ['content.parent', 'content.node' ],
36+ ['content.view', 'view' ],
37+ ['view.parent', 'view.node' ],
38+ ['widget.parent', 'widget.node' ],
39+ ['widget.view', 'view.widget' ],
40+ ],
41+ },
42+}
--- trunk/webapp/Widget/HTML.rb (revision 54)
+++ trunk/webapp/Widget/HTML.rb (revision 55)
@@ -62,7 +62,11 @@
6262 render_html_head(head, builder)
6363 end
6464 html.tag('body', 'id' => html_id) do |body|
65- super(body, builder)
65+ if builder.empty?(self)
66+ body.text('')
67+ else
68+ super(body, builder)
69+ end
6670 end
6771 end
6872 end
--- trunk/webapp/ServiceTable.rb (revision 54)
+++ trunk/webapp/ServiceTable.rb (revision 55)
@@ -14,32 +14,36 @@
1414 end
1515
1616 def dispatch(model, request, response)
17- _nil, name, *param = request['path_info'].split('/')
17+ path_info = request['path_info'] || '/'
18+
19+ _nil, name, *param = path_info.split('/')
20+
1821 if s = fetch_by_name(name || 'index')
1922 response.code = 200
2023 s.dispatch(model, param, request, response)
2124 else
2225 response.code = 404
23- if @pub_dir
24- file = File.expand_path(@pub_dir + request['path_info'])
25- if %r!^#{@pub_dir}!.match(file) && File.file?(file)
26- ct = case File.extname(file).downcase
27- when '.txt'
28- 'text/plain'
29- when '.js'
30- 'text/javascript'
31- when '.css'
32- 'text/css'
33- when '.swf'
34- 'application/x-shockwave-flash'
35- end
36- unless ct.nil?
37- response.code = 200
38- response['content-type'] = ct
39- response.body << File.open(file).read
40- end
41- end
26+
27+ return unless @pub_dir
28+
29+ file = File.expand_path(@pub_dir + path_info)
30+ return unless (%r!^#{@pub_dir}!.match(file) && File.file?(file))
31+
32+ ct = case File.extname(file).downcase
33+ when '.txt'
34+ 'text/plain'
35+ when '.js'
36+ 'text/javascript'
37+ when '.css'
38+ 'text/css'
39+ when '.swf'
40+ 'application/x-shockwave-flash'
4241 end
42+ unless ct.nil?
43+ response.code = 200
44+ response['content-type'] = ct
45+ response.body << File.open(file).read
46+ end
4347 end
4448 end
4549 end
Show on old repository browser