修訂 | 107 (tree) |
---|---|
時間 | 2008-09-05 21:33:49 |
作者 | junkikuchi |
updated.
@@ -66,7 +66,7 @@ | ||
66 | 66 | :row => {}, |
67 | 67 | :relation => {'view' => 'view:admin'}, |
68 | 68 | :property => { |
69 | - 'resource.table._name' => 'adminsession' | |
69 | + :table_name => 'adminsession' | |
70 | 70 | }, |
71 | 71 | }, |
72 | 72 | { |
@@ -75,9 +75,9 @@ | ||
75 | 75 | :row => {}, |
76 | 76 | :relation => {'view' => 'view:admin'}, |
77 | 77 | :property => { |
78 | - 'resource.table._name' => 'admin', | |
79 | - 'auth.login.view' => :'view:admin.content', | |
80 | - 'auth.logout.view' => :'view:admin.login', | |
78 | + :table_name => 'admin', | |
79 | + :login_view => :'view:admin.content', | |
80 | + :logout_view => :'view:admin.login', | |
81 | 81 | }, |
82 | 82 | }, |
83 | 83 | { |
@@ -93,8 +93,8 @@ | ||
93 | 93 | :row => {}, |
94 | 94 | :relation => {'view' => 'view:admin'}, |
95 | 95 | :property => { |
96 | - 'html.attribute._id' => 'doc3', | |
97 | - 'html.attribute._class' => 'yui-t3' | |
96 | + :html_attr_id => 'doc3', | |
97 | + :html_attr_class => 'yui-t3' | |
98 | 98 | }, |
99 | 99 | }, |
100 | 100 | { |
@@ -103,7 +103,7 @@ | ||
103 | 103 | :row => {}, |
104 | 104 | :relation => {'view' => 'view:admin'}, |
105 | 105 | :property => { |
106 | - 'html.attribute._id' => 'hd' | |
106 | + :html_attr_id => 'hd' | |
107 | 107 | }, |
108 | 108 | }, |
109 | 109 | { |
@@ -112,7 +112,7 @@ | ||
112 | 112 | :row => {}, |
113 | 113 | :relation => {'view' => 'view:admin'}, |
114 | 114 | :property => { |
115 | - 'html.attribute._id' => 'bd' | |
115 | + :html_attr_id => 'bd' | |
116 | 116 | }, |
117 | 117 | }, |
118 | 118 | { |
@@ -121,7 +121,7 @@ | ||
121 | 121 | :row => {}, |
122 | 122 | :relation => {'view' => 'view:admin'}, |
123 | 123 | :property => { |
124 | - 'html.attribute._id' => 'ft' | |
124 | + :html_attr_id => 'ft' | |
125 | 125 | }, |
126 | 126 | }, |
127 | 127 |
@@ -154,7 +154,7 @@ | ||
154 | 154 | :row => {}, |
155 | 155 | :relation => {'view' => 'view:admin.content'}, |
156 | 156 | :property => { |
157 | - 'html.attribute._id' => 'yui-main' | |
157 | + :html_attr_id => 'yui-main' | |
158 | 158 | }, |
159 | 159 | }, |
160 | 160 | { |
@@ -163,7 +163,7 @@ | ||
163 | 163 | :row => {}, |
164 | 164 | :relation => {'view' => 'view:admin.content'}, |
165 | 165 | :property => { |
166 | - 'html.attribute._class' => 'yui-b' | |
166 | + :html_attr_class => 'yui-b' | |
167 | 167 | }, |
168 | 168 | }, |
169 | 169 | { |
@@ -172,7 +172,7 @@ | ||
172 | 172 | :row => {}, |
173 | 173 | :relation => {'view' => 'view:admin.content'}, |
174 | 174 | :property => { |
175 | - 'html.attribute._class' => 'yui-b' | |
175 | + :html_attr_class => 'yui-b' | |
176 | 176 | }, |
177 | 177 | }, |
178 | 178 | { |
@@ -232,7 +232,7 @@ | ||
232 | 232 | :row => {}, |
233 | 233 | :relation => {'view' => 'view:user'}, |
234 | 234 | :property => { |
235 | - 'resource.table._name' => 'usersession' | |
235 | + :table_name => 'usersession' | |
236 | 236 | }, |
237 | 237 | }, |
238 | 238 | { |
@@ -241,8 +241,8 @@ | ||
241 | 241 | :row => {}, |
242 | 242 | :relation => {'view' => 'view:user'}, |
243 | 243 | :property => { |
244 | - 'auth.login.view' => :'view:user.content', | |
245 | - 'auth.logout.view' => :'view:user.login', | |
244 | + :login_view => :'view:user.content', | |
245 | + :logout_view => :'view:user.login', | |
246 | 246 | }, |
247 | 247 | }, |
248 | 248 | { |
@@ -1,62 +0,0 @@ | ||
1 | -# | |
2 | -# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com> | |
3 | -# | |
4 | - | |
5 | -begin | |
6 | - require 'mongrel' | |
7 | -rescue LoadError | |
8 | - require 'rubygems' | |
9 | - require 'mongrel' | |
10 | -end | |
11 | - | |
12 | -require 'tenarai/cgi' | |
13 | - | |
14 | -module Tenarai | |
15 | - class Mongrel | |
16 | - class Request < CGI::Request | |
17 | - def initialize(request, param) | |
18 | - super(request.body, request.params, param) | |
19 | - end | |
20 | - end | |
21 | - | |
22 | - class Response < CGI::Response | |
23 | - def flush | |
24 | - @out.start(@code.to_i) do |h, b| | |
25 | - @header.sort.each do |key, val| h[_n(key)] = val end | |
26 | - @cookie.sort.each do |val| h[_n('set-cookie')] = val end | |
27 | - b.write @content | |
28 | - end | |
29 | - end | |
30 | - end | |
31 | - | |
32 | - class Handler < ::Mongrel::HttpHandler | |
33 | - def initialize(param, &block) | |
34 | - @param = param | |
35 | - @block = block | |
36 | - end | |
37 | - | |
38 | - def process(_request, _response) | |
39 | - request = Request.new(_request, @param) | |
40 | - response = Response.new(_response) | |
41 | - @block.call(request, response) | |
42 | - response.flush | |
43 | - end | |
44 | - end | |
45 | - | |
46 | - def initialize(param={}, &block) | |
47 | - @param = param | |
48 | - @param[:address] ||= '0.0.0.0' | |
49 | - @param[:port] ||= '8080' | |
50 | - @param[:path] ||= '/' | |
51 | - | |
52 | - server = ::Mongrel::HttpServer.new(@param[:address], @param[:port]) | |
53 | - | |
54 | - Signal.trap('INT') do | |
55 | - server.stop | |
56 | - end | |
57 | - | |
58 | - server.register(param[:path], Mongrel::Handler.new(@param, &block)) | |
59 | - server.run.join | |
60 | - end | |
61 | - end | |
62 | -end |
@@ -1,139 +0,0 @@ | ||
1 | -# | |
2 | -# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com> | |
3 | -# | |
4 | - | |
5 | -require 'tenarai/meta' | |
6 | -require 'tenarai/container' | |
7 | -require 'tenarai/tree' | |
8 | - | |
9 | -module Tenarai | |
10 | - module Property | |
11 | - include Meta | |
12 | - | |
13 | - class Container < Tenarai::Container | |
14 | - def <<(val) | |
15 | - instance_eval %Q{ | |
16 | - def #{val.name} | |
17 | - fetch('#{val.name}') | |
18 | - end | |
19 | - }, __FILE__, __LINE__ | |
20 | - super | |
21 | - end | |
22 | - | |
23 | - def deep_clone | |
24 | - inject(self.class.new) do |ret, val| | |
25 | - ret << val.deep_clone | |
26 | - ret | |
27 | - end | |
28 | - end | |
29 | - | |
30 | - def find(key) | |
31 | - fetch(key.split('.').shift).find(key) | |
32 | - end | |
33 | - | |
34 | - def traverse(&block) | |
35 | - each do |val| | |
36 | - val.traverse(&block) | |
37 | - end | |
38 | - end | |
39 | - | |
40 | - def load_param(val) | |
41 | - ret = deep_clone | |
42 | - Marshal.load(val).each do |k, v| | |
43 | - ret.find(k).value = v | |
44 | - end unless val.nil? | |
45 | - ret | |
46 | - end | |
47 | - | |
48 | - def dump_param(meta) | |
49 | - ret = {} | |
50 | - traverse do |val| | |
51 | - if val.is_a?(Tenarai::Property::Item) | |
52 | - key = val.path_name | |
53 | - if !val.value.nil? && (val.value != meta.find(key).value) | |
54 | - ret[key] = val.value | |
55 | - end | |
56 | - end | |
57 | - end | |
58 | - Marshal.dump(ret) | |
59 | - end | |
60 | - end | |
61 | - | |
62 | - class Node < Tenarai::HashTree | |
63 | - def <<(val) | |
64 | - instance_eval %Q{ | |
65 | - def #{val.name} | |
66 | - fetch('#{val.name}') | |
67 | - end | |
68 | - }, __FILE__, __LINE__ | |
69 | - super | |
70 | - end | |
71 | - | |
72 | - def deep_clone | |
73 | - inject(self.class.new(@name)) do |ret, val| | |
74 | - ret << val.deep_clone | |
75 | - ret | |
76 | - end | |
77 | - end | |
78 | - | |
79 | - def traverse(&block) | |
80 | - block.call(self) | |
81 | - each do |val| | |
82 | - val.traverse(&block) | |
83 | - end | |
84 | - end | |
85 | - end | |
86 | - | |
87 | - class Group < Tenarai::Property::Node | |
88 | - def group(name, &block) | |
89 | - self << Tenarai::Property::Group.new(name) unless self.key?(name) | |
90 | - val = self[name] | |
91 | - block.call(val) if block_given? | |
92 | - val | |
93 | - end | |
94 | - | |
95 | - def item(name, value=nil) | |
96 | - self << Tenarai::Property::Item.new(name) unless self.key?(name) | |
97 | - val = self[name] | |
98 | - val.value = value | |
99 | - block.call(val) if block_given? | |
100 | - val | |
101 | - end | |
102 | - end | |
103 | - | |
104 | - class Item < Tenarai::Property::Node | |
105 | - attr_accessor :value | |
106 | - | |
107 | - def initialize(name) | |
108 | - super | |
109 | - @value = nil | |
110 | - end | |
111 | - | |
112 | - def deep_clone | |
113 | - ret = self.class.new(@name) | |
114 | - ret.value = @value | |
115 | - ret | |
116 | - end | |
117 | - end | |
118 | - | |
119 | - class << self | |
120 | - def extended(mod) | |
121 | - mod.meta[:property] = Tenarai::Property::Container.new | |
122 | - end | |
123 | - end | |
124 | - | |
125 | - def property(name, &block) | |
126 | - unless self.meta[:property].key?(name) | |
127 | - self.meta[:property] << Tenarai::Property::Group.new(name) | |
128 | - end | |
129 | - val = self.meta[:property][name] | |
130 | - block.call(val) if block_given? | |
131 | - val | |
132 | - end | |
133 | - | |
134 | - def inherited(subclass) | |
135 | - super | |
136 | - subclass.meta[:property] = self.meta[:property].deep_clone | |
137 | - end | |
138 | - end | |
139 | -end |
@@ -1,59 +0,0 @@ | ||
1 | -# | |
2 | -# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com> | |
3 | -# | |
4 | - | |
5 | -require 'webrick' | |
6 | -require 'stringio' | |
7 | -require 'tenarai/cgi' | |
8 | - | |
9 | -module Tenarai | |
10 | - class WEBrick | |
11 | - class Request < CGI::Request | |
12 | - def initialize(request, param) | |
13 | - super(StringIO.new(request.body.to_s), request.meta_vars, param) | |
14 | - end | |
15 | - end | |
16 | - | |
17 | - class Response < CGI::Response | |
18 | - def flush | |
19 | - # @out is a WEBrick::HTTPResponse | |
20 | - @out.status = @code.to_i | |
21 | - @header.sort.each do |key, val| @out[_n(key)] = val end | |
22 | - @cookie.sort.each do |val| | |
23 | - cookie = ::WEBrick::Cookie.new(val.name, "#{val.value}") | |
24 | - cookie.domain = val.domain if val.domain | |
25 | - cookie.expires = val.expires if val.expires | |
26 | - cookie.path = val.path if val.path | |
27 | - cookie.secure = val.secure if val.secure | |
28 | - @out.cookies << cookie | |
29 | - end | |
30 | - @out.body << @content | |
31 | - end | |
32 | - end | |
33 | - | |
34 | - def initialize(param={}, &block) | |
35 | - @param = param | |
36 | - @param[:address] ||= '0.0.0.0' | |
37 | - @param[:port] ||= '8080' | |
38 | - @param[:path] ||= '/' | |
39 | - | |
40 | - server = ::WEBrick::HTTPServer.new( | |
41 | - :BindAddress => @param[:address], | |
42 | - :Port => @param[:port] | |
43 | - ) | |
44 | - | |
45 | - Signal.trap('INT') do | |
46 | - server.shutdown | |
47 | - end | |
48 | - | |
49 | - server.mount_proc(param[:path]) do |_request, _response| | |
50 | - request = Request.new(_request, @param) | |
51 | - response = Response.new(_response) | |
52 | - block.call(request, response) | |
53 | - response.flush | |
54 | - end | |
55 | - | |
56 | - server.start | |
57 | - end | |
58 | - end | |
59 | -end |
@@ -1,43 +0,0 @@ | ||
1 | -# | |
2 | -# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com> | |
3 | -# | |
4 | - | |
5 | -require 'tenarai/db/table' | |
6 | -require 'tenarai/property' | |
7 | - | |
8 | -module Tenarai | |
9 | - class DB | |
10 | - class Property < Column | |
11 | - def execute(command) | |
12 | - command.property(self) | |
13 | - end | |
14 | - end | |
15 | - | |
16 | - class Engine | |
17 | - module Load | |
18 | - def property(col) | |
19 | - @handler[col.name] = lambda do |row, val| | |
20 | - row.class.meta[:property].load_param(val) | |
21 | - end | |
22 | - end | |
23 | - end | |
24 | - | |
25 | - module Dump | |
26 | - def property(col) | |
27 | - super | |
28 | - @handler[col.name] = lambda do |row, val| | |
29 | - val.dump_param(row.class.meta[:property]) | |
30 | - end | |
31 | - end | |
32 | - end | |
33 | - | |
34 | - class Command | |
35 | - def property(col) handler(col); end | |
36 | - end | |
37 | - | |
38 | - class CreateTable < Command | |
39 | - alias :property :text | |
40 | - end | |
41 | - end | |
42 | - end | |
43 | -end |
@@ -0,0 +1,62 @@ | ||
1 | +# | |
2 | +# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com> | |
3 | +# | |
4 | + | |
5 | +begin | |
6 | + require 'mongrel' | |
7 | +rescue LoadError | |
8 | + require 'rubygems' | |
9 | + require 'mongrel' | |
10 | +end | |
11 | + | |
12 | +require 'tenarai/cgi' | |
13 | + | |
14 | +module Tenarai | |
15 | + class Mongrel | |
16 | + class Request < CGI::Request | |
17 | + def initialize(request, param) | |
18 | + super(request.body, request.params, param) | |
19 | + end | |
20 | + end | |
21 | + | |
22 | + class Response < CGI::Response | |
23 | + def flush | |
24 | + @out.start(@code.to_i) do |h, b| | |
25 | + @header.sort.each do |key, val| h[_n(key)] = val end | |
26 | + @cookie.sort.each do |val| h[_n('set-cookie')] = val end | |
27 | + b.write @content | |
28 | + end | |
29 | + end | |
30 | + end | |
31 | + | |
32 | + class Handler < ::Mongrel::HttpHandler | |
33 | + def initialize(param, &block) | |
34 | + @param = param | |
35 | + @block = block | |
36 | + end | |
37 | + | |
38 | + def process(_request, _response) | |
39 | + request = Request.new(_request, @param) | |
40 | + response = Response.new(_response) | |
41 | + @block.call(request, response) | |
42 | + response.flush | |
43 | + end | |
44 | + end | |
45 | + | |
46 | + def initialize(param={}, &block) | |
47 | + @param = param | |
48 | + @param[:address] ||= '0.0.0.0' | |
49 | + @param[:port] ||= '8080' | |
50 | + @param[:path] ||= '/' | |
51 | + | |
52 | + server = ::Mongrel::HttpServer.new(@param[:address], @param[:port]) | |
53 | + | |
54 | + Signal.trap('INT') do | |
55 | + server.stop | |
56 | + end | |
57 | + | |
58 | + server.register(param[:path], Mongrel::Handler.new(@param, &block)) | |
59 | + server.run.join | |
60 | + end | |
61 | + end | |
62 | +end |
@@ -0,0 +1,59 @@ | ||
1 | +# | |
2 | +# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com> | |
3 | +# | |
4 | + | |
5 | +require 'webrick' | |
6 | +require 'stringio' | |
7 | +require 'tenarai/cgi' | |
8 | + | |
9 | +module Tenarai | |
10 | + class WEBrick | |
11 | + class Request < CGI::Request | |
12 | + def initialize(request, param) | |
13 | + super(StringIO.new(request.body.to_s), request.meta_vars, param) | |
14 | + end | |
15 | + end | |
16 | + | |
17 | + class Response < CGI::Response | |
18 | + def flush | |
19 | + # @out is a WEBrick::HTTPResponse | |
20 | + @out.status = @code.to_i | |
21 | + @header.sort.each do |key, val| @out[_n(key)] = val end | |
22 | + @cookie.sort.each do |val| | |
23 | + cookie = ::WEBrick::Cookie.new(val.name, "#{val.value}") | |
24 | + cookie.domain = val.domain if val.domain | |
25 | + cookie.expires = val.expires if val.expires | |
26 | + cookie.path = val.path if val.path | |
27 | + cookie.secure = val.secure if val.secure | |
28 | + @out.cookies << cookie | |
29 | + end | |
30 | + @out.body << @content | |
31 | + end | |
32 | + end | |
33 | + | |
34 | + def initialize(param={}, &block) | |
35 | + @param = param | |
36 | + @param[:address] ||= '0.0.0.0' | |
37 | + @param[:port] ||= '8080' | |
38 | + @param[:path] ||= '/' | |
39 | + | |
40 | + server = ::WEBrick::HTTPServer.new( | |
41 | + :BindAddress => @param[:address], | |
42 | + :Port => @param[:port] | |
43 | + ) | |
44 | + | |
45 | + Signal.trap('INT') do | |
46 | + server.shutdown | |
47 | + end | |
48 | + | |
49 | + server.mount_proc(param[:path]) do |_request, _response| | |
50 | + request = Request.new(_request, @param) | |
51 | + response = Response.new(_response) | |
52 | + block.call(request, response) | |
53 | + response.flush | |
54 | + end | |
55 | + | |
56 | + server.start | |
57 | + end | |
58 | + end | |
59 | +end |
@@ -20,12 +20,12 @@ | ||
20 | 20 | end |
21 | 21 | |
22 | 22 | def webrick |
23 | - require 'tenarai/webrick' | |
23 | + require 'tenarai/server/webrick' | |
24 | 24 | Tenarai::WEBrick.new(@param, &@handler) |
25 | 25 | end |
26 | 26 | |
27 | 27 | def mongrel |
28 | - require 'tenarai/mongrel' | |
28 | + require 'tenarai/server/mongrel' | |
29 | 29 | Tenarai::Mongrel.new(@param, &@handler) |
30 | 30 | end |
31 | 31 | end |
@@ -118,9 +118,7 @@ | ||
118 | 118 | end |
119 | 119 | |
120 | 120 | a = map[key][v[:name]] |
121 | - if pref = a.property.find(pk) | |
122 | - pref.value = pv | |
123 | - end | |
121 | + a.property[pk] = pv if a.property.key?(pk) | |
124 | 122 | end if v[:property] |
125 | 123 | |
126 | 124 | map[key][v[:name]].save |
@@ -25,24 +25,24 @@ | ||
25 | 25 | 'usersession' => {:row => 'Session', :class => 'SessionTable'}, |
26 | 26 | 'admin' => {:row => 'User', :class => 'UserTable' }, |
27 | 27 | 'adminsession' => {:row => 'Session', :class => 'SessionTable'}, |
28 | - 'content' => {:row => 'Content' }, | |
29 | - 'view' => {:row => 'View' }, | |
30 | - 'widget' => {:row => 'Widget' }, | |
28 | + 'content' => {:row => 'Content'}, | |
29 | + 'view' => {:row => 'View' }, | |
30 | + 'widget' => {:row => 'Widget' }, | |
31 | 31 | }, |
32 | 32 | |
33 | 33 | :relation => [ |
34 | - ['service.default_view', 'view' ], | |
35 | - ['user.content', 'content' ], | |
36 | - ['user.view', 'view' ], | |
37 | - ['user.session', 'usersession.user' ], | |
38 | - ['admin.content', 'content' ], | |
39 | - ['admin.view', 'view' ], | |
40 | - ['admin.session', 'adminsession.user' ], | |
41 | - ['content.parent', 'content.node' ], | |
42 | - ['content.view', 'view' ], | |
43 | - ['view.parent', 'view.node' ], | |
44 | - ['view.resource', 'widget' ], | |
45 | - ['widget.parent', 'widget.node' ], | |
46 | - ['widget.view', 'view.widget' ], | |
34 | + ['service.default_view', 'view' ], | |
35 | + ['user.content', 'content' ], | |
36 | + ['user.view', 'view' ], | |
37 | + ['user.session', 'usersession.user' ], | |
38 | + ['admin.content', 'content' ], | |
39 | + ['admin.view', 'view' ], | |
40 | + ['admin.session', 'adminsession.user'], | |
41 | + ['content.parent', 'content.node' ], | |
42 | + ['content.view', 'view' ], | |
43 | + ['view.parent', 'view.node' ], | |
44 | + ['view.resource', 'widget' ], | |
45 | + ['widget.parent', 'widget.node' ], | |
46 | + ['widget.view', 'view.widget' ], | |
47 | 47 | ], |
48 | 48 | } |
@@ -1,45 +0,0 @@ | ||
1 | -# | |
2 | -# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com> | |
3 | -# | |
4 | - | |
5 | -Tenarai::ClassLoader.load_class('Widget') | |
6 | - | |
7 | -class Resource < ::Widget | |
8 | - extend Tenarai::ClassLoader | |
9 | - | |
10 | - property('resource').group('table').item('_name') | |
11 | - | |
12 | - attr_reader :content | |
13 | - | |
14 | - def init(builder, service, _id=nil) | |
15 | - super(builder, service) | |
16 | - | |
17 | - unless @builder.preview? | |
18 | - if property.resource.table._name.value.nil? | |
19 | - property.resource.table._name.value = self.class.name.split( | |
20 | - '::' | |
21 | - ).pop.downcase | |
22 | - end | |
23 | - @content = model.fetch(_id) | |
24 | - end | |
25 | - end | |
26 | - | |
27 | - def model | |
28 | - @service.model[property.resource.table._name.value] | |
29 | - end | |
30 | - | |
31 | - def uri(view, *param, &block) | |
32 | - query = Tenarai::CGI::Query.new | |
33 | - block.call(query) if block_given? | |
34 | - build_uri(view, param, query) | |
35 | - end | |
36 | - | |
37 | - def widget_uri(path, query, param=[]) | |
38 | - param = [@content.id] if param.empty? && @content | |
39 | - if view.resource.path.include?(self) | |
40 | - path << param.join(',') | |
41 | - else | |
42 | - query[html_id] = param.join(',') | |
43 | - end | |
44 | - end | |
45 | -end |
@@ -2,32 +2,26 @@ | ||
2 | 2 | # Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com> |
3 | 3 | # |
4 | 4 | |
5 | -Tenarai::ClassLoader.load_class('Resource') | |
5 | +Tenarai::ClassLoader.load_class('Widget::Resource') | |
6 | 6 | |
7 | 7 | class Widget |
8 | - class User < Resource | |
8 | + class User < Widget::Resource | |
9 | 9 | extend Tenarai::ClassLoader |
10 | 10 | |
11 | 11 | resource 'Widget::Session' |
12 | 12 | |
13 | - property('auth').group('login').item('view') | |
14 | - property('auth').group('logout').item('view') | |
13 | + property :login_view | |
14 | + property :logout_view | |
15 | 15 | |
16 | - def login_view | |
17 | - @service.model['view'].fetch(property.auth.login.view.value) | |
18 | - end | |
19 | - | |
20 | - def logout_view | |
21 | - @service.model['view'].fetch(property.auth.logout.view.value) | |
22 | - end | |
23 | - | |
24 | 16 | def auth |
25 | 17 | unless @builder.preview? |
26 | 18 | if content |
19 | + login_view = @service.model['view'].fetch(property[:login_view]) | |
27 | 20 | unless login_view.include?(@builder.view) |
28 | 21 | raise ::Service::Redirect.new(@service.uri(login_view)) |
29 | 22 | end |
30 | 23 | else |
24 | + logout_view = @service.model['view'].fetch(property[:logout_view]) | |
31 | 25 | unless logout_view.include?(@builder.view) |
32 | 26 | raise ::Service::Redirect.new(@service.uri(logout_view)) |
33 | 27 | end |
@@ -2,18 +2,14 @@ | ||
2 | 2 | # Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com> |
3 | 3 | # |
4 | 4 | |
5 | -Tenarai::ClassLoader.load_class('Resource') | |
5 | +Tenarai::ClassLoader.load_class('Widget::Resource') | |
6 | 6 | |
7 | 7 | class Widget |
8 | - class Session < Resource | |
8 | + class Session < Widget::Resource | |
9 | 9 | extend Tenarai::ClassLoader |
10 | 10 | |
11 | - property 'session' do |ppt| | |
12 | - ppt.group 'cookie' do |s| | |
13 | - s.item '_name', 'sid_%s' | |
14 | - s.item '_path_name', '/' | |
15 | - end | |
16 | - end | |
11 | + property :cookie_name, 'sid_%s' | |
12 | + property :cookie_path, '/' | |
17 | 13 | |
18 | 14 | attr_reader :content |
19 | 15 |
@@ -21,20 +17,18 @@ | ||
21 | 17 | super |
22 | 18 | |
23 | 19 | unless @builder.preview? |
24 | - session_name = property.session.cookie._name.value % primary_key | |
25 | - path_name = property.session.cookie._path_name.value | |
20 | + cookie_name = property[:cookie_name] % primary_key | |
21 | + cookie_path = property[:cookie_path] | |
26 | 22 | |
27 | - @content = model.fetch_session( | |
28 | - service.request.cookie[session_name] | |
29 | - ) | |
23 | + @content = model.fetch_session(service.request.cookie[cookie_name]) | |
30 | 24 | @content.date = Time.now |
31 | 25 | @content.ip = service.request['remote_addr'] |
32 | 26 | @content.save |
33 | 27 | |
34 | 28 | service.response.set_cookie( |
35 | - session_name, | |
29 | + cookie_name, | |
36 | 30 | @content.session_id, |
37 | - :path => path_name | |
31 | + :path => cookie_path | |
38 | 32 | ) |
39 | 33 | end |
40 | 34 | end |
@@ -2,10 +2,10 @@ | ||
2 | 2 | # Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com> |
3 | 3 | # |
4 | 4 | |
5 | -Tenarai::ClassLoader.load_class('Resource') | |
5 | +Tenarai::ClassLoader.load_class('Widget::Resource') | |
6 | 6 | |
7 | 7 | class Widget |
8 | - class Widget < Resource | |
8 | + class Widget < Widget::Resource | |
9 | 9 | extend Tenarai::ClassLoader |
10 | 10 | |
11 | 11 | resource 'Widget::View' |
@@ -0,0 +1,42 @@ | ||
1 | +# | |
2 | +# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com> | |
3 | +# | |
4 | + | |
5 | +Tenarai::ClassLoader.load_class('Widget') | |
6 | + | |
7 | +class Widget | |
8 | + class Resource < ::Widget | |
9 | + extend Tenarai::ClassLoader | |
10 | + | |
11 | + property :table_name | |
12 | + | |
13 | + attr_reader :content | |
14 | + attr_reader :model | |
15 | + | |
16 | + def init(builder, service, _id=nil) | |
17 | + super(builder, service) | |
18 | + | |
19 | + if property[:table_name].nil? | |
20 | + property[:table_name] = self.class.name.split('::').pop.downcase | |
21 | + end | |
22 | + | |
23 | + @model = @service.model[property[:table_name]] | |
24 | + @content = @model.fetch(_id) | |
25 | + end | |
26 | + | |
27 | + def uri(view, *param, &block) | |
28 | + query = Tenarai::CGI::Query.new | |
29 | + block.call(query) if block_given? | |
30 | + build_uri(view, param, query) | |
31 | + end | |
32 | + | |
33 | + def widget_uri(path, query, param=[]) | |
34 | + param = [@content.id] if param.empty? && @content | |
35 | + if view.resource.path.include?(self) | |
36 | + path << param.join(',') | |
37 | + else | |
38 | + query[html_id] = param.join(',') | |
39 | + end | |
40 | + end | |
41 | + end | |
42 | +end |
@@ -2,10 +2,10 @@ | ||
2 | 2 | # Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com> |
3 | 3 | # |
4 | 4 | |
5 | -Tenarai::ClassLoader.load_class('Widget') | |
5 | +Tenarai::ClassLoader.load_class('Widget::Resource') | |
6 | 6 | |
7 | 7 | class Widget |
8 | - class Attach < Resource | |
8 | + class Attach < Widget::Resource | |
9 | 9 | extend Tenarai::ClassLoader |
10 | 10 | |
11 | 11 | resource 'Widget::Content' |
@@ -7,10 +7,7 @@ | ||
7 | 7 | class ResetFontsGrids < ::Widget |
8 | 8 | extend Tenarai::ClassLoader |
9 | 9 | |
10 | - property('yui').group('src').item( | |
11 | - 'uri', | |
12 | - '/yui/build/reset-fonts-grids/reset-fonts-grids.css' | |
13 | - ) | |
10 | + property :src, '/yui/build/reset-fonts-grids/reset-fonts-grids.css' | |
14 | 11 | |
15 | 12 | def render_html(head, body) |
16 | 13 | head.tag( |
@@ -17,7 +14,7 @@ | ||
17 | 14 | 'link', |
18 | 15 | 'rel' => 'stylesheet', |
19 | 16 | 'type' => 'text/css', |
20 | - 'href' => property.yui.src.uri.value | |
17 | + 'href' => property[:src] | |
21 | 18 | ) |
22 | 19 | end |
23 | 20 | end |
@@ -2,10 +2,10 @@ | ||
2 | 2 | # Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com> |
3 | 3 | # |
4 | 4 | |
5 | -Tenarai::ClassLoader.load_class('Resource') | |
5 | +Tenarai::ClassLoader.load_class('Widget::Resource') | |
6 | 6 | |
7 | 7 | class Widget |
8 | - class View < Resource | |
8 | + class View < Widget::Resource | |
9 | 9 | extend Tenarai::ClassLoader |
10 | 10 | |
11 | 11 | def init(builder, service, id=nil) |
@@ -2,10 +2,10 @@ | ||
2 | 2 | # Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com> |
3 | 3 | # |
4 | 4 | |
5 | -Tenarai::ClassLoader.load_class('Resource') | |
5 | +Tenarai::ClassLoader.load_class('Widget::Resource') | |
6 | 6 | |
7 | 7 | class Widget |
8 | - class Content < Resource | |
8 | + class Content < Widget::Resource | |
9 | 9 | extend Tenarai::ClassLoader |
10 | 10 | |
11 | 11 | resource 'Widget::User' |
@@ -3,138 +3,26 @@ | ||
3 | 3 | # |
4 | 4 | |
5 | 5 | require 'tenarai/db/tree' |
6 | -require 'tenarai/db/property' | |
7 | 6 | |
8 | 7 | class Widget < Tenarai::DB::Row::Tree |
9 | 8 | extend Tenarai::ClassLoader |
10 | - extend Tenarai::Property | |
11 | 9 | |
12 | - class CSS < Tenarai::Container | |
13 | - CSS = Tenarai::Container.new | |
14 | - CSS << Tenarai::Container::Value.new( | |
15 | - 'font', | |
16 | - [ | |
17 | - 'font-family', | |
18 | - 'font-weight', | |
19 | - 'font-size', | |
20 | - 'font-style', | |
21 | - 'font-variant', | |
22 | - ] | |
23 | - ) | |
24 | - CSS << Tenarai::Container::Value.new( | |
25 | - 'text', | |
26 | - [ | |
27 | - 'color', | |
28 | - 'text-indent', | |
29 | - 'text-align', | |
30 | - 'line-height', | |
31 | - 'vertical-align', | |
32 | - 'word-spacing', | |
33 | - 'letter-spacing', | |
34 | - 'text-transform', | |
35 | - 'text-decoration', | |
36 | - 'white-space', | |
37 | - ] | |
38 | - ) | |
39 | - CSS << Tenarai::Container::Value.new( | |
40 | - 'background', | |
41 | - [ | |
42 | - 'background-color', | |
43 | - 'background-image', | |
44 | - 'background-repeat', | |
45 | - 'background-position', | |
46 | - 'background-attachment', | |
47 | - ] | |
48 | - ) | |
49 | - CSS << Tenarai::Container::Value.new( | |
50 | - 'margin', | |
51 | - [ | |
52 | - 'margin', | |
53 | - 'margin-top', | |
54 | - 'margin-right', | |
55 | - 'margin-bottom', | |
56 | - 'margin-left', | |
57 | - ] | |
58 | - ) | |
59 | - CSS << Tenarai::Container::Value.new( | |
60 | - 'border', | |
61 | - [ | |
62 | - 'border', | |
63 | - 'border-top', | |
64 | - 'border-right', | |
65 | - 'border-bottom', | |
66 | - 'border-left', | |
67 | - ] | |
68 | - ) | |
69 | - CSS << Tenarai::Container::Value.new( | |
70 | - 'padding', | |
71 | - [ | |
72 | - 'padding', | |
73 | - 'padding-top', | |
74 | - 'padding-right', | |
75 | - 'padding-bottom', | |
76 | - 'padding-left', | |
77 | - ] | |
78 | - ) | |
79 | - CSS << Tenarai::Container::Value.new( | |
80 | - 'size', | |
81 | - [ | |
82 | - 'width', | |
83 | - 'height', | |
84 | - 'min-width', | |
85 | - 'min-height', | |
86 | - 'max-width', | |
87 | - 'max-height', | |
88 | - ] | |
89 | - ) | |
90 | - CSS << Tenarai::Container::Value.new( | |
91 | - 'layout', | |
92 | - [ | |
93 | - 'float', | |
94 | - 'clear', | |
95 | - 'position', | |
96 | - 'top', | |
97 | - 'right', | |
98 | - 'bottom', | |
99 | - 'left', | |
100 | - 'overflow', | |
101 | - 'clip', | |
102 | - 'visibility', | |
103 | - 'z-index', | |
104 | - 'display', | |
105 | - ] | |
106 | - ) | |
107 | - CSS << Tenarai::Container::Value.new( | |
108 | - 'list', | |
109 | - [ | |
110 | - 'list-style-type', | |
111 | - ] | |
112 | - ) | |
113 | - CSS << Tenarai::Container::Value.new( | |
114 | - 'ui', | |
115 | - [ | |
116 | - 'cursor', | |
117 | - ] | |
118 | - ) | |
10 | + meta[:property] = {} | |
11 | + meta[:resource] = nil | |
119 | 12 | |
120 | - def [](key) | |
121 | - fetch(key).value if key?(key) | |
13 | + class << self | |
14 | + def create_row(class_name, table, row) | |
15 | + Tenarai::ClassLoader[class_name].new(table, row) | |
122 | 16 | end |
123 | 17 | |
124 | - def []=(key, val) | |
125 | - if key?(key) | |
126 | - fetch(key).value = val | |
127 | - else | |
128 | - self << Tenarai::Container::Value.new(key, val) | |
129 | - end unless val.empty? | |
18 | + def property(name, value=nil) | |
19 | + meta[:property][name] = value | |
130 | 20 | end |
131 | - end | |
132 | 21 | |
133 | - meta[:css] = Tenarai::Container.new | |
22 | + def css(name=nil, *selectors) | |
23 | + end | |
134 | 24 | |
135 | - class << self | |
136 | - def create_row(class_name, table, row) | |
137 | - Tenarai::ClassLoader[class_name].new(table, row) | |
25 | + def css_list | |
138 | 26 | end |
139 | 27 | |
140 | 28 | def resource(klass) |
@@ -148,22 +36,9 @@ | ||
148 | 36 | nil |
149 | 37 | end |
150 | 38 | |
151 | - def css(name=nil, *selector) | |
152 | - meta[:css] << Tenarai::Container::Value.new(name, selector) | |
153 | - end | |
154 | - | |
155 | - def css_list | |
156 | - css 'ul' | |
157 | - css 'li ul' | |
158 | - css 'ul li' | |
159 | - css 'a' | |
160 | - css 'a.selected' | |
161 | - css 'a:hover' | |
162 | - end | |
163 | - | |
164 | 39 | def inherited(subclass) |
165 | 40 | super |
166 | - subclass.meta[:css] = meta[:css].clone | |
41 | + subclass.meta[:property] = meta[:property].clone | |
167 | 42 | subclass.meta[:resource] = subclass.name.sub(/\w+?$/, '').sub(/::+?$/, '') |
168 | 43 | subclass.meta[:resource] = nil if subclass.meta[:resource].empty? |
169 | 44 | end |
@@ -170,23 +45,25 @@ | ||
170 | 45 | end |
171 | 46 | |
172 | 47 | column Tenarai::DB::Reference.new('view') |
173 | - column Tenarai::DB::Property.new('property') | |
48 | + column Tenarai::DB::Serialize.new('property') | |
174 | 49 | column Tenarai::DB::Serialize.new('css') |
175 | 50 | index Tenarai::DB::Index.new('build_idx', :cols => ['view', 'min']) |
176 | 51 | |
177 | - property('html').group('attribute') do |attribute| | |
178 | - attribute.item('_id') | |
179 | - attribute.item('_class') | |
180 | - end | |
52 | + property :html_attr_id | |
53 | + property :html_attr_class | |
181 | 54 | |
55 | + attr_reader :resource | |
56 | + | |
182 | 57 | def initialize(table, row={}) |
183 | 58 | super |
184 | - self.css ||= ::Widget::CSS.new | |
59 | + self.property ||= self.class.meta[:property].clone | |
60 | + self.css ||= [] | |
185 | 61 | end |
186 | 62 | |
187 | 63 | def init(builder, service, *param) |
188 | - @builder = builder | |
189 | - @service = service | |
64 | + @builder = builder | |
65 | + @service = service | |
66 | + @resource = self.class.fetch_resource(self) || @service | |
190 | 67 | end |
191 | 68 | |
192 | 69 | def each_widget(&block) |
@@ -193,10 +70,6 @@ | ||
193 | 70 | @builder.each(self, &block) |
194 | 71 | end |
195 | 72 | |
196 | - def resource | |
197 | - self.class.fetch_resource(self) || @service | |
198 | - end | |
199 | - | |
200 | 73 | def uri(view, *param, &block) |
201 | 74 | resource.uri(view, *param, &block) |
202 | 75 | end |
@@ -220,9 +93,9 @@ | ||
220 | 93 | end |
221 | 94 | |
222 | 95 | def css_id(val=nil) |
223 | - ret = if @builder.preview? then '#preview_' else '#' end | |
96 | + ret = '#' | |
224 | 97 | |
225 | - _id = property.html.attribute._id.value.to_s | |
98 | + _id = property[:html_attr_id].to_s | |
226 | 99 | if _id.empty? |
227 | 100 | ret << 'id' << primary_key.to_s |
228 | 101 | else |
@@ -237,13 +110,9 @@ | ||
237 | 110 | end |
238 | 111 | |
239 | 112 | def html_id |
240 | - _id = property.html.attribute._id.value.to_s | |
113 | + _id = property[:html_attr_id].to_s | |
241 | 114 | |
242 | - if @builder.preview? | |
243 | - 'preview_' | |
244 | - else | |
245 | - '' | |
246 | - end << if _id.empty? | |
115 | + if _id.empty? | |
247 | 116 | 'id' << primary_key.to_s |
248 | 117 | else |
249 | 118 | _id |
@@ -250,13 +119,12 @@ | ||
250 | 119 | end |
251 | 120 | end |
252 | 121 | |
253 | - def html_class | |
254 | - property.html.attribute._class.value | |
255 | - end | |
256 | - | |
257 | 122 | def html_attr |
258 | 123 | ret = {'id' => html_id} |
124 | + | |
125 | + html_class = property[:html_attr_class].to_s | |
259 | 126 | ret['class'] = html_class unless html_class.to_s.empty? |
127 | + | |
260 | 128 | ret |
261 | 129 | end |
262 | 130 |
@@ -2,7 +2,7 @@ | ||
2 | 2 | # Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com> |
3 | 3 | # |
4 | 4 | |
5 | -Tenarai::ClassLoader.load_class('Resource') | |
5 | +Tenarai::ClassLoader.load_class('Widget::Resource') | |
6 | 6 | |
7 | 7 | class View |
8 | 8 | class Builder |
@@ -45,7 +45,7 @@ | ||
45 | 45 | else |
46 | 46 | widget[nil] = val |
47 | 47 | end |
48 | - if val.is_a?(Resource) && view.resource.path.include?(val) | |
48 | + if val.is_a?(::Widget::Resource) && view.resource.path.include?(val) | |
49 | 49 | val.init(self, service, param.shift) |
50 | 50 | else |
51 | 51 | if rs.key?(val) |