wire-framework 0.1.5.3 → 0.1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/app/db.rb +6 -6
- data/lib/app/render/page.rb +30 -28
- data/lib/app/render/partial.rb +37 -30
- data/lib/wire.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b5de5f8f3c28bf3c2ef3b16bef0bafe113e1051
|
4
|
+
data.tar.gz: 5b544c2cedf9eecb08b7be6a03bfa7e74f1f89b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bf313c114a0f4290cb63b6a71a8bba334eef09766d666fbe21245d2040b96f1bc3944b6764f8476fae9ac80f601b5b85f51961c5c4ab8dca8dd26d938fafdc9
|
7
|
+
data.tar.gz: 7855b60d903c318c3ed4eb537eb859e4b78da08e792cc59925ceab335570d0cc6719d82e800ab15ef239c43b47ecfc4af6430ff9333646e0d38d6c5ce88ae22b
|
data/lib/app/db.rb
CHANGED
@@ -115,14 +115,13 @@ module DB
|
|
115
115
|
def self.do_read(context)
|
116
116
|
model = context.config['models'][context.resource]
|
117
117
|
return 404 unless model
|
118
|
-
id = context.
|
118
|
+
id = context.uri[3]
|
119
119
|
if id.eql?('new') or id.eql? 'upload'
|
120
120
|
return '{}'
|
121
121
|
end
|
122
122
|
object = model[id]
|
123
|
-
|
124
|
-
|
125
|
-
end
|
123
|
+
return 404 unless object
|
124
|
+
[200, {}, object.to_json]
|
126
125
|
end
|
127
126
|
|
128
127
|
# Update a specific object in the DB table
|
@@ -131,7 +130,8 @@ module DB
|
|
131
130
|
def self.do_update(context)
|
132
131
|
model = context.config['models'][context.resource]
|
133
132
|
return 404 unless model
|
134
|
-
instance = model[context.
|
133
|
+
instance = model[context.uri[3]]
|
134
|
+
return 404 unless instance
|
135
135
|
instance.update(context.json)
|
136
136
|
end
|
137
137
|
|
@@ -141,7 +141,7 @@ module DB
|
|
141
141
|
def self.do_delete(context)
|
142
142
|
model = context.config['models'][context.resource]
|
143
143
|
return 404 unless model
|
144
|
-
instance = model[context.
|
144
|
+
instance = model[context.uri[3]]
|
145
145
|
if instance
|
146
146
|
if instance.delete
|
147
147
|
200
|
data/lib/app/render/page.rb
CHANGED
@@ -27,34 +27,36 @@ module Render
|
|
27
27
|
# @return [Response] a Rack Response triplet, or status code
|
28
28
|
def self.render_template(actions, context, template, content)
|
29
29
|
if template['file']
|
30
|
-
hash = {
|
31
|
-
template['sources']
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
30
|
+
hash = {actions: actions, context: context, content: content}
|
31
|
+
if template['sources']
|
32
|
+
template['sources'].each do |k, s|
|
33
|
+
uri = "http://#{context.config['remote'].split('/')[0]}"
|
34
|
+
go_ahead = true
|
35
|
+
if s.is_a? Hash
|
36
|
+
uri += "/#{s['uri']}"
|
37
|
+
case s['key']
|
38
|
+
when 'user'
|
39
|
+
go_ahead = (context.user and !context.user.empty?)
|
40
|
+
uri += "/#{context.user}"
|
41
|
+
when 'resource'
|
42
|
+
go_ahead = (context.resource and !context.resource.empty?)
|
43
|
+
uri += "/#{context.resource}"
|
44
|
+
else
|
45
|
+
# do nothing
|
46
|
+
end
|
47
|
+
else
|
48
|
+
uri += "/#{s}"
|
45
49
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
rescue
|
57
|
-
hash[k.to_sym] = temp[2]
|
50
|
+
temp = []
|
51
|
+
if go_ahead
|
52
|
+
temp = RL.request(:get, uri, {remote_user: context.user})
|
53
|
+
end
|
54
|
+
if temp[0] == 200
|
55
|
+
begin
|
56
|
+
hash[k.to_sym] = JSON.parse_clean(temp[2])
|
57
|
+
rescue
|
58
|
+
hash[k.to_sym] = temp[2]
|
59
|
+
end
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
@@ -77,7 +79,7 @@ module Render
|
|
77
79
|
if context.resource
|
78
80
|
result = context.forward(specific)
|
79
81
|
#TODO: fix lookup
|
80
|
-
name
|
82
|
+
name = context.config['template']
|
81
83
|
template = $wire_templates[name]
|
82
84
|
if template
|
83
85
|
result[1]['Content-Type'] = 'text/html'
|
data/lib/app/render/partial.rb
CHANGED
@@ -28,14 +28,11 @@ module Render
|
|
28
28
|
def self.configure(conf)
|
29
29
|
conf['resources'].each do |k, v|
|
30
30
|
if v.is_a? Hash
|
31
|
-
conf['resources'][k]['multiple'] = Tilt.new(v['multiple'], 1, {
|
32
|
-
conf['resources'][k]['single'] = Tilt.new(v['single'], 1, {
|
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
33
|
elsif v.is_a? String
|
34
34
|
#TODO: fix needless duplication
|
35
|
-
conf['resources'][k] = {
|
36
|
-
'multiple': Tilt.new(v, 1, { ugly: true }),
|
37
|
-
'single': Tilt.new(v, 1, { ugly: true })
|
38
|
-
}
|
35
|
+
conf['resources'][k] = {'all' => Tilt.new(v, 1, {ugly: true})}
|
39
36
|
end
|
40
37
|
end
|
41
38
|
conf
|
@@ -46,33 +43,37 @@ module Render
|
|
46
43
|
# @param [Hash] context the context for this request
|
47
44
|
# @return [Response] a Rack Response triplet, or status code
|
48
45
|
def self.do_read_all(actions, context)
|
49
|
-
resource = context.uri[2]
|
50
46
|
body = ''
|
51
47
|
mime = ''
|
52
|
-
|
48
|
+
resource = context.config['resources'][context.resource]
|
49
|
+
if resource['use_forward']
|
53
50
|
response = context.forward(:readAll)
|
54
51
|
return response if response[0] != 200
|
55
52
|
mime = response[1][:content_type]
|
56
53
|
body = response[2]
|
57
54
|
end
|
58
|
-
|
55
|
+
if resource['all']
|
56
|
+
template = resource['all']
|
57
|
+
else
|
58
|
+
template = resource['multiple']
|
59
|
+
end
|
59
60
|
if template
|
60
|
-
hash = {
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
if
|
65
|
-
|
61
|
+
hash = {actions: actions,
|
62
|
+
resource: resource,
|
63
|
+
mime: mime,
|
64
|
+
response: body}
|
65
|
+
if resource['extras']
|
66
|
+
resource['extras'].each do |k, v|
|
66
67
|
hash[k] = RL.request(:get,
|
67
|
-
"http://#{context.
|
68
|
-
{
|
68
|
+
"http://#{context.config['remote']}/#{v}",
|
69
|
+
{remote_user: context.user}
|
69
70
|
)[2]
|
70
71
|
end
|
71
72
|
end
|
72
73
|
mime = 'text/html'
|
73
74
|
body = template.render(self, hash)
|
74
75
|
end
|
75
|
-
[200, {
|
76
|
+
[200, {'Content-Type': mime}, body]
|
76
77
|
end
|
77
78
|
|
78
79
|
# Read a Partial and render it to HTML
|
@@ -82,29 +83,35 @@ module Render
|
|
82
83
|
def self.do_read(actions, context)
|
83
84
|
body = ''
|
84
85
|
mime = ''
|
85
|
-
|
86
|
+
resource = context.config['resources'][context.resource]
|
87
|
+
|
88
|
+
if resource['use_forward']
|
86
89
|
response = context.forward(:read)
|
87
90
|
return response if response[0] != 200
|
88
91
|
mime = response[1][:content_type]
|
89
92
|
body = response[2]
|
90
93
|
end
|
91
|
-
|
94
|
+
if resource['all']
|
95
|
+
template = resource['all']
|
96
|
+
else
|
97
|
+
template = resource['single']
|
98
|
+
end
|
92
99
|
if template
|
93
|
-
hash = {
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
if
|
100
|
-
|
101
|
-
hash[k] = RL.request(:get, "http://#{context.
|
100
|
+
hash = {actions: actions,
|
101
|
+
app: context.app,
|
102
|
+
resource: context.resource,
|
103
|
+
id: context.id,
|
104
|
+
mime: mime,
|
105
|
+
response: body}
|
106
|
+
if resource['extras']
|
107
|
+
resource['extras'].each do |k, v|
|
108
|
+
hash[k] = RL.request(:get, "http://#{context.config[:remote_host]}/#{v}")[2]
|
102
109
|
end
|
103
110
|
end
|
104
111
|
mime = 'text/html'
|
105
112
|
body = template.render(self, hash)
|
106
113
|
end
|
107
|
-
[200, {
|
114
|
+
[200, {'Content-Type': mime}, body]
|
108
115
|
end
|
109
116
|
|
110
117
|
# Proxy method used when routing
|
data/lib/wire.rb
CHANGED