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/file.rb
CHANGED
@@ -1,81 +1,85 @@
|
|
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
|
+
|
1
17
|
require 'awesome_print'
|
2
|
-
require_relative '../wire'
|
3
18
|
|
4
19
|
# Static is a Wire::App for serving read-only, static files
|
5
20
|
# @author Bryan T. Meyers
|
6
21
|
module Static
|
7
|
-
extend Wire::App
|
8
|
-
extend Wire::Resource
|
9
|
-
|
10
|
-
# Map a file folder to a sub-URI
|
11
|
-
# @param [String] resource the sub-URI
|
12
|
-
# @param [Class] path the file folder
|
13
|
-
# @return [void]
|
14
|
-
def self.local(resource, path)
|
15
|
-
$current_app[:resources][resource] = { local: path }
|
16
|
-
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
# Get a file listing for this folder
|
24
|
+
# @param [Hash] context the context for this request
|
25
|
+
# @return [Response] a listing, or status code
|
26
|
+
def self.do_read_all(context)
|
27
|
+
path = context.config['path']
|
28
|
+
if path
|
29
|
+
return 404 unless File.exists?(path)
|
30
|
+
if File.directory? path
|
31
|
+
Dir.entries(path).sort.to_s
|
32
|
+
else
|
33
|
+
401
|
34
|
+
end
|
35
|
+
else
|
36
|
+
404
|
37
|
+
end
|
38
|
+
end
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
40
|
+
# Get a file from this folder
|
41
|
+
# @param [Hash] context the context for this request
|
42
|
+
# @return [Response] a file, listing, or status code
|
43
|
+
def self.do_read(context)
|
44
|
+
path = context.config['path']
|
45
|
+
if path
|
46
|
+
ext_path = File.join(path, context.resource, context.id)
|
47
|
+
return 404 unless File.exists?(ext_path)
|
48
|
+
if File.directory?(ext_path)
|
49
|
+
"#{ap Dir.entries(ext_path).sort}"
|
50
|
+
else
|
51
|
+
if ext_path.end_with?('.wiki') || ext_path.end_with?('.mediawiki')
|
52
|
+
mime = 'text/wiki'
|
53
|
+
else
|
54
|
+
mime = `mimetype --brief #{ext_path}`
|
55
|
+
end
|
56
|
+
headers = {}
|
57
|
+
headers['Content-Type'] = mime
|
58
|
+
headers['Cache-Control'] = 'public'
|
59
|
+
headers['Expires'] = "#{(Time.now + 30000000).utc}"
|
60
|
+
body = File.read(ext_path)
|
61
|
+
[200, headers, body]
|
62
|
+
end
|
63
|
+
else
|
64
|
+
404
|
65
|
+
end
|
66
|
+
end
|
63
67
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
68
|
+
# Proxy method used when routing
|
69
|
+
# @param [Array] actions the allowed actions for this URI
|
70
|
+
# @param [Hash] context the context for this request
|
71
|
+
# @return [Response] a Rack Response triplet, or status code
|
72
|
+
def self.invoke(actions, context)
|
73
|
+
return 404 unless context.resource
|
74
|
+
case context.action
|
75
|
+
when :read
|
76
|
+
if context.id
|
77
|
+
do_read(context)
|
78
|
+
else
|
79
|
+
do_read_all(context)
|
80
|
+
end
|
81
|
+
else
|
82
|
+
403
|
83
|
+
end
|
84
|
+
end
|
81
85
|
end
|
data/lib/app/history.rb
CHANGED
@@ -1,59 +1,60 @@
|
|
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 'tilt'
|
3
|
-
require_relative '../wire'
|
4
18
|
require_relative 'history/svn'
|
5
19
|
|
6
20
|
# History is a Wire::App for accessing the history of versioned content
|
7
21
|
# @author Bryan T. Meyers
|
8
22
|
module History
|
9
23
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# Select the render template for histories
|
18
|
-
# @param [Symbol] path location of the Tilt compatible template
|
19
|
-
# @return [void]
|
20
|
-
def log(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
|
24
|
+
# Configure this History with a log template
|
25
|
+
# @param [Hash] conf the raw configuration
|
26
|
+
# @return [Hash] post-processed configuration
|
27
|
+
def self.configure(conf)
|
28
|
+
conf['log'] = Tilt.new(conf['log'], 1, { ugly: true })
|
29
|
+
conf
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
32
|
+
# Get the history of a single file or directory
|
33
|
+
# @param [Hash] context the context for this request
|
34
|
+
# @return [Response] the history, or status code
|
35
|
+
def do_read(actions, context)
|
36
|
+
list = get_log(context.config['host'],
|
37
|
+
context.resource,
|
38
|
+
context.config['web_folder'],
|
39
|
+
context.id)
|
40
|
+
if list == 404
|
41
|
+
return 404
|
42
|
+
end
|
43
|
+
template = context.config['log']
|
44
|
+
template.render(self, actions: actions, context: context, list: list)
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
47
|
+
# Proxy method used when routing
|
48
|
+
# @param [Array] actions the allowed actions for this URI
|
49
|
+
# @param [Hash] context the context for this request
|
50
|
+
# @return [Response] a Rack Response triplet, or status code
|
51
|
+
def invoke(actions, context)
|
52
|
+
return 404 unless context.resource
|
53
|
+
case context.action
|
54
|
+
when :read
|
55
|
+
do_read(actions, context)
|
56
|
+
else
|
57
|
+
403
|
58
|
+
end
|
59
|
+
end
|
59
60
|
end
|
data/lib/app/history/svn.rb
CHANGED
@@ -1,30 +1,49 @@
|
|
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
|
+
|
1
17
|
require_relative '../repo'
|
2
18
|
require 'cobravsmongoose'
|
3
19
|
|
4
20
|
module History
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
extend Wire::Resource
|
10
|
-
extend History
|
21
|
+
# History::SVN is a connector for viewing log information in SVN
|
22
|
+
# @author Bryan T. Meyers
|
23
|
+
module SVN
|
24
|
+
extend History
|
11
25
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
# Get the log information for any part of a Repo
|
27
|
+
# @param [String] host the name of the host to connect to
|
28
|
+
# @param [String] repo the name of the repository to access
|
29
|
+
# @param [String] web the web path of the repo
|
30
|
+
# @param [String] id the sub-URI of the item to access
|
31
|
+
# @return [Hash] the history entries
|
32
|
+
def self.get_log(host, repo, web, id = nil)
|
33
|
+
options = "--username #{$environment[:repos_user]} --password #{$environment[:repos_password]}"
|
34
|
+
uri = "svn://#{host}/#{repo}"
|
35
|
+
if id
|
36
|
+
if web
|
37
|
+
uri += "/#{web}"
|
38
|
+
end
|
39
|
+
uri += "/#{id}"
|
40
|
+
end
|
41
|
+
log = `svn log #{options} -v --xml '#{uri}'`
|
42
|
+
if $?.exitstatus != 0
|
43
|
+
return 404
|
44
|
+
end
|
45
|
+
log = CobraVsMongoose.xml_to_hash(log)
|
46
|
+
log['log']['logentry']
|
47
|
+
end
|
48
|
+
end
|
30
49
|
end
|
data/lib/app/login.rb
CHANGED
@@ -1,14 +1,29 @@
|
|
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
|
+
|
1
17
|
# Login is a Wire::App for forcing user logins
|
2
18
|
# @author Bryan T. Meyers
|
3
19
|
module Login
|
4
20
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
21
|
+
# Proxy method used when routing
|
22
|
+
# @param [Array] actions the allowed actions for this URI
|
23
|
+
# @param [Hash] context the context for this request
|
24
|
+
# @return [Response] a redirect message returning to the previous page
|
25
|
+
def self.invoke(actions, context)
|
26
|
+
[307, { 'Location': context.referer.join('/') }, ['Login Redirect']]
|
27
|
+
end
|
13
28
|
|
14
29
|
end
|
data/lib/app/render.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
+
|
8
17
|
require_relative 'render/document'
|
9
18
|
require_relative 'render/editor'
|
10
19
|
require_relative 'render/error'
|
@@ -16,103 +25,5 @@ require_relative 'render/style'
|
|
16
25
|
# Render is an Abstract Wire::App for transforming content
|
17
26
|
# @author Bryan T. Meyers
|
18
27
|
module Render
|
19
|
-
include Wire::Resource
|
20
|
-
|
21
|
-
# Setup the remote connection for content
|
22
|
-
# @param [String] hostname http hostname and port of remote
|
23
|
-
# @param [String] uri the base URI for content on the remote
|
24
|
-
# @return [void]
|
25
|
-
def remote(hostname, uri)
|
26
|
-
$current_app[:remote_host] = hostname
|
27
|
-
$current_app[:remote_uri] = uri
|
28
|
-
end
|
29
|
-
|
30
|
-
# Setup the template for rendering
|
31
|
-
# @param [String] path location of the template
|
32
|
-
# @param [Proc] block block to execute for setting up template
|
33
|
-
# @return [void]
|
34
|
-
def template(path, &block)
|
35
|
-
$current_app[:template] = { path: path.nil? ? nil : Tilt.new(path, 1, { ugly: true }), sources: {} }
|
36
|
-
if block
|
37
|
-
Docile.dsl_eval(self, &block)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Enable the use of an outer layout, for the current template
|
42
|
-
def use_layout
|
43
|
-
$current_app[:template][:use_layout] = true
|
44
|
-
end
|
45
|
-
|
46
|
-
# Setup the source for additional template information
|
47
|
-
# @param [Symbol] key the type of key for this source
|
48
|
-
# @param [String] uri the path for a remote source
|
49
|
-
# @param [Proc] block block to execute for setting up source
|
50
|
-
# @return [void]
|
51
|
-
def source(key, uri, &block)
|
52
|
-
$current_app[:template][:sources][key] = { uri: uri, key: nil }
|
53
|
-
$current_source = $current_app[:template][:sources][key]
|
54
|
-
if block
|
55
|
-
Docile.dsl_eval(self, &block)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Setup the key for additional source information
|
60
|
-
# @param [Symbol] type the type of key for this source
|
61
|
-
# @return [void]
|
62
|
-
def key(type)
|
63
|
-
$current_source[:key] = type
|
64
|
-
end
|
65
|
-
|
66
|
-
# Setup the template for rendering single items
|
67
|
-
# @param [String] template the path to the template
|
68
|
-
# @return [void]
|
69
|
-
def single(template)
|
70
|
-
partial = Tilt.new(template, 1, { ugly: true })
|
71
|
-
$current_resource[:single] = partial
|
72
|
-
end
|
73
|
-
|
74
|
-
# Setup the template for rendering multiple items
|
75
|
-
# @param [String] template the path to the template
|
76
|
-
# @return [void]
|
77
|
-
def multiple(template)
|
78
|
-
partial = Tilt.new(template, 1, { ugly: true })
|
79
|
-
$current_resource[:multiple] = partial
|
80
|
-
end
|
81
|
-
|
82
|
-
# Setup the template for rendering one or more items
|
83
|
-
# @param [String] template the path to the template
|
84
|
-
# @return [void]
|
85
|
-
def all(template)
|
86
|
-
multiple(template)
|
87
|
-
single(template)
|
88
|
-
end
|
89
|
-
|
90
|
-
CONVERT = {
|
91
|
-
create: :post,
|
92
|
-
read: :get,
|
93
|
-
readAll: :get,
|
94
|
-
update: :put,
|
95
|
-
delete: :delete
|
96
|
-
}
|
97
28
|
|
98
|
-
# Proxy method used when forwarding requests
|
99
|
-
# @param [Symbol] method the action to use when forwarding
|
100
|
-
# @param [Hash] context the context for this request
|
101
|
-
# @return [Response] a Rack Response triplet, or status code
|
102
|
-
def forward(method, context)
|
103
|
-
host = context.app[:remote_host]
|
104
|
-
path = context.app[:remote_uri]
|
105
|
-
resource = context.uri[2]
|
106
|
-
referer = context.referer.join('/')
|
107
|
-
q = '?' + context.query_string
|
108
|
-
id = context.uri[3...context.uri.length].join('/')
|
109
|
-
headers = {referer: referer, remote_user: context.user}
|
110
|
-
verb = CONVERT[method]
|
111
|
-
uri = "http://#{host}/#{path}/#{resource}"
|
112
|
-
uri += "/#{id}" if [:update,:read,:delete].include?( method )
|
113
|
-
uri += q
|
114
|
-
body = [:create,:update].include?(method) ? context.body : nil
|
115
|
-
$stderr.puts "#{verb.upcase}: Forward Request to #{uri}"
|
116
|
-
RL.request verb, uri, headers, body
|
117
|
-
end
|
118
29
|
end
|