wire-framework 0.1.4.15 → 0.1.4.16
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/lib/app/cache.rb +17 -28
- data/lib/app/db.rb +16 -7
- data/lib/app/history/svn.rb +6 -11
- data/lib/app/render.rb +16 -20
- data/lib/app/render/document.rb +10 -18
- data/lib/app/render/editor.rb +9 -15
- data/lib/app/render/error.rb +10 -25
- data/lib/app/render/page.rb +10 -26
- data/lib/app/render/partial.rb +31 -40
- data/lib/app/render/style.rb +7 -11
- data/lib/wire.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eea3c0482d64af86058b1aedb0f7db041125b326
|
4
|
+
data.tar.gz: f65c26db02144d4bf72eae3c963db99c91ec69a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d8ae75a3d7d99b00423e518f3846b1e9bc18c8152afe563feea1487f427a767dae0f923f9a534ef5b5128843e66997925b565f2c45608d2b1c327086d1ad8e4
|
7
|
+
data.tar.gz: 89f722fc74dd12e378cdab09c6ad6a7d331948b5837b14a2b6314e46f5f0bb7e0418f03fd0ad56abc67016cf64c1cbaefee21d04241f5409acc8f2b61b460e2e
|
data/lib/app/cache.rb
CHANGED
@@ -17,40 +17,33 @@ module Cache
|
|
17
17
|
all = context.uri[0..2].join('/')
|
18
18
|
env = $cache[context.app[:remote_uri]]
|
19
19
|
db = env.database
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
else
|
32
|
-
db[uri] = result
|
33
|
-
end
|
20
|
+
if context.uri[3]
|
21
|
+
result = forward(:read,context)
|
22
|
+
else
|
23
|
+
result = forward(:readAll,context)
|
24
|
+
end
|
25
|
+
if result[0] == 200
|
26
|
+
env.transaction do
|
27
|
+
if context.action == :delete
|
28
|
+
db.destroy(uri)
|
29
|
+
else
|
30
|
+
db[uri] = result[2]
|
34
31
|
end
|
35
32
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
if
|
33
|
+
end
|
34
|
+
if [:create,:update,:delete].include? context.action
|
35
|
+
thing = forward(:readAll,context)
|
36
|
+
if thing[0] == 200
|
40
37
|
env.transaction do
|
41
|
-
db[all] = thing
|
38
|
+
db[all] = thing[2]
|
42
39
|
end
|
43
40
|
end
|
44
|
-
rescue RestClient::ResourceNotFound
|
45
|
-
# gracefully ignore
|
46
|
-
result = 404
|
47
41
|
end
|
48
42
|
result
|
49
43
|
end
|
50
44
|
|
51
45
|
def self.get_cached(context)
|
52
46
|
uri = context.uri.join('/')
|
53
|
-
|
54
47
|
env = $cache[context.app[:remote_uri]]
|
55
48
|
db = env.database
|
56
49
|
result = nil
|
@@ -82,7 +75,6 @@ module Cache
|
|
82
75
|
$cache[context.app[:remote_uri]] = LMDB.new("/tmp/cache/#{context.app[:remote_uri]}", mapsize: 2**30)
|
83
76
|
end
|
84
77
|
|
85
|
-
begin
|
86
78
|
case context.action
|
87
79
|
when :create,:update,:delete
|
88
80
|
result = forward(context.action,context)
|
@@ -94,14 +86,11 @@ module Cache
|
|
94
86
|
cached = update_cached(context)
|
95
87
|
end
|
96
88
|
if cached
|
97
|
-
cached
|
89
|
+
[200,{},cached]
|
98
90
|
else
|
99
91
|
404
|
100
92
|
end
|
101
93
|
end
|
102
|
-
rescue RestClient::ResourceNotFound
|
103
|
-
404
|
104
|
-
end
|
105
94
|
end
|
106
95
|
end
|
107
96
|
end
|
data/lib/app/db.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'data_objects'
|
1
2
|
require 'dm-serializer/to_json'
|
2
3
|
require_relative '../app'
|
3
4
|
require_relative '../closet/resource'
|
@@ -63,7 +64,6 @@ module DB
|
|
63
64
|
end
|
64
65
|
end
|
65
66
|
if errors.length > 0
|
66
|
-
ap errors
|
67
67
|
[400, nil, errors]
|
68
68
|
else
|
69
69
|
200
|
@@ -79,12 +79,21 @@ module DB
|
|
79
79
|
if model.instance_methods.include?(:created_by)
|
80
80
|
context.json[:created_by] = context.user
|
81
81
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
82
|
+
begin
|
83
|
+
instance = model.create(context.json)
|
84
|
+
instance.save
|
85
|
+
if instance.saved?
|
86
|
+
200
|
87
|
+
else
|
88
|
+
[504,{}, instance.errors]
|
89
|
+
end
|
90
|
+
rescue => e
|
91
|
+
case e.class
|
92
|
+
when DataObjects::IntegrityError.class
|
93
|
+
[400,{},e.message]
|
94
|
+
else
|
95
|
+
[500,{},e.message]
|
96
|
+
end
|
88
97
|
end
|
89
98
|
end
|
90
99
|
else
|
data/lib/app/history/svn.rb
CHANGED
@@ -16,18 +16,13 @@ module History
|
|
16
16
|
# @return [Hash] the history entries
|
17
17
|
def self.get_log(web, repo, id = nil)
|
18
18
|
options = "--username #{$environment[:repos_user]} --password #{$environment[:repos_password]}"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
log = `svn log #{options} -v --xml 'svn://localhost/#{repo}/#{id}'`
|
24
|
-
else
|
25
|
-
log = `svn log #{options} -v --xml 'svn://localhost/#{repo}/#{web}/#{id}'`
|
26
|
-
end
|
27
|
-
end
|
28
|
-
unless $?.exitstatus == 0
|
29
|
-
return 404
|
19
|
+
uri = "svn://localhost/#{repo}"
|
20
|
+
if id
|
21
|
+
uri += "/#{web}" if web
|
22
|
+
uri += "/#{id}"
|
30
23
|
end
|
24
|
+
log = `svn log #{options} -v --xml '#{uri}'`
|
25
|
+
return 404 if $?.exitstatus != 0
|
31
26
|
log = CobraVsMongoose.xml_to_hash(log)
|
32
27
|
log['log']['logentry']
|
33
28
|
end
|
data/lib/app/render.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'nokogiri'
|
2
|
-
require 'rest-client'
|
3
2
|
require 'awesome_print'
|
3
|
+
require 'rest-less'
|
4
4
|
require 'docile'
|
5
5
|
require 'tilt'
|
6
6
|
require 'json'
|
@@ -87,6 +87,14 @@ module Render
|
|
87
87
|
single(template)
|
88
88
|
end
|
89
89
|
|
90
|
+
CONVERT = {
|
91
|
+
create: :post,
|
92
|
+
read: :get,
|
93
|
+
readAll: :get,
|
94
|
+
update: :put,
|
95
|
+
delete: :delete
|
96
|
+
}
|
97
|
+
|
90
98
|
# Proxy method used when forwarding requests
|
91
99
|
# @param [Symbol] method the action to use when forwarding
|
92
100
|
# @param [Hash] context the context for this request
|
@@ -99,24 +107,12 @@ module Render
|
|
99
107
|
q = '?' + context.query_string
|
100
108
|
id = context.uri[3...context.uri.length].join('/')
|
101
109
|
headers = {referer: referer, remote_user: context.user}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
when :readAll
|
110
|
-
$stderr.puts "GET: Forward Request to https://#{host}/#{path}/#{resource}#{q}"
|
111
|
-
RestClient.get "http://#{host}/#{path}/#{resource}#{q}", headers
|
112
|
-
when :read
|
113
|
-
$stderr.puts "GET: Forward Request to https://#{host}/#{path}/#{resource}/#{id}#{q}"
|
114
|
-
RestClient.get "http://#{host}/#{path}/#{resource}/#{id}#{q}", headers
|
115
|
-
when :delete
|
116
|
-
$stderr.puts "DELETE: Forward Request to https://#{host}/#{path}/#{resource}/#{id}#{q}"
|
117
|
-
RestClient.delete "http://#{host}/#{path}/#{resource}/#{id}#{q}" , headers
|
118
|
-
else
|
119
|
-
401
|
120
|
-
end
|
110
|
+
verb = CONVERT[method]
|
111
|
+
uri = "http://#{host}/#{path}/#{resource}"
|
112
|
+
uri += id if [:update,:get,: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
|
121
117
|
end
|
122
118
|
end
|
data/lib/app/render/document.rb
CHANGED
@@ -12,18 +12,14 @@ module Render
|
|
12
12
|
# @param [Symbol] specific the type of read to perform
|
13
13
|
# @return [Response] a Rack Response triplet, or status code
|
14
14
|
def self.do_read(actions, context, specific)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
response
|
24
|
-
end
|
25
|
-
rescue RestClient::ResourceNotFound => e
|
26
|
-
[404, {}, [e.response]]
|
15
|
+
response = forward(specific, context)
|
16
|
+
mime = response[1][:content_type]
|
17
|
+
renderer = $renderers[mime]
|
18
|
+
if renderer
|
19
|
+
template = $templates[renderer]
|
20
|
+
template.render(self, { actions: actions, context: context, mime: mime, response: response[2] })
|
21
|
+
else
|
22
|
+
response
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
@@ -33,18 +29,14 @@ module Render
|
|
33
29
|
# @return [Response] a Rack Response triplet, or status code
|
34
30
|
def self.invoke(actions, context)
|
35
31
|
case context.action
|
36
|
-
when :create
|
37
|
-
forward(
|
32
|
+
when :create,:update,:delete
|
33
|
+
forward(context.action, context)
|
38
34
|
when :read
|
39
35
|
if context.uri[3]
|
40
36
|
do_read(actions, context, :read)
|
41
37
|
else
|
42
38
|
do_read(actions, context, :readAll)
|
43
39
|
end
|
44
|
-
when :update
|
45
|
-
forward(:update, context)
|
46
|
-
when :delete
|
47
|
-
forward(:delete, context)
|
48
40
|
else
|
49
41
|
405
|
50
42
|
end
|
data/lib/app/render/editor.rb
CHANGED
@@ -15,17 +15,13 @@ module Render
|
|
15
15
|
resource = context.uri[2]
|
16
16
|
query = context.query
|
17
17
|
id = context.uri[3...context.uri.length].join('/')
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
mime = query[:type]
|
26
|
-
else
|
27
|
-
return [404, {}, 'EDITOR: Document type not set for new document']
|
28
|
-
end
|
18
|
+
response = forward(:read, context)
|
19
|
+
return response if response[0] != 200
|
20
|
+
body = response[2]
|
21
|
+
if query[:type]
|
22
|
+
mime = query[:type]
|
23
|
+
else
|
24
|
+
return [404, {}, 'EDITOR: Document type not set for new document']
|
29
25
|
end
|
30
26
|
template = $editors[mime]
|
31
27
|
if template
|
@@ -41,12 +37,10 @@ module Render
|
|
41
37
|
# @return [Response] a Rack Response triplet, or status code
|
42
38
|
def self.invoke(actions, context)
|
43
39
|
case context.action
|
44
|
-
when :create
|
45
|
-
forward(
|
40
|
+
when :create,:update
|
41
|
+
forward(context.action, context)
|
46
42
|
when :read
|
47
43
|
do_read(actions, context)
|
48
|
-
when :update
|
49
|
-
forward(:update, context)
|
50
44
|
else
|
51
45
|
405
|
52
46
|
end
|
data/lib/app/render/error.rb
CHANGED
@@ -14,7 +14,7 @@ module Render
|
|
14
14
|
def self.error_check(actions, context, result)
|
15
15
|
errors = context.app[:errors]
|
16
16
|
if errors
|
17
|
-
template = errors[result
|
17
|
+
template = errors[result[0]]
|
18
18
|
if template
|
19
19
|
result[2] = template.render(self, {actions: actions, context: context, result: result})
|
20
20
|
end
|
@@ -23,32 +23,17 @@ module Render
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.invoke(actions, context)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
result = forward(:read, context)
|
33
|
-
else
|
34
|
-
result = forward(:readAll, context)
|
35
|
-
end
|
36
|
-
when :update
|
37
|
-
result = forward(:update, context)
|
26
|
+
case context.action
|
27
|
+
when :create,:update
|
28
|
+
result = forward(context.action, context)
|
29
|
+
when :read
|
30
|
+
if context.uri[3]
|
31
|
+
result = forward(:read, context)
|
38
32
|
else
|
39
|
-
result =
|
40
|
-
end
|
41
|
-
if result.is_a? Fixnum
|
42
|
-
result = [result,{},[]]
|
43
|
-
else
|
44
|
-
headers = {}
|
45
|
-
result.headers.each do |k,v|
|
46
|
-
headers[k.to_s.capitalize] = v
|
33
|
+
result = forward(:readAll, context)
|
47
34
|
end
|
48
|
-
|
49
|
-
|
50
|
-
rescue RestClient::ResourceNotFound => e
|
51
|
-
result = [404,{},e.to_s]
|
35
|
+
else
|
36
|
+
result = 405
|
52
37
|
end
|
53
38
|
error_check(actions, context, result)
|
54
39
|
end
|
data/lib/app/render/page.rb
CHANGED
@@ -29,11 +29,7 @@ module Render
|
|
29
29
|
end
|
30
30
|
temp = nil
|
31
31
|
if go_ahead
|
32
|
-
|
33
|
-
temp = RestClient.get uri
|
34
|
-
rescue RestClient::ResourceNotFound
|
35
|
-
temp = nil
|
36
|
-
end
|
32
|
+
temp = RL.request(:get, uri)[2]
|
37
33
|
end
|
38
34
|
hash[k] = temp
|
39
35
|
end
|
@@ -53,26 +49,18 @@ module Render
|
|
53
49
|
# @param [Symbol] specific the kind of read to perform
|
54
50
|
# @return [Response] a Rack Response triplet, or status code
|
55
51
|
def do_read(actions, context, specific)
|
56
|
-
template = context.app[:template]
|
57
52
|
resource = context.uri[2]
|
58
|
-
message = 'Resource not specified'
|
59
|
-
headers = {}
|
60
53
|
if resource
|
61
|
-
|
62
|
-
|
63
|
-
status = 200
|
64
|
-
rescue RestClient::ResourceNotFound => e
|
65
|
-
result = e.response
|
66
|
-
status = 404
|
67
|
-
end
|
54
|
+
result = forward(specific, context)
|
55
|
+
template = context.app[:template]
|
68
56
|
if template
|
69
|
-
|
70
|
-
|
71
|
-
headers['Content-Type'] = result.headers[:content_type]
|
72
|
-
message = [status, headers, result]
|
57
|
+
result[1]['Content-Type'] = 'text/html'
|
58
|
+
result[2] = render_template(actions, context, template, result)
|
73
59
|
end
|
60
|
+
else
|
61
|
+
result = [401,{},'Resource not specified']
|
74
62
|
end
|
75
|
-
|
63
|
+
result
|
76
64
|
end
|
77
65
|
|
78
66
|
# Proxy method used when routing
|
@@ -81,18 +69,14 @@ module Render
|
|
81
69
|
# @return [Response] a Rack Response triplet, or status code
|
82
70
|
def self.invoke(actions, context)
|
83
71
|
case context.action
|
84
|
-
when :create
|
85
|
-
forward(
|
72
|
+
when :create,:update,:delete
|
73
|
+
forward(context.action, context)
|
86
74
|
when :read
|
87
75
|
if context.uri[3]
|
88
76
|
do_read(actions, context, :read)
|
89
77
|
else
|
90
78
|
do_read(actions, context, :readAll)
|
91
79
|
end
|
92
|
-
when :update
|
93
|
-
forward(:update, context)
|
94
|
-
when :delete
|
95
|
-
forward(:delete, context)
|
96
80
|
else
|
97
81
|
405
|
98
82
|
end
|
data/lib/app/render/partial.rb
CHANGED
@@ -29,33 +29,26 @@ module Render
|
|
29
29
|
# @return [Response] a Rack Response triplet, or status code
|
30
30
|
def self.do_read_all(actions, context)
|
31
31
|
resource = context.uri[2]
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
template = context.resource[:multiple]
|
32
|
+
body = ''
|
33
|
+
mime = ''
|
34
|
+
if context.resource[:forward]
|
35
|
+
response = forward(:readAll, context)
|
36
|
+
return response if response[0] != 200
|
37
|
+
mime = response[1][:content_type]
|
38
|
+
body = response[2]
|
39
|
+
end
|
40
|
+
template = context.resource[:multiple]
|
41
|
+
if template
|
44
42
|
hash = { actions: actions, resource: resource, mime: mime, response: body }
|
45
43
|
if context.resource[:sources]
|
46
44
|
context.resource[:sources].each do |k, v|
|
47
|
-
hash[k] =
|
45
|
+
hash[k] = RL.request(:get, "http://#{context.app[:remote_host]}/#{v}")[2]
|
48
46
|
end
|
49
47
|
end
|
50
48
|
mime = 'text/html'
|
51
|
-
|
52
|
-
[200, { 'Content-Type' => mime }, [template.render(self, hash)]]
|
53
|
-
else
|
54
|
-
[200, { 'Content-Type' => mime }, [body]]
|
55
|
-
end
|
56
|
-
rescue RestClient::ResourceNotFound
|
57
|
-
404
|
49
|
+
body = template.render(self,hash)
|
58
50
|
end
|
51
|
+
[200,{'Content-Type' => mime },body]
|
59
52
|
end
|
60
53
|
|
61
54
|
# Read a Partial and render it to HTML
|
@@ -63,27 +56,29 @@ module Render
|
|
63
56
|
# @param [Hash] context the context for this request
|
64
57
|
# @return [Response] a Rack Response triplet, or status code
|
65
58
|
def self.do_read(actions, context)
|
66
|
-
app = context.
|
59
|
+
app = context.uri[1]
|
67
60
|
resource = context.uri[2]
|
68
|
-
|
61
|
+
id = context.uri[3...context.uri.length].join('/')
|
62
|
+
body = ''
|
63
|
+
mime = ''
|
64
|
+
if context.resource[:forward]
|
69
65
|
response = forward(:read, context)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
return response if response[0] != 200
|
67
|
+
mime = response[1][:content_type]
|
68
|
+
body = response[2]
|
69
|
+
end
|
70
|
+
template = context.resource[:single]
|
71
|
+
if template
|
72
|
+
hash = { actions: actions, app: app, resource: resource, id: id, mime: mime, response: body }
|
74
73
|
if context.resource[:sources]
|
75
74
|
context.resource[:sources].each do |k, v|
|
76
|
-
hash[k] =
|
75
|
+
hash[k] = RL.request(:get, "http://#{context.app[:remote_host]}/#{v}")[2]
|
77
76
|
end
|
78
77
|
end
|
79
|
-
|
80
|
-
|
81
|
-
else
|
82
|
-
[200, { 'Content-Type' => 'text/plain' }, [response.body]]
|
83
|
-
end
|
84
|
-
rescue RestClient::ResourceNotFound
|
85
|
-
404
|
78
|
+
mime = 'text/html'
|
79
|
+
body = template.render(self,hash)
|
86
80
|
end
|
81
|
+
[200,{'Content-Type' => mime },body]
|
87
82
|
end
|
88
83
|
|
89
84
|
# Proxy method used when routing
|
@@ -92,18 +87,14 @@ module Render
|
|
92
87
|
# @return [Response] a Rack Response triplet, or status code
|
93
88
|
def self.invoke(actions, context)
|
94
89
|
case context.action
|
95
|
-
when :create
|
96
|
-
forward(
|
90
|
+
when :create,:update,:delete
|
91
|
+
forward(context.action, context)
|
97
92
|
when :read
|
98
93
|
if context.uri[3]
|
99
94
|
do_read(actions, context)
|
100
95
|
else
|
101
96
|
do_read_all(actions, context)
|
102
97
|
end
|
103
|
-
when :update
|
104
|
-
forward(:update, context)
|
105
|
-
when :delete
|
106
|
-
forward(:delete, context)
|
107
98
|
else
|
108
99
|
403
|
109
100
|
end
|
data/lib/app/render/style.rb
CHANGED
@@ -21,17 +21,13 @@ module Render
|
|
21
21
|
# @param [Hash] context the context for this request
|
22
22
|
# @return [Response] a Rack Response triplet, or status code
|
23
23
|
def self.do_read_all(context)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
else
|
32
|
-
500
|
33
|
-
end
|
34
|
-
rescue RestClient::ResourceNotFound
|
24
|
+
resource = context.uri[2]
|
25
|
+
template = context.app[:styles][resource]
|
26
|
+
headers = {'Cache-Control' => 'public,max-age=3600'}
|
27
|
+
if template
|
28
|
+
headers['Content-Type'] = 'text/css'
|
29
|
+
[200, headers, [template]]
|
30
|
+
else
|
35
31
|
404
|
36
32
|
end
|
37
33
|
end
|
data/lib/wire.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wire-framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.4.
|
4
|
+
version: 0.1.4.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan T. Meyers
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name: rest-
|
126
|
+
name: rest-less
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|