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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ebd683681680431232080fb04b684f7096990ea
4
- data.tar.gz: 7f2eb0f1413f4b05dba58f0f6cf4b5687d9faacc
3
+ metadata.gz: 505ec6c0b755cfae4d95193fe452246ecec7bb56
4
+ data.tar.gz: aff6de3c8994e6fa3cfc85a19f60942a1d2a77cf
5
5
  SHA512:
6
- metadata.gz: 9c135eb80f258c823ea98467fb958696fdf99e1587fd797130e2b1cb2f5d6d3aa11bb1d261c105b33997b3fe1a5a997905c7d4bae6c5746bd68d3cb5733864fc
7
- data.tar.gz: 9d4df9a01574a401b93d90f5ce8330d2a0ddef27271264d2254abda8492c522494f777a8cfb1d4c98f3c39eea33e2ee3f7e70a3b67cc8781ab19310ade63d180
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
- - Database connection
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= @params.merge Hash[callpath[:params].zip @infos[:path]]
14
- @params= @params.select{|k,v|k}
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
- def self.ct_plain
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
- # Fill params with default parameters (status, plain errors)
30
- def self.set_default_params params
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
- if (params.keys & [:plain, :html, :json, :type]).empty?
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[:plain] ||= params[:content] || "Error: #{params[:status]} code"
45
+ params[:content] = "Error: #{params[:status]} code"
37
46
  elsif params[:status].to_s.match(/^[3]\d\d$/)
38
- params[:plain] ||= params[:content] || "Redirected: #{params[:status]} code"
47
+ params[:content] = "Redirected: #{params[:status]} code"
39
48
  else
40
- params[:plain] ||= params[:content] || "Status: #{params[:status]} code"
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
- # search the content to render from the params,
53
- # based on content_type (plain, html, ...).
54
- # If not, check for specific type
55
- def self.params_content_type_value params
56
- type = params_content_type(params)
57
- if type
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
- params_content_type_value(params),
71
- [params[params_content_type(params) || :content]],
72
+ params[:type],
73
+ [params[:content]],
72
74
  ]
73
75
  end
74
76
 
data/version CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.1.11
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nephos-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a