修訂 | 54 (tree) |
---|---|
時間 | 2008-03-04 23:10:21 |
作者 | junkikuchi |
updated.
@@ -55,7 +55,7 @@ | ||
55 | 55 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
56 | 56 | <html lang="ja" xml:lang="ja" xmlns="http://www.w3.org/1999/xhtml"> |
57 | 57 | <head> |
58 | - <title>Title Text</title> | |
58 | + <title>Title Text</title> | |
59 | 59 | <link href="/style.css" rel="stylesheet" type="text/css" /> |
60 | 60 | <script type="text/javascript"></script> |
61 | 61 | <script type="text/javascript"> |
@@ -67,8 +67,8 @@ | ||
67 | 67 | </script> |
68 | 68 | </head> |
69 | 69 | <body> |
70 | - <h1 class="title">H1 Text</h1> | |
71 | - <p>"a", <b> and 'c'</p> | |
70 | + <h1 class="title">H1 Text</h1> | |
71 | + <p>"a", <b> and 'c'</p> | |
72 | 72 | <!-- |
73 | 73 | Comment Text |
74 | 74 | -->Text<![CDATA[CDATA Text]]>Text</body> |
@@ -76,10 +76,10 @@ | ||
76 | 76 | END |
77 | 77 | |
78 | 78 | xml =<<END |
79 | -<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html lang="ja" xml:lang="ja" xmlns="http://www.w3.org/1999/xhtml"><head><title>Title Text</title><link href="/style.css" rel="stylesheet" type="text/css" /><script type="text/javascript"></script><script type="text/javascript">function hello() { | |
79 | +<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html lang="ja" xml:lang="ja" xmlns="http://www.w3.org/1999/xhtml"><head><title>Title Text</title><link href="/style.css" rel="stylesheet" type="text/css" /><script type="text/javascript"></script><script type="text/javascript">function hello() { | |
80 | 80 | alert('Hello'); |
81 | 81 | } |
82 | -</script></head><body><h1 class="title">H1 Text</h1><p>"a", <b> and 'c'</p><!-- Comment Text -->Text<![CDATA[CDATA Text]]>Text</body></html> | |
82 | +</script></head><body><h1 class="title">H1 Text</h1><p>"a", <b> and 'c'</p><!-- Comment Text -->Text<![CDATA[CDATA Text]]>Text</body></html> | |
83 | 83 | END |
84 | 84 | |
85 | 85 | #puts(@xml.to_xml) |
@@ -64,7 +64,7 @@ | ||
64 | 64 | </ol> |
65 | 65 | <dl> |
66 | 66 | <dt>aaa</dt> |
67 | - <dd>a description</dd> | |
67 | + <dd>a description</dd> | |
68 | 68 | <dt>bbb</dt> |
69 | 69 | <dd>b:description</dd> |
70 | 70 | </dl> |
@@ -73,7 +73,7 @@ | ||
73 | 73 | <p>aaabbbccc</p> |
74 | 74 | <dl> |
75 | 75 | <dt>aaa</dt> |
76 | - <dd>a description</dd> | |
76 | + <dd>a description</dd> | |
77 | 77 | <dt>bbb</dt> |
78 | 78 | <dd>b:description</dd> |
79 | 79 | </dl> |
@@ -469,6 +469,7 @@ | ||
469 | 469 | |
470 | 470 | def server(name) |
471 | 471 | model do |m| |
472 | + m['service'].pub_dir = File.dirname(__FILE__) + '/pub' | |
472 | 473 | Tenarai::Server.new(@config[:server]) do |request, response| |
473 | 474 | m['service'].dispatch(m, request, response) |
474 | 475 | m.refresh |
@@ -13,7 +13,7 @@ | ||
13 | 13 | end |
14 | 14 | |
15 | 15 | class Redirect < Error |
16 | - def initialize(url, code=303) | |
16 | + def initialize(url, code=302) | |
17 | 17 | super() |
18 | 18 | @code = code |
19 | 19 | @url = url |
@@ -50,7 +50,7 @@ | ||
50 | 50 | @response = response |
51 | 51 | |
52 | 52 | method = (@request.method || 'get').downcase |
53 | - ws, rs = {}, {} | |
53 | + ws, rs, qs = {}, {}, {} | |
54 | 54 | |
55 | 55 | if method == 'get' |
56 | 56 | @request.query |
@@ -68,6 +68,8 @@ | ||
68 | 68 | key = nil |
69 | 69 | rs[wid] ||= {} |
70 | 70 | rs[wid] = val |
71 | + else | |
72 | + qs[key] = val | |
71 | 73 | end |
72 | 74 | end |
73 | 75 |
@@ -104,7 +106,7 @@ | ||
104 | 106 | end |
105 | 107 | end |
106 | 108 | |
107 | - widget.__send__(method, self) | |
109 | + widget.__send__(method, self, qs) | |
108 | 110 | end |
109 | 111 | rescue Error => err |
110 | 112 | err.exec(self) |
@@ -15,13 +15,13 @@ | ||
15 | 15 | case markup |
16 | 16 | when 'html' |
17 | 17 | @markup = markup |
18 | - content = 'text/html' | |
18 | + content = 'text/html; charset=utf-8' | |
19 | 19 | when 'css' |
20 | 20 | @markup = markup |
21 | - content = 'text/css' | |
21 | + content = 'text/css; charset=utf-8' | |
22 | 22 | else |
23 | 23 | @markup = 'html' |
24 | - content = 'text/html' | |
24 | + content = 'text/html; charset=utf-8' | |
25 | 25 | end |
26 | 26 | |
27 | 27 | service.response['content-type'] = content |
@@ -53,7 +53,6 @@ | ||
53 | 53 | 'lang' => 'ja' |
54 | 54 | ) do |html| |
55 | 55 | html.tag('head') do |head| |
56 | - render_html_head(head, builder) | |
57 | 56 | head.tag( |
58 | 57 | 'link', |
59 | 58 | 'rel' => 'stylesheet', |
@@ -60,6 +59,7 @@ | ||
60 | 59 | 'type' => 'text/css', |
61 | 60 | 'href' => url('css') |
62 | 61 | ) |
62 | + render_html_head(head, builder) | |
63 | 63 | end |
64 | 64 | html.tag('body', 'id' => html_id) do |body| |
65 | 65 | super(body, builder) |
@@ -5,6 +5,8 @@ | ||
5 | 5 | class ServiceTable < Tenarai::DB::Table |
6 | 6 | extend Tenarai::ClassLoader |
7 | 7 | |
8 | + attr_accessor :pub_dir | |
9 | + | |
8 | 10 | def fetch_by_name(name) |
9 | 11 | query('WHERE name = ?', name) do |service| |
10 | 12 | return service |
@@ -13,6 +15,31 @@ | ||
13 | 15 | |
14 | 16 | def dispatch(model, request, response) |
15 | 17 | _nil, name, *param = request['path_info'].split('/') |
16 | - fetch_by_name(name || 'index').dispatch(model, param, request, response) | |
18 | + if s = fetch_by_name(name || 'index') | |
19 | + response.code = 200 | |
20 | + s.dispatch(model, param, request, response) | |
21 | + else | |
22 | + response.code = 404 | |
23 | + if @pub_dir | |
24 | + file = File.expand_path(@pub_dir + request['path_info']) | |
25 | + if %r!^#{@pub_dir}!.match(file) && File.file?(file) | |
26 | + ct = case File.extname(file).downcase | |
27 | + when '.txt' | |
28 | + 'text/plain' | |
29 | + when '.js' | |
30 | + 'text/javascript' | |
31 | + when '.css' | |
32 | + 'text/css' | |
33 | + when '.swf' | |
34 | + 'application/x-shockwave-flash' | |
35 | + end | |
36 | + unless ct.nil? | |
37 | + response.code = 200 | |
38 | + response['content-type'] = ct | |
39 | + response.body << File.open(file).read | |
40 | + end | |
41 | + end | |
42 | + end | |
43 | + end | |
17 | 44 | end |
18 | 45 | end |