wire-framework 0.1.4.26 → 0.1.5
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/LICENSE +201 -339
- data/README.md +16 -0
- data/lib/app.rb +38 -19
- data/lib/app/cache.rb +93 -84
- data/lib/app/db.rb +195 -196
- data/lib/app/file.rb +76 -72
- data/lib/app/history.rb +50 -49
- data/lib/app/history/svn.rb +43 -24
- data/lib/app/login.rb +23 -8
- data/lib/app/render.rb +16 -105
- data/lib/app/render/document.rb +57 -40
- data/lib/app/render/editor.rb +59 -44
- data/lib/app/render/error.rb +55 -35
- data/lib/app/render/instant.rb +71 -60
- data/lib/app/render/page.rb +104 -79
- data/lib/app/render/partial.rb +120 -99
- data/lib/app/render/style.rb +56 -42
- data/lib/app/repo.rb +141 -135
- data/lib/app/repo/svn.rb +203 -177
- data/lib/closet.rb +104 -92
- data/lib/closet/auth.rb +37 -53
- data/lib/closet/config.rb +34 -0
- data/lib/closet/context.rb +142 -98
- data/lib/closet/renderer.rb +44 -41
- data/lib/wire.rb +28 -16
- metadata +11 -40
- data/lib/closet/resource.rb +0 -20
data/lib/app/render/partial.rb
CHANGED
@@ -1,106 +1,127 @@
|
|
1
|
-
|
1
|
+
##
|
2
|
+
# Copyright 2017 Bryan T. Meyers
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
##
|
2
16
|
|
3
|
-
|
4
|
-
|
5
|
-
# @author Bryan T.Meyers
|
6
|
-
module Partial
|
7
|
-
extend Render
|
17
|
+
require 'rest-less'
|
18
|
+
require 'tilt'
|
8
19
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
20
|
+
module Render
|
21
|
+
# Partials are URI mapped renderers which generate only a piece of a document
|
22
|
+
# @author Bryan T.Meyers
|
23
|
+
module Partial
|
14
24
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
# Configure repo with listing template
|
26
|
+
# @param [Hash] conf the raw configuration
|
27
|
+
# @return [Hash] post-processed configuration
|
28
|
+
def self.configure(conf)
|
29
|
+
conf['resources'].each do |k, v|
|
30
|
+
if v.is_a? Hash
|
31
|
+
conf['resources'][k]['multiple'] = Tilt.new(v['multiple'], 1, { ugly: true })
|
32
|
+
conf['resources'][k]['single'] = Tilt.new(v['single'], 1, { ugly: true })
|
33
|
+
elsif v.is_a? String
|
34
|
+
#TODO: fix needless duplication
|
35
|
+
conf['resources'][k]['multiple'] = Tilt.new(v, 1, { ugly: true })
|
36
|
+
conf['resources'][k]['single'] = Tilt.new(v, 1, { ugly: true })
|
37
|
+
end
|
38
|
+
end
|
39
|
+
conf
|
40
|
+
end
|
25
41
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
42
|
+
# Read a listing and render to HTML
|
43
|
+
# @param [Array] actions the allowed actions for this URI
|
44
|
+
# @param [Hash] context the context for this request
|
45
|
+
# @return [Response] a Rack Response triplet, or status code
|
46
|
+
def self.do_read_all(actions, context)
|
47
|
+
resource = context.uri[2]
|
48
|
+
body = ''
|
49
|
+
mime = ''
|
50
|
+
if context.app['use_forward']
|
51
|
+
response = context.forward(:readAll)
|
52
|
+
return response if response[0] != 200
|
53
|
+
mime = response[1][:content_type]
|
54
|
+
body = response[2]
|
55
|
+
end
|
56
|
+
template = context.app['resources'][context.resource]['multiple']
|
57
|
+
if template
|
58
|
+
hash = { actions: actions,
|
59
|
+
resource: resource,
|
60
|
+
mime: mime,
|
61
|
+
response: body }
|
62
|
+
if ccontext.app['resources'][context.resource]['extras']
|
63
|
+
context.app['resources'][context.resource]['extras'].each do |k, v|
|
64
|
+
hash[k] = RL.request(:get,
|
65
|
+
"http://#{context.app['remote']}/#{v}",
|
66
|
+
{ remote_user: context.user }
|
67
|
+
)[2]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
mime = 'text/html'
|
71
|
+
body = template.render(self, hash)
|
72
|
+
end
|
73
|
+
[200, { 'Content-Type': mime }, body]
|
74
|
+
end
|
56
75
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
76
|
+
# Read a Partial and render it to HTML
|
77
|
+
# @param [Array] actions the allowed actions for this URI
|
78
|
+
# @param [Hash] context the context for this request
|
79
|
+
# @return [Response] a Rack Response triplet, or status code
|
80
|
+
def self.do_read(actions, context)
|
81
|
+
body = ''
|
82
|
+
mime = ''
|
83
|
+
if context.app['resources'][context.resource]['use_forward']
|
84
|
+
response = context.forward(:read)
|
85
|
+
return response if response[0] != 200
|
86
|
+
mime = response[1][:content_type]
|
87
|
+
body = response[2]
|
88
|
+
end
|
89
|
+
template = context.app['resources'][context.resource]['single']
|
90
|
+
if template
|
91
|
+
hash = { actions: actions,
|
92
|
+
app: context.app,
|
93
|
+
resource: context.resource,
|
94
|
+
id: context.id,
|
95
|
+
mime: mime,
|
96
|
+
response: body }
|
97
|
+
if context.app['resources'][context.resource]['extras']
|
98
|
+
context.app['resources'][context.resource]['extras'].each do |k, v|
|
99
|
+
hash[k] = RL.request(:get, "http://#{context.app[:remote_host]}/#{v}")[2]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
mime = 'text/html'
|
103
|
+
body = template.render(self, hash)
|
104
|
+
end
|
105
|
+
[200, { 'Content-Type': mime }, body]
|
106
|
+
end
|
86
107
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
108
|
+
# Proxy method used when routing
|
109
|
+
# @param [Array] actions the allowed actions for this URI
|
110
|
+
# @param [Hash] context the context for this request
|
111
|
+
# @return [Response] a Rack Response triplet, or status code
|
112
|
+
def self.invoke(actions, context)
|
113
|
+
case context.action
|
114
|
+
when :create, :update, :delete
|
115
|
+
context.forward(context.action)
|
116
|
+
when :read
|
117
|
+
if context.id
|
118
|
+
do_read(actions, context)
|
119
|
+
else
|
120
|
+
do_read_all(actions, context)
|
121
|
+
end
|
122
|
+
else
|
123
|
+
403
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
106
127
|
end
|
data/lib/app/render/style.rb
CHANGED
@@ -1,48 +1,62 @@
|
|
1
|
-
|
1
|
+
##
|
2
|
+
# Copyright 2017 Bryan T. Meyers
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
##
|
16
|
+
|
17
|
+
require 'tilt'
|
2
18
|
|
3
19
|
module Render
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
extend Render
|
20
|
+
# Style uses Tilt to render and serve stylesheets
|
21
|
+
# @author Bryan T. Meyers
|
22
|
+
module Style
|
8
23
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
24
|
+
# Configure styles
|
25
|
+
# @param [Hash] conf the raw configuration
|
26
|
+
# @return [Hash] post-processed configuration
|
27
|
+
def self.configure(conf)
|
28
|
+
conf['styles'].each do |k, v|
|
29
|
+
conf['styles'][k] = Tilt.new(v, 1, {ugly: true}).render
|
30
|
+
end
|
31
|
+
conf
|
32
|
+
end
|
19
33
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
# Render a stylesheet to CSS
|
35
|
+
# @param [Hash] context the context for this request
|
36
|
+
# @return [Response] a Rack Response triplet, or status code
|
37
|
+
def self.do_read_all(context)
|
38
|
+
resource = context.uri[2]
|
39
|
+
template = context.app['styles'][resource]
|
40
|
+
headers = {'Cache-Control': 'public,max-age=3600'}
|
41
|
+
if template
|
42
|
+
headers['Content-Type'] = 'text/css'
|
43
|
+
[200, headers, [template]]
|
44
|
+
else
|
45
|
+
404
|
46
|
+
end
|
47
|
+
end
|
34
48
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
# Proxy method used when routing
|
50
|
+
# @param [Array] actions the allowed actions for this URI
|
51
|
+
# @param [Hash] context the context for this request
|
52
|
+
# @return [Response] a Rack Response triplet, or status code
|
53
|
+
def self.invoke(actions, context)
|
54
|
+
case context.action
|
55
|
+
when :read
|
56
|
+
do_read_all(context)
|
57
|
+
else
|
58
|
+
403
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
48
62
|
end
|
data/lib/app/repo.rb
CHANGED
@@ -1,148 +1,154 @@
|
|
1
|
-
|
1
|
+
##
|
2
|
+
# Copyright 2017 Bryan T. Meyers
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
##
|
16
|
+
|
2
17
|
require 'base64'
|
3
|
-
|
18
|
+
require 'tilt'
|
4
19
|
require_relative 'repo/svn'
|
5
20
|
|
6
21
|
# Repo is a Wire::App for accessing versioned content
|
7
22
|
# @author Bryan T. Meyers
|
8
23
|
module Repo
|
9
24
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# Select the render template for file listings
|
18
|
-
# @param [Symbol] path location of the Tilt compatible template
|
19
|
-
# @return [void]
|
20
|
-
def listing(path)
|
21
|
-
$current_app[:template] = Tilt.new(path, 1, { ugly: true })
|
22
|
-
end
|
23
|
-
|
24
|
-
# Select the sub-directory for web-serveable content
|
25
|
-
# @param [Symbol] path the sub-directory path
|
26
|
-
# @return [void]
|
27
|
-
def web_folder(path)
|
28
|
-
$current_app[:web] = path
|
29
|
-
end
|
25
|
+
# Configure repo with listing template
|
26
|
+
# @param [Hash] conf the raw configuration
|
27
|
+
# @return [Hash] post-processed configuration
|
28
|
+
def self.configure(conf)
|
29
|
+
conf['listing'] = Tilt.new(conf['listing'], 1, { ugly: true })
|
30
|
+
conf
|
31
|
+
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
33
|
+
# Create a new Repo
|
34
|
+
# @param [Hash] context the context for this request
|
35
|
+
# @return [Response] status code
|
36
|
+
def do_create(context)
|
37
|
+
path = context.config['repos']
|
38
|
+
resource = context.resource
|
39
|
+
if path
|
40
|
+
if Dir.exist?("#{path}/#{resource}")
|
41
|
+
401
|
42
|
+
else
|
43
|
+
do_create_file(path, resource)
|
44
|
+
end
|
45
|
+
else
|
46
|
+
400
|
47
|
+
end
|
48
|
+
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
50
|
+
# Get the a root directory listing
|
51
|
+
# @param [Hash] context the context for this request
|
52
|
+
# @return [Response] the listing, or status code
|
53
|
+
def do_read_all(context)
|
54
|
+
mime = 'text/html'
|
55
|
+
list = do_read_listing(context.config['web'],
|
56
|
+
context.config['repos'],
|
57
|
+
context.resource)
|
58
|
+
if list == 404
|
59
|
+
return 404
|
60
|
+
end
|
61
|
+
template = context.config['listing']
|
62
|
+
list = template.render(self,
|
63
|
+
list: list,
|
64
|
+
resource: context.resource,
|
65
|
+
id: '',
|
66
|
+
referrer: context.referer)
|
67
|
+
headers = { 'Content-Type': mime,
|
68
|
+
'Cache-Control': 'public',
|
69
|
+
'Expires': "#{(Time.now + 1000).utc}" }
|
70
|
+
[200, headers, [list]]
|
71
|
+
end
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
73
|
+
# Get the a single file or directory listing
|
74
|
+
# @param [Hash] context the context for this request
|
75
|
+
# @return [Response] the file, listing, or status code
|
76
|
+
def do_read(context)
|
77
|
+
path = context.resource
|
78
|
+
referrer = context.referer
|
79
|
+
repos = context.config['repos']
|
80
|
+
web = context.config['web']
|
81
|
+
rev = context.query[:rev]
|
82
|
+
id = context.id
|
83
|
+
info = do_read_info(rev, web, repos, path, id)
|
84
|
+
if info == 404
|
85
|
+
return 404
|
86
|
+
end
|
87
|
+
type = info[:@kind]
|
88
|
+
if type.eql? 'dir'
|
89
|
+
mime = 'text/html'
|
90
|
+
list = do_read_listing(web, repos, path, id)
|
91
|
+
template = context.config['listing']
|
92
|
+
body = template.render(self,
|
93
|
+
list: list,
|
94
|
+
resource: path,
|
95
|
+
id: id,
|
96
|
+
referrer: referrer)
|
97
|
+
else
|
98
|
+
body = do_read_file(rev, web, repos, path, id)
|
99
|
+
if body == 500
|
100
|
+
return body
|
101
|
+
end
|
102
|
+
mime = do_read_mime(rev, web, repos, path, id)
|
103
|
+
end
|
104
|
+
headers = { 'Content-Type': mime,
|
105
|
+
'Cache-Control': 'public',
|
106
|
+
'Expires': "#{(Time.now + 1000).utc}" }
|
107
|
+
[200, headers, [body]]
|
108
|
+
end
|
103
109
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
110
|
+
# Update the a single file
|
111
|
+
# @param [Hash] context the context for this request
|
112
|
+
# @return [Response] status code
|
113
|
+
def do_update(context)
|
114
|
+
path = context.resource
|
115
|
+
repos = context.config['repos']
|
116
|
+
web = context.config['web']
|
117
|
+
content = context.json
|
118
|
+
id = context.id
|
119
|
+
if content[:file]
|
120
|
+
file = content[:file][:content].match(/base64,(.*)/)[1]
|
121
|
+
file = Base64.decode64(file)
|
122
|
+
if context.query[:type]
|
123
|
+
mime = context.query[:type]
|
124
|
+
else
|
125
|
+
mime = content[:file][:mime]
|
126
|
+
end
|
127
|
+
do_update_file(web, repos, path, id, file, content[:message], mime, context.user)
|
128
|
+
else
|
129
|
+
do_update_file(web, repos, path, id, URI.unescape(content[:updated]), content[:message], context.query[:type], context.user)
|
130
|
+
end
|
131
|
+
end
|
126
132
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
133
|
+
# Proxy method used when routing
|
134
|
+
# @param [Array] actions the allowed actions for this URI
|
135
|
+
# @param [Hash] context the context for this request
|
136
|
+
# @return [Response] a Rack Response triplet, or status code
|
137
|
+
def invoke(actions, context)
|
138
|
+
return 404 unless context.resource
|
139
|
+
case context.action
|
140
|
+
when :create
|
141
|
+
do_create(context)
|
142
|
+
when :read
|
143
|
+
if context.id
|
144
|
+
do_read(context)
|
145
|
+
else
|
146
|
+
do_read_all(context)
|
147
|
+
end
|
148
|
+
when :update
|
149
|
+
do_update(context)
|
150
|
+
else
|
151
|
+
403
|
152
|
+
end
|
153
|
+
end
|
148
154
|
end
|