• R/O
  • SSH
  • HTTPS

tenarai: 提交


Commit MetaInfo

修訂44 (tree)
時間2008-02-10 20:11:37
作者junkikuchi

Log Message

updated widgets.
fixed Tenarai::CGI::Query.

Change Summary

差異

--- trunk/test/test_cgi_query.rb (revision 43)
+++ trunk/test/test_cgi_query.rb (revision 44)
@@ -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'])
@@ -22,9 +22,9 @@
2222 end
2323
2424 def test_decode
25- q = Tenarai::CGI::Query.decode('d=;a=10;b=a+b+c;c=a;c=1;c=2;c=a')
25+ 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'])
@@ -66,7 +66,7 @@
6666
6767 c = a.merge(b)
6868
69- assert_equal('a=10;b=1;b=2;b=2;b=3;c=20', c.to_s)
69+ assert_equal('a=10&b=1&b=2&b=2&b=3&c=20', c.to_s)
7070
7171 assert_equal('10', c['a'])
7272 assert_equal(['1', '2', '2', '3'], c['b'])
--- trunk/Rakefile (revision 43)
+++ trunk/Rakefile (revision 44)
@@ -55,7 +55,7 @@
5555 :class => 'Service',
5656 :row => {'name' => 'user'},
5757 :relation => {
58- 'widget' => 'widget:session.user.content.view.html',
58+ 'widget' => 'widget:session.user.content.view.widget.html',
5959 },
6060 },
6161 ],
@@ -106,6 +106,64 @@
106106 },
107107 :relation => {'view' => 'view:resource.admin'},
108108 },
109+
110+ {
111+ :name => 'admin.content',
112+ :class => 'Content',
113+ :row => {
114+ 'title' => 'content',
115+ 'body' => 'content',
116+ },
117+ :relation => {'view' => 'view:resource.admin'},
118+ },
119+
120+ {
121+ :name => 'admin.content.c1',
122+ :class => 'Content',
123+ :row => { 'title' => 'c1', 'body' => 'c1', },
124+ :relation => {'view' => 'view:resource.admin'},
125+ },
126+ {
127+ :name => 'admin.content.c2',
128+ :class => 'Content',
129+ :row => { 'title' => 'c2', 'body' => 'c2', },
130+ :relation => {'view' => 'view:resource.admin'},
131+ },
132+ {
133+ :name => 'admin.content.c3',
134+ :class => 'Content',
135+ :row => { 'title' => 'c3', 'body' => 'c3', },
136+ :relation => {'view' => 'view:resource.admin'},
137+ },
138+
139+ {
140+ :name => 'admin.view',
141+ :class => 'Content',
142+ :row => {
143+ 'title' => 'view',
144+ 'body' => 'view',
145+ },
146+ :relation => {'view' => 'view:resource.admin'},
147+ },
148+
149+ {
150+ :name => 'admin.view.v1',
151+ :class => 'Content',
152+ :row => { 'title' => 'v1', 'body' => 'v1', },
153+ :relation => {'view' => 'view:resource.admin'},
154+ },
155+ {
156+ :name => 'admin.view.v2',
157+ :class => 'Content',
158+ :row => { 'title' => 'v2', 'body' => 'v2', },
159+ :relation => {'view' => 'view:resource.admin'},
160+ },
161+ {
162+ :name => 'admin.view.v3',
163+ :class => 'Content',
164+ :row => { 'title' => 'v3', 'body' => 'v3', },
165+ :relation => {'view' => 'view:resource.admin'},
166+ },
109167 ],
110168
111169 'view' => [
@@ -143,6 +201,7 @@
143201 :relation => {'view' => 'view:resource'},
144202 :preference => {
145203 'preference.default.user_id' => :'user:login'
204+ #'preference.default.user_id' => :'user:admin'
146205 }
147206 },
148207
@@ -161,7 +220,15 @@
161220 },
162221
163222 {
164- :name => 'session.user.content.view.html',
223+ :name => 'session.user.content.view.widget',
224+ :class => 'Widget::Widget',
225+ :row => {},
226+ :relation => {'view' => 'view:resource'},
227+ :preference => {}
228+ },
229+
230+ {
231+ :name => 'session.user.content.view.widget.html',
165232 :class => 'Widget::HTML',
166233 :row => {},
167234 :relation => {'view' => 'view:resource'},
@@ -169,21 +236,22 @@
169236 },
170237
171238 {
172- :name => 'session.user.content.view.html.login',
239+ :name => 'session.user.content.view.widget.html.login',
173240 :class => 'Widget',
174241 :row => {},
175242 :relation => {'view' => 'view:resource.login'},
243+ :preference => {}
176244 },
177245
178246 {
179- :name => 'session.user.content.view.html.login.title',
247+ :name => 'session.user.content.view.widget.html.login.title',
180248 :class => 'Widget::Content::Title',
181249 :row => {},
182250 :relation => {'view' => 'view:resource.login'},
183251 },
184-
252+=begin
185253 {
186- :name => 'session.user.content.view.html.login.reset_style',
254+ :name => 'session.user.content.view.widget.login.reset_style',
187255 :class => 'Widget::YUI::ResetFontsGrids',
188256 :row => {},
189257 :relation => {'view' => 'view:resource.login'},
@@ -191,9 +259,9 @@
191259 'yui.reset_fonts_grids.url' => 'http://localhost/yui/build/reset-fonts-grids/reset-fonts-grids.css',
192260 }
193261 },
194-
262+=end
195263 {
196- :name => 'session.user.content.view.html.login.header',
264+ :name => 'session.user.content.view.widget.html.login.header',
197265 :class => 'Widget::Content::Header',
198266 :row => {},
199267 :relation => {'view' => 'view:resource.login'},
@@ -200,7 +268,7 @@
200268 },
201269
202270 {
203- :name => 'session.user.content.view.html.login.login_form',
271+ :name => 'session.user.content.view.widget.html.login.login_form',
204272 :class => 'Widget::User::LoginForm',
205273 :row => {},
206274 :relation => {'view' => 'view:resource.login'},
@@ -207,14 +275,15 @@
207275 },
208276
209277 {
210- :name => 'session.user.content.view.html.admin',
278+ :name => 'session.user.content.view.widget.html.admin',
211279 :class => 'Widget',
212280 :row => {},
213281 :relation => {'view' => 'view:resource.admin'},
282+ :preference => {}
214283 },
215284
216285 {
217- :name => 'session.user.content.view.html.admin.logout',
286+ :name => 'session.user.content.view.widget.html.admin.logout',
218287 :class => 'Widget::User::Logout',
219288 :row => {},
220289 :relation => {'view' => 'view:resource.admin'},
@@ -221,14 +290,14 @@
221290 },
222291
223292 {
224- :name => 'session.user.content.view.html.admin.title',
293+ :name => 'session.user.content.view.widget.html.admin.title',
225294 :class => 'Widget::Content::Title',
226295 :row => {},
227296 :relation => {'view' => 'view:resource.admin'},
228297 },
229-
298+=begin
230299 {
231- :name => 'session.user.content.view.html.admin.reset_style',
300+ :name => 'session.user.content.view.widget.html.admin.reset_style',
232301 :class => 'Widget::YUI::ResetFontsGrids',
233302 :row => {},
234303 :relation => {'view' => 'view:resource.admin'},
@@ -236,13 +305,64 @@
236305 'yui.reset_fonts_grids.url' => 'http://localhost/yui/build/reset-fonts-grids/reset-fonts-grids.css',
237306 }
238307 },
239-
308+=end
240309 {
241- :name => 'session.user.content.view.html.admin.header',
310+ :name => 'session.user.content.view.widget.html.admin.header',
242311 :class => 'Widget::Content::Header',
243312 :row => {},
244313 :relation => {'view' => 'view:resource.admin'},
245314 },
315+
316+ {
317+ :name => 'session.user.content.view.widget.html.admin.tab',
318+ :class => 'Widget::Content::Tab',
319+ :row => {},
320+ :relation => {'view' => 'view:resource.admin'},
321+ },
322+
323+ {
324+ :name => 'session.user.content.view.widget.html.admin.path',
325+ :class => 'Widget::Content::Path',
326+ :row => {},
327+ :relation => {'view' => 'view:resource.admin'},
328+ },
329+
330+ {
331+ :name => 'session.user.content.view.widget.html.admin.list',
332+ :class => 'Widget::Content::List',
333+ :row => {},
334+ :relation => {'view' => 'view:resource.admin'},
335+ },
336+
337+ {
338+ :name => 'session.user.content.view.widget.html.admin.newform',
339+ :class => 'Widget::Content::Form',
340+ :row => {},
341+ :relation => {'view' => 'view:resource.admin'},
342+ :preference => {'preference.form.type' => 'new'}
343+ },
344+
345+ {
346+ :name => 'session.user.content.view.widget.html.admin.editform',
347+ :class => 'Widget::Content::Form',
348+ :row => {},
349+ :relation => {'view' => 'view:resource.admin'},
350+ :preference => {'preference.form.type' => 'edit'}
351+ },
352+
353+ {
354+ :name => 'session.user.content.view.widget.html.admin.view',
355+ :class => 'Widget::View::List',
356+ :row => {},
357+ :relation => {'view' => 'view:resource.admin'},
358+ },
359+
360+ {
361+ :name => 'session.user.content.view.widget.html.admin.widget',
362+ :class => 'Widget::Widget::List',
363+ :row => {},
364+ :relation => {'view' => 'view:resource.admin'},
365+ },
246366 ],
247367 }
248368
--- trunk/lib/tenarai/cgi/query.rb (revision 43)
+++ trunk/lib/tenarai/cgi/query.rb (revision 44)
@@ -68,13 +68,21 @@
6868 @query.sort.inject([]) do |ret, (key, val)|
6969 if val.is_a?(Array)
7070 val.each do |v|
71- ret << "%s=%s" % [key, CGI.encode(v)]
71+ if v.nil?
72+ ret << key
73+ else
74+ ret << "%s=%s" % [key, CGI.encode(v)]
75+ end
7276 end
7377 else
74- ret << "%s=%s" % [key, CGI.encode(val)]
78+ if val.nil?
79+ ret << key
80+ else
81+ ret << "%s=%s" % [key, CGI.encode(val)]
82+ end
7583 end
7684 ret
77- end.join(';')
85+ end.join('&')
7886 end
7987
8088 def empty?
--- trunk/webapp/Widget/Widget/List.rb (nonexistent)
+++ trunk/webapp/Widget/Widget/List.rb (revision 44)
@@ -0,0 +1,31 @@
1+#
2+# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
3+#
4+
5+Tenarai::ClassLoader.load_class('Widget::Widget')
6+
7+class Widget
8+ class Widget
9+ class List < ::Widget
10+ extend Tenarai::ClassLoader
11+
12+ preference_css 'box'
13+
14+ def render_html(xml, builder)
15+ xml.tag('div', 'id' => html_id) do |div|
16+ ws = {}
17+ resource.each do |w|
18+ if w.parent.nil?
19+ div.tag('ul')
20+ else
21+ ws[w.parent.id]
22+ end.tag('li') do |li|
23+ li.tag('a', 'href' => url(w.id)).text(w.class.name)
24+ ws[w.id] = li.tag('ul')
25+ end
26+ end
27+ end
28+ end
29+ end
30+ end
31+end
--- trunk/webapp/Widget/Widget.rb (nonexistent)
+++ trunk/webapp/Widget/Widget.rb (revision 44)
@@ -0,0 +1,29 @@
1+#
2+# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com>
3+#
4+
5+Tenarai::ClassLoader.load_class('Resource')
6+
7+class Widget
8+ class Widget < Resource
9+ extend Tenarai::ClassLoader
10+ include Enumerable
11+
12+ resource 'Widget::View'
13+
14+ def init(service, id=nil)
15+ super
16+
17+ @content = resource.content.widget.root if @content.nil?
18+
19+ unless resource.content.include?(@content.view)
20+ @content = resource.content.widget.root
21+ #raise Service::Redirect.new(url(resource.content.view.id))
22+ end unless resource.content.nil?
23+ end
24+
25+ def each(&block)
26+ resource.content.widget.each(&block)
27+ end
28+ end
29+end
--- trunk/webapp/Widget/Content/NewForm.rb (revision 43)
+++ trunk/webapp/Widget/Content/NewForm.rb (nonexistent)
@@ -1,85 +0,0 @@
1-#
2-# Copyright (C) 2007 Jun Kikuchi <kikuchi@bonnou.com>
3-#
4-
5-Tenarai::ClassLoader.load_class('Widget::Content')
6-
7-class Widget
8- class Content
9- class NewForm < Widget
10- extend Tenarai::ClassLoader
11-
12- preference_css 'box'
13- preference_css 'msg', 'p'
14- preference_css 'form_label', 'label'
15- preference_css 'form_title', 'input'
16- preference_css 'form_content', 'textarea'
17- preference_css 'form_submit', 'input[type="submit"]'
18-
19- preference 'title'
20- preference 'body'
21- preference 'submit'
22-
23- def render_css(css)
24- super
25-
26- css.style(css_id + ' input') do |s|
27- s['display'] = 'block'
28- end
29-
30- css.style(css_id + ' textarea') do |s|
31- s['display'] = 'block'
32- end
33- end
34-
35- def render_body(xml)
36- preference_clone do |pref|
37- xml.tag('div', 'id' => html_id) do |div|
38- div.tag(
39- 'form',
40- 'method' => 'post',
41- 'action' => url(:view => view)
42- ) do |form|
43- form.tag('p') do |p|
44- p.text(@msg)
45- end if @msg
46-
47- form.tag('div') do |div|
48- div.tag('label') do |label|
49- label.text('Title:')
50- label.tag(
51- 'input',
52- 'type' => 'text',
53- 'name' => pref.title.path_name,
54- 'value' => pref.title.value
55- )
56- end
57- div.tag('br')
58-
59- div.tag('label') do |label|
60- label.text('Content:')
61- label.tag(
62- 'textarea',
63- 'name' => pref.body.path_name
64- ).text(pref.body.value)
65- end
66- div.tag('br')
67-
68- div.tag(
69- 'input',
70- 'type' => 'submit',
71- 'name' => pref.submit.path_name
72- )
73- end
74- end
75- end
76- end
77- end
78-
79- def exec
80- model.new(preference.title.value, preference.body.value)
81- @msg = 'New content was created.'
82- end
83- end
84- end
85-end
--- trunk/webapp/Widget/Content/AdminMenu.rb (revision 43)
+++ trunk/webapp/Widget/Content/AdminMenu.rb (nonexistent)
@@ -1,50 +0,0 @@
1-#
2-# Copyright (C) 2007 Jun Kikuchi <kikuchi@bonnou.com>
3-#
4-
5-Tenarai::ClassLoader.load_class('Widget::Content')
6-
7-class Widget
8- class Content
9- class AdminMenu < Widget
10- extend Tenarai::ClassLoader
11-
12- preference_css 'box'
13- preference_css 'menu', 'a'
14- preference_css 'menu_selected', 'a.selected'
15- preference_css 'menu_hover', 'a:hover'
16-
17- preference 'list'
18- preference 'new'
19-
20- def render_css(css)
21- super
22- css.style(css_id + ' li') do |s|
23- s['list-style'] = 'none'
24- s['display'] = 'inline'
25- s['margin'] = '0'
26- end
27- end
28-
29- def render_body(xml)
30- xml.tag('ul', 'id' => html_id) do |ul|
31- list = service.models['views'].fetch(preference.list.value)
32- ul.tag('li') do |li|
33- li.tag('a') do |a|
34- a['href'] = url(:view => list)
35- a['class'] = 'selected' if service.view.equal?(list)
36- end.text('List')
37- end
38-
39- new = service.models['views'].fetch(preference.new.value)
40- ul.tag('li') do |li|
41- li.tag('a') do |a|
42- a['href'] = url(:view => new)
43- a['class'] = 'selected' if service.view.equal?(new)
44- end.text('New')
45- end
46- end
47- end
48- end
49- end
50-end
--- trunk/webapp/Widget/Content/AdminList.rb (revision 43)
+++ trunk/webapp/Widget/Content/AdminList.rb (nonexistent)
@@ -1,65 +0,0 @@
1-#
2-# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com>
3-#
4-
5-Tenarai::ClassLoader.load_class('Widget::Content')
6-
7-class Widget
8- class Content
9- class AdminList < Widget
10- extend Tenarai::ClassLoader
11-
12- preference_css 'box'
13- preference_css 'header', 'th'
14- preference_css 'body', 'td'
15-
16- preference 'content' do |c|
17- c.group 'view' do |m|
18- m.edit 'edit'
19- end
20- end
21-
22- def edit_view
23- service.models['views'].fetch(preference.content.view.edit.value)
24- end
25-
26- def render_css(css)
27- super
28- css.style(css_id + ' table') do |s|
29- s['width'] = '100%'
30- end
31- end
32-
33- def render_body(xml)
34- xml.tag('div', 'id' => html_id) do |div|
35- div.tag('table') do |table|
36- table.tag('thead') do |thead|
37- thead.tag('tr') do |tr|
38- tr.tag('th').text('ID')
39- tr.tag('th').text('Title')
40- tr.tag('th').text('View')
41- tr.tag('th').text('')
42- end
43- end
44- table.tag('tbody') do |tbody|
45- model.content.nodes.each do |val|
46- tbody.tag('tr') do |tr|
47- tr.tag('td').text(val.id)
48- tr.tag('td').tag(
49- 'a',
50- 'href' => url(:content => val)
51- ).text(val.title)
52- tr.tag('td').text(if val.view then val.view.name end)
53- tr.tag('td').tag(
54- 'a',
55- 'href' => url(:content => val, :view => edit_view)
56- ).text('Edit')
57- end
58- end
59- end
60- end
61- end
62- end
63- end
64- end
65-end
--- trunk/webapp/Widget/Content/EditForm.rb (revision 43)
+++ trunk/webapp/Widget/Content/EditForm.rb (nonexistent)
@@ -1,87 +0,0 @@
1-#
2-# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
3-#
4-
5-Tenarai::ClassLoader.load_class('Widget::Content')
6-
7-class Widget
8- class Content
9- class EditForm < Widget
10- extend Tenarai::ClassLoader
11-
12- preference_css 'box'
13- preference_css 'msg', 'p'
14- preference_css 'form_label', 'label'
15- preference_css 'form_title', 'input'
16- preference_css 'form_content', 'textarea'
17- preference_css 'form_submit', 'input[type="submit"]'
18-
19- preference 'title'
20- preference 'body'
21- preference 'submit'
22-
23- def render_css(css)
24- super
25-
26- css.style(css_id + ' input') do |s|
27- s['display'] = 'block'
28- end
29-
30- css.style(css_id + ' textarea') do |s|
31- s['display'] = 'block'
32- end
33- end
34-
35- def render_body(xml)
36- preference_clone do |pref|
37- xml.tag('div', 'id' => html_id) do |div|
38- div.tag(
39- 'form',
40- 'method' => 'post',
41- 'action' => url(:view => view)
42- ) do |form|
43- form.tag('p') do |p|
44- p.text(@msg)
45- end if @msg
46-
47- form.tag('div') do |div|
48- div.tag('label') do |label|
49- label.text('Title:')
50- label.tag(
51- 'input',
52- 'type' => 'text',
53- 'name' => pref.title.path_name,
54- 'value' => model.content.title
55- )
56- end
57- div.tag('br')
58-
59- div.tag('label') do |label|
60- label.text('Content:')
61- label.tag(
62- 'textarea',
63- 'name' => pref.body.path_name
64- ).text(model.content.body)
65- end
66- div.tag('br')
67-
68- div.tag(
69- 'input',
70- 'type' => 'submit',
71- 'name' => pref.submit.path_name
72- )
73- end
74- end
75- end
76- end
77- end
78-
79- def exec
80- model.content.title = preference.title.value
81- model.content.body = preference.body.value
82- model.content.save
83- @msg = 'content was saved.'
84- end
85- end
86- end
87-end
--- trunk/webapp/Widget/Content/Title.rb (revision 43)
+++ trunk/webapp/Widget/Content/Title.rb (revision 44)
@@ -6,7 +6,7 @@
66
77 class Widget
88 class Content
9- class Title < Widget
9+ class Title < ::Widget
1010 extend Tenarai::ClassLoader
1111
1212 preference 'title' do |form|
--- trunk/webapp/Widget/Content/Form.rb (nonexistent)
+++ trunk/webapp/Widget/Content/Form.rb (revision 44)
@@ -0,0 +1,88 @@
1+#
2+# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
3+#
4+
5+Tenarai::ClassLoader.load_class('Widget::Content')
6+
7+class Widget
8+ class Content
9+ class Form < ::Widget
10+ extend Tenarai::ClassLoader
11+
12+ preference_css 'box'
13+ preference_css 'msg', 'p'
14+ preference_css 'form_label', 'label'
15+ preference_css 'form_title', 'input'
16+ preference_css 'form_content', 'textarea'
17+ preference_css 'form_submit', 'input[type="submit"]'
18+
19+ preference 'preference' do |pref|
20+ pref.group('form') do |form|
21+ form.edit 'type' do |type|
22+ type.value = 'new'
23+ end
24+ end
25+ end
26+
27+ def form_type
28+ if preference.preference.form.type.value == 'edit'
29+ :edit
30+ else
31+ :new
32+ end
33+ end
34+ private :form_type
35+
36+ def post(service, query={})
37+ if form_type == :new
38+ resource.new(query)
39+ else
40+ resource.content.title = query['title']
41+ resource.content.body = query['body']
42+ resource.content.save
43+ end
44+ end
45+
46+ def render_html(xml, builder)
47+ if form_type == :new
48+ title, body = '', ''
49+ else
50+ title, body = resource.content.title, resource.content.body
51+ end
52+
53+ xml.tag('div', 'id' => html_id) do |div|
54+ div.tag('form', 'method' => 'post', 'action' => url) do |form|
55+ form.tag('p') do |p|
56+ p.text(@msg)
57+ end if @msg
58+
59+ form.tag('div') do |div|
60+ div.tag('label') do |label|
61+ label.text('Title:')
62+ label.tag(
63+ 'input',
64+ 'type' => 'text',
65+ 'name' => html_id('title'),
66+ 'value' => title
67+ )
68+ end
69+ div.tag('br')
70+
71+ div.tag('label') do |label|
72+ label.text('Content:')
73+ label.tag('textarea', 'name' => html_id('body')).text(body)
74+ end
75+ div.tag('br')
76+
77+ div.tag(
78+ 'input',
79+ 'type' => 'submit',
80+ 'name' => html_id('submit')
81+ )
82+ end
83+ end
84+ end
85+ end
86+ end
87+ end
88+end
--- trunk/webapp/Widget/Content/Tab.rb (revision 43)
+++ trunk/webapp/Widget/Content/Tab.rb (revision 44)
@@ -1,5 +1,5 @@
11 #
2-# Copyright (C) 2007 Jun Kikuchi <kikuchi@bonnou.com>
2+# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com>
33 #
44
55 Tenarai::ClassLoader.load_class('Widget::Content')
@@ -6,7 +6,7 @@
66
77 class Widget
88 class Content
9- class Tab < Widget
9+ class Tab < ::Widget
1010 extend Tenarai::ClassLoader
1111
1212 preference_css 'box'
@@ -14,30 +14,20 @@
1414 preference_css 'tab_selected', 'a.selected'
1515 preference_css 'tab_hover', 'a:hover'
1616
17- def render_css(css)
18- super
19-
20- css.style(css_id + ' li') do |s|
21- s['list-style'] = 'none'
22- s['display'] = 'inline'
23- s['margin'] = '0'
24- end
25- end
26-
27- def render_body(xml)
28- c = service._content
17+ def render_html(xml, builder)
18+ c = resource.content.root
2919 xml.tag('ul', 'id' => html_id) do |ul|
3020 ul.tag('li') do |li|
3121 li.tag('a') do |a|
32- a['href'] = url(:content => c)
33- a['class'] = 'selected' if model.content == c
22+ a['href'] = url(c.id)
23+ a['class'] = 'selected' if resource.content.path.include?(c)
3424 end.text(c.title)
3525 end
36- c.nodes.each do |val|
26+ c.node.each do |val|
3727 ul.tag('li') do |li|
3828 li.tag('a') do |a|
39- a['href'] = url(:content => val)
40- a['class'] = 'selected' if model.content == val
29+ a['href'] = url(val.id)
30+ a['class'] = 'selected' if resource.content.path.include?(val)
4131 end.text(val.title)
4232 end
4333 end
--- trunk/webapp/Widget/Content/Header.rb (revision 43)
+++ trunk/webapp/Widget/Content/Header.rb (revision 44)
@@ -6,7 +6,7 @@
66
77 class Widget
88 class Content
9- class Header < Widget
9+ class Header < ::Widget
1010 extend Tenarai::ClassLoader
1111
1212 preference_css 'box'
--- trunk/webapp/Widget/Content/List.rb (nonexistent)
+++ trunk/webapp/Widget/Content/List.rb (revision 44)
@@ -0,0 +1,51 @@
1+#
2+# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
3+#
4+
5+Tenarai::ClassLoader.load_class('Widget::Content')
6+
7+class Widget
8+ class Content
9+ class List < ::Widget
10+ extend Tenarai::ClassLoader
11+
12+ preference_css 'box'
13+ preference_css 'list', 'a'
14+ preference_css 'list_selected', 'a.selected'
15+ preference_css 'list_hover', 'a:hover'
16+
17+ def render_html(xml, builder, content=nil)
18+ if content.nil?
19+ content = resource.content.root
20+ xml.tag('div', 'id' => html_id) do |div|
21+ div.tag('ul') do |ul|
22+ ul.tag('li') do |li|
23+ li.tag('a') do |a|
24+ a['href'] = url(content.id)
25+ a['class'] = 'selected' if resource.content.equal?(content)
26+ end.text(content.title)
27+ if resource.content.path.include?(content)
28+ render_html(li, builder, content)
29+ end unless content.node.empty?
30+ end
31+ end
32+ end
33+ else
34+ xml.tag('ul') do |ul|
35+ content.node.each do |c|
36+ ul.tag('li') do |li|
37+ li.tag('a') do |a|
38+ a['href'] = url(c.id)
39+ a['class'] = 'selected' if resource.content.equal?(c)
40+ end.text(c.title)
41+ if resource.content.path.include?(c)
42+ render_html(li, builder, c)
43+ end unless c.node.empty?
44+ end
45+ end
46+ end
47+ end
48+ end
49+ end
50+ end
51+end
--- trunk/webapp/Widget/Content/Path.rb (revision 43)
+++ trunk/webapp/Widget/Content/Path.rb (revision 44)
@@ -1,5 +1,5 @@
11 #
2-# Copyright (C) 2007 Jun Kikuchi <kikuchi@bonnou.com>
2+# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com>
33 #
44
55 Tenarai::ClassLoader.load_class('Widget::Content')
@@ -6,7 +6,7 @@
66
77 class Widget
88 class Content
9- class Path < Widget
9+ class Path < ::Widget
1010 extend Tenarai::ClassLoader
1111
1212 preference_css 'box'
@@ -14,25 +14,13 @@
1414 preference_css 'path_selected', 'a.selected'
1515 preference_css 'path_hover', 'a:hover'
1616
17- def render_css(css)
18- super
19-
20- css.style(css_id + ' ul') do |s|
21- s['display'] = 'inline'
22- end
23-
24- css.style(css_id + ' ul li') do |s|
25- s['display'] = 'inline'
26- end
27- end
28-
29- def render_body(xml)
17+ def render_html(xml, builder)
3018 xml.tag('div', 'id' => html_id) do |t|
31- model.content.path.each do |val|
19+ resource.content.path.each do |val|
3220 t.tag('ul') do |ul|
3321 ul.tag('li') do |li|
34- li.tag('a', 'href' => url(:content => val)) do |a|
35- a['class'] = 'selected' if model.content == val
22+ li.tag('a', 'href' => url(val.id)) do |a|
23+ a['class'] = 'selected' if resource.content.equal?(val)
3624 end.text(val.title)
3725 t = li
3826 end
--- trunk/webapp/Widget/View/Widget/List.rb (revision 43)
+++ trunk/webapp/Widget/View/Widget/List.rb (nonexistent)
@@ -1,40 +0,0 @@
1-#
2-# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
3-#
4-
5-Tenarai::ClassLoader.load_class('Widget::View::Widget')
6-
7-class Widget
8- class View
9- class Widget
10- class List < Widget
11- extend Tenarai::ClassLoader
12-
13- preference_css 'box'
14-
15- def render_list(xml, widget)
16- xml.tag('ul') do |ul|
17- widget.each do |val|
18- ul.tag('li') do |li|
19- li.text(val.class.name)
20- render_list(li, val)
21- end
22- end
23- end unless widget.nil? || widget.empty?
24- end
25-
26- def render_body(xml)
27- xml.tag('div', 'id' => html_id) do |div|
28- widget = model.content
29- div.tag('ul') do |ul|
30- ul.tag('li') do |li|
31- li.text(widget.class.name)
32- render_list(li, widget)
33- end
34- end unless widget.nil?
35- end
36- end
37- end
38- end
39- end
40-end
--- trunk/webapp/Widget/View/Widget.rb (revision 43)
+++ trunk/webapp/Widget/View/Widget.rb (nonexistent)
@@ -1,23 +0,0 @@
1-#
2-# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
3-#
4-
5-Tenarai::ClassLoader.load_class('Widget::View')
6-
7-class Widget
8- class View
9- class Widget < Model
10- extend Tenarai::ClassLoader
11-
12- preference 'content'
13-
14- attr_reader :content
15-
16- def build(builder)
17- super
18- @content = service.models['widgets'].fetch(preference.content.value)
19- @content = model.content.builder.root_widget if @content.nil?
20- end
21- end
22- end
23-end
--- trunk/webapp/Widget/View/List.rb (revision 43)
+++ trunk/webapp/Widget/View/List.rb (revision 44)
@@ -6,33 +6,44 @@
66
77 class Widget
88 class View
9- class List < Widget
9+ class List < ::Widget
1010 extend Tenarai::ClassLoader
1111
1212 preference_css 'box'
13+ preference_css 'list', 'a'
14+ preference_css 'list_selected', 'a.selected'
15+ preference_css 'list_hover', 'a:hover'
1316
14- def render_body(xml)
15- xml.tag('div', 'id' => html_id) do |t|
16- model.content.path.each do |val|
17- t.tag('ul') do |ul|
17+ def render_html(xml, builder, content=nil)
18+ if content.nil?
19+ content = resource.content.root
20+ xml.tag('div', 'id' => html_id) do |div|
21+ div.tag('ul') do |ul|
1822 ul.tag('li') do |li|
19- li.tag('a', 'href' => url(:content => val)) do |a|
20- a['class'] = 'selected' if model.content == val
21- end.text(val.name)
22- if model.content == val
23- li.tag('ul') do |u|
24- model.content.nodes.each do |v|
25- u.tag('li').tag(
26- 'a',
27- 'href' => url(:content => v)
28- ).text(v.name)
29- end
30- end unless model.content.nodes.empty?
31- end
32- t = li
23+ li.tag('a') do |a|
24+ a['href'] = url(content.id)
25+ a['class'] = 'selected' if resource.content.equal?(content)
26+ end.text(content.name)
27+ if resource.content.path.include?(content)
28+ render_html(li, builder, content)
29+ end unless content.node.empty?
3330 end
3431 end
3532 end
33+ else
34+ xml.tag('ul') do |ul|
35+ content.node.each do |c|
36+ ul.tag('li') do |li|
37+ li.tag('a') do |a|
38+ a['href'] = url(c.id)
39+ a['class'] = 'selected' if resource.content.equal?(c)
40+ end.text(c.name)
41+ if resource.content.path.include?(c)
42+ render_html(li, builder, c)
43+ end unless c.node.empty?
44+ end
45+ end
46+ end
3647 end
3748 end
3849 end
--- trunk/webapp/Widget/Content.rb (revision 43)
+++ trunk/webapp/Widget/Content.rb (revision 44)
@@ -12,11 +12,17 @@
1212
1313 def init(service, id=nil)
1414 super
15- unless resource.content.nil?
16- unless resource.content.content.include?(@content)
17- @content = resource.content.content
18- end
19- end
15+ unless resource.content.content.include?(@content)
16+ @content = resource.content.content
17+ #raise Service::Redirect.new(url(resource.content.content.id))
18+ end unless resource.content.nil?
2019 end
20+
21+ def new(row)
22+ @content.node << c = ::Content.new(@service.model['content'], row)
23+ @content.save
24+ c.view = @content.view
25+ c.save
26+ end
2127 end
2228 end
--- trunk/webapp/Widget/View.rb (revision 43)
+++ trunk/webapp/Widget/View.rb (revision 44)
@@ -12,11 +12,10 @@
1212
1313 def init(service, id=nil)
1414 super
15- unless resource.content.nil?
16- unless resource.content.view.include?(@content)
17- @content = resource.content.view
18- end
19- end
15+ unless resource.content.view.include?(@content)
16+ @content = resource.content.view
17+ #raise Service::Redirect.new(url(resource.content.view.id))
18+ end unless resource.content.nil?
2019 end
2120 end
2221 end
--- trunk/webapp/Widget.rb (revision 43)
+++ trunk/webapp/Widget.rb (revision 44)
@@ -99,6 +99,7 @@
9999 widget.path.reverse.each do |val|
100100 return val if val.class.name == meta[:resource]
101101 end
102+ nil
102103 end
103104
104105 def inherited(subclass)
--- trunk/webapp/Resource.rb (revision 43)
+++ trunk/webapp/Resource.rb (revision 44)
@@ -16,14 +16,14 @@
1616
1717 def url(*param)
1818 [
19- if parent.nil?
19+ if resource.nil?
2020 @service.url
2121 else
22- parent.url
22+ resource.url
2323 end,
2424 if param.empty?
2525 if @content
26- @content.primary_key
26+ @content.id
2727 else
2828 nil
2929 end
--- trunk/webapp/View.rb (revision 43)
+++ trunk/webapp/View.rb (revision 44)
@@ -10,6 +10,20 @@
1010 class Widgets < Tenarai::DB::Reference::Multiple
1111 alias :each_widget :each
1212
13+ def root
14+ vars = @row.path.map do |val| val.primary_key end
15+ cond = "WHERE %s IN (%s) ORDER BY min LIMIT 1" % [
16+ @link.dst_col,
17+ (['?'] * vars.size).join(', ')
18+ ]
19+
20+ @link.dst_table.each(cond, *vars) do |widget|
21+ return widget
22+ end
23+
24+ nil
25+ end
26+
1327 def each(&block)
1428 vars = @row.path.map do |val| val.primary_key end
1529 cond = "WHERE %s IN (%s) ORDER BY min" % [
Show on old repository browser