cassette-rack 0.4.0 → 0.4.1

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: 41fd94c93390feedfb4b437fe9770ada43beb1b0
4
- data.tar.gz: 1d5bd08c1c4c656979f800d47b946c5b61a11d3f
3
+ metadata.gz: 4c827fb45c350323207577d2f55c0b8907c0c1cf
4
+ data.tar.gz: 1dea33463a3ac0d384a37bab30248ed9612006e7
5
5
  SHA512:
6
- metadata.gz: 67d52b9fff5af84bcfa5f12616cd8eb5104f33bf369a87718fdb9913a358563f8b82b322ae382499d8d32f385a980db49d8b769a81b3662951af804916dd45a3
7
- data.tar.gz: 379495c4b20ab95b3ec17efc145f0cc6194df6b34e7e61ad1da8ddd96850d2f0b5b1223fd8655c972e6025bdf8d0efc29a36a2f50a2158adb86c43e1c2c9441f
6
+ metadata.gz: 90e36902bde61636a5ea50a0efc279589b987ad559bf7dc9f5bb02dc05b6be0bbc34a3cc6ec60a9ec210b85efce1ca178e8345f55204d098478bf581e2029b52
7
+ data.tar.gz: 1345cf19838a737f75c03c46a933329cca0dac88d24c70e881329911e4781808d3ab0426717ba97227c9c6e3009b4fc38f1dbf1ddf12099ff50d92252a407054
@@ -3,7 +3,7 @@ require 'vcr'
3
3
  module CassetteRack
4
4
  module Configure
5
5
  class << self
6
- attr_accessor :cassette_extension, :cassette_path, :url
6
+ attr_accessor :cassette_path, :url
7
7
 
8
8
  def setup
9
9
  keys.each do |key|
@@ -18,7 +18,7 @@ module CassetteRack
18
18
  end
19
19
 
20
20
  def keys
21
- @keys ||= %i[cassette_extension cassette_path url]
21
+ @keys ||= %i[cassette_path url]
22
22
  end
23
23
 
24
24
  def source_path
@@ -37,6 +37,10 @@ module CassetteRack
37
37
  @content_layout ||= File.expand_path('content.md.liquid', File.join(self.templates_path, 'layouts'))
38
38
  end
39
39
 
40
+ def preview_layout
41
+ @preview_layout ||= File.expand_path('preview.liquid', File.join(self.templates_path, 'layouts'))
42
+ end
43
+
40
44
  def application_template
41
45
  File.read(self.application_layout)
42
46
  end
@@ -44,6 +48,10 @@ module CassetteRack
44
48
  def content_template
45
49
  File.read(self.content_layout)
46
50
  end
51
+
52
+ def preview_template
53
+ File.read(self.preview_layout)
54
+ end
47
55
  end
48
56
  end
49
57
  end
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  module CassetteRack
2
4
  module Decorator
3
5
  class Response
@@ -1,6 +1,5 @@
1
1
  module CassetteRack
2
2
  module Default
3
- CASSETTE_EXTENSION = 'yml'.freeze
4
3
  CASSETTE_PATH = 'spec/cassettes'.freeze
5
4
  URL = 'http://localhost:3000'.freeze
6
5
 
@@ -9,10 +8,6 @@ module CassetteRack
9
8
  Hash[CassetteRack::Configure.keys.map{|key| [key, send(key)]}]
10
9
  end
11
10
 
12
- def cassette_extension
13
- CASSETTE_EXTENSION
14
- end
15
-
16
11
  def cassette_path
17
12
  CASSETTE_PATH
18
13
  end
@@ -1,3 +1,5 @@
1
+ require 'kramdown'
2
+
1
3
  require_relative 'decorator/request'
2
4
  require_relative 'decorator/response'
3
5
 
@@ -19,22 +19,37 @@ module CassetteRack
19
19
  private
20
20
  def controller(env)
21
21
  request = Rack::Request.new(env)
22
+ params = Hash[URI.decode_www_form(request.query_string)]
23
+ body = Hash[URI.decode_www_form(request.body.read)]
22
24
  drawer = CassetteRack::Drawer.new(request.path_info)
23
25
 
