tofu 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/tofu.rb +55 -6
- 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
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6d48e9fc0850cb2924f8323bd67fcbf3909a52cdf8f1eaff34ae4bbd59faf1ba
|
|
4
|
+
data.tar.gz: 563baa1c17bd1bb2e1ddd449b45162fc0039e2232c0196ed7997f86758bb123c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 12cd6476f3c110a6ddf91befa94ccacf5c7fb07acc65ec5a8d792ce02830a93d4b24c42b9e63343a2dda47428610bbeae0bf14d8fa3dd79e0d495f4ce0959408
|
|
7
|
+
data.tar.gz: 7e8269c55da03135d8af4e9ac49a492cecd7ce904f740419ce7c94f59b149e1f7da3d61fc13165cf2644de5fe7a8ecd6f7c411fb758921fa91b1dcf4f59eb5f7
|
data/.gitignore
CHANGED
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
|
|
@@ -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
|
|
@@ -466,6 +466,16 @@ module Tofu
|
|
|
466
466
|
def service(req, res)
|
|
467
467
|
Context.new(req, res).service(@bartender)
|
|
468
468
|
end
|
|
469
|
+
|
|
470
|
+
def start(env, stdin, stdout)
|
|
471
|
+
if env["SERVER_SOFTWARE"]
|
|
472
|
+
@config[:ServerSoftware] = env["SERVER_SOFTWARE"]
|
|
473
|
+
end
|
|
474
|
+
if %r{HTTP/(\d+\.\d+)} =~ env["SERVER_PROTOCOL"]
|
|
475
|
+
@config[:HTTPVersion] = $1
|
|
476
|
+
end
|
|
477
|
+
super(env, stdin, stdout)
|
|
478
|
+
end
|
|
469
479
|
end
|
|
470
480
|
end
|
|
471
481
|
|
|
@@ -575,6 +585,45 @@ EOS
|
|
|
575
585
|
throw(:tofu_done)
|
|
576
586
|
end
|
|
577
587
|
end
|
|
588
|
+
|
|
589
|
+
class ChunkedStream
|
|
590
|
+
def initialize(stream)
|
|
591
|
+
@data = nil
|
|
592
|
+
@cursor = 0
|
|
593
|
+
@stream = stream
|
|
594
|
+
end
|
|
595
|
+
|
|
596
|
+
def next_chunk
|
|
597
|
+
@stream.pop
|
|
598
|
+
rescue
|
|
599
|
+
raise EOFError
|
|
600
|
+
end
|
|
601
|
+
|
|
602
|
+
def close
|
|
603
|
+
@stream.close
|
|
604
|
+
end
|
|
605
|
+
|
|
606
|
+
def readpartial(size, buf='')
|
|
607
|
+
buf.clear
|
|
608
|
+
unless @data
|
|
609
|
+
@cursor = 0
|
|
610
|
+
@data = next_chunk
|
|
611
|
+
@data.force_encoding("ascii-8bit")
|
|
612
|
+
end
|
|
613
|
+
if @data.bytesize <= size
|
|
614
|
+
buf << @data
|
|
615
|
+
@data = nil
|
|
616
|
+
else
|
|
617
|
+
slice = @data.byteslice(@cursor, size)
|
|
618
|
+
@cursor += slice.bytesize
|
|
619
|
+
buf << slice
|
|
620
|
+
if @data.bytesize <= @cursor
|
|
621
|
+
@data = nil
|
|
622
|
+
end
|
|
623
|
+
end
|
|
624
|
+
buf
|
|
625
|
+
end
|
|
626
|
+
end
|
|
578
627
|
end
|
|
579
628
|
|
|
580
629
|
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
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tofu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
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: 2019-06-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -62,6 +62,9 @@ files:
|
|
|
62
62
|
- doc/yfd03.obj
|
|
63
63
|
- lib/tofu.rb
|
|
64
64
|
- lib/tofu/version.rb
|
|
65
|
+
- sample/kd/base.erb
|
|
66
|
+
- sample/kd/wiki.erb
|
|
67
|
+
- sample/kd/wikir.rb
|
|
65
68
|
- sample/koto/base.erb
|
|
66
69
|
- sample/koto/enter.erb
|
|
67
70
|
- sample/koto/koto.rb
|
|
@@ -86,8 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
86
89
|
- !ruby/object:Gem::Version
|
|
87
90
|
version: '0'
|
|
88
91
|
requirements: []
|
|
89
|
-
|
|
90
|
-
rubygems_version: 2.7.7
|
|
92
|
+
rubygems_version: 3.0.4
|
|
91
93
|
signing_key:
|
|
92
94
|
specification_version: 4
|
|
93
95
|
summary: tiny web-ui framework for me.
|