• R/O
  • SSH
  • HTTPS

tenarai: 提交


Commit MetaInfo

修訂99 (tree)
時間2008-07-21 04:12:17
作者junkikuchi

Log Message

updated.

Change Summary

差異

--- trunk/webapp/Widget/Widget/Property.rb (nonexistent)
+++ trunk/webapp/Widget/Widget/Property.rb (revision 99)
@@ -0,0 +1,33 @@
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 Property < ::Widget
10+ extend Tenarai::ClassLoader
11+
12+ css 'box'
13+
14+ def render_html(head, body)
15+ body.tag('div', 'id' => html_id) do |div|
16+ div.tag('form') do |form|
17+ form['method'] = 'post'
18+ form['action'] = uri(@builder.view, resource.content.id) do |query|
19+ query[html_id('update')] = nil
20+ end
21+ resource.content.property.each do |val|
22+ form << val.to_xml
23+ end
24+ end
25+ end
26+ end
27+
28+ def post(query={})
29+ p query
30+ end
31+ end
32+ end
33+end
--- trunk/webapp/Widget/View/Menu.rb (nonexistent)
+++ trunk/webapp/Widget/View/Menu.rb (revision 99)
@@ -0,0 +1,64 @@
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 Menu < ::Widget
10+ extend Tenarai::ClassLoader
11+
12+ preference_css 'box'
13+ preference_list
14+
15+ preference 'preference' do |pref|
16+ pref.group 'default' do |default|
17+ default.edit 'view_id'
18+ end
19+ end
20+
21+ def default_view
22+ service.model['view'].fetch(preference.preference.default.view_id.value)
23+ end
24+
25+ def build_uri(param, query)
26+ service.build_uri(
27+ path.inject([]) do |ret, val|
28+ if val.equal?(resource)
29+ val.widget_uri(ret, query, param)
30+ else
31+ val.widget_uri(ret, query)
32+ end
33+ ret
34+ end,
35+ query
36+ )
37+ end
38+
39+ def uri(*param, &block)
40+ query = Tenarai::CGI::Query.new
41+ block.call(query) if block_given?
42+ build_uri(param, query)
43+ end
44+
45+ def render_html(xml, builder, content=nil)
46+ content ||= default_view || resource.content.root
47+
48+ xml.tag('div', 'id' => html_id) do |div|
49+ div.tag('ul') do |ul|
50+ content.node.each do |c|
51+ ul.tag('li') do |li|
52+ li.tag('a') do |a|
53+ a['href'] = uri(c.id)
54+ a['class'] = 'selected' if resource.content.equal?(c)
55+ end.text(c.name)
56+ render_html(li, builder, c) unless c.node.empty?
57+ end
58+ end
59+ end
60+ end
61+ end
62+ end
63+ end
64+end
--- trunk/webapp/Widget/Content/View/HTML.rb (nonexistent)
+++ trunk/webapp/Widget/Content/View/HTML.rb (revision 99)
@@ -0,0 +1,92 @@
1+#
2+# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
3+#
4+
5+Tenarai::ClassLoader.load_class('Widget::Content::View')
6+Tenarai::ClassLoader.load_class('Resource')
7+
8+class Widget
9+ class Content
10+ class View
11+ class HTML < Resource
12+ extend Tenarai::ClassLoader
13+
14+ preference_css 'html', 'html'
15+ preference_css 'body', 'body'
16+ preference_css 'a', 'a'
17+ preference_css 'a_link', 'a:link'
18+ preference_css 'a_visited', 'a:visited'
19+ preference_css 'a_hover', 'a:hover'
20+ preference_css 'a_active', 'a:active'
21+
22+ def init(service, markup='html')
23+ super
24+
25+ case markup
26+ when 'html'
27+ @markup = markup
28+ content = 'text/html; charset=utf-8'
29+ when 'css'
30+ @markup = markup
31+ content = 'text/css; charset=utf-8'
32+ else
33+ @markup = 'html'
34+ content = 'text/html; charset=utf-8'
35+ end
36+
37+ service.response['content-type'] = content
38+ end
39+
40+ def get(service, query={})
41+ unless resource.content.nil?
42+ resource.build(query)
43+ service.response.content << resource.content.__send__('to_' + @markup)
44+ end
45+ end
46+
47+ def post(service, query={})
48+ unless resource.resource.content.nil?
49+ resource.build(query)
50+ service.response.content << resource.content.__send__('to_' + @markup)
51+ end
52+ end
53+
54+ def render_css(css, builder)
55+ render_preference_css(css)
56+ builder.each(self) do |w|
57+ w.render_css(css, builder)
58+ end
59+ end
60+
61+ def render_html(xml, builder)
62+ xml.xml('1.0', 'utf-8')
63+ xml.doctype(
64+ 'html',
65+ '-//W3C//DTD XHTML 1.0 Strict//EN',
66+ 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
67+ )
68+ xml.tag(
69+ 'html',
70+ 'xmlns' => 'http://www.w3.org/1999/xhtml',
71+ 'xml:lang' => 'ja',
72+ 'lang' => 'ja'
73+ ) do |html|
74+ html.tag('head') do |head|
75+ render_html_head(head, builder)
76+ head.tag('style') do |style|
77+ style.code(resource.content.to_css)
78+ end
79+ end
80+ html.tag('body', 'id' => html_id) do |body|
81+ if builder.empty?(self)
82+ body.text('')
83+ else
84+ super(body, builder)
85+ end
86+ end
87+ end
88+ end
89+ end
90+ end
91+ end
92+end
--- trunk/webapp/Widget/Content/View/Menu.rb (nonexistent)
+++ trunk/webapp/Widget/Content/View/Menu.rb (revision 99)
@@ -0,0 +1,68 @@
1+#
2+# Copyright (C) 2008 Jun Kikuchi <kikuchi@bonnou.com>
3+#
4+
5+Tenarai::ClassLoader.load_class('Widget::Content::View')
6+
7+class Widget
8+ class Content
9+ class View
10+ class Menu < ::Widget
11+ extend Tenarai::ClassLoader
12+
13+ preference_css 'box'
14+ preference_list
15+
16+ preference 'preference' do |pref|
17+ pref.group 'default' do |default|
18+ default.edit 'view_id'
19+ end
20+ end
21+
22+ def default_view
23+ service.model['view'].fetch(
24+ preference.preference.default.view_id.value
25+ )
26+ end
27+
28+ def build_uri(param, query)
29+ service.build_uri(
30+ path.inject([]) do |ret, val|
31+ if val.equal?(resource)
32+ val.widget_uri(ret, query, param)
33+ else
34+ val.widget_uri(ret, query)
35+ end
36+ ret
37+ end,
38+ query
39+ )
40+ end
41+
42+ def uri(*param, &block)
43+ query = Tenarai::CGI::Query.new
44+ block.call(query) if block_given?
45+ build_uri(param, query)
46+ end
47+
48+ def render_html(xml, builder, content=nil)
49+ content ||= default_view || resource.content.root
50+
51+ xml.tag('div', 'id' => html_id) do |div|
52+ div.tag('ul') do |ul|
53+ content.node.each do |c|
54+ ul.tag('li') do |li|
55+ li.tag('a') do |a|
56+ a['href'] = uri(c.id)
57+ a['class'] = 'selected' if resource.content.equal?(c)
58+ end.text(c.name)
59+ render_html(li, builder, c) unless c.node.empty?
60+ end
61+ end
62+ end
63+ end
64+ end
65+ end
66+ end
67+ end
68+end
--- trunk/webapp/Widget/Content/View.rb (nonexistent)
+++ trunk/webapp/Widget/Content/View.rb (revision 99)
@@ -0,0 +1,52 @@
1+#
2+# Copyright (C) 2007, 2008 Jun Kikuchi <kikuchi@bonnou.com>
3+#
4+
5+Tenarai::ClassLoader.load_class('Widget::Content')
6+Tenarai::ClassLoader.load_class('Resource')
7+
8+class Widget
9+ class Content
10+ class View < Resource
11+ extend Tenarai::ClassLoader
12+
13+ def init(service, id=nil)
14+ super
15+ if @content.nil?
16+ @content = resource.content.view
17+ else
18+ unless resource.resource.content.view.include?(@content)
19+ raise Service::Redirect.new(uri(resource.resource.content.view.id))
20+ end
21+ end
22+ end
23+
24+ def build(query)
25+ ws, rs = {}, {}
26+
27+ query.each do |key, val|
28+ case key
29+ when /id(\d+):(.+)/
30+ if w = @service.model['widget'].fetch($1)
31+ ws[w] ||= Tenarai::CGI::Query.new
32+ ws[w][$2] = val
33+ end
34+ when /id(\d+)/
35+ if w = @service.model['widget'].fetch($1)
36+ rs[w] = val
37+ end
38+ end
39+ end
40+
41+ @content.widget.each do |val|
42+ val.init(@service, *rs[val]) if val.view.path.size != 1
43+ end
44+
45+ ws.each do |w, q|
46+ w.init(service)
47+ w.__send__(@service.request.method, self, q)
48+ end
49+ end
50+ end
51+ end
52+end
Show on old repository browser