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/document.rb
CHANGED
@@ -1,45 +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
|
+
##
|
2
16
|
|
3
17
|
module Render
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
extend Render
|
18
|
+
# Document renders a file to an HTML representation
|
19
|
+
# @author Bryan T. Meyers
|
20
|
+
module Document
|
8
21
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
# Renders a document or listing to HTML
|
23
|
+
# @param [Array] actions the actions allowed for this URI
|
24
|
+
# @param [Wire::Context] context the context for this request
|
25
|
+
# @param [Symbol] specific the type of read to perform
|
26
|
+
# @return [Response] a Rack Response triplet, or status code
|
27
|
+
def self.do_read(actions, context, specific)
|
28
|
+
response = context.forward(specific)
|
29
|
+
mime = response[1]['content-type']
|
30
|
+
#TODO: Fix lookup
|
31
|
+
renderer = $wire_renderers[mime]
|
32
|
+
if renderer
|
33
|
+
template = renderer['partial']
|
34
|
+
template.render(self, { actions: actions,
|
35
|
+
context: context,
|
36
|
+
mime: mime,
|
37
|
+
response: response[2] })
|
38
|
+
else
|
39
|
+
response
|
40
|
+
end
|
41
|
+
end
|
25
42
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
# Proxy method used when routing
|
44
|
+
# @param [Array] actions the allowed actions for this URI
|
45
|
+
# @param [Hash] context the context for this request
|
46
|
+
# @return [Response] a Rack Response triplet, or status code
|
47
|
+
def self.invoke(actions, context)
|
48
|
+
case context.action
|
49
|
+
when :create, :update, :delete
|
50
|
+
context.forward(context.action)
|
51
|
+
when :read
|
52
|
+
if context.id
|
53
|
+
do_read(actions, context, :read)
|
54
|
+
else
|
55
|
+
do_read(actions, context, :readAll)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
405
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
45
62
|
end
|
data/lib/app/render/editor.rb
CHANGED
@@ -1,50 +1,65 @@
|
|
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
17
|
module Render
|
4
18
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
extend Render
|
19
|
+
# Editor allows a document to be displayed in an editing form
|
20
|
+
# @author Bryan T. Meyers
|
21
|
+
module Editor
|
9
22
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
# Open an editor for a document
|
24
|
+
# @param [Array] actions the allowed actions for this URI
|
25
|
+
# @param [Hash] context the context for this request
|
26
|
+
# @return [Response] the Editor with containing document, or status code
|
27
|
+
def self.do_read(actions, context)
|
28
|
+
response = context.forward(:read)
|
29
|
+
body = (response[0] == 200) ? response[2] : ''
|
30
|
+
if context.query[:type]
|
31
|
+
mime = context.query[:type]
|
32
|
+
elsif response[1]['content-type']
|
33
|
+
mime = response[1]['content-type']
|
34
|
+
else
|
35
|
+
return [404, {}, 'EDITOR: Document type not set for new document']
|
36
|
+
end
|
37
|
+
#TODO: Fix lookup
|
38
|
+
template = $wire_editors[mime]
|
39
|
+
if template
|
40
|
+
template.render(self, { actions: actions,
|
41
|
+
resource: context.resource,
|
42
|
+
id: context.id,
|
43
|
+
mime: mime,
|
44
|
+
response: body })
|
45
|
+
else
|
46
|
+
body
|
47
|
+
end
|
48
|
+
end
|
34
49
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
+
# Proxy method used when routing
|
51
|
+
# @param [Array] actions the allowed actions for this URI
|
52
|
+
# @param [Hash] context the context for this request
|
53
|
+
# @return [Response] a Rack Response triplet, or status code
|
54
|
+
def self.invoke(actions, context)
|
55
|
+
case context.action
|
56
|
+
when :create, :update
|
57
|
+
context.forward(context.action)
|
58
|
+
when :read
|
59
|
+
do_read(actions, context)
|
60
|
+
else
|
61
|
+
405
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
50
65
|
end
|
data/lib/app/render/error.rb
CHANGED
@@ -1,41 +1,61 @@
|
|
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
|
-
extend Render
|
20
|
+
module Error
|
6
21
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
22
|
+
# Configure error templates
|
23
|
+
# @param [Hash] conf the raw configuration
|
24
|
+
# @return [Hash] post-processed configuration
|
25
|
+
def self.configure(conf)
|
26
|
+
conf['errors'].each do |k, v|
|
27
|
+
conf['errors'][k] = Tilt.new(v, 1, { ugly: true })
|
28
|
+
end
|
29
|
+
conf
|
30
|
+
end
|
13
31
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
32
|
+
def self.error_check(actions, context, result)
|
33
|
+
errors = context.app['errors']
|
34
|
+
if errors
|
35
|
+
template = errors[result[0]]
|
36
|
+
if template
|
37
|
+
result[2] = template.render(self, { actions: actions,
|
38
|
+
context: context,
|
39
|
+
result: result })
|
40
|
+
end
|
41
|
+
end
|
42
|
+
result
|
43
|
+
end
|
24
44
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
45
|
+
def self.invoke(actions, context)
|
46
|
+
case context.action
|
47
|
+
when :create, :update
|
48
|
+
result = context.forward(context.action)
|
49
|
+
when :read
|
50
|
+
if context.id
|
51
|
+
result = context.forward(:read)
|
52
|
+
else
|
53
|
+
result = context.forward(:readAll)
|
54
|
+
end
|
55
|
+
else
|
56
|
+
result = 405
|
57
|
+
end
|
58
|
+
error_check(actions, context, result)
|
59
|
+
end
|
60
|
+
end
|
41
61
|
end
|
data/lib/app/render/instant.rb
CHANGED
@@ -1,65 +1,76 @@
|
|
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
17
|
module Render
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
extend Render
|
18
|
+
# Instant allows for previews of edited documents
|
19
|
+
# @author Bryan T. Meyers
|
20
|
+
module Instant
|
8
21
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
[status, {}, message]
|
51
|
-
end
|
22
|
+
# Render a temporary document to HTML
|
23
|
+
# @param [Array] actions the allowed actions for this URI
|
24
|
+
# @param [Hash] context the context for this request
|
25
|
+
# @return [Response] a Rack Response triplet, or status code
|
26
|
+
def self.do_update(actions, context)
|
27
|
+
## Default to not found
|
28
|
+
message = ''
|
29
|
+
status = 404
|
30
|
+
if context.resource
|
31
|
+
body = context.body
|
32
|
+
if body
|
33
|
+
#TODO: This looks off...
|
34
|
+
body = body.split('=')[1]
|
35
|
+
if body
|
36
|
+
body = URI.decode(body)
|
37
|
+
end
|
38
|
+
## Assume unsupported mime type
|
39
|
+
status = 415
|
40
|
+
message = 'INSTANT: Unsupported MIME Type'
|
41
|
+
renderer = $wire_renderers["#{context.resource}/#{context.id}"]
|
42
|
+
if renderer
|
43
|
+
template = $wire_templates[renderer]
|
44
|
+
result = template.render(self, { actions: actions,
|
45
|
+
context: context,
|
46
|
+
mime: "#{context.resource}/#{context.id}",
|
47
|
+
response: body, })
|
48
|
+
#TODO: Fix template lookup
|
49
|
+
template = context.app[:template]
|
50
|
+
if template
|
51
|
+
message = template[:path].render(self, { actions: actions,
|
52
|
+
context: context,
|
53
|
+
content: result })
|
54
|
+
else
|
55
|
+
message = result
|
56
|
+
end
|
57
|
+
status = 200
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
[status, {}, message]
|
62
|
+
end
|
52
63
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
64
|
+
# Proxy method used when routing
|
65
|
+
# @param [Array] actions the allowed actions for this URI
|
66
|
+
# @param [Hash] context the context for this request
|
67
|
+
# @return [Response] a Rack Response triplet, or status code
|
68
|
+
def self.invoke(actions, context)
|
69
|
+
if context.action.eql? :update
|
70
|
+
do_update(actions, context)
|
71
|
+
else
|
72
|
+
405
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
65
76
|
end
|
data/lib/app/render/page.rb
CHANGED
@@ -1,85 +1,110 @@
|
|
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
17
|
module Render
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
include Render
|
8
|
-
extend self
|
18
|
+
# Page builds the a page that is presented directly to a user
|
19
|
+
# @author Bryan T. Meyers
|
20
|
+
module Page
|
9
21
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
22
|
+
# Render a full template, handling the gathering of additional Sources
|
23
|
+
# @param [Array] actions the allowed actions for this URI
|
24
|
+
# @param [Hash] context the context for this request
|
25
|
+
# @param [Tilt::Template] template a pre-loaded Tilt template to render
|
26
|
+
# @param [String] content the content to render into the page
|
27
|
+
# @return [Response] a Rack Response triplet, or status code
|
28
|
+
def render_template(actions, context, template, content)
|
29
|
+
if template['file']
|
30
|
+
hash = { actions: actions, context: context, content: content }
|
31
|
+
template['sources'].each do |k, s|
|
32
|
+
uri = "http://#{context.app[:remote_host]}"
|
33
|
+
go_ahead = true
|
34
|
+
if s.is_a? Hash
|
35
|
+
uri += "/#{hash['uri']}"
|
36
|
+
case s['key']
|
37
|
+
when 'user'
|
38
|
+
go_ahead = (context.user and !context.user.empty?)
|
39
|
+
uri += "/#{context.user}"
|
40
|
+
when 'resource'
|
41
|
+
go_ahead = (context.uri[2] and !context.uri[2].empty?)
|
42
|
+
uri += "/#{context.uri[2]}"
|
43
|
+
else
|
44
|
+
# do nothing
|
45
|
+
end
|
46
|
+
else
|
47
|
+
uri += s
|
48
|
+
end
|
49
|
+
temp = []
|
50
|
+
if go_ahead
|
51
|
+
temp = RL.request(:get, uri, { remote_user: context.user })
|
52
|
+
end
|
53
|
+
if temp[0] == 200
|
54
|
+
begin
|
55
|
+
hash[k] = JSON.parse_clean(temp[2])
|
56
|
+
rescue
|
57
|
+
hash[k] = temp[2]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
message = template[:path].render(self, hash)
|
62
|
+
if template['use_layout']
|
63
|
+
message = render_template(actions, context, $wire_apps[:global][:template], message)
|
64
|
+
end
|
65
|
+
else
|
66
|
+
message = 'Invalid Template'
|
67
|
+
end
|
68
|
+
message
|
69
|
+
end
|
45
70
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
71
|
+
# Render a page to its final form
|
72
|
+
# @param [Array] actions the allowed actions for this URI
|
73
|
+
# @param [Hash] context the context for this request
|
74
|
+
# @param [Symbol] specific the kind of read to perform
|
75
|
+
# @return [Response] a Rack Response triplet, or status code
|
76
|
+
def do_read(actions, context, specific)
|
77
|
+
if context.resource
|
78
|
+
result = context.forward(specific)
|
79
|
+
#TODO: fix lookup
|
80
|
+
template = context.app[:template]
|
81
|
+
if template
|
82
|
+
result[1]['Content-Type'] = 'text/html'
|
83
|
+
result[2] = render_template(actions, context, template, result[2])
|
84
|
+
end
|
85
|
+
else
|
86
|
+
result = [401, {}, 'Resource not specified']
|
87
|
+
end
|
88
|
+
result
|
89
|
+
end
|
65
90
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
91
|
+
# Proxy method used when routing
|
92
|
+
# @param [Array] actions the allowed actions for this URI
|
93
|
+
# @param [Hash] context the context for this request
|
94
|
+
# @return [Response] a Rack Response triplet, or status code
|
95
|
+
def self.invoke(actions, context)
|
96
|
+
case context.action
|
97
|
+
when :create, :update, :delete
|
98
|
+
context.forward(context.action)
|
99
|
+
when :read
|
100
|
+
if context.uri[3]
|
101
|
+
do_read(actions, context, :read)
|
102
|
+
else
|
103
|
+
do_read(actions, context, :readAll)
|
104
|
+
end
|
105
|
+
else
|
106
|
+
405
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
85
110
|
end
|