dassets 0.13.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA512:
3
+ metadata.gz: 7402d80d36dfa89d1f68c64a739ffbc516eb1901694e9638ee930835f8b68807fa8dd56245265f8c68af4719633d4b273f13c67ff744f60904f66c5ec27231c5
4
+ data.tar.gz: 657e6338f28159a89ef32225be168b3ca03379b26b73a6db01f0f3b0c0b11a01c3659286185d9d01471dc06aadcb308cbd51700ccf8bdfd0f0261f358fa9f27a
5
+ SHA1:
6
+ metadata.gz: 98e6907a11c2dc4e0409f14c0361094ecffa8396
7
+ data.tar.gz: fafaeb2c34ac116922f469b2ec7317f2688de99e
@@ -56,6 +56,10 @@ class Dassets::AssetFile
56
56
  Rack::Mime.mime_type(@extname)
57
57
  end
58
58
 
59
+ def response_headers
60
+ @source_proxy.response_headers
61
+ end
62
+
59
63
  def exists?
60
64
  @source_proxy.exists?
61
65
  end
@@ -21,7 +21,7 @@ class Dassets::Server
21
21
  @asset_file.digest!
22
22
  body = Body.new(env, @asset_file)
23
23
  [ body.partial? ? 206 : 200,
24
- Rack::Utils::HeaderHash.new.tap do |h|
24
+ Rack::Utils::HeaderHash.new.merge(@asset_file.response_headers).tap do |h|
25
25
  h['Last-Modified'] = mtime
26
26
  h['Content-Type'] = @asset_file.mime_type.to_s
27
27
  h['Content-Length'] = body.size.to_s
@@ -3,12 +3,13 @@ require 'dassets/engine'
3
3
  module Dassets; end
4
4
  class Dassets::Source
5
5
 
6
- attr_reader :path, :engines
6
+ attr_reader :path, :engines, :response_headers
7
7
 
8
8
  def initialize(path)
9
9
  @path = path.to_s
10
10
  @filter = proc{ |paths| paths }
11
11
  @engines = Hash.new{ |h,k| Dassets::NullEngine.new }
12
+ @response_headers = Hash.new
12
13
  end
13
14
 
14
15
  def filter(&block)
@@ -60,6 +60,10 @@ module Dassets
60
60
  File.mtime(@file_path)
61
61
  end
62
62
 
63
+ def response_headers
64
+ self.source.nil? ? Hash.new : self.source.response_headers
65
+ end
66
+
63
67
  def ==(other_source_file)
64
68
  self.file_path == other_source_file.file_path
65
69
  end
@@ -35,6 +35,10 @@ class Dassets::SourceProxy
35
35
  @source_files.map{ |f| f.mtime }.compact.max
36
36
  end
37
37
 
38
+ def response_headers
39
+ @source_files.inject(Hash.new){ |hash, f| hash.merge!(f.response_headers) }
40
+ end
41
+
38
42
  def exists?
39
43
  @source_files.inject(true){ |res, f| res && f.exists? }
40
44
  end
@@ -1,3 +1,3 @@
1
1
  module Dassets
2
- VERSION = "0.13.0"
2
+ VERSION = "0.13.1"
3
3
  end
data/test/helper.rb CHANGED
@@ -29,5 +29,6 @@ Dassets.configure do |c|
29
29
  c.source TEST_SUPPORT_PATH.join("app/assets") do |s|
30
30
  s.engine 'dumb', @dumb_engine
31
31
  s.engine 'useless', @useless_engine
32
+ s.response_headers[Factory.string] = Factory.string
32
33
  end
33
34
  end
@@ -25,10 +25,11 @@ class Dassets::AssetFile
25
25
  assert_equal 'file1', subject.basename
26
26
  end
27
27
 
28
- should "use its source file attrs as its own" do
28
+ should "use its source proxy attrs as its own" do
29
29
  assert_equal subject.source_proxy.mtime.httpdate, subject.mtime
30
30
  assert_equal Rack::Utils.bytesize(subject.content), subject.size
31
31
  assert_equal "text/plain", subject.mime_type
32
+ assert_equal subject.source_proxy.response_headers, subject.response_headers
32
33
  assert subject.exists?
33
34
 
34
35
  null_file = Dassets::AssetFile.new('')
@@ -36,6 +37,7 @@ class Dassets::AssetFile
36
37
  assert_nil null_file.size
37
38
  assert_nil null_file.mime_type
38
39
  assert_not null_file.exists?
40
+ assert_equal null_file.source_proxy.response_headers, null_file.response_headers
39
41
  end
40
42
 
41
43
  should "know its source proxy" do
@@ -40,11 +40,11 @@ class Dassets::Server::Response
40
40
  exp_body = Body.new(@env, @asset_file)
41
41
  assert_equal exp_body, resp.body
42
42
 
43
- exp_headers = {
43
+ exp_headers = @asset_file.response_headers.merge({
44
44
  'Content-Type' => 'text/plain',
45
45
  'Content-Length' => Rack::Utils.bytesize(@asset_file.content).to_s,
46
46
  'Last-Modified' => @asset_file.mtime.to_s
47
- }
47
+ })
48
48
  assert_equal exp_headers, resp.headers
49
49
 
50
50
  assert_equal [200, exp_headers, exp_body], resp.to_rack
@@ -17,33 +17,43 @@ class Dassets::SourceFile
17
17
 
18
18
  should have_readers :file_path
19
19
  should have_imeths :source, :asset_file, :digest_path
20
- should have_imeths :compiled, :exists?, :mtime
20
+ should have_imeths :compiled, :exists?, :mtime, :response_headers
21
21
  should have_cmeth :find_by_digest_path
22
22
 
23
23
  should "know its file path" do
24
24
  assert_equal @file_path.to_s, subject.file_path
25
25
  end
26
26
 
27
- should "know if it exists" do
28
- assert subject.exists?
27
+ should "know its configured source" do
28
+ exp_source = Dassets.config.sources.select{ |s| @file_path.include?(s.path) }.last
29
+ assert_equal exp_source, subject.source
29
30
  end
30
31
 
31
- should "use the mtime of its file as its mtime" do
32
- assert_equal File.mtime(subject.file_path), subject.mtime
32
+ should "know its asset file" do
33
+ assert_kind_of Dassets::AssetFile, subject.asset_file
34
+ assert_equal Dassets::AssetFile.new(subject.digest_path), subject.asset_file
33
35
  end
34
36
 
35
37
  should "know its digest path" do
36
38
  assert_equal 'file1.txt', subject.digest_path
37
39
  end
38
40
 
39
- should "know its asset file" do
40
- assert_kind_of Dassets::AssetFile, subject.asset_file
41
- assert_equal Dassets::AssetFile.new(subject.digest_path), subject.asset_file
41
+ should "not memoize its compiled source" do
42
+ compiled1 = subject.compiled
43
+ compiled2 = subject.compiled
44
+ assert_not_same compiled2, compiled1
42
45
  end
43
46
 
44
- should "know its configured source" do
45
- exp_source = Dassets.config.sources.select{ |s| @file_path.include?(s.path) }.last
46
- assert_equal exp_source, subject.source
47
+ should "know if it exists" do
48
+ assert subject.exists?
49
+ end
50
+
51
+ should "use the mtime of its file as its mtime" do
52
+ assert_equal File.mtime(subject.file_path), subject.mtime
53
+ end
54
+
55
+ should "use the response headers of its source as its response headers" do
56
+ assert_same subject.source.response_headers, subject.response_headers
47
57
  end
48
58
 
49
59
  should "be findable by its digest path" do
@@ -53,12 +63,6 @@ class Dassets::SourceFile
53
63
  assert_not_same subject, found
54
64
  end
55
65
 
56
- should "not memoize its compiled source" do
57
- compiled1 = subject.compiled
58
- compiled2 = subject.compiled
59
- assert_not_same compiled2, compiled1
60
- end
61
-
62
66
  end
63
67
 
64
68
  class NullSourceTests < UnitTests
@@ -80,6 +84,7 @@ class Dassets::SourceFile
80
84
  assert_equal false, null_src.exists?
81
85
  assert_nil null_src.compiled
82
86
  assert_nil null_src.mtime
87
+ assert_equal Hash.new, null_src.response_headers
83
88
  end
84
89
 
85
90
  should "pass options to a null src when finding by an unknown digest path" do
@@ -17,7 +17,8 @@ class Dassets::SourceProxy
17
17
 
18
18
  should have_readers :digest_path, :content_cache, :fingerprint_cache
19
19
  should have_readers :source_files
20
- should have_imeths :key, :content, :fingerprint, :mtime, :exists?
20
+ should have_imeths :key, :content, :fingerprint, :mtime, :response_headers
21
+ should have_imeths :exists?
21
22
 
22
23
  end
23
24
 
@@ -38,13 +39,13 @@ class Dassets::SourceProxy
38
39
 
39
40
  should "have a single source file" do
40
41
  assert_equal 1, subject.source_files.size
41
- exp_source_file = Dassets::SourceFile.find_by_digest_path('file1.txt')
42
- assert_equal exp_source_file, subject.source_files.first
42
+ exp = Dassets::SourceFile.find_by_digest_path('file1.txt')
43
+ assert_equal exp, subject.source_files.first
43
44
  end
44
45
 
45
46
  should "use its digest path and mtime as its key" do
46
- exp_key = "#{subject.digest_path} -- #{subject.mtime}"
47
- assert_equal exp_key, subject.key
47
+ exp = "#{subject.digest_path} -- #{subject.mtime}"
48
+ assert_equal exp, subject.key
48
49
  end
49
50
 
50
51
  should "get its content from the compiled source of the single source file" do
@@ -52,14 +53,18 @@ class Dassets::SourceProxy
52
53
  end
53
54
 
54
55
  should "get its fingerprint by MD5 hashing the content" do
55
- exp_fp = Digest::MD5.new.hexdigest(subject.content)
56
- assert_equal exp_fp, subject.fingerprint
56
+ exp = Digest::MD5.new.hexdigest(subject.content)
57
+ assert_equal exp, subject.fingerprint
57
58
  end
58
59
 
59
60
  should "use its single source file's max mtime as its mtime" do
60
61
  assert_equal subject.source_files.first.mtime, subject.mtime
61
62
  end
62
63
 
64
+ should "use its single source file's response headers as its resonse headers" do
65
+ assert_equal subject.source_files.first.response_headers, subject.response_headers
66
+ end
67
+
63
68
  should "exist if its single source file exists" do
64
69
  assert_equal subject.source_files.first.exists?, subject.exists?
65
70
  end
@@ -100,18 +105,25 @@ class Dassets::SourceProxy
100
105
  end
101
106
 
102
107
  should "get its content from the compiled source of its source files" do
103
- exp_content = subject.source_files.map{ |f| f.compiled }.join("\n")
104
- assert_equal exp_content, subject.content
108
+ exp = subject.source_files.map{ |f| f.compiled }.join("\n")
109
+ assert_equal exp, subject.content
105
110
  end
106
111
 
107
112
  should "use its source files' max mtime as its mtime" do
108
- exp_mtime = subject.source_files.map{ |f| f.mtime }.max
109
- assert_equal exp_mtime, subject.mtime
113
+ exp = subject.source_files.map{ |f| f.mtime }.max
114
+ assert_equal exp, subject.mtime
115
+ end
116
+
117
+ should "use its source files' merged response headers as its response headers" do
118
+ exp = subject.source_files.inject(Hash.new) do |hash, file|
119
+ hash.merge!(file.response_headers)
120
+ end
121
+ assert_equal exp, subject.response_headers
110
122
  end
111
123
 
112
124
  should "exist if its all its source files exist" do
113
- exp_exists = subject.source_files.inject(true){ |res, f| res && f.exists? }
114
- assert_equal exp_exists, subject.exists?
125
+ exp = subject.source_files.inject(true){ |res, f| res && f.exists? }
126
+ assert_equal exp, subject.exists?
115
127
  end
116
128
 
117
129
  end
@@ -13,7 +13,7 @@ class Dassets::Source
13
13
  end
14
14
  subject{ @source }
15
15
 
16
- should have_reader :path, :engines
16
+ should have_reader :path, :engines, :response_headers
17
17
  should have_imeth :files, :filter, :engine
18
18
 
19
19
  should "know its path and default filter" do
@@ -49,6 +49,14 @@ class Dassets::Source
49
49
  assert_kind_of Dassets::NullEngine, subject.engines['something']
50
50
  end
51
51
 
52
+ should "know its response headers" do
53
+ assert_equal Hash.new, subject.response_headers
54
+
55
+ name, value = Factory.string, Factory.string
56
+ subject.response_headers[name] = value
57
+ assert_equal value, subject.response_headers[name]
58
+ end
59
+
52
60
  end
53
61
 
54
62
  class EmptySourceTests < UnitTests
metadata CHANGED
@@ -1,13 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dassets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 43
5
- prerelease:
6
- segments:
7
- - 0
8
- - 13
9
- - 0
10
- version: 0.13.0
4
+ version: 0.13.1
11
5
  platform: ruby
12
6
  authors:
13
7
  - Kelly Redding
@@ -16,83 +10,57 @@ autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
12
 
19
- date: 2015-12-22 00:00:00 Z
13
+ date: 2016-02-23 00:00:00 Z
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
16
+ name: assert
17
+ prerelease: false
22
18
  requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
19
  requirements:
25
20
  - - ~>
26
21
  - !ruby/object:Gem::Version
27
- hash: 29
28
- segments:
29
- - 2
30
- - 15
31
22
  version: "2.15"
32
23
  type: :development
33
- name: assert
34
24
  version_requirements: *id001
35
- prerelease: false
36
25
  - !ruby/object:Gem::Dependency
26
+ name: assert-rack-test
27
+ prerelease: false
37
28
  requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
29
  requirements:
40
30
  - - ~>
41
- - !ruby/object:Gem::Version
42
- hash: 15
43
- segments:
44
- - 1
45
- - 0
31
+ - &id005 !ruby/object:Gem::Version
46
32
  version: "1.0"
47
33
  type: :development
48
- name: assert-rack-test
49
34
  version_requirements: *id002
50
- prerelease: false
51
35
  - !ruby/object:Gem::Dependency
36
+ name: sinatra
37
+ prerelease: false
52
38
  requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
39
  requirements:
55
40
  - - ~>
56
41
  - !ruby/object:Gem::Version
57
- hash: 7
58
- segments:
59
- - 1
60
- - 4
61
42
  version: "1.4"
62
43
  type: :development
63
- name: sinatra
64
44
  version_requirements: *id003
65
- prerelease: false
66
45
  - !ruby/object:Gem::Dependency
46
+ name: ns-options
47
+ prerelease: false
67
48
  requirement: &id004 !ruby/object:Gem::Requirement
68
- none: false
69
49
  requirements:
70
50
  - - ~>
71
51
  - !ruby/object:Gem::Version
72
- hash: 13
73
- segments:
74
- - 1
75
- - 1
76
52
  version: "1.1"
77
53
  type: :runtime
78
- name: ns-options
79
54
  version_requirements: *id004
80
- prerelease: false
81
55
  - !ruby/object:Gem::Dependency
82
- requirement: &id005 !ruby/object:Gem::Requirement
83
- none: false
56
+ name: rack
57
+ prerelease: false
58
+ requirement: &id006 !ruby/object:Gem::Requirement
84
59
  requirements:
85
60
  - - ~>
86
- - !ruby/object:Gem::Version
87
- hash: 15
88
- segments:
89
- - 1
90
- - 0
91
- version: "1.0"
61
+ - *id005
92
62
  type: :runtime
93
- name: rack
94
- version_requirements: *id005
95
- prerelease: false
63
+ version_requirements: *id006
96
64
  description: Digest and serve HTML asset files
97
65
  email:
98
66
  - kelly@kellyredding.com
@@ -158,35 +126,28 @@ files:
158
126
  homepage: http://github.com/redding/dassets
159
127
  licenses:
160
128
  - MIT
129
+ metadata: {}
130
+
161
131
  post_install_message:
162
132
  rdoc_options: []
163
133
 
164
134
  require_paths:
165
135
  - lib
166
136
  required_ruby_version: !ruby/object:Gem::Requirement
167
- none: false
168
137
  requirements:
169
- - - ">="
138
+ - &id007
139
+ - ">="
170
140
  - !ruby/object:Gem::Version
171
- hash: 3
172
- segments:
173
- - 0
174
141
  version: "0"
175
142
  required_rubygems_version: !ruby/object:Gem::Requirement
176
- none: false
177
143
  requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- hash: 3
181
- segments:
182
- - 0
183
- version: "0"
144
+ - *id007
184
145
  requirements: []
185
146
 
186
147
  rubyforge_project:
187
- rubygems_version: 1.8.25
148
+ rubygems_version: 2.5.1
188
149
  signing_key:
189
- specification_version: 3
150
+ specification_version: 4
190
151
  summary: Digested asset files
191
152
  test_files:
192
153
  - test/helper.rb