24
- case request.request_method
26
+ case body['_method']
27
+ when 'delete'
28
+ request_method = body['_method'].upcase
29
+ else
30
+ request_method = request.request_method
31
+ end
32
+
33
+ case request_method
25
34
  when 'DELETE'
26
35
  drawer.delete
27
36
  end
28
37
 
29
- tree = CassetteRack::Tree.create(CassetteRack::Configure.source_path)
30
- cassettes_tag = render_branch(tree, request.script_name, request.path_info)
31
- cassette_tag = render_leaf(drawer, request.script_name + request.path_info)
38
+ case params['response']
39
+ when 'preview'
40
+ template = Liquid::Template.parse(CassetteRack::Configure.preview_template)
41
+ body = template.render('body' => drawer.http.response.body)
42
+ else
43
+ tree = CassetteRack::Tree.create(CassetteRack::Configure.source_path)
44
+ cassettes_tag = render_branch(tree, request.script_name, request.path_info)
45
+ cassette_tag = render_leaf(drawer, request.script_name + request.path_info)
46
+
47
+ template = Liquid::Template.parse(CassetteRack::Configure.application_template)
48
+ body = template.render('cassettes_tag' => cassettes_tag, 'cassette_tag' => cassette_tag)
49
+ end
32
50
 
33
51
  status = 200
34
52
  headers = {'Content-Type' => 'text/html'}
35
- template = Liquid::Template.parse(CassetteRack::Configure.application_template)
36
- body = template.render('cassettes_tag' => cassettes_tag, 'cassette_tag' => cassette_tag)
37
-
38
53
  [status, headers, [body]]
39
54
  end
40
55
 
@@ -68,10 +83,14 @@ module CassetteRack
68
83
  def render_leaf(drawer, action)
69
84
  if drawer.exist?
70
85
  raw = drawer.render
86
+ raw += "<div class='btn-group'>\n"
87
+ raw += "<a class='btn btn-primary' href='#{action}?response=preview'>\n"
88
+ raw += "<span>Preview</span></a>\n"
71
89
  raw += "<form method='post' action='#{action}'>\n"
72
90
  raw += "<input name='_method' value='delete' type='hidden' />\n"
73
91
  raw += "<input class='btn btn-danger' type='submit' value='Destroy'>\n"
74
92
  raw += "</form>\n"
93
+ raw += "</div>\n"
75
94
  else
76
95
  raw = "<h3>Please select cassette</h3>"
77
96
  end
@@ -1,3 +1,3 @@
1
1
  module CassetteRack
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
@@ -80,20 +80,32 @@
80
80
  }
81
81
 
82
82
  .btn {
83
- padding: 5px 10px;
84
83
  margin-left: 10px;
85
84
  cursor: pointer;
86
85
  background-image: none;
87
86
  border: 1px solid transparent;
88
- padding: 8px 12px;
89
87
  font-size: 12px;
88
+ text-decoration: none;
89
+ }
90
+
91
+ .btn-primary {
92
+ padding: 8px 12px;
93
+ color: #ffffff;
94
+ background-color: #008cba;
95
+ border-color: #0079a1;
90
96
  }
91
97
 
92
98
  .btn-danger {
99
+ padding: 10px 12px;
93
100
  color: #ffffff;
94
101
  background-color: #f04124;
95
102
  border-color: #ea2f10;
96
103
  }
104
+
105
+ .btn-group {
106
+ margin-left: 10px;
107
+ display: inline-flex;
108
+ }
97
109
  </style>
98
110
  </head>
99
111
  <body>
@@ -0,0 +1 @@
1
+ {{ body }}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassette-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ogom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-28 00:00:00.000000000 Z
11
+ date: 2015-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -137,6 +137,7 @@ files:
137
137
  - lib/cassette-rack/version.rb
138
138
  - lib/templates/layouts/application.html.liquid
139
139
  - lib/templates/layouts/content.md.liquid
140
+ - lib/templates/layouts/preview.liquid
140
141
  - spec/grant-front_spec.rb
141
142
  - spec/lib/version_spec.rb
142
143
  - spec/spec_helper.rb
@@ -168,3 +169,4 @@ test_files:
168
169
  - spec/grant-front_spec.rb
169
170
  - spec/lib/version_spec.rb
170
171
  - spec/spec_helper.rb
172
+ has_rdoc: