middleman-sprockets 3.3.4 → 3.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/.simplecov +9 -0
  5. data/Gemfile +2 -2
  6. data/README.md +47 -2
  7. data/Rakefile +4 -1
  8. data/features/bower.feature +7 -0
  9. data/features/support/env.rb +10 -0
  10. data/fixtures/bower-individual-outputdir-app/bower.json +7 -0
  11. data/fixtures/bower-individual-outputdir-app/bower_components/underscore/bower.json +8 -0
  12. data/fixtures/bower-individual-outputdir-app/bower_components/underscore/underscore.js +1343 -0
  13. data/fixtures/bower-individual-outputdir-app/config.rb +6 -0
  14. data/fixtures/bower-individual-outputdir-app/source/javascripts/application.js +1 -0
  15. data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/.bower.json +34 -0
  16. data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/bower.json +26 -0
  17. data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/img/close.png +0 -0
  18. data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/js/lightbox.js +2 -0
  19. data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/package.json +37 -0
  20. data/lib/middleman-sprockets/asset.rb +185 -0
  21. data/lib/middleman-sprockets/asset_list.rb +41 -0
  22. data/lib/middleman-sprockets/config_only_environment.rb +4 -4
  23. data/lib/middleman-sprockets/environment.rb +7 -2
  24. data/lib/middleman-sprockets/extension.rb +32 -52
  25. data/lib/middleman-sprockets/imported_asset.rb +57 -0
  26. data/lib/middleman-sprockets/pathname_extensions.rb +10 -0
  27. data/lib/middleman-sprockets/version.rb +1 -1
  28. data/spec/asset_list_spec.rb +38 -0
  29. data/spec/asset_spec.rb +116 -0
  30. data/spec/imported_asset_spec.rb +72 -0
  31. data/spec/spec_helper.rb +16 -0
  32. data/spec/support/aruba.rb +18 -0
  33. data/spec/support/rspec.rb +17 -0
  34. metadata +34 -2
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+ module Middleman
3
+ module Sprockets
4
+ # ImportedAsset
5
+ class ImportedAsset
6
+ attr_reader :logical_path, :output_path, :real_path
7
+
8
+ # Create instance
9
+ #
10
+ # @param [Pathname] logical_path
11
+ # The logical path to the asset given in config.rb
12
+ #
13
+ # @param [proc] output_dir
14
+ # An individual output directory for that particular asset
15
+ def initialize(logical_path, determine_output_path = proc { nil })
16
+ @logical_path = Pathname.new(logical_path)
17
+ @output_path = if output_path = determine_output_path.call(@logical_path)
18
+ Pathname.new(output_path)
19
+ else
20
+ nil
21
+ end
22
+ end
23
+
24
+ # Resolve logical path to real path
25
+ #
26
+ # @param [#resolve] resolver
27
+ # The objects which is able to resolve a logical path
28
+ def resolve_path_with(resolver)
29
+ @real_path = resolver.resolve(logical_path)
30
+
31
+ raise ::Sprockets::FileNotFound, "Couldn't find asset '#{logical_path}'" if real_path == nil || real_path == ''
32
+ end
33
+
34
+ # String representation of asset
35
+ #
36
+ # @return [String]
37
+ # The logical path as string
38
+ def to_s
39
+ logical_path.to_s
40
+ end
41
+
42
+ # Does the given patch matches asset
43
+ #
44
+ # @param [Pathname] path
45
+ # The path to be checked
46
+ def match?(path)
47
+ has_real_path? path
48
+ end
49
+
50
+ private
51
+
52
+ def has_real_path?(path)
53
+ real_path == path
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+ class Pathname
3
+ def start_with?(*paths)
4
+ to_s.start_with?(*paths)
5
+ end
6
+
7
+ def end_with?(*paths)
8
+ to_s.end_with?(*paths)
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Sprockets
3
- VERSION = "3.3.4"
3
+ VERSION = "3.3.6"
4
4
  end
5
5
  end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ RSpec.describe AssetList do
