rasti-web 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rasti/web/render.rb +9 -0
- data/lib/rasti/web/version.rb +1 -1
- data/lib/rasti/web.rb +1 -0
- data/rasti-web.gemspec +2 -1
- data/spec/minitest_helper.rb +1 -0
- data/spec/render_spec.rb +40 -0
- data/spec/sample_file.zip +0 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b24dfc486a03d7e1c5e7c535f631311ccb3d263
|
4
|
+
data.tar.gz: 3ca07ae28c45cf51ffa6e4fe4acc5be0d114b159
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 301968af1068afca49f4cf1198a7b44994f4665f5cd22d6fbaf0f8d73f4f29285296ba982d2369471801429525c18f3622bd05091555ec6c0ce81a01de13b5e5
|
7
|
+
data.tar.gz: fac959563b845b652af63c2cb779328386ecc8f5c9fa0561602efd5fd1838d80ed7f84c0e3d3b41c2ec44821e558eea11b16befb39b67626db9615ee388a1194
|
data/lib/rasti/web/render.rb
CHANGED
@@ -40,6 +40,15 @@ module Rasti
|
|
40
40
|
script
|
41
41
|
end
|
42
42
|
|
43
|
+
def file(filename, *args)
|
44
|
+
content_type = MIME::Types.of(filename).first.content_type
|
45
|
+
body = File.read filename
|
46
|
+
|
47
|
+
respond_with extract_status(args),
|
48
|
+
extract_headers(args).merge('Content-Type' => content_type),
|
49
|
+
body
|
50
|
+
end
|
51
|
+
|
43
52
|
def partial(template, locals={})
|
44
53
|
response['Content-Type'] = 'text/html'
|
45
54
|
response.write view_context.render(template, locals)
|
data/lib/rasti/web/version.rb
CHANGED
data/lib/rasti/web.rb
CHANGED
data/rasti-web.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency 'rack'
|
22
22
|
spec.add_dependency 'tilt'
|
23
|
+
spec.add_dependency 'mime-types'
|
23
24
|
spec.add_dependency 'class_config', '~> 0.0.2'
|
24
25
|
|
25
26
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
@@ -27,6 +28,6 @@ Gem::Specification.new do |spec|
|
|
27
28
|
spec.add_development_dependency 'minitest', '~> 4.7'
|
28
29
|
spec.add_development_dependency 'turn', '~> 0.9'
|
29
30
|
spec.add_development_dependency 'simplecov'
|
30
|
-
spec.add_development_dependency 'pry'
|
31
|
+
spec.add_development_dependency 'pry-nav'
|
31
32
|
spec.add_development_dependency 'rack-test'
|
32
33
|
end
|
data/spec/minitest_helper.rb
CHANGED
data/spec/render_spec.rb
CHANGED
@@ -204,6 +204,46 @@ describe Rasti::Web::Render do
|
|
204
204
|
|
205
205
|
end
|
206
206
|
|
207
|
+
describe 'File' do
|
208
|
+
|
209
|
+
let(:filename) { File.expand_path '../sample_file.zip', __FILE__ }
|
210
|
+
|
211
|
+
it 'Body' do
|
212
|
+
render.file filename
|
213
|
+
|
214
|
+
response.status.must_equal 200
|
215
|
+
response['Content-Type'].must_equal 'application/zip'
|
216
|
+
response.body.must_equal [File.read(filename)]
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'Body and status' do
|
220
|
+
render.file filename, 206
|
221
|
+
|
222
|
+
response.status.must_equal 206
|
223
|
+
response['Content-Type'].must_equal 'application/zip'
|
224
|
+
response.body.must_equal [File.read(filename)]
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'Body and headers' do
|
228
|
+
render.file filename, 'Content-Disposition' => 'attachment; filename=test_file.zip'
|
229
|
+
|
230
|
+
response.status.must_equal 200
|
231
|
+
response['Content-Type'].must_equal 'application/zip'
|
232
|
+
response['Content-Disposition'].must_equal 'attachment; filename=test_file.zip'
|
233
|
+
response.body.must_equal [File.read(filename)]
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'Body, status and headers' do
|
237
|
+
render.file filename, 206, 'Content-Disposition' => 'attachment; filename=test_file.zip'
|
238
|
+
|
239
|
+
response.status.must_equal 206
|
240
|
+
response['Content-Type'].must_equal 'application/zip'
|
241
|
+
response['Content-Disposition'].must_equal 'attachment; filename=test_file.zip'
|
242
|
+
response.body.must_equal [File.read(filename)]
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
|
207
247
|
it 'Partial' do
|
208
248
|
render.partial 'context_and_locals', title: 'Welcome', text: 'Hello world'
|
209
249
|
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasti-web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-08 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: mime-types
|
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: class_config
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,7 +137,7 @@ dependencies:
|
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
|
-
name: pry
|
140
|
+
name: pry-nav
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
143
|
- - '>='
|
@@ -188,6 +202,7 @@ files:
|
|
188
202
|
- spec/request_spec.rb
|
189
203
|
- spec/route_spec.rb
|
190
204
|
- spec/router_spec.rb
|
205
|
+
- spec/sample_file.zip
|
191
206
|
- spec/template_spec.rb
|
192
207
|
- spec/views/context_and_locals.erb
|
193
208
|
- spec/views/context_method.erb
|
@@ -229,6 +244,7 @@ test_files:
|
|
229
244
|
- spec/request_spec.rb
|
230
245
|
- spec/route_spec.rb
|
231
246
|
- spec/router_spec.rb
|
247
|
+
- spec/sample_file.zip
|
232
248
|
- spec/template_spec.rb
|
233
249
|
- spec/views/context_and_locals.erb
|
234
250
|
- spec/views/context_method.erb
|