zassets 0.1.8 → 0.1.9
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.
- data/lib/zassets/config.rb +4 -0
- data/lib/zassets/memory_file.rb +22 -0
- data/lib/zassets/server.rb +6 -1
- data/lib/zassets/version.rb +1 -1
- data/lib/zassets.rb +1 -0
- data/spec/fixtures/public/index.html +1 -0
- data/spec/zassets/config_spec.rb +5 -0
- data/spec/zassets/memory_file_spec.rb +44 -0
- data/spec/zassets/server_spec.rb +13 -0
- metadata +6 -4
data/lib/zassets/config.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module ZAssets
|
2
|
+
class MemoryFile
|
3
|
+
def initialize(file)
|
4
|
+
@file = file
|
5
|
+
end
|
6
|
+
|
7
|
+
def headers
|
8
|
+
{
|
9
|
+
'Content-Type' => 'text/html',
|
10
|
+
'Content-Length' => body.length.to_s
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def body
|
15
|
+
@content ||= @file.read
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
[200, headers, [body]]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/zassets/server.rb
CHANGED
@@ -39,7 +39,12 @@ module ZAssets
|
|
39
39
|
end
|
40
40
|
|
41
41
|
map '/' do
|
42
|
-
|
42
|
+
if config[:public_file]
|
43
|
+
file = File.new(File.join(config[:public_path], config[:public_file]))
|
44
|
+
run MemoryFile.new file
|
45
|
+
else
|
46
|
+
run Rack::File.new config[:public_path]
|
47
|
+
end
|
43
48
|
end
|
44
49
|
end
|
45
50
|
end
|
data/lib/zassets/version.rb
CHANGED
data/lib/zassets.rb
CHANGED
@@ -4,6 +4,7 @@ module ZAssets
|
|
4
4
|
autoload :CLI, 'zassets/cli'
|
5
5
|
autoload :Compiler, 'zassets/compiler'
|
6
6
|
autoload :Config, 'zassets/config'
|
7
|
+
autoload :MemoryFile, 'zassets/memory_file'
|
7
8
|
autoload :Server, 'zassets/server'
|
8
9
|
autoload :SprocketsEnv, 'zassets/sprockets_env'
|
9
10
|
autoload :Version, 'zassets/version'
|
@@ -0,0 +1 @@
|
|
1
|
+
hello HTML!
|
data/spec/zassets/config_spec.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAssets::MemoryFile do
|
4
|
+
include FixturesHelpers
|
5
|
+
|
6
|
+
let(:file_path) { fixture_path_for('public/index.html') }
|
7
|
+
let(:file) { File.new file_path }
|
8
|
+
let(:subject) { described_class.new(file) }
|
9
|
+
|
10
|
+
describe '#headers' do
|
11
|
+
it 'sets the content type to text/html' do
|
12
|
+
subject.headers['Content-Type'].should == 'text/html'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'sets the content length to the file length' do
|
16
|
+
subject.headers['Content-Length'].should == file.size.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#body' do
|
21
|
+
it 'returns the file content' do
|
22
|
+
subject.body.should == File.read(file_path)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#call' do
|
27
|
+
require 'rack'
|
28
|
+
|
29
|
+
let(:app) { Rack::MockRequest.new(subject) }
|
30
|
+
let(:response) { app.get('/') }
|
31
|
+
|
32
|
+
it 'returns a successful response' do
|
33
|
+
response.should be_ok
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'sets required headers' do
|
37
|
+
response.headers.should == subject.headers
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns the body' do
|
41
|
+
response.body.should == subject.body
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/zassets/server_spec.rb
CHANGED
@@ -86,6 +86,19 @@ module ZAssets
|
|
86
86
|
response.body.should == "hello!\n"
|
87
87
|
end
|
88
88
|
end
|
89
|
+
|
90
|
+
context 'when a public file is configured' do
|
91
|
+
let(:config) { Config.new(public_file: 'index.html') }
|
92
|
+
|
93
|
+
it 'serves the public file' do
|
94
|
+
within_fixture_path do
|
95
|
+
response = app.get('/')
|
96
|
+
response.should be_ok
|
97
|
+
response.content_type.should == 'text/html'
|
98
|
+
response.body.should == "hello HTML!\n"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
89
102
|
end
|
90
103
|
end
|
91
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zassets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|
@@ -159,17 +159,20 @@ files:
|
|
159
159
|
- lib/zassets/compiler.rb
|
160
160
|
- lib/zassets/config.rb
|
161
161
|
- lib/zassets/exceptions.rb
|
162
|
+
- lib/zassets/memory_file.rb
|
162
163
|
- lib/zassets/server.rb
|
163
164
|
- lib/zassets/sprockets_env.rb
|
164
165
|
- lib/zassets/version.rb
|
165
166
|
- spec/fixtures/assets/app.js
|
166
167
|
- spec/fixtures/config/zassets.yaml
|
167
168
|
- spec/fixtures/public/hello.txt
|
169
|
+
- spec/fixtures/public/index.html
|
168
170
|
- spec/spec_helper.rb
|
169
171
|
- spec/support/fixtures_helpers.rb
|
170
172
|
- spec/zassets/cli_spec.rb
|
171
173
|
- spec/zassets/compiler_spec.rb
|
172
174
|
- spec/zassets/config_spec.rb
|
175
|
+
- spec/zassets/memory_file_spec.rb
|
173
176
|
- spec/zassets/server_spec.rb
|
174
177
|
- spec/zassets/sprockets_env_spec.rb
|
175
178
|
- zassets.gemspec
|
@@ -196,6 +199,5 @@ rubyforge_project:
|
|
196
199
|
rubygems_version: 1.8.23
|
197
200
|
signing_key:
|
198
201
|
specification_version: 3
|
199
|
-
summary: zassets-0.1.
|
202
|
+
summary: zassets-0.1.9
|
200
203
|
test_files: []
|
201
|
-
has_rdoc:
|