tofu 0.2.0 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/LICENSE +21 -0
- data/lib/tofu.rb +57 -7
- data/lib/tofu/version.rb +1 -1
- data/sample/kd/base.erb +8 -0
- data/sample/kd/wiki.erb +13 -0
- data/sample/kd/wikir.rb +143 -0
- data/tofu.gemspec +2 -2
- metadata +13 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c43ebdfd3a81da31a173dad8b6e7f51b78fdf9674cf965f2f01dcfc4c16ce05
|
4
|
+
data.tar.gz: f7655329fa596b9bff8efdfbc968cccf10ef116ca96a09548fccfde2f22a67e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78d2db1a810ce63f71c946c8c65e1be9264c306dad490ecf0b21f0b4d2cc30d89dbb47075cd5a0a13c32ee89019def32163ba4fd88203cb9c3f9a279948977a9
|
7
|
+
data.tar.gz: 28b6e8fbb2616e7ee13a5fc15129615511a89e912f1ceeec4e9df73ddd07f24aa7a7aae2b9b21eddf549677cc433fec414314cba97917714b6a296a9b05c4311
|
data/.gitignore
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Masatoshi SEKI
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/lib/tofu.rb
CHANGED
@@ -3,10 +3,10 @@ require "tofu/version"
|
|
3
3
|
require 'erb'
|
4
4
|
require 'drb/drb'
|
5
5
|
require 'monitor'
|
6
|
-
require 'digest/md5'
|
7
6
|
require 'webrick'
|
8
7
|
require 'webrick/cgi'
|
9
8
|
require 'uri'
|
9
|
+
require 'securerandom'
|
10
10
|
|
11
11
|
module Tofu
|
12
12
|
class Session
|
@@ -14,7 +14,7 @@ module Tofu
|
|
14
14
|
|
15
15
|
def initialize(bartender, hint=nil)
|
16
16
|
super()
|
17
|
-
@session_id =
|
17
|
+
@session_id = SecureRandom.uuid
|
18
18
|
@contents = {}
|
19
19
|
@hint = hint
|
20
20
|
renew
|
@@ -136,9 +136,9 @@ module Tofu
|
|
136
136
|
|
137
137
|
def service(context)
|
138
138
|
begin
|
139
|
-
|
140
|
-
|
141
|
-
|
139
|
+
session = retrieve_session(context)
|
140
|
+
catch(:tofu_done) { session.service(context) }
|
141
|
+
store_session(context, session)
|
142
142
|
ensure
|
143
143
|
end
|
144
144
|
end
|
@@ -336,7 +336,7 @@ module Tofu
|
|
336
336
|
end
|
337
337
|
param = make_param(method_name, add_param)
|
338
338
|
hidden = input_hidden(param)
|
339
|
-
%Q!<form action="#{action(context)}" method="post">\n! + hidden
|
339
|
+
%Q!<form action="#{action(context)}" method="post" enctype="multipart/form-data">\n! + hidden
|
340
340
|
end
|
341
341
|
|
342
342
|
def href(method_name, add_param, context)
|
@@ -365,7 +365,7 @@ module Tofu
|
|
365
365
|
|
366
366
|
def reload_erb
|
367
367
|
ObjectSpace.each_object(Class) do |o|
|
368
|
-
if o.ancestors.include?(Tofu::Tofu)
|
368
|
+
if o.ancestors.include?(::Tofu::Tofu)
|
369
369
|
o.reload_erb
|
370
370
|
end
|
371
371
|
end
|
@@ -408,6 +408,7 @@ module Tofu
|
|
408
408
|
value = WEBrick::HTTPUtils::escape(value)
|
409
409
|
c = WEBrick::Cookie.new(name, value)
|
410
410
|
c.expires = expires if expires
|
411
|
+
c.path = req_script_name.to_s
|
411
412
|
@res.cookies.push(c)
|
412
413
|
end
|
413
414
|
|
@@ -466,6 +467,16 @@ module Tofu
|
|
466
467
|
def service(req, res)
|
467
468
|
Context.new(req, res).service(@bartender)
|
468
469
|
end
|
470
|
+
|
471
|
+
def start(env, stdin, stdout)
|
472
|
+
if env["SERVER_SOFTWARE"]
|
473
|
+
@config[:ServerSoftware] = env["SERVER_SOFTWARE"]
|
474
|
+
end
|
475
|
+
if %r{HTTP/(\d+\.\d+)} =~ env["SERVER_PROTOCOL"]
|
476
|
+
@config[:HTTPVersion] = $1
|
477
|
+
end
|
478
|
+
super(env, stdin, stdout)
|
479
|
+
end
|
469
480
|
end
|
470
481
|
end
|
471
482
|
|
@@ -575,6 +586,45 @@ EOS
|
|
575
586
|
throw(:tofu_done)
|
576
587
|
end
|
577
588
|
end
|
589
|
+
|
590
|
+
class ChunkedStream
|
591
|
+
def initialize(stream)
|
592
|
+
@data = nil
|
593
|
+
@cursor = 0
|
594
|
+
@stream = stream
|
595
|
+
end
|
596
|
+
|
597
|
+
def next_chunk
|
598
|
+
@stream.pop
|
599
|
+
rescue
|
600
|
+
raise EOFError
|
601
|
+
end
|
602
|
+
|
603
|
+
def close
|
604
|
+
@stream.close
|
605
|
+
end
|
606
|
+
|
607
|
+
def readpartial(size, buf='')
|
608
|
+
buf.clear
|
609
|
+
unless @data
|
610
|
+
@cursor = 0
|
611
|
+
@data = next_chunk
|
612
|
+
@data.force_encoding("ascii-8bit")
|
613
|
+
end
|
614
|
+
if @data.bytesize <= size
|
615
|
+
buf << @data
|
616
|
+
@data = nil
|
617
|
+
else
|
618
|
+
slice = @data.byteslice(@cursor, size)
|
619
|
+
@cursor += slice.bytesize
|
620
|
+
buf << slice
|
621
|
+
if @data.bytesize <= @cursor
|
622
|
+
@data = nil
|
623
|
+
end
|
624
|
+
end
|
625
|
+
buf
|
626
|
+
end
|
627
|
+
end
|
578
628
|
end
|
579
629
|
|
580
630
|
if __FILE__ == $0
|
data/lib/tofu/version.rb
CHANGED
data/sample/kd/base.erb
ADDED
data/sample/kd/wiki.erb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
<script language="JavaScript">
|
2
|
+
function open_edit(){
|
3
|
+
document.getElementById('edit').style.display = "block";
|
4
|
+
}
|
5
|
+
</script>
|
6
|
+
<%= page(context).html %>
|
7
|
+
<a href='javascript:open_edit()'>[edit]</a>
|
8
|
+
<div id='edit' style='display:none;'>
|
9
|
+
<%=form('edit', {'name' => context.req_path_info}, context) %>
|
10
|
+
<textarea name='text' rows="40" cols="50"><%=h page(context).src %></textarea>
|
11
|
+
<input type='submit' name='ok' value='ok'/>
|
12
|
+
</form>
|
13
|
+
</div>
|
data/sample/kd/wikir.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'tofu'
|
2
|
+
require 'kramdown'
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
module WikiR
|
6
|
+
class Book
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@monitor = Monitor.new
|
11
|
+
@pages = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def [](name)
|
15
|
+
@pages[name] || Page.new(name)
|
16
|
+
end
|
17
|
+
|
18
|
+
def []=(name, src)
|
19
|
+
@monitor.synchronize do
|
20
|
+
page = self[name]
|
21
|
+
@pages[name] = page
|
22
|
+
page.src = src
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Page
|
28
|
+
def initialize(name)
|
29
|
+
@name = name
|
30
|
+
self.src = "# #{name}\n\nan empty page. edit me."
|
31
|
+
end
|
32
|
+
attr_reader :name, :src, :html, :warnings
|
33
|
+
|
34
|
+
def src=(text)
|
35
|
+
@src = text
|
36
|
+
document = Kramdown::Document.new(text)
|
37
|
+
@html = document.to_html
|
38
|
+
@warnings = document.warnings
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class WikiRSession < Tofu::Session
|
44
|
+
def initialize(bartender, hint=nil)
|
45
|
+
super
|
46
|
+
@book = WikiR::Book.instance
|
47
|
+
@base = BaseTofu.new(self)
|
48
|
+
end
|
49
|
+
attr_reader :book
|
50
|
+
|
51
|
+
def lookup_view(context)
|
52
|
+
@base
|
53
|
+
end
|
54
|
+
|
55
|
+
def do_GET(context)
|
56
|
+
context.res_header('pragma', 'no-cache')
|
57
|
+
context.res_header('cache-control', 'no-cache')
|
58
|
+
context.res_header('expires', 'Thu, 01 Dec 1994 16:00:00 GMT')
|
59
|
+
super(context)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class BaseTofu < Tofu::Tofu
|
64
|
+
set_erb('base.erb')
|
65
|
+
|
66
|
+
def initialize(session)
|
67
|
+
super(session)
|
68
|
+
@wiki = WikiTofu.new(session)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class WikiTofu < Tofu::Tofu
|
73
|
+
set_erb('wiki.erb')
|
74
|
+
|
75
|
+
def book
|
76
|
+
@session.book
|
77
|
+
end
|
78
|
+
|
79
|
+
def do_edit(context, params)
|
80
|
+
text ,= params['text']
|
81
|
+
return if text.nil? || text.empty?
|
82
|
+
text = text.force_encoding('utf-8')
|
83
|
+
name ,= params['name']
|
84
|
+
return if name.nil? || name.empty?
|
85
|
+
name = name.force_encoding('utf-8')
|
86
|
+
book[name] = text
|
87
|
+
end
|
88
|
+
|
89
|
+
def page(context)
|
90
|
+
book[context.req_path_info]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
module Tofu
|
95
|
+
def reload_erb
|
96
|
+
p 1
|
97
|
+
ObjectSpace.each_object(Class) do |o|
|
98
|
+
if o.ancestors.include?(::Tofu::Tofu)
|
99
|
+
o.reload_erb
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
module_function :reload_erb
|
104
|
+
end
|
105
|
+
|
106
|
+
class MyTofulet < Tofu::CGITofulet
|
107
|
+
def [](key)
|
108
|
+
WikiR::Book.instance if key == 'book'
|
109
|
+
end
|
110
|
+
|
111
|
+
def reload_erb
|
112
|
+
Tofu::reload_erb
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
WEBrick::Daemon.start unless $DEBUG
|
117
|
+
tofu = Tofu::Bartender.new(WikiRSession, 'wikir_8083')
|
118
|
+
uri = ARGV.shift || 'druby://localhost:54322'
|
119
|
+
DRb.start_service(uri, MyTofulet.new(tofu))
|
120
|
+
s = WEBrick::HTTPServer.new(:Port => 8083)
|
121
|
+
s.mount("/", Tofu::Tofulet, tofu)
|
122
|
+
s.start
|
123
|
+
|
124
|
+
=begin
|
125
|
+
# dRuby & CGI style
|
126
|
+
unless $DEBUG
|
127
|
+
exit!(0) if fork
|
128
|
+
Process.setsid
|
129
|
+
exit!(0) if fork
|
130
|
+
end
|
131
|
+
|
132
|
+
uri = ARGV.shift || 'druby://localhost:54322'
|
133
|
+
tofu = Tofu::Bartender.new(WikiRSession, 'wikir_' + uri.split(':').last)
|
134
|
+
DRb.start_service(uri, MyTofulet.new(tofu))
|
135
|
+
|
136
|
+
unless $DEBUG
|
137
|
+
STDIN.reopen('/dev/null')
|
138
|
+
STDOUT.reopen('/dev/null', 'w')
|
139
|
+
STDERR.reopen('/dev/null', 'w')
|
140
|
+
end
|
141
|
+
|
142
|
+
DRb.thread.join
|
143
|
+
=end
|
data/tofu.gemspec
CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_development_dependency "bundler", "
|
23
|
-
spec.add_development_dependency "rake", "~>
|
22
|
+
spec.add_development_dependency "bundler", ">= 2.2.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
24
24
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tofu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masatoshi SEKI
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.10
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.10
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
description: tiny web-ui framework for plain WEBrick lovers
|
42
42
|
email:
|
43
43
|
- seki@ruby-lang.org
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
49
|
- Gemfile
|
50
|
+
- LICENSE
|
50
51
|
- README.md
|
51
52
|
- Rakefile
|
52
53
|
- doc/Div.rd
|
@@ -62,6 +63,9 @@ files:
|
|
62
63
|
- doc/yfd03.obj
|
63
64
|
- lib/tofu.rb
|
64
65
|
- lib/tofu/version.rb
|
66
|
+
- sample/kd/base.erb
|
67
|
+
- sample/kd/wiki.erb
|
68
|
+
- sample/kd/wikir.rb
|
65
69
|
- sample/koto/base.erb
|
66
70
|
- sample/koto/enter.erb
|
67
71
|
- sample/koto/koto.rb
|
@@ -86,8 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
90
|
- !ruby/object:Gem::Version
|
87
91
|
version: '0'
|
88
92
|
requirements: []
|
89
|
-
|
90
|
-
rubygems_version: 2.7.7
|
93
|
+
rubygems_version: 3.2.3
|
91
94
|
signing_key:
|
92
95
|
specification_version: 4
|
93
96
|
summary: tiny web-ui framework for me.
|