4
+ context '#add' do
5
+ it 'adds an asset to the list' do
6
+ asset = instance_double 'Middleman::Sprockets::Asset'
7
+ list = AssetList.new
8
+
9
+ expect {
10
+ list << asset
11
+ }.not_to raise_error
12
+ end
13
+ end
14
+ context '#lookup' do
15
+ it 'finds an asset in list' do
16
+ asset = instance_double 'Middleman::Sprockets::Asset'
17
+ expect(asset).to receive(:source_path).and_return 'path/to/source'
18
+ expect(asset).to receive(:match?).and_return true
19
+
20
+ list = AssetList.new
21
+ list << asset
22
+
23
+ expect(list.lookup(asset)).to be asset
24
+ end
25
+
26
+ it 'supports a block which gets the found asset passed' do
27
+ asset = instance_double 'Middleman::Sprockets::Asset'
28
+ allow(asset).to receive(:source_path).and_return 'path/to/source'
29
+ expect(asset).to receive(:destination_path=).with 'path/to/source'
30
+ expect(asset).to receive(:match?).and_return true
31
+
32
+ list = AssetList.new
33
+ list << asset
34
+
35
+ list.lookup(asset) { |candidate, found_asset| found_asset.destination_path = found_asset.source_path }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,116 @@
1
+ # encoding: utf-8
2
+ RSpec.describe Asset do
3
+ context '#has_type?' do
4
+ it 'finds type by extension' do
5
+ asset = Asset.new('/source/path/to/image.png', source_directory: '/source/path/to')
6
+ expect(asset).to have_type :image
7
+ end
8
+
9
+ it 'finds type by path' do
10
+ asset = Asset.new('/source/path/to/images/image.xz', source_directory: '/source/path/to/images')
11
+ expect(asset).to have_type :image
12
+ end
13
+ end
14
+
15
+ context '#import?, #import_it' do
16
+ it 'fails if file does not exist' do
17
+ in_current_dir do
18
+ base_path = File.expand_path('source/path/to')
19
+ file_path = File.expand_path('source/path/to/image.xz')
20
+
21
+ asset = Asset.new(file_path, source_directory: base_path)
22
+
23
+ expect(asset).not_to be_import
24
+ end
25
+ end
26
+
27
+ it 'succeeds if import it is set' do
28
+ in_current_dir do
29
+ base_path = File.expand_path('source/path/to')
30
+ file_path = File.expand_path('source/path/to/image.xz')
31
+ write_file file_path, 'asdf'
32
+
33
+ asset = Asset.new(file_path, source_directory: base_path)
34
+ asset.import_it
35
+
36
+ expect(asset).to be_import
37
+ end
38
+ end
39
+
40
+ it 'succeeds if is in trusted directory images' do
41
+ in_current_dir do
42
+ base_path = File.expand_path('source/path/to/images')
43
+ file_path = File.expand_path('source/path/to/images/image.xz')
44
+ write_file file_path, 'asdf'
45
+
46
+ asset = Asset.new(file_path, source_directory: base_path)
47
+
48
+ expect(asset).to be_import
49
+ end
50
+ end
51
+ end
52
+
53
+ context '#destination_path, #destination_path=, #destination_directory' do
54
+ it 'returns @destination_path if set' do
55
+ in_current_dir do
56
+ base_path = File.expand_path('source/path/to/images')
57
+ file_path = File.expand_path('source/path/to/images/image.xz')
58
+
59
+ asset = Asset.new(file_path, source_directory: base_path)
60
+ asset.destination_path = 'asdf/image.xz'
61
+
62
+ expect(asset.destination_path).to eq Pathname.new('asdf/image.xz')
63
+ end
64
+ end
65
+
66
+ it 'builds path based on destination_directory and relative file path' do
67
+ in_current_dir do
68
+ base_path = File.expand_path('source/path/to/images')
69
+ file_path = File.expand_path('source/path/to/images/image.xz')
70
+
71
+ asset = Asset.new(file_path, source_directory: base_path)
72
+ asset.destination_directory = '/images'
73
+
74
+ expect(asset.destination_path.to_s).to eq '/images/image.xz'
75
+ end
76
+ end
77
+
78
+ it 'fails if destination_directory and @destination_path are not set' do
79
+ in_current_dir do
80
+ base_path = File.expand_path('source/path/to/images')
81
+ file_path = File.expand_path('source/path/to/images/image.xz')
82
+
83
+ asset = Asset.new(file_path, source_directory: base_path)
84
+
85
+ expect {
86
+ asset.destination_path
87
+ }.to raise_error ::Sprockets::FileNotFound
88
+ end
89
+ end
90
+ end
91
+
92
+ context '#match?' do
93
+ it 'success if source path is equal' do
94
+ in_current_dir do
95
+ base_path = File.expand_path('source/path/to')
96
+ file_path = File.expand_path('source/path/to/images/image.xz')
97
+
98
+ asset1 = Asset.new(file_path, source_directory: base_path)
99
+
100
+ expect(asset1).to be_match file_path
101
+ end
102
+ end
103
+
104
+ it 'fails if source path is not equal' do
105
+ in_current_dir do
106
+ base_path = File.expand_path('source/path/to')
107
+ file_path = File.expand_path('source/path/to/images/image.xz')
108
+
109
+ asset1 = Asset.new(file_path, source_directory: base_path)
110
+
111
+ expect(asset1).not_to be_match 'asdf'
112
+ end
113
+ end
114
+ end
115
+
116
+ end
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+ RSpec.describe ImportedAsset do
3
+ context '#output_path' do
4
+ it 'uses block as second argument on initialize to get path' do
5
+ asset = ImportedAsset.new 'source/to/asset/image.png', proc { 'hello/world.png' }
6
+
7
+ expect(asset.output_path.to_s).to eq 'hello/world.png'
8
+ end
9
+ end
10
+
11
+ context '#resolve_path_with' do
12
+ it 'resolves path' do
13
+ in_current_dir do
14
+ relative_path = 'source/path/to/image.xz'
15
+ file_path = File.expand_path(relative_path)
16
+
17
+ resolver = double('Environment')
18
+ expect(resolver).to receive(:resolve).with(Pathname.new(relative_path)).and_return file_path
19
+
20
+ asset = ImportedAsset.new relative_path
21
+ asset.resolve_path_with resolver
22
+ end
23
+ end
24
+
25
+ it 'raises an error if path could not be resolved' do
26
+ in_current_dir do
27
+ relative_path = 'source/path/to/image.xz'
28
+
29
+ resolver = double('Environment')
30
+ allow(resolver).to receive(:resolve).with(Pathname.new(relative_path)).and_return nil
31
+
32
+ asset = ImportedAsset.new relative_path
33
+
34
+ expect {
35
+ asset.resolve_path_with resolver
36
+ }.to raise_error ::Sprockets::FileNotFound
37
+ end
38
+ end
39
+ end
40
+
41
+ context '#match?' do
42
+ it 'succeeds if real path matches' do
43
+ in_current_dir do
44
+ relative_path = 'source/path/to/image.xz'
45
+ file_path = File.expand_path(relative_path)
46
+
47
+ resolver = double('Environment')
48
+ allow(resolver).to receive(:resolve).and_return file_path
49
+
50
+ asset = ImportedAsset.new relative_path
51
+ asset.resolve_path_with resolver
52
+
53
+ expect(asset).to be_match file_path
54
+ end
55
+ end
56
+
57
+ it 'fails if does not match' do
58
+ in_current_dir do
59
+ relative_path = 'source/path/to/image.xz'
60
+ file_path = File.expand_path(relative_path)
61
+
62
+ resolver = double('Environment')
63
+ allow(resolver).to receive(:resolve).and_return file_path + 'fail'
64
+
65
+ asset = ImportedAsset.new relative_path
66
+ asset.resolve_path_with resolver
67
+
68
+ expect(asset).not_to be_match file_path
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'simplecov'
5
+ SimpleCov.command_name 'rspec'
6
+ SimpleCov.start
7
+
8
+ # Pull in all of the gems including those in the `test` group
9
+ require 'bundler'
10
+ Bundler.require :default, :test, :development
11
+
12
+ require 'middleman-sprockets/extension'
13
+
14
+ Dir.glob(File.expand_path('../support/*', __FILE__)).each { |f| require_relative f }
15
+
16
+ include Middleman::Sprockets
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require 'aruba/api'
3
+
4
+ module Middleman
5
+ module Sprockets
6
+ module SpecHelper
7
+ include ::Aruba::Api
8
+ end
9
+ end
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ config.before(:each) do
14
+ clean_current_dir
15
+ end
16
+
17
+ config.include Middleman::Sprockets::SpecHelper
18
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ RSpec.configure do |config|
3
+ config.filter_run :focus
4
+ config.run_all_when_everything_filtered = true
5
+
6
+ config.order = :random
7
+ Kernel.srand config.seed
8
+
9
+ config.expect_with :rspec do |expectations|
10
+ expectations.syntax = :expect
11
+ end
12
+
13
+ config.mock_with :rspec do |mocks|
14
+ mocks.syntax = :expect
15
+ mocks.verify_partial_doubles = true
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.4
4
+ version: 3.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Reynolds
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-07-30 00:00:00.000000000 Z
13
+ date: 2014-08-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: middleman-core
@@ -78,6 +78,8 @@ extensions: []
78
78
  extra_rdoc_files: []
