dassets 0.10.1 → 0.11.0

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: 6276fedfd2895a526ed5a1593dae1a3a1d0ae726
4
- data.tar.gz: 248ce8d0a5548d7454fb5675296df73e52c0ad3f
3
+ metadata.gz: 244a7ebdc3e3946a77738679d15461540e10fdf4
4
+ data.tar.gz: f9139f0feab58b8ec02fdb7f65741e1066e13968
5
5
  SHA512:
6
- metadata.gz: 9428c6ed5707756a0bd9e3e81197548394d1da94735d1ccd66d4cf837a024de745bd94db73e0452fd4fdc41053aca798177bc0692cb8cc569da4e9786ed0fc95
7
- data.tar.gz: dfa8a1d4831ba49d293650a363ac71020bb6d62cf9d54e09d3c6c9791b2b5acdb9ec9c4f7b9d4c61b85fff82b39840a35c1e838ba58bcc052af31239cc9f4a0e
6
+ metadata.gz: d0986dc632093cc8960fb505c67bfec57e760e25c51a5023a307cb628ce45e4bc1939cf24afa756dd81d74a313e214f99671704d5d6ca900c9bfb8eba8a570f1
7
+ data.tar.gz: af99765ab02de4783213f347106fe2fff5d863120b0a687f17c84e47a7a66d1e16a1539e00348447bea0ff3d307df5a114fc0bba8de92cdd7045eb9f1a978752
data/dassets.gemspec CHANGED
@@ -18,10 +18,9 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_development_dependency("assert", ["~> 2.12"])
21
+ gem.add_development_dependency("assert", ["~> 2.15"])
22
22
  gem.add_development_dependency('assert-rack-test', ["~> 1.0"])
23
- gem.add_development_dependency("sinatra", ["~> 1.4"])
24
-
23
+ gem.add_development_dependency("sinatra", ["~> 1.4"])
25
24
 
26
25
  gem.add_dependency('ns-options', ["~> 1.1"])
27
26
  gem.add_dependency("rack", ["~> 1.0"])
@@ -17,18 +17,20 @@ class Dassets::AssetFile
17
17
 
18
18
  def digest!
19
19
  return if !self.exists?
20
- Dassets.config.file_store.save(self.url){ self.content }
20
+ Dassets.config.file_store.save(self.path){ self.content }
21
21
  end
22
22
 
