chaplin 0.0.0 → 0.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 913d6d26f30963578fc07305f2a8c3165fcc54c5
4
- data.tar.gz: 9651466b98f18f4ad9d9c746304f5f834a2598a1
3
+ metadata.gz: cbd8ebac77c6a8a27494b48d685dc562f7023358
4
+ data.tar.gz: 3aadf20135b6e120ba278d1a2df293cfeb6dd04a
5
5
  SHA512:
6
- metadata.gz: 7748940639a04dd6cb00fc53fbf61646a69ff71fb7c72617ce831b1aa0b777342b0f7f1e164626498a3c44f61e8b046edbbf273946014f29ad49a6c104a68ce7
7
- data.tar.gz: 387add2e988ad1800459294ce1acaf4d20da74dcab09199ba5b061945679ffa4f47f82121f468b8febb22957e81d29a0ed2bbe3d4f3b8df5c98c4744f7ee8878
6
+ metadata.gz: 1aff9dc262f855bc4b351a2c0832e81a3a083c76d2d9f099a734073535360594ed3e07ba38d3a772b1f110c7bed5482f09dcc89ec82f5c2dad7ba10059488240
7
+ data.tar.gz: b1b93e5ee8c04fa65f12f9bb3d231b3da0f403d96ea8e8e14e48fdd3efe8fbf5bb9f30412922ebab124c9eab2777f3e49e97e886d2ddabc67163e955fd2deb09
@@ -22,19 +22,19 @@ class Chaplin
22
22
  @@default_headers = default_headers || {}
23
23
  end
24
24
 
25
- def render(request_params)
26
- response_body = api_response(request_params).body
25
+ def render(chaplin_request_params)
26
+ response_body = api_response(chaplin_request_params).body
27
27
  return nil if (response_body == 'null' or response_body == '')
28
28
  JSON.parse(response_body)
29
29
  end
30
30
 
31
31
  private
32
32
 
33
- def api_response(request_params)
33
+ def api_response(chaplin_request_params)
34
34
  @@client.send(
35
35
  http_method,
36
- parsed_path(request_params),
37
- api_request_params(request_params),
36
+ parsed_path(chaplin_request_params),
37
+ api_request_params(chaplin_request_params),
38
38
  @@default_headers
39
39
  )
40
40
  end
@@ -55,14 +55,14 @@ class Chaplin
55
55
  @@default_headers.merge(headers)
56
56
  end
57
57
 
58
- def rendered_params(request_params)
58
+ def rendered_params(chaplin_request_params)
59
59
  params.each_with_object({}) do |(key, value), rendered_params|
60
- rendered_params[key] = Mustache.render(value, request_params)
60
+ rendered_params[key] = Mustache.render(value, chaplin_request_params)
61
61
  end
62
62
  end
63
63
 
64
- def parsed_path(request_params)
65
- Mustache.render(path, request_params)
64
+ def parsed_path(chaplin_request_params)
65
+ Mustache.render(path, chaplin_request_params)
66
66
  end
67
67
  end
68
68
  end
@@ -14,6 +14,10 @@ class Chaplin
14
14
  load_json || load_yaml || no_file_found
15
15
  end
16
16
 
17
+ def not_found_page
18
+ app_declaration[404]
19
+ end
20
+
17
21
  private
18
22
 
19
23
  def load_json
@@ -19,12 +19,22 @@ class Chaplin
19
19
  Router.new(routes_declaration, pages, redirects).routes
20
20
  end
21
21
 
22
+ def self.not_found_response(project_path)
23
+ parser.not_found_response(project_path)
24
+ end
25
+
26
+ def not_found_response(project_path)
27
+ self.project_path = project_path
28
+ return unless DeclarationFile.new(project_path).not_found_page
29
+ pages[DeclarationFile.new(project_path).not_found_page]
30
+ end
31
+
22
32
  private
23
33
 
24
34
  attr_accessor :project_path
25
35
 
26
36
  def pages
27
- Pages.load(pages_declaration, project_path, layout_name)
37
+ @pages ||= Pages.load(pages_declaration, project_path, layout_name)
28
38
  end
29
39
 
30
40
  def redirects
@@ -1,7 +1,9 @@
1
1
  require 'sinatra/base'
2
+ require "sinatra/cookies"
2
3
 
3
4
  class Chaplin
4
5
  class Server < Sinatra::Base
6
+ helpers Sinatra::Cookies
5
7
 
6
8
  def self.setup(project_path)
7
9
  set :public_folder, project_path + '/public'
@@ -9,7 +11,8 @@ class Chaplin
9
11
 
10
12
  def self.add_route(endpoint, response)
11
13
  send(endpoint.http_method, endpoint.path) do
12
- response.execute(params, self)
14
+ params_with_cookies = (params || {}).merge(cookies: cookies)
15
+ response.execute(params_with_cookies, self)
13
16
  end
14
17
  end
15
18
  end
data/lib/chaplin.rb CHANGED
@@ -14,6 +14,7 @@ class Chaplin
14
14
  ApiEndpoint.configure(@config.api_url, @config.default_headers, @config.basic_auth)
15
15
  Server.setup(@project_path)
16
16
  build_server
17
+ setup_404_page
17
18
  Server.new
18
19
  end
19
20
 
@@ -25,5 +26,15 @@ class Chaplin
25
26
  end
26
27
  end
27
28
 
29
+ def setup_404_page
30
+ not_found_page = Parser.not_found_response(@project_path)
31
+
32
+ return unless not_found_page
33
+
34
+ Server.not_found do
35
+ not_found_page.execute({}, Server)
36
+ end
37
+ end
38
+
28
39
  end
29
40
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chaplin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Mours
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-24 00:00:00.000000000 Z
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sinatra-contrib
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: faraday
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -228,7 +242,7 @@ files:
228
242
  - lib/chaplin/responses/page.rb
229
243
  - lib/chaplin/responses/redirect.rb
230
244
  - lib/chaplin/server.rb
231
- homepage: https://github.com/victormours/chaplin
245
+ homepage:
232
246
  licenses:
233
247
  - MIT
234
248
  metadata: {}
@@ -253,4 +267,3 @@ signing_key:
253
267
  specification_version: 4
254
268
  summary: Build HTML apps from JSON APIs in no time
255
269
  test_files: []
256
- has_rdoc: