• R/O
  • SSH
  • HTTPS

tenarai: 提交


Commit MetaInfo

修訂46 (tree)
時間2008-02-14 23:00:45
作者junkikuchi

Log Message

updated.

Change Summary

差異

--- trunk/test/test_cgi_query.rb (revision 45)
+++ trunk/test/test_cgi_query.rb (revision 46)
@@ -11,7 +11,7 @@
1111 'd'=>nil, 'a'=>10, 'b'=>'a b c', 'c'=>['a', 2, 1]
1212 )
1313
14- assert_equal('a=10&b=a+b+c&c=1&c=2&c=a&d=', q.to_s)
14+ assert_equal('a=10&b=a+b+c&c=1&c=2&c=a&d', q.to_s)
1515
1616 assert_equal('10', q['a'])
1717 assert_equal('a b c', q['b'])
@@ -24,7 +24,7 @@
2424 def test_decode
2525 q = Tenarai::CGI::Query.decode('d=&a=10&b=a+b+c&c=a&c=1&c=2&c=a')
2626
27- assert_equal('a=10&b=a+b+c&c=1&c=2&c=a&c=a&d=', q.to_s)
27+ assert_equal('a=10&b=a+b+c&c=1&c=2&c=a&c=a&d', q.to_s)
2828
2929 assert_equal('10', q['a'])
3030 assert_equal('a b c', q['b'])
@@ -45,7 +45,7 @@
4545 q['c'] = 2
4646 q['c'] = [3, 4]
4747
48- assert_equal('a=10&b=a+b+c&c=1&c=2&c=2&c=3&c=4&c=a&d=', q.to_s)
48+ assert_equal('a=10&b=a+b+c&c=1&c=2&c=2&c=3&c=4&c=a&d', q.to_s)
4949
5050 assert_equal('10', q['a'])
5151 assert_equal('a b c', q['b'])
--- trunk/Rakefile (revision 45)
+++ trunk/Rakefile (revision 46)
@@ -365,6 +365,38 @@
365365 :row => {},
366366 :relation => {'view' => 'view:resource.admin'},
367367 },
368+
369+ {
370+ :name => 'session.user.content.view.widget.html.admin.panel',
371+ :class => 'Widget::Panel',
372+ :row => {},
373+ :relation => {'view' => 'view:resource.admin'},
374+ :preference => {
375+ 'box.size.width' => '100px',
376+ 'box.size.height' => '100px',
377+ 'box.padding.padding_left' => '10px',
378+ 'box.padding.padding_top' => '10px',
379+ 'box.padding.padding_right' => '10px',
380+ 'box.padding.padding_bottom' => '10px',
381+ 'box.background.background_color' => 'gray',
382+ }
383+ },
384+
385+ {
386+ :name => 'session.user.content.view.widget.html.admin.panel.panel',
387+ :class => 'Widget::Panel',
388+ :row => {},
389+ :relation => {'view' => 'view:resource.admin'},
390+ :preference => {
391+ 'box.size.width' => '80px',
392+ 'box.size.height' => '80px',
393+ 'box.margin.margin_left' => '10px',
394+ 'box.margin.margin_top' => '10px',
395+ 'box.margin.margin_right' => '10px',
396+ 'box.margin.margin_bottom' => '10px',
397+ 'box.background.background_color' => 'green',
398+ }
399+ },
368400 ],
369401 }
370402
--- trunk/lib/tenarai/cgi/query.rb (revision 45)
+++ trunk/lib/tenarai/cgi/query.rb (revision 46)
@@ -27,8 +27,12 @@
2727
2828 include Enumerable
2929
30- def initialize(query={})
31- @query = query
30+ #def initialize(query={})
31+ # @query = query
32+ #end
33+ #
34+ def initialize
35+ @query = {}
3236 end
3337
3438 def [](key)
@@ -68,7 +72,7 @@
6872 @query.sort.inject([]) do |ret, (key, val)|
6973 if val.is_a?(Array)
7074 val.each do |v|
71- if v.nil?
75+ if v.empty?
7276 ret << key
7377 else
7478 ret << "%s=%s" % [key, CGI.encode(v)]
@@ -75,7 +79,7 @@
7579 end
7680 end
7781 else
78- if val.nil?
82+ if val.empty?
7983 ret << key
8084 else
8185 ret << "%s=%s" % [key, CGI.encode(val)]
--- trunk/webapp/Service.rb (revision 45)
+++ trunk/webapp/Service.rb (revision 46)
@@ -33,10 +33,16 @@
3333 attr_reader :request
3434 attr_reader :response
3535
36- def url
37- ['', name].join('/')
36+ def _build_url(param, res, query)
37+ url = [nil, name, res].join('/')
38+ url += '?' + query.to_s unless query.empty?
39+ url
3840 end
3941
42+ def url(*param)
43+ _build_url([], param)
44+ end
45+
4046 def dispatch(model, param, request, response)
4147 begin
4248 @model = model
@@ -43,29 +49,51 @@
4349 @request = request
4450 @response = response
4551
46- widget.path.each do |r|
47- r.init(self, *(param.shift || '').split(','))
48- end
49-
5052 method = (@request.method || 'get').downcase
53+ ws, rs = {}, {}
5154
5255 if method == 'get'
5356 @request.query
5457 else
5558 @request.query.merge(@request.content)
56- end.inject({}) do |ws, (key, val)|
57- if /id(\d+):(.+)/.match(key)
58- wid = $1
59+ end.each do |key, val|
60+ case key
61+ when /id(\d+):(.+)/
62+ wid = $1.to_i
5963 key = $2
64+ ws[wid] ||= {}
65+ ws[wid][key] = val
66+ when /id(\d+)/
67+ wid = $1.to_i
68+ key = nil
69+ rs[wid] ||= {}
70+ rs[wid] = val
71+ end
72+ end
73+
74+ widget.path.each do |r|
75+ if param.empty?
76+ if rs.key?(r.id)
77+ r.init(self, *rs.delete(r.id).split(','))
78+ else
79+ r.init(self)
80+ end
6081 else
61- #wid = primary_key
82+ r.init(self, *(param.shift || '').split(','))
6283 end
84+ end
6385
64- ws[wid] ||= {}
65- ws[wid][key] = val
86+ rs.inject({}) do |ret, (wid, val)|
87+ w = @model['widget'].fetch(wid)
88+ ret[w] = val unless w.nil?
89+ ret
90+ end.sort do |(aw, aval), (bw, bval)|
91+ aw.min <=> bw.min
92+ end.each do |w, val|
93+ w.init(self, *val.split(','))
94+ end
6695
67- ws
68- end.each do |wid, query|
96+ ws.each do |wid, query|
6997 if w = @model['widget'].fetch(wid)
7098 w.__send__(method, self, query)
7199 end
--- trunk/webapp/Widget/Model.rb (revision 45)
+++ trunk/webapp/Widget/Model.rb (nonexistent)
@@ -1,17 +0,0 @@
1-#
2-# Copyright (C) 2007 Jun Kikuchi <kikuchi@bonnou.com>
3-#
4-
5-class Widget
6- class Model < Widget
7- extend Tenarai::ClassLoader
8-
9- def url(params={})
10- if parent.nil?
11- model.url(params)
12- else
13- parent.url(params)
14- end
15- end
16- end
17-end
--- trunk/webapp/Widget/Panel.rb (revision 45)
+++ trunk/webapp/Widget/Panel.rb (revision 46)
@@ -2,17 +2,17 @@
22 # Copyright (C) 2007 Jun Kikuchi <kikuchi@bonnou.com>
33 #
44
5-Tenarai::ClassLoader.load_class('Widget::Content')
5+Tenarai::ClassLoader.load_class('Widget')
66
77 class Widget
8- class Panel < Widget
8+ class Panel < ::Widget
99 extend Tenarai::ClassLoader
1010
1111 preference_css 'box'
1212
13- def render_body(xml)
13+ def render_html(xml, builder)
1414 xml.tag('div', 'id' => html_id) do |div|
15- super(div)
15+ super(div, builder)
1616 end
1717 end
1818 end
--- trunk/webapp/Widget/Session.rb (revision 45)
+++ trunk/webapp/Widget/Session.rb (revision 46)
@@ -38,8 +38,8 @@
3838 )
3939 end
4040
41- def url(*param)
42- super('')
41+ def build_url(param)
42+ nil
4343 end
4444
4545 def render_html(xml, builder)
--- trunk/webapp/Widget/YUI/ResetFontsGrids.rb (revision 45)
+++ trunk/webapp/Widget/YUI/ResetFontsGrids.rb (revision 46)
@@ -4,7 +4,7 @@
44
55 class Widget
66 module YUI
7- class ResetFontsGrids < Widget
7+ class ResetFontsGrids < ::Widget
88 extend Tenarai::ClassLoader
99
1010 preference 'yui' do |yui|
--- trunk/webapp/Widget/User/Logout.rb (revision 45)
+++ trunk/webapp/Widget/User/Logout.rb (revision 46)
@@ -6,7 +6,7 @@
66
77 class Widget
88 class User
9- class Logout < Widget
9+ class Logout < ::Widget
1010 extend Tenarai::ClassLoader
1111
1212 preference_css 'box'
@@ -16,10 +16,11 @@
1616 end
1717
1818 def render_html(xml, builder)
19- query = Tenarai::CGI::Query.new(html_id('logout') => nil)
20-
2119 xml.tag('div', 'id' => html_id) do |div|
22- div.tag('a', 'href' => url + '?' + query.to_s).text('logout')
20+ div.tag(
21+ 'a',
22+ 'href' => url do |query| query[html_id('logout')] = nil end
23+ ).text('logout')
2324 end
2425 end
2526 end
--- trunk/webapp/Widget/User/LoginForm.rb (revision 45)
+++ trunk/webapp/Widget/User/LoginForm.rb (revision 46)
@@ -6,7 +6,7 @@
66
77 class Widget
88 class User
9- class LoginForm < Widget
9+ class LoginForm < ::Widget
1010 extend Tenarai::ClassLoader
1111
1212 preference_css 'box'
--- trunk/webapp/Widget.rb (revision 45)
+++ trunk/webapp/Widget.rb (revision 46)
@@ -138,8 +138,8 @@
138138 self.class.fetch_resource(self)
139139 end
140140
141- def url(*param)
142- resource.url(*param)
141+ def url(*param, &block)
142+ resource.url(*param, &block)
143143 end
144144
145145 def init(service, *param)
--- trunk/webapp/Resource.rb (revision 45)
+++ trunk/webapp/Resource.rb (revision 46)
@@ -4,7 +4,7 @@
44
55 Tenarai::ClassLoader.load_class('Widget')
66
7-class Resource < Widget
7+class Resource < ::Widget
88 extend Tenarai::ClassLoader
99
1010 attr_reader :content
@@ -14,22 +14,38 @@
1414 @content = service.model[self.class.name.split('::').pop.downcase].fetch(id)
1515 end
1616
17- def url(*param)
18- [
19- if resource.nil?
20- @service.url
17+ def build_url(param)
18+ if param.empty?
19+ if @content
20+ @content.id
2121 else
22- resource.url
23- end,
24- if param.empty?
25- if @content
26- @content.id
27- else
28- nil
29- end
30- else
31- param.join(',')
22+ nil
3223 end
33- ].join('/')
24+ else
25+ param
26+ end
3427 end
28+
29+ def _build_url(param, _resource, _query)
30+ _param = [build_url(param)].join(',')
31+
32+ if view.path.size == 1
33+ #_resource.unshift(_param)
34+ _query[html_id] = _param
35+ else
36+ _query[html_id] = _param
37+ end
38+
39+ if resource.nil?
40+ @service
41+ else
42+ resource
43+ end._build_url([], _resource, _query)
44+ end
45+
46+ def url(*param, &block)
47+ query = Tenarai::CGI::Query.new
48+ block.call(query) if block_given?
49+ _build_url(param, [], query)
50+ end
3551 end
Show on old repository browser