nephos-server 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -2
- data/lib/nephos-server/routing/controller.rb +2 -2
- data/lib/nephos-server/routing/load.rb +2 -1
- data/lib/nephos-server/server/responder.rb +36 -34
- data/version +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: 505ec6c0b755cfae4d95193fe452246ecec7bb56
|
4
|
+
data.tar.gz: aff6de3c8994e6fa3cfc85a19f60942a1d2a77cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06aa251c55dd7ac4234aa5a2fdbc3ba428639c5a4bb3fcca97f6147ef6e96d31ed0ac4a062e58c6bff2201343b36b1f6028c4fdb91aaf05c2c1bcd2c15e51dcf
|
7
|
+
data.tar.gz: 9bee705a410c42ff8765635f2bd12781715e72010fefc51190ef928c1f960a38816c8664c1d3c94df49700d4badedc8c22e97fa16231aa42f5162cbb9e1266ad
|
data/README.md
CHANGED
@@ -12,11 +12,30 @@ This is a simple web server, based on rack and puma, with a minimal help:
|
|
12
12
|
- Rendering
|
13
13
|
- Routing
|
14
14
|
|
15
|
+
No templating, no database by default. They are extensions of your choice.
|
15
16
|
|
16
|
-
# TODO
|
17
17
|
|
18
|
-
|
18
|
+
# TODO
|
19
19
|
|
20
|
+
## TODO v0.2
|
21
|
+
|
22
|
+
- Test
|
23
|
+
- Unitary tests
|
24
|
+
- rendering
|
25
|
+
- routing
|
26
|
+
- Documentation
|
27
|
+
- Render Api
|
28
|
+
- Routing
|
29
|
+
|
30
|
+
## TODO v1
|
31
|
+
- Improved Routing (more helper options)
|
32
|
+
- Improved Rendering (more options)
|
33
|
+
- Guide about
|
34
|
+
- Controllers
|
35
|
+
- Routing
|
36
|
+
- Api Creation
|
37
|
+
- Database creation
|
38
|
+
- Web HTML with templating
|
20
39
|
|
21
40
|
# Start
|
22
41
|
|
@@ -10,8 +10,8 @@ module Nephos
|
|
10
10
|
@infos= parsed
|
11
11
|
@callpath= callpath
|
12
12
|
@params= parsed[:args]
|
13
|
-
@params
|
14
|
-
@params
|
13
|
+
@params.merge! Hash[callpath[:params].zip @infos[:path]]
|
14
|
+
@params.select!{|k,v|k}
|
15
15
|
end
|
16
16
|
|
17
17
|
def arguments
|
@@ -11,8 +11,9 @@ module Nephos
|
|
11
11
|
p.match(/:\w+/) ? {p: "[[:graph:]]+", name: p} : {p: p, name: nil}
|
12
12
|
end
|
13
13
|
url = params.map{|e| e[:p]}.join("/")
|
14
|
+
url = "/" if url.empty?
|
14
15
|
what[:match] = /^#{url}$/
|
15
|
-
what[:params] = params.map{|e| e[:name] && e[:name][1..-1]}[1..-1]
|
16
|
+
what[:params] = params.map{|e| e[:name] && e[:name][1..-1]}[1..-1] || []
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.check!(what)
|
@@ -8,15 +8,7 @@ module Nephos
|
|
8
8
|
def self.content_type(kind, type, charset='UTF-8')
|
9
9
|
{'Content-type' => "#{kind}/#{type}" + CT_CHARSET_PREFIX + charset}
|
10
10
|
end
|
11
|
-
|
12
|
-
content_type(:text, :plain)
|
13
|
-
end
|
14
|
-
def self.ct_html
|
15
|
-
content_type(:text, :html)
|
16
|
-
end
|
17
|
-
def self.ct_json
|
18
|
-
content_type(:text, :javascript)
|
19
|
-
end
|
11
|
+
|
20
12
|
# @param params [Hash] containing :type => "kind/type", example: "text/html"
|
21
13
|
def self.ct_specific(params)
|
22
14
|
kind, type = params[:type].match(/^(\w+)\/(\w+)$/)[1..2]
|
@@ -26,39 +18,49 @@ module Nephos
|
|
26
18
|
content_type(kind, type)
|
27
19
|
end
|
28
20
|
|
29
|
-
|
30
|
-
|
21
|
+
PRESET_CT = {
|
22
|
+
plain: "text/plain",
|
23
|
+
html: "text/html",
|
24
|
+
json: "text/javascript",
|
25
|
+
}
|
26
|
+
|
27
|
+
private
|
28
|
+
# if not :status entry, set to 200
|
29
|
+
def self.set_default_params_status params
|
31
30
|
if (params.keys & [:status]).empty?
|
32
31
|
params[:status] ||= 200
|
33
32
|
end
|
34
|
-
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.set_default_params_type params
|
36
|
+
return if not params[:type].nil?
|
37
|
+
params[:type] = PRESET_CT[(params.keys & [:plain, :html, :json]).first || :plain]
|
38
|
+
params[:type] = ct_specific(params)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.set_default_params_content params
|
42
|
+
type = (params.keys & [:plain, :html, :json, :content]).first
|
43
|
+
if type.nil?
|
35
44
|
if params[:status].to_s.match(/^[45]\d\d$/)
|
36
|
-
params[:
|
45
|
+
params[:content] = "Error: #{params[:status]} code"
|
37
46
|
elsif params[:status].to_s.match(/^[3]\d\d$/)
|
38
|
-
params[:
|
47
|
+
params[:content] = "Redirected: #{params[:status]} code"
|
39
48
|
else
|
40
|
-
params[:
|
49
|
+
params[:content] = "Status: #{params[:status]} code"
|
41
50
|
end
|
51
|
+
else
|
52
|
+
params[type] = params[type].to_json if type == :json
|
53
|
+
params[:content] = params[type]
|
42
54
|
end
|
43
|
-
params
|
44
|
-
end
|
45
|
-
|
46
|
-
# @return [Symbol, nil] :plain, :html, :json, or nil
|
47
|
-
# search the content type
|
48
|
-
def self.params_content_type params
|
49
|
-
(params.keys & [:plain, :html, :json]).first
|
50
55
|
end
|
56
|
+
public
|
51
57
|
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
self.send("ct_#{type}")
|
59
|
-
else
|
60
|
-
self.send("ct_specific", params)
|
61
|
-
end
|
58
|
+
# Fill params with default parameters (status, plain errors)
|
59
|
+
def self.set_default_params params
|
60
|
+
set_default_params_status(params)
|
61
|
+
set_default_params_type(params)
|
62
|
+
set_default_params_content(params)
|
63
|
+
params
|
62
64
|
end
|
63
65
|
|
64
66
|
# @param params [Hash, Symbol]
|
@@ -67,8 +69,8 @@ module Nephos
|
|
67
69
|
params = set_default_params(params)
|
68
70
|
return [
|
69
71
|
params[:status],
|
70
|
-
|
71
|
-
[params[
|
72
|
+
params[:type],
|
73
|
+
[params[:content]],
|
72
74
|
]
|
73
75
|
end
|
74
76
|
|
data/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.11
|