• R/O
  • SSH
  • HTTPS

tenarai: 提交


Commit MetaInfo

修訂36 (tree)
時間2008-01-31 00:24:18
作者junkikuchi

Log Message

merged Resource class to Widget class.

Change Summary

差異

--- trunk/Rakefile (revision 35)
+++ trunk/Rakefile (revision 36)
@@ -28,7 +28,6 @@
2828 :model => {
2929 :table => {
3030 'service' => {:row => 'Service', :class => 'ServiceTable'},
31- 'resource'=> {:row => 'Resource'},
3231 'user' => {:row => 'User', :class => 'UserTable' },
3332 'session' => {:row => 'Session', :class => 'SessionTable'},
3433 'content' => {:row => 'Content' },
@@ -37,15 +36,14 @@
3736 },
3837
3938 :relation => [
40- ['service.resource', 'resource' ],
41- ['resource.parent', 'resource.node'],
42- ['user.content', 'content' ],
43- ['user.session', 'session.user' ],
44- ['content.parent', 'content.node' ],
45- ['content.view', 'view' ],
46- ['view.parent', 'view.node' ],
47- ['widget.parent', 'widget.node' ],
48- ['widget.view', 'view.widget' ],
39+ ['service.widget', 'widget' ],
40+ ['user.content', 'content' ],
41+ ['user.session', 'session.user' ],
42+ ['content.parent', 'content.node' ],
43+ ['content.view', 'view' ],
44+ ['view.parent', 'view.node' ],
45+ ['widget.parent', 'widget.node' ],
46+ ['widget.view', 'view.widget' ],
4947 ],
5048 },
5149 }
@@ -57,7 +55,7 @@
5755 :class => 'Service',
5856 :row => {'name' => 'index'},
5957 :relation => {
60- 'resource' => 'resource:index',
58+ 'widget' => 'widget:index',
6159 },
6260 },
6361
@@ -66,7 +64,7 @@
6664 :class => 'Service',
6765 :row => {'name' => 'login'},
6866 :relation => {
69- 'resource' => 'resource:login',
67+ 'widget' => 'widget:user.content.view',
7068 },
7169 },
7270
@@ -75,48 +73,11 @@
7573 :class => 'Service',
7674 :row => {'name' => 'user'},
7775 :relation => {
78- 'resource' => 'resource:user.content.view',
76+ 'widget' => 'widget:user.content.view',
7977 },
8078 },
8179 ],
8280
83- 'resource' => [
84- {
85- :name => 'index',
86- :class => 'Resource',
87- :row => {},
88- :relation => {},
89- },
90-
91- {
92- :name => 'login',
93- :class => 'Resource',
94- :row => {},
95- :relation => {},
96- },
97-
98- {
99- :name => 'user',
100- :class => 'Resource::User',
101- :row => {},
102- :relation => {},
103- },
104-
105- {
106- :name => 'user.content',
107- :class => 'Resource::Content',
108- :row => {},
109- :relation => {},
110- },
111-
112- {
113- :name => 'user.content.view',
114- :class => 'Resource::View',
115- :row => {},
116- :relation => {},
117- },
118- ],
119-
12081 'content' => [
12182 {
12283 :name => 'user',
@@ -152,19 +113,31 @@
152113
153114 'widget' => [
154115 {
116+ :name => 'index',
117+ :class => 'Resource',
118+ :row => {},
119+ :relation => {},
120+ },
121+
122+ {
155123 :name => 'user',
124+ :class => 'Widget::User',
125+ :row => {},
126+ :relation => {},
127+ },
128+
129+ {
130+ :name => 'user.content',
156131 :class => 'Widget::Content',
157132 :row => {},
158- :relation => {'view' => 'view:user'},
159- :preference => {},
133+ :relation => {},
160134 },
161135
162136 {
163- :name => 'user.html',
164- :class => 'Widget::Content::HTML',
137+ :name => 'user.content.view',
138+ :class => 'Widget::View',
165139 :row => {},
166- :relation => {'view' => 'view:user.index'},
167- :preference => {},
140+ :relation => {},
168141 },
169142 ],
170143 }
--- trunk/webapp/Resource/View.rb (revision 35)
+++ trunk/webapp/Resource/View.rb (nonexistent)
@@ -1,9 +0,0 @@
1-#
2-# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
3-#
4-
5-Tenarai::ClassLoader.load_class('Resource')
6-
7-class Resource::View < Resource
8- extend Tenarai::ClassLoader
9-end
--- trunk/webapp/Resource/Content.rb (revision 35)
+++ trunk/webapp/Resource/Content.rb (nonexistent)
@@ -1,9 +0,0 @@
1-#
2-# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
3-#
4-
5-Tenarai::ClassLoader.load_class('Resource')
6-
7-class Resource::Content < Resource
8- extend Tenarai::ClassLoader
9-end
--- trunk/webapp/Resource/User.rb (revision 35)
+++ trunk/webapp/Resource/User.rb (nonexistent)
@@ -1,9 +0,0 @@
1-#
2-# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
3-#
4-
5-Tenarai::ClassLoader.load_class('Resource')
6-
7-class Resource::User < Resource
8- extend Tenarai::ClassLoader
9-end
--- trunk/webapp/Service.rb (revision 35)
+++ trunk/webapp/Service.rb (revision 36)
@@ -8,7 +8,7 @@
88 extend Tenarai::ClassLoader
99
1010 column Tenarai::DB::String.new('name', :length => 255)
11- column Tenarai::DB::Reference.new('resource')
11+ column Tenarai::DB::Reference.new('widget')
1212 index Tenarai::DB::Index.new('name_idx', :cols => ['name'], :unique => true)
1313
1414 attr_reader :model
@@ -20,9 +20,9 @@
2020 @request = request
2121 @response = response
2222
23- resource.path.each do |r|
23+ widget.path.each do |r|
2424 r.init(self, *(param.shift || '').split(','))
2525 end
26- resource.dispatch(self)
26+ widget.dispatch(self)
2727 end
2828 end
--- trunk/webapp/Widget/User.rb (nonexistent)
+++ trunk/webapp/Widget/User.rb (revision 36)
@@ -0,0 +1,9 @@
1+#
2+# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
3+#
4+
5+Tenarai::ClassLoader.load_class('Resource')
6+
7+class Widget::User < Resource
8+ extend Tenarai::ClassLoader
9+end
--- trunk/webapp/Widget/Content.rb (revision 35)
+++ trunk/webapp/Widget/Content.rb (revision 36)
@@ -1,47 +1,9 @@
11 #
2-# Copyright (C) 2007 Jun Kikuchi <kikuchi@bonnou.com>
2+# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com>
33 #
44
5-Tenarai::ClassLoader.load_class('Widget::Model')
5+Tenarai::ClassLoader.load_class('Resource')
66
7-class Widget
8- class Content < Model
9- extend Tenarai::ClassLoader
10-
11- preference 'content'
12-
13- attr_reader :content
14-
15- def build(builder)
16- super
17- @content ||= service.models['contents'].fetch(preference.content.value)
18- @content ||= model.content
19- end
20-
21- def url(params={})
22- preference_clone do |pref|
23- unless params[:content].nil?
24- pref.content.value = params[:content].id
25- params[:content] = nil
26- end
27-
28- params[:query] = if params[:query].nil?
29- pref.to_query
30- else
31- pref.to_query.merge(params[:query])
32- end
33-
34- super(params)
35- end
36- end
37-
38- def new(title, body)
39- c = Tenarai::ClassLoader['Content'].new(service.models['contents'])
40- c.title = title
41- c.body = body
42- c.parent = @content
43- c.save
44- @content.save
45- end
46- end
7+class Widget::Content < Resource
8+ extend Tenarai::ClassLoader
479 end
--- trunk/webapp/Widget/View.rb (revision 35)
+++ trunk/webapp/Widget/View.rb (revision 36)
@@ -1,46 +1,9 @@
11 #
2-# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
2+# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com>
33 #
44
5-Tenarai::ClassLoader.load_class('Widget::Model')
5+Tenarai::ClassLoader.load_class('Resource')
66
7-class Widget
8- class View < Model
9- extend Tenarai::ClassLoader
10-
11- preference 'content'
12-
13- attr_reader :content
14-
15- def build(builder)
16- super
17- @content = service.models['views'].fetch(preference.content.value)
18- @content.build(service)
19- end
20-
21- def url(params={})
22- preference_clone do |pref|
23- unless params[:content].nil?
24- pref.content.value = params[:content].id
25- params[:content] = nil
26- end
27-
28- params[:query] = if params[:query].nil?
29- pref.to_query
30- else
31- pref.to_query.merge(params[:query])
32- end
33-
34- super(params)
35- end
36- end
37-
38- def new(name)
39- v = Tenarai::ClassLoader['View'].new(service.models['views'])
40- v.name = name
41- v.parent = @content
42- v.save
43- @content.save
44- end
45- end
7+class Widget::View < Resource
8+ extend Tenarai::ClassLoader
469 end
--- trunk/webapp/Widget.rb (revision 35)
+++ trunk/webapp/Widget.rb (revision 36)
@@ -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 require 'tenarai/db/tree'
@@ -9,6 +9,49 @@
99 extend Tenarai::ClassLoader
1010 extend Tenarai::Preference::Container
1111
12+ class << self
13+ def create_row(class_name, table, row)
14+ Tenarai::ClassLoader[class_name].new(table, row)
15+ end
16+
17+ def resource(klass)
18+ meta[:resource] = klass
19+ end
20+
21+ def fetch_resource(widget)
22+ widget.path.reverse.each do |val|
23+ return val if val.class.name == meta[:resource]
24+ end
25+ end
26+
27+ def inherited(subclass)
28+ super
29+ subclass.meta[:resource] = subclass.name.sub(/\w+?$/, '').sub(/::+?$/, '')
30+ subclass.meta[:resource] = nil if subclass.meta[:resource].empty?
31+
32+ subclass.meta[:preference_css] = meta[:preference_css].map do |val|
33+ val.inject({}) do |ret, (k, v)|
34+ ret[k] = v.clone
35+ end
36+ end
37+ end
38+
39+ def preference_css(name, *selecter)
40+ selecter << '' if selecter.empty?
41+ meta[:preference_css] << {:name => name, :selecter => selecter}
42+
43+ preference name do |css|
44+ PREF_CSS.each do |key, val|
45+ css.group key do |group|
46+ val.each do |v|
47+ group.edit v
48+ end
49+ end
50+ end
51+ end
52+ end
53+ end
54+
1255 column Tenarai::DB::Reference.new('view')
1356 column Tenarai::DB::Preference.new('preference')
1457
@@ -89,128 +132,10 @@
89132 ]
90133 }
91134
92- class << self
93- def create_row(class_name, table, row)
94- Tenarai::ClassLoader[class_name].new(table, row)
95- end
96-
97- def model(klass)
98- meta[:model] = klass
99- end
100-
101- def fetch_model(widget)
102- widget.path.reverse.each do |val|
103- return val if val.class.name == meta[:model]
104- end
105- widget.builder.service
106- end
107-
108- def preference_css(name, *selecter)
109- selecter << '' if selecter.empty?
110- meta[:preference_css] << {:name => name, :selecter => selecter}
111-
112- preference name do |css|
113- PREF_CSS.each do |key, val|
114- css.group key do |group|
115- val.each do |v|
116- group.edit v
117- end
118- end
119- end
120- end
121- end
122-
123- def inherited(subclass)
124- super
125-
126- subclass.meta[:model] = subclass.name.sub(/\w+?$/, '').sub(/::+?$/, '')
127- subclass.meta[:model] = nil if subclass.meta[:model].empty?
128-
129- subclass.meta[:preference_css] = meta[:preference_css].map do |val|
130- val.inject({}) do |ret, (k, v)|
131- ret[k] = v.clone
132- end
133- end
134- end
135+ def init(service, id=nil)
135136 end
136137
137- attr_reader :builder
138- attr_reader :service
139-
140- def preference_clone(&block)
141- v = Tenarai::HashTree.new('v' + service.view.primary_key.to_s)
142- v << w = Tenarai::HashTree.new('w' + primary_key.to_s)
143-
144- pref = preference.deep_clone
145- pref.map do |val|
146- w << val
147- end
148-
149- block.call(pref)
138+ def resource
139+ self.class.fetch_resource(self)
150140 end
151-
152- def css_id
153- "#w%s" % primary_key
154- end
155-
156- def html_id
157- "w%s" % primary_key
158- end
159-
160- def model
161- self.class.fetch_model(self)
162- end
163-
164- def build(builder)
165- @builder = builder
166- @service = builder.service
167- end
168-
169- def each(&block)
170- @builder.each(self, &block)
171- end
172-
173- def empty?
174- @builder.empty?(self)
175- end
176-
177- def render_preference_css(css, css_id)
178- self.class.meta[:preference_css].each do |prefcss|
179- preference[prefcss[:name]].each do |val|
180- val.each do |v|
181- prefcss[:selecter].each do |selecter|
182- css.style(css_id + ' ' + selecter) do |style|
183- style[v.name.gsub('_', '-')] = v.value unless v.value.to_s.empty?
184- end
185- end
186- end
187- end
188- end
189- end
190-
191- def render_css(css)
192- render_preference_css(css, css_id)
193- each do |val|
194- val.render_css(css)
195- end
196- end
197-
198- def render_head(xml)
199- each do |val|
200- val.render_head(xml)
201- end
202- end
203-
204- def render_body(xml)
205- each do |val|
206- val.render_body(xml)
207- end
208- end
209-
210- def exec
211- end
212-
213- def url(params={})
214- model.url(params)
215- end
216141 end
--- trunk/webapp/Resource.rb (revision 35)
+++ trunk/webapp/Resource.rb (revision 36)
@@ -2,17 +2,11 @@
22 # Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
33 #
44
5-require 'tenarai/db/tree'
5+Tenarai::ClassLoader.load_class('Widget')
66
7-class Resource < Tenarai::DB::Row::Tree
7+class Resource < Widget
88 extend Tenarai::ClassLoader
99
10- class << self
11- def create_row(class_name, table, row)
12- Tenarai::ClassLoader[class_name].new(table, row)
13- end
14- end
15-
1610 attr_reader :content
1711
1812 def init(service, id=nil)
--- trunk/webapp/Content/Root.rb (revision 35)
+++ trunk/webapp/Content/Root.rb (nonexistent)
@@ -1,13 +0,0 @@
1-#
2-# Copyright (C) 2007 Jun Kikuchi <kikuchi@bonnou.com>
3-#
4-
5-require 'tenarai/db/tree'
6-
7-Tenarai::ClassLoader.load_class('Content')
8-
9-class Content
10- class Root < Content
11- extend Tenarai::ClassLoader
12- end
13-end
--- trunk/webapp/View/Root.rb (revision 35)
+++ trunk/webapp/View/Root.rb (nonexistent)
@@ -1,13 +0,0 @@
1-#
2-# Copyright (C) 2007 Jun Kikuchi <kikuchi@bonnou.com>
3-#
4-
5-require 'tenarai/db/tree'
6-
7-Tenarai::ClassLoader.load_class('View')
8-
9-class View
10- class Root < View
11- extend Tenarai::ClassLoader
12- end
13-end
Show on old repository browser