23
- def url
24
- url_basename = "#{@basename}-#{self.fingerprint}#{@extname}"
25
- File.join(@dirname, url_basename).sub(/^\.\//, '').sub(/^\//, '')
23
+ def path
24
+ path_basename = "#{@basename}-#{self.fingerprint}#{@extname}"
25
+ File.join(@dirname, path_basename).sub(/^\.\//, '').sub(/^\//, '')
26
26
  end
27
27
 
28
- def href
29
- "/#{self.url}"
28
+ def url
29
+ "#{dassets_base_url}/#{self.path}"
30
30
  end
31
31
 
32
+ alias_method :href, :url
33
+
32
34
  def fingerprint
33
35
  return nil if !self.exists?
34
36
  @source_proxy.fingerprint
@@ -64,4 +66,10 @@ class Dassets::AssetFile
64
66
  self.fingerprint == other_asset_file.fingerprint
65
67
  end
66
68
 
69
+ private
70
+
71
+ def dassets_base_url
72
+ Dassets.config.base_url.to_s
73
+ end
74
+
67
75
  end
@@ -21,10 +21,14 @@ module Dassets
21
21
  end
22
22
 
23
23
  def base_url(value = nil)
24
- @base_url = value if !value.nil?
24
+ set_base_url(value) if !value.nil?
25
25
  @base_url
26
26
  end
27
27
 
28
+ def set_base_url(value)
29
+ @base_url = value
30
+ end
31
+
28
32
  def source(path, &block)
29
33
  @sources << Source.new(path).tap{ |s| block.call(s) if block }
30
34
  end
@@ -1,3 +1,3 @@
1
1
  module Dassets
2
- VERSION = "0.10.1"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -15,8 +15,8 @@ class Dassets::AssetFile
15
15
  subject{ @asset_file }
16
16
 
17
17
  should have_readers :digest_path, :dirname, :extname, :basename, :source_proxy
18
- should have_imeths :digest!, :url, :fingerprint, :content
19
- should have_imeths :href, :mtime, :size, :mime_type, :exists?, :==
18
+ should have_imeths :digest!, :path, :url, :href, :fingerprint, :content
19
+ should have_imeths :mtime, :size, :mime_type, :exists?, :==
20
20
 
21
21
  should "know its digest path, dirname, extname, and basename" do
22
22
  assert_equal 'file1.txt', subject.digest_path
@@ -68,29 +68,40 @@ class Dassets::AssetFile
68
68
  assert_equal exp_content, without_output.content
69
69
  end
70
70
 
71
- should "build it's url from the path and the fingerprint" do
72
- assert_match /^file1-[a-f0-9]{32}\.txt$/, subject.url
71
+ should "build it's path from the file and the fingerprint" do
72
+ assert_match /^file1-[a-f0-9]{32}\.txt$/, subject.path
73
73
 
74
74
  nested = Dassets::AssetFile.new('nested/file1.txt')
75
- assert_equal "nested/file1-.txt", nested.url
75
+ assert_equal "nested/file1-.txt", nested.path
76
76
  end
77
77
 
78
- should "build it's href from the url" do
79
- assert_match /^\/file1-[a-f0-9]{32}\.txt$/, subject.href
78
+ should "build it's url/href from the path and any configured base url" do
79
+ assert_match /^\/file1-[a-f0-9]{32}\.txt$/, subject.url
80
+ assert_match subject.url, subject.href
80
81
 
81
82
  nested = Dassets::AssetFile.new('nested/file1.txt')
82
- assert_equal "/nested/file1-.txt", nested.href
83
+ assert_equal "/nested/file1-.txt", nested.url
84
+ assert_equal nested.url, nested.href
85
+
86
+ base_url = Factory.url
87
+ Dassets.config.base_url base_url
88
+
89
+ assert_match /^#{base_url}\/file1-[a-f0-9]{32}\.txt$/, subject.url
90
+ assert_match subject.url, subject.href
91
+
92
+ assert_equal "#{base_url}/nested/file1-.txt", nested.url
93
+ assert_equal nested.url, nested.href
83
94
  end
84
95
 
85
96
  should "not memoize its attributes" do
97
+ path1 = subject.path
98
+ path2 = subject.path
99
+ assert_not_same path2, path1
100
+
86
101
  url1 = subject.url
87
102
  url2 = subject.url
88
103
  assert_not_same url2, url1
89
104
 
90
- href1 = subject.href
91
- href2 = subject.href
92
- assert_not_same href2, href1
93
-
94
105
  fingerprint1 = subject.fingerprint
95
106
  fingerprint2 = subject.fingerprint
96
107
  assert_not_same fingerprint2, fingerprint1
@@ -111,7 +122,7 @@ class Dassets::AssetFile
111
122
  setup do
112
123
  Dassets.config.file_store = TEST_SUPPORT_PATH.join('public').to_s
113
124
  @save_path = @asset_file.digest!
114
- @outfile = Dassets.config.file_store.store_path(@asset_file.url)
125
+ @outfile = Dassets.config.file_store.store_path(@asset_file.path)
115
126
  end
116
127
  teardown do
117
128
  Dassets.config.file_store = Dassets::FileStore::NullStore.new
@@ -18,19 +18,31 @@ class Dassets::Config
18
18
 
19
19
  should have_options :file_store, :cache
20
20
  should have_readers :combinations
21
- should have_imeths :base_url, :source, :combination, :combination?
21
+ should have_imeths :base_url, :set_base_url
22
+ should have_imeths :source, :combination, :combination?
22
23
 
23
24
  should "have no base url by default" do
24
25
  assert_nil subject.base_url
25
26
  end
26
27
 
27
- should "set a base url" do
28
+ should "set non-nil base urls" do
28
29
  url = Factory.url
29
30
  subject.base_url url
31
+ assert_equal url, subject.base_url
30
32
 
33
+ subject.base_url(nil)
31
34
  assert_equal url, subject.base_url
32
35
  end
33
36
 
37
+ should "force set any base urls" do
38
+ url = Factory.url
39
+ subject.set_base_url url
40
+ assert_equal url, subject.base_url
41
+
42
+ subject.set_base_url(nil)
43
+ assert_nil subject.base_url
44
+ end
45
+
34
46
  should "default the file store option to a null file store" do
35
47
  assert_kind_of Dassets::FileStore::NullStore, subject.file_store
36
48
  end
@@ -85,11 +85,11 @@ class Dassets::Server::Request
85
85
  desc "when a base url is configured"
86
86
  setup do
87
87
  @orig_base_url = Dassets.config.base_url
88
- @new_base_url = Factory.url
88
+ @new_base_url = Factory.url
89
89
  Dassets.config.base_url(@new_base_url)
90
90
  end
91
91
  teardown do
92
- Dassets.config.base_url(@orig_base_url)
92
+ Dassets.config.set_base_url(@orig_base_url)
93
93
  end
94
94
 
95
95
  should "have the same base url as is configured" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dassets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-10 00:00:00.000000000 Z
12
+ date: 2015-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: assert
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '2.12'
20
+ version: '2.15'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '2.12'
27
+ version: '2.15'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: assert-rack-test
30
30
  requirement: !ruby/object:Gem::Requirement