79
79
  files:
80
80
  - .gitignore
81
+ - .rspec
82
+ - .simplecov
81
83
  - .travis.yml
82
84
  - CHANGELOG.md
83
85
  - CONTRIBUTING.md
@@ -129,6 +131,16 @@ files:
129
131
  - fixtures/bower-app/bower_components/underscore/underscore.js
130
132
  - fixtures/bower-app/config.rb
131
133
  - fixtures/bower-app/source/javascripts/application.js
134
+ - fixtures/bower-individual-outputdir-app/bower.json
135
+ - fixtures/bower-individual-outputdir-app/bower_components/underscore/bower.json
136
+ - fixtures/bower-individual-outputdir-app/bower_components/underscore/underscore.js
137
+ - fixtures/bower-individual-outputdir-app/config.rb
138
+ - fixtures/bower-individual-outputdir-app/source/javascripts/application.js
139
+ - fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/.bower.json
140
+ - fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/bower.json
141
+ - fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/img/close.png
142
+ - fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/js/lightbox.js
143
+ - fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/package.json
132
144
  - fixtures/bower-json-app/config.rb
133
145
  - fixtures/bower-json-app/source/javascripts/application.js.coffee
134
146
  - fixtures/bower-json-app/source/javascripts/bower.json
@@ -200,13 +212,23 @@ files:
200
212
  - fixtures/sprockets-images-app/source/library/images/cat.jpg
201
213
  - fixtures/sprockets-images-app/vendor/assets/images/cat-2.jpg
202
214
  - lib/middleman-sprockets.rb
215
+ - lib/middleman-sprockets/asset.rb
216
+ - lib/middleman-sprockets/asset_list.rb
203
217
  - lib/middleman-sprockets/asset_tag_helpers.rb
204
218
  - lib/middleman-sprockets/config_only_environment.rb
205
219
  - lib/middleman-sprockets/environment.rb
206
220
  - lib/middleman-sprockets/extension.rb
221
+ - lib/middleman-sprockets/imported_asset.rb
222
+ - lib/middleman-sprockets/pathname_extensions.rb
207
223
  - lib/middleman-sprockets/sass_function_hack.rb
208
224
  - lib/middleman-sprockets/version.rb
209
225
  - middleman-sprockets.gemspec
226
+ - spec/asset_list_spec.rb
227
+ - spec/asset_spec.rb
228
+ - spec/imported_asset_spec.rb
229
+ - spec/spec_helper.rb
230
+ - spec/support/aruba.rb
231
+ - spec/support/rspec.rb
210
232
  homepage: https://github.com/middleman/middleman-sprockets
211
233
  licenses:
212
234
  - MIT
@@ -276,6 +298,16 @@ test_files:
276
298
  - fixtures/bower-app/bower_components/underscore/underscore.js
277
299
  - fixtures/bower-app/config.rb
278
300
  - fixtures/bower-app/source/javascripts/application.js
301
+ - fixtures/bower-individual-outputdir-app/bower.json
302
+ - fixtures/bower-individual-outputdir-app/bower_components/underscore/bower.json
303
+ - fixtures/bower-individual-outputdir-app/bower_components/underscore/underscore.js
304
+ - fixtures/bower-individual-outputdir-app/config.rb
305
+ - fixtures/bower-individual-outputdir-app/source/javascripts/application.js
306
+ - fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/.bower.json
307
+ - fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/bower.json
308
+ - fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/img/close.png
309
+ - fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/js/lightbox.js
310
+ - fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/package.json
279
311
  - fixtures/bower-json-app/config.rb
280
312
  - fixtures/bower-json-app/source/javascripts/application.js.coffee
281
313
  - fixtures/bower-json-app/source/javascripts/bower.json