middleman-sprockets 3.3.10 → 3.4.1
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Rakefile +5 -1
- data/features/sprockets.feature +12 -0
- data/fixtures/sprockets-imported-asset-path-conflicts-app/config.rb +4 -0
- data/fixtures/sprockets-imported-asset-path-conflicts-app/resources/assets/stylesheets/test.css +3 -0
- data/fixtures/sprockets-imported-assets-match-multiple-paths-app/config.rb +4 -0
- data/fixtures/sprockets-imported-assets-match-multiple-paths-app/vendor/assets/css/test.css +3 -0
- data/lib/middleman-sprockets.rb +7 -2
- data/lib/middleman-sprockets/asset.rb +57 -120
- data/lib/middleman-sprockets/environment.rb +8 -0
- data/lib/middleman-sprockets/extension.rb +62 -35
- data/lib/middleman-sprockets/imported_asset.rb +12 -39
- data/lib/middleman-sprockets/sass_utils.rb +14 -0
- data/lib/middleman-sprockets/version.rb +1 -1
- data/middleman-sprockets.gemspec +2 -2
- data/spec/asset_spec.rb +88 -95
- data/spec/imported_asset_spec.rb +25 -55
- metadata +27 -20
- data/lib/middleman-sprockets/asset_list.rb +0 -37
- data/spec/asset_list_spec.rb +0 -38
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 10c8f9ee3155e55fa3f141e5396cfac8ca05e3a5
|
|
4
|
+
data.tar.gz: 7ef430536757c24bf59da6aeb2563725415e0db1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed05bb9f91b5272b6540eccf96ee5722bb54e8b9972988db0e54f9d15bebaf827fc58b181760af011ff1c9a898f786294c328be949cb7e2b76869751073575d6
|
|
7
|
+
data.tar.gz: 49d1cc180c9ca4127859bc9564749aaffa93c26e925bac02b7df58fe169ba3a54c0a07a823846304731be5db22c973cd2656f2bdcde3a5956c50466625e4520d
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
|
@@ -13,7 +13,11 @@ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
|
|
13
13
|
t.cucumber_opts = "--color #{exempt_tags.join(" ")} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
16
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
17
|
+
if RUBY_VERSION < '2.0'
|
|
18
|
+
t.rspec_opts = '--tag ~@skip:one-nine'
|
|
19
|
+
end
|
|
20
|
+
end
|
|
17
21
|
|
|
18
22
|
require 'rake/clean'
|
|
19
23
|
|
data/features/sprockets.feature
CHANGED
|
@@ -146,3 +146,15 @@ Feature: Sprockets
|
|
|
146
146
|
Then a file named "fonts/font-awesome/fonts/fontawesome-webfont-bower.svg.gz" should exist
|
|
147
147
|
Then a file named "javascripts/jquery/jquery.min.js" should exist
|
|
148
148
|
Then a file named "javascripts/jquery/jquery.asdf.asdf.js.min.asdf" should exist
|
|
149
|
+
|
|
150
|
+
Scenario: Imported Asset matches multiple sprockets paths
|
|
151
|
+
Given a successfully built app at "sprockets-imported-assets-match-multiple-paths-app"
|
|
152
|
+
When I cd to "build"
|
|
153
|
+
Then a file named "assets/css/test.css" should exist
|
|
154
|
+
And a file named "assets/css/css/test.css" should not exist
|
|
155
|
+
|
|
156
|
+
Scenario: Imported Asset has a different 'asset type' directory than in config
|
|
157
|
+
Given a successfully built app at "sprockets-imported-asset-path-conflicts-app"
|
|
158
|
+
When I cd to "build"
|
|
159
|
+
Then a file named "assets/css/test.css" should exist
|
|
160
|
+
And a file named "assets/css/stylesheets/test.css" should not exist
|
data/lib/middleman-sprockets.rb
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
require "middleman-core"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
params = [:sprockets]
|
|
4
|
+
|
|
5
|
+
# If we're in v4
|
|
6
|
+
params << { auto_activate: :before_configuration } if Middleman::Extensions.method(:register).arity != -1
|
|
7
|
+
|
|
8
|
+
Middleman::Extensions.register(*params) do
|
|
4
9
|
require "middleman-sprockets/extension"
|
|
5
10
|
Middleman::SprocketsExtension
|
|
6
|
-
end
|
|
11
|
+
end
|
|
@@ -1,99 +1,40 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
module Middleman
|
|
3
3
|
module Sprockets
|
|
4
|
-
# Asset
|
|
5
|
-
class Asset
|
|
6
|
-
attr_reader :source_path, :relative_source_path, :base_name, :destination_directory, :source_directory
|
|
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(source_path, options)
|
|
16
|
-
source_directory = options.fetch(:source_directory, nil)
|
|
17
|
-
|
|
18
|
-
fail ArgumentError, 'Missing argument source_directory' unless source_directory
|
|
19
|
-
|
|
20
|
-
@source_directory = source_directory
|
|
21
|
-
|
|
22
|
-
@source_path = Pathname.new(source_path)
|
|
23
|
-
@relative_source_path = @source_path.relative_path_from(Pathname.new(source_directory))
|
|
24
|
-
@base_name = @source_path.basename
|
|
25
|
-
@import_it = false
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Should the asset imported?
|
|
29
|
-
#
|
|
30
|
-
# @return [true, false]
|
|
31
|
-
# Is true if it should be imported
|
|
32
|
-
def import?
|
|
33
|
-
valid? && (in_trusted_source_directory? || import_it?)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# Check on file type
|
|
37
|
-
#
|
|
38
|
-
# @return [true, false]
|
|
39
|
-
# Is true if has type
|
|
40
|
-
def has_type?(t)
|
|
41
|
-
type == t
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Path where the asset should be stored
|
|
45
|
-
#
|
|
46
|
-
# @return [Pathname]
|
|
47
|
-
# Returns `destination_path` if set, otherwise build result: destination_directory + relative_source_path
|
|
48
|
-
#
|
|
49
|
-
# @raise [::Sprockets::FileNotFound]
|
|
50
|
-
# Raise error if destination_directory was not set previously from outside
|
|
51
|
-
def destination_path
|
|
52
|
-
return @destination_path if @destination_path
|
|
53
4
|
|
|
54
|
-
|
|
5
|
+
class Asset
|
|
55
6
|
|
|
56
|
-
|
|
57
|
-
end
|
|
7
|
+
attr_reader :app, :sprockets, :asset
|
|
58
8
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
# to `Pathname`.
|
|
64
|
-
def destination_path=(path)
|
|
65
|
-
@destination_path = Pathname.new path
|
|
66
|
-
end
|
|
9
|
+
def initialize app, lookup_path, sprockets = app.sprockets
|
|
10
|
+
@app = app
|
|
11
|
+
@sprockets = sprockets
|
|
12
|
+
@asset = sprockets[ sprockets.resolve(lookup_path) ]
|
|
67
13
|
|
|
68
|
-
|
|
69
|
-
#
|
|
70
|
-
# @param [String] path
|
|
71
|
-
# The path to the destination directory
|
|
72
|
-
#
|
|
73
|
-
# @return [Pathname]
|
|
74
|
-
# The path as pathname
|
|
75
|
-
def destination_directory=(path)
|
|
76
|
-
@destination_directory = Pathname.new path
|
|
14
|
+
raise ::Sprockets::FileNotFound, "Couldn't find asset '#{lookup_path}'" if @asset.nil?
|
|
77
15
|
end
|
|
78
16
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
17
|
+
def destination_path
|
|
18
|
+
case type
|
|
19
|
+
when :image then
|
|
20
|
+
Pathname.new(app.config[:images_dir]) + remove_asset_dir(asset.logical_path, image_paths)
|
|
21
|
+
when :script then
|
|
22
|
+
Pathname.new(app.config[:js_dir]) + remove_asset_dir(asset.logical_path, script_paths)
|
|
23
|
+
when :font then
|
|
24
|
+
Pathname.new(app.config[:fonts_dir]) + remove_asset_dir(asset.logical_path, font_paths)
|
|
25
|
+
when :stylesheet then
|
|
26
|
+
Pathname.new(app.config[:css_dir]) + remove_asset_dir(asset.logical_path, stylesheet_paths)
|
|
27
|
+
else
|
|
28
|
+
asset.logical_path
|
|
29
|
+
end
|
|
87
30
|
end
|
|
88
31
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
@import_it = true # single =
|
|
32
|
+
def source_dir
|
|
33
|
+
@source_dir ||= source_path.sub /\/?#{asset.logical_path}$/, ''
|
|
92
34
|
end
|
|
93
35
|
|
|
94
|
-
def
|
|
95
|
-
|
|
96
|
-
source_directory.end_with?('fonts')
|
|
36
|
+
def source_path
|
|
37
|
+
asset.pathname
|
|
97
38
|
end
|
|
98
39
|
|
|
99
40
|
def type
|
|
@@ -110,31 +51,14 @@ module Middleman
|
|
|
110
51
|
end
|
|
111
52
|
end
|
|
112
53
|
|
|
113
|
-
|
|
114
|
-
source_path.file?
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def partial?
|
|
118
|
-
base_name.to_s.start_with? '_'
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
# Is it a valid asset
|
|
122
|
-
# @return [true, false]
|
|
123
|
-
# If the asset is valid return true
|
|
124
|
-
def valid?
|
|
125
|
-
file? && !partial?
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def import_it?
|
|
129
|
-
@import_it == true # double =
|
|
130
|
-
end
|
|
54
|
+
private
|
|
131
55
|
|
|
132
|
-
def has_extname?
|
|
133
|
-
!(
|
|
56
|
+
def has_extname? *exts
|
|
57
|
+
!(exts & asset.pathname.to_s.scan(/(\.[^.]+)/).flatten).empty?
|
|
134
58
|
end
|
|
135
59
|
|
|
136
|
-
def
|
|
137
|
-
|
|
60
|
+
def remove_asset_dir pathname, asset_dir_paths
|
|
61
|
+
pathname.sub(/^(#{asset_dir_paths.map { |p| Regexp.new(p) }.join('|')})\/?/, '')
|
|
138
62
|
end
|
|
139
63
|
|
|
140
64
|
def is_image?
|
|
@@ -142,10 +66,8 @@ module Middleman
|
|
|
142
66
|
end
|
|
143
67
|
|
|
144
68
|
def is_image_by_path?
|
|
145
|
-
|
|
146
|
-
File.basename(
|
|
147
|
-
source_path.dirname.basename.to_s == 'images' ||
|
|
148
|
-
source_path.dirname.basename.to_s == 'img'
|
|
69
|
+
image_paths.include?(source_path.dirname.basename.to_s) ||
|
|
70
|
+
image_paths.include?(File.basename(source_dir.to_s))
|
|
149
71
|
end
|
|
150
72
|
alias_method :is_in_images_directory?, :is_image_by_path?
|
|
151
73
|
|
|
@@ -153,19 +75,26 @@ module Middleman
|
|
|
153
75
|
has_extname?(*%w(.gif .png .jpg .jpeg .webp .svg .svgz))
|
|
154
76
|
end
|
|
155
77
|
|
|
78
|
+
def image_paths
|
|
79
|
+
%w( images img )
|
|
80
|
+
end
|
|
81
|
+
|
|
156
82
|
def is_stylesheet?
|
|
157
83
|
is_stylesheet_by_path? || is_stylesheet_by_extension?
|
|
158
84
|
end
|
|
159
85
|
|
|
86
|
+
def is_stylesheet_by_path?
|
|
87
|
+
stylesheet_paths.include?(source_path.dirname.basename.to_s) ||
|
|
88
|
+
stylesheet_paths.include?(File.basename(source_dir.to_s))
|
|
89
|
+
end
|
|
90
|
+
alias_method :is_in_stylesheet_directory?, :is_stylesheet_by_path?
|
|
91
|
+
|
|
160
92
|
def is_stylesheet_by_extension?
|
|
161
93
|
has_extname?(*%w(.css .sass .scss .styl .less))
|
|
162
94
|
end
|
|
163
95
|
|
|
164
|
-
def
|
|
165
|
-
|
|
166
|
-
File.basename(source_directory.to_s) == 'css' ||
|
|
167
|
-
source_path.dirname.basename.to_s == 'stylesheets' ||
|
|
168
|
-
source_path.dirname.basename.to_s == 'css'
|
|
96
|
+
def stylesheet_paths
|
|
97
|
+
%w( stylesheets css )
|
|
169
98
|
end
|
|
170
99
|
|
|
171
100
|
def is_font?
|
|
@@ -173,8 +102,8 @@ module Middleman
|
|
|
173
102
|
end
|
|
174
103
|
|
|
175
104
|
def is_font_by_path?
|
|
176
|
-
|
|
177
|
-
|
|
105
|
+
font_paths.include?(source_path.dirname.basename.to_s) ||
|
|
106
|
+
font_paths.include?(File.basename(source_dir.to_s))
|
|
178
107
|
end
|
|
179
108
|
alias_method :is_in_fonts_directory?, :is_font_by_path?
|
|
180
109
|
|
|
@@ -182,20 +111,28 @@ module Middleman
|
|
|
182
111
|
has_extname?(*%w(.ttf .woff .eot .otf .svg .svgz))
|
|
183
112
|
end
|
|
184
113
|
|
|
114
|
+
def font_paths
|
|
115
|
+
%w( fonts )
|
|
116
|
+
end
|
|
117
|
+
|
|
185
118
|
def is_script?
|
|
186
119
|
is_script_by_path? || is_script_by_extension?
|
|
187
120
|
end
|
|
188
121
|
|
|
189
122
|
def is_script_by_path?
|
|
190
|
-
|
|
191
|
-
File.basename(
|
|
192
|
-
source_path.dirname.basename.to_s == 'javascripts' ||
|
|
193
|
-
source_path.dirname.basename.to_s == 'js'
|
|
123
|
+
script_paths.include?(source_path.dirname.basename.to_s) ||
|
|
124
|
+
script_paths.include?(File.basename(source_dir.to_s))
|
|
194
125
|
end
|
|
126
|
+
alias_method :is_in_scripts_directory?, :is_script_by_path?
|
|
195
127
|
|
|
196
128
|
def is_script_by_extension?
|
|
197
129
|
has_extname?(*%w(.js .coffee))
|
|
198
130
|
end
|
|
131
|
+
|
|
132
|
+
def script_paths
|
|
133
|
+
%w( javascripts js )
|
|
134
|
+
end
|
|
135
|
+
|
|
199
136
|
end
|
|
200
137
|
end
|
|
201
138
|
end
|
|
@@ -215,6 +215,14 @@ module Middleman
|
|
|
215
215
|
return response
|
|
216
216
|
end
|
|
217
217
|
|
|
218
|
+
if resource
|
|
219
|
+
# incase the path has been rewrite, let sprockets know the original so it can find it
|
|
220
|
+
logical_path = resource.metadata.fetch(:options, {})
|
|
221
|
+
.fetch(:sprockets, {})
|
|
222
|
+
.fetch(:logical_path, nil)
|
|
223
|
+
env['PATH_INFO'] = logical_path.to_s if logical_path
|
|
224
|
+
end
|
|
225
|
+
|
|
218
226
|
super
|
|
219
227
|
end
|
|
220
228
|
|
|
@@ -2,11 +2,22 @@ require "sprockets"
|
|
|
2
2
|
require "sprockets-sass"
|
|
3
3
|
require "middleman-sprockets/asset"
|
|
4
4
|
require "middleman-sprockets/imported_asset"
|
|
5
|
-
require "middleman-sprockets/asset_list"
|
|
6
5
|
require "middleman-sprockets/config_only_environment"
|
|
7
6
|
require "middleman-sprockets/environment"
|
|
8
7
|
require "middleman-sprockets/asset_tag_helpers"
|
|
9
8
|
|
|
9
|
+
class Sprockets::Sass::SassTemplate
|
|
10
|
+
# Get the default, global Sass options. Start with Compass's
|
|
11
|
+
# options, if it's available.
|
|
12
|
+
def default_sass_options
|
|
13
|
+
if defined?(Compass) && defined?(Compass.configuration)
|
|
14
|
+
merge_sass_options Compass.configuration.to_sass_engine_options.dup, Sprockets::Sass.options
|
|
15
|
+
else
|
|
16
|
+
Sprockets::Sass.options.dup
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
10
21
|
# Sprockets extension
|
|
11
22
|
module Middleman
|
|
12
23
|
class SprocketsExtension < Extension
|
|
@@ -26,13 +37,19 @@ module Middleman
|
|
|
26
37
|
|
|
27
38
|
def initialize(app, options_hash={}, &block)
|
|
28
39
|
require "middleman-sprockets/sass_function_hack"
|
|
40
|
+
require "middleman-sprockets/sass_utils"
|
|
29
41
|
|
|
30
42
|
super
|
|
31
43
|
|
|
32
44
|
# Start out with a stub environment that can only be configured (paths and such)
|
|
33
45
|
@environment = ::Middleman::Sprockets::ConfigOnlyEnvironment.new
|
|
34
46
|
|
|
35
|
-
|
|
47
|
+
# v4
|
|
48
|
+
if app.respond_to? :add_to_config_context
|
|
49
|
+
app.add_to_config_context :sprockets, &method(:environment)
|
|
50
|
+
else
|
|
51
|
+
app.send :include, SprocketsAccessor
|
|
52
|
+
end
|
|
36
53
|
end
|
|
37
54
|
|
|
38
55
|
helpers do
|
|
@@ -45,7 +62,9 @@ module Middleman
|
|
|
45
62
|
::Tilt.register ::Sprockets::EcoTemplate, 'eco'
|
|
46
63
|
::Tilt.register ::Sprockets::JstProcessor, 'jst'
|
|
47
64
|
|
|
48
|
-
app.template_extensions
|
|
65
|
+
if app.respond_to?(:template_extensions)
|
|
66
|
+
app.template_extensions :jst => :js, :eco => :js, :ejs => :js
|
|
67
|
+
end
|
|
49
68
|
|
|
50
69
|
if app.config.defines_setting?(:debug_assets) && !options.setting(:debug_assets).value_set?
|
|
51
70
|
options[:debug_assets] = app.config[:debug_assets]
|
|
@@ -57,6 +76,7 @@ module Middleman
|
|
|
57
76
|
config_environment.apply_to_environment(@environment)
|
|
58
77
|
|
|
59
78
|
append_paths_from_gems
|
|
79
|
+
import_images_and_fonts_from_gems
|
|
60
80
|
|
|
61
81
|
# Setup Sprockets Sass options
|
|
62
82
|
if app.config.defines_setting?(:sass)
|
|
@@ -73,43 +93,24 @@ module Middleman
|
|
|
73
93
|
|
|
74
94
|
# Add sitemap resource for every image in the sprockets load path
|
|
75
95
|
def manipulate_resource_list(resources)
|
|
76
|
-
imported_assets = Middleman::Sprockets::AssetList.new
|
|
77
|
-
|
|
78
|
-
environment.imported_assets.each do |asset|
|
|
79
|
-
asset.resolve_path_with environment
|
|
80
|
-
@app.logger.debug "== Importing Sprockets asset #{asset.real_path}"
|
|
81
|
-
|
|
82
|
-
imported_assets << asset
|
|
83
|
-
end
|
|
84
|
-
|
|
85
96
|
resources_list = []
|
|
86
|
-
environment.paths.each do |load_path|
|
|
87
|
-
environment.each_entry(load_path) do |path|
|
|
88
|
-
asset = Middleman::Sprockets::Asset.new(path, source_directory: load_path)
|
|
89
|
-
|
|
90
|
-
imported_assets.lookup(asset) do |candidate, found_asset|
|
|
91
|
-
candidate.destination_path = found_asset.output_path if found_asset.output_path
|
|
92
|
-
candidate.import_it
|
|
93
|
-
end
|
|
94
97
|
|
|
95
|
-
|
|
98
|
+
environment.imported_assets.each do |imported_asset|
|
|
99
|
+
asset = Middleman::Sprockets::Asset.new @app, imported_asset.logical_path, environment
|
|
100
|
+
if imported_asset.output_path
|
|
101
|
+
destination = imported_asset.output_path
|
|
102
|
+
else
|
|
103
|
+
destination = @app.sitemap.extensionless_path( asset.destination_path.to_s )
|
|
104
|
+
end
|
|
96
105
|
|
|
97
|
-
|
|
98
|
-
asset.destination_directory = @app.config[:images_dir]
|
|
99
|
-
elsif asset.has_type? :script
|
|
100
|
-
asset.destination_directory = @app.config[:js_dir]
|
|
101
|
-
elsif asset.has_type? :font
|
|
102
|
-
asset.destination_directory = @app.config[:fonts_dir]
|
|
103
|
-
elsif asset.has_type? :stylesheet
|
|
104
|
-
asset.destination_directory = @app.config[:css_dir]
|
|
105
|
-
end
|
|
106
|
+
next if @app.sitemap.find_resource_by_destination_path destination.to_s
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
resource = ::Middleman::Sitemap::Resource.new( @app.sitemap, destination.to_s, asset.source_path.to_s )
|
|
109
|
+
resource.add_metadata options: { sprockets: { logical_path: imported_asset.logical_path }}
|
|
108
110
|
|
|
109
|
-
|
|
110
|
-
resources_list << ::Middleman::Sitemap::Resource.new(@app.sitemap, new_path.to_s, path.to_s)
|
|
111
|
-
end
|
|
111
|
+
resources_list << resource
|
|
112
112
|
end
|
|
113
|
+
|
|
113
114
|
resources + resources_list
|
|
114
115
|
end
|
|
115
116
|
|
|
@@ -117,7 +118,7 @@ module Middleman
|
|
|
117
118
|
|
|
118
119
|
# Add any directories from gems with Rails-like paths to sprockets load path
|
|
119
120
|
def append_paths_from_gems
|
|
120
|
-
root_paths =
|
|
121
|
+
root_paths = rubygems_latest_specs.map(&:full_gem_path) << app.root
|
|
121
122
|
base_paths = %w[assets app app/assets vendor vendor/assets lib lib/assets]
|
|
122
123
|
asset_dirs = %w[javascripts js stylesheets css images img fonts]
|
|
123
124
|
|
|
@@ -126,5 +127,31 @@ module Middleman
|
|
|
126
127
|
environment.append_path(path) if File.directory?(path)
|
|
127
128
|
end
|
|
128
129
|
end
|
|
130
|
+
|
|
131
|
+
# Backwards compatible means of finding all the latest gemspecs
|
|
132
|
+
# available on the system
|
|
133
|
+
#
|
|
134
|
+
# @private
|
|
135
|
+
# @return [Array] Array of latest Gem::Specification
|
|
136
|
+
def rubygems_latest_specs
|
|
137
|
+
# If newer Rubygems
|
|
138
|
+
if ::Gem::Specification.respond_to? :latest_specs
|
|
139
|
+
::Gem::Specification.latest_specs(true)
|
|
140
|
+
else
|
|
141
|
+
::Gem.source_index.latest_specs
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def import_images_and_fonts_from_gems
|
|
146
|
+
trusted_paths = environment.paths.select { |p| p.end_with?('images') || p.end_with?('fonts') }
|
|
147
|
+
trusted_paths.each do |load_path|
|
|
148
|
+
environment.each_entry(load_path) do |path|
|
|
149
|
+
if path.file? && !path.basename.to_s.start_with?('_')
|
|
150
|
+
logical_path = path.sub /^#{load_path}/, ''
|
|
151
|
+
environment.imported_assets << Middleman::Sprockets::ImportedAsset.new(logical_path)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
129
156
|
end
|
|
130
157
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
module Middleman
|
|
3
3
|
module Sprockets
|
|
4
|
-
# ImportedAsset
|
|
4
|
+
# ImportedAsset
|
|
5
5
|
class ImportedAsset
|
|
6
|
-
attr_reader :logical_path, :output_path
|
|
6
|
+
attr_reader :logical_path, :output_path
|
|
7
7
|
|
|
8
8
|
# Create instance
|
|
9
9
|
#
|
|
@@ -12,45 +12,18 @@ module Middleman
|
|
|
12
12
|
#
|
|
13
13
|
# @param [proc] output_dir
|
|
14
14
|
# An individual output directory for that particular asset
|
|
15
|
-
def initialize
|
|
16
|
-
@logical_path = Pathname.new
|
|
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
|
|
15
|
+
def initialize logical_path, output_path = nil
|
|
16
|
+
@logical_path = Pathname.new logical_path
|
|
49
17
|
|
|
50
|
-
|
|
18
|
+
if output_path.respond_to? :call
|
|
19
|
+
if output_path.arity.abs == 1
|
|
20
|
+
output_path = output_path.call(@logical_path)
|
|
21
|
+
else
|
|
22
|
+
output_path = output_path.call
|
|
23
|
+
end
|
|
24
|
+
end
|
|
51
25
|
|
|
52
|
-
|
|
53
|
-
real_path == path
|
|
26
|
+
@output_path = Pathname.new output_path if output_path
|
|
54
27
|
end
|
|
55
28
|
end
|
|
56
29
|
end
|
data/middleman-sprockets.gemspec
CHANGED
|
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
|
|
|
15
15
|
s.files = `git ls-files -z`.split("\0")
|
|
16
16
|
s.test_files = `git ls-files -z -- {fixtures,features}/*`.split("\0")
|
|
17
17
|
s.require_paths = ["lib"]
|
|
18
|
-
s.add_dependency("middleman-core", ["
|
|
18
|
+
s.add_dependency("middleman-core", [">= 3.3"])
|
|
19
19
|
s.add_dependency("sprockets", ["~> 2.12.1"])
|
|
20
|
-
s.add_dependency("sprockets-sass", ["~> 1.
|
|
20
|
+
s.add_dependency("sprockets-sass", ["~> 1.3.0"])
|
|
21
21
|
s.add_dependency("sprockets-helpers", ["~> 1.1.0"])
|
|
22
22
|
end
|
data/spec/asset_spec.rb
CHANGED
|
@@ -1,125 +1,118 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
-
RSpec.describe Asset do
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
RSpec.describe Middleman::Sprockets::Asset do
|
|
3
|
+
|
|
4
|
+
def build_subject_asset logical_path, source_dir
|
|
5
|
+
source_path = File.join source_dir, logical_path
|
|
6
|
+
@sprockets_double = instance_double("Middleman::Sprockets::Environment")
|
|
7
|
+
@app_double = double("Middleman::Application",
|
|
8
|
+
sprockets: @sprockets_double,
|
|
9
|
+
config: ::Middleman::Util.recursively_enhance(images_dir: 'images'))
|
|
10
|
+
@asset_double = instance_double("Sprockets::BundledAsset",
|
|
11
|
+
pathname: Pathname.new(source_path),
|
|
12
|
+
logical_path: logical_path)
|
|
13
|
+
allow( @sprockets_double ).to receive(:resolve).with(source_path)
|
|
14
|
+
.and_return("anything")
|
|
15
|
+
allow( @sprockets_double ).to receive(:[]).with("anything")
|
|
16
|
+
.and_return(@asset_double)
|
|
17
|
+
|
|
18
|
+
return described_class.new @app_double, source_path
|
|
19
|
+
end
|
|
8
20
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
end
|
|
21
|
+
describe "#initialize" do
|
|
22
|
+
it "raises Sprockets::FileNotFound if sprockets can't find the asset" do
|
|
23
|
+
source_path = "/path/to/nowhere.jpg"
|
|
13
24
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
@sprockets_double = instance_double("Middleman::Sprockets::Environment")
|
|
26
|
+
@app_double = double("Middleman::Application",
|
|
27
|
+
sprockets: @sprockets_double)
|
|
28
|
+
allow( @sprockets_double ).to receive(:resolve).with(source_path)
|
|
29
|
+
.and_return("anything")
|
|
18
30
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
# mimic sprockets unable to find an asset
|
|
32
|
+
allow( @sprockets_double ).to receive(:[]).with("anything")
|
|
33
|
+
.and_return(nil)
|
|
34
|
+
|
|
35
|
+
expect {
|
|
36
|
+
described_class.new @app_double, source_path
|
|
37
|
+
}.to raise_error Sprockets::FileNotFound
|
|
22
38
|
end
|
|
23
39
|
end
|
|
24
40
|
|
|
25
|
-
|
|
26
|
-
it 'fails if file does not exist' do
|
|
27
|
-
in_current_dir do
|
|
28
|
-
base_path = File.expand_path('source/path/to')
|
|
29
|
-
file_path = File.expand_path('source/path/to/image.xz')
|
|
41
|
+
describe "#type" do
|
|
30
42
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
end
|
|
35
|
-
end
|
|
43
|
+
it 'finds type by extension' do
|
|
44
|
+
image = build_subject_asset 'path/to/image.png', 'source'
|
|
45
|
+
expect( image.type ).to eq :image
|
|
36
46
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
base_path = File.expand_path('source/path/to')
|
|
40
|
-
file_path = File.expand_path('source/path/to/image.xz')
|
|
41
|
-
write_file file_path, 'asdf'
|
|
47
|
+
stylesheet = build_subject_asset 'path/to/stylesheet.css', 'source'
|
|
48
|
+
expect( stylesheet.type ).to eq :stylesheet
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
script = build_subject_asset 'path/to/script.js', 'source'
|
|
51
|
+
expect( script.type ).to eq :script
|
|
45
52
|
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
font = build_subject_asset 'path/to/font.ttf', 'source'
|
|
54
|
+
expect( font.type ).to eq :font
|
|
48
55
|
end
|
|
49
56
|
|
|
50
|
-
it '
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
it 'finds type by path' do
|
|
58
|
+
image = build_subject_asset 'path/to/images/image.foo', 'source'
|
|
59
|
+
expect( image.type ).to eq :image
|
|
60
|
+
image = build_subject_asset 'path/to/image.foo', 'images'
|
|
61
|
+
expect( image.type ).to eq :image
|
|
62
|
+
|
|
63
|
+
stylesheet = build_subject_asset 'path/to/css/stylesheet.foo', 'source'
|
|
64
|
+
expect( stylesheet.type ).to eq :stylesheet
|
|
65
|
+
image = build_subject_asset 'path/to/stylesheet.foo', 'css'
|
|
66
|
+
expect( image.type ).to eq :stylesheet
|
|
67
|
+
|
|
68
|
+
script = build_subject_asset 'path/to/javascripts/script.foo', 'source'
|
|
69
|
+
expect( script.type ).to eq :script
|
|
70
|
+
image = build_subject_asset 'path/to/script.foo', 'javascripts'
|
|
71
|
+
expect( image.type ).to eq :script
|
|
72
|
+
|
|
73
|
+
font = build_subject_asset 'path/to/fonts/font.foo', 'source'
|
|
74
|
+
expect( font.type ).to eq :font
|
|
75
|
+
font = build_subject_asset 'path/to/font.foo', 'fonts'
|
|
76
|
+
expect( font.type ).to eq :font
|
|
60
77
|
end
|
|
61
|
-
end
|
|
62
78
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
base_path = File.expand_path('source/path/to/images')
|
|
67
|
-
file_path = File.expand_path('source/path/to/images/image.xz')
|
|
79
|
+
it 'finds type by double extension' do
|
|
80
|
+
image = build_subject_asset 'path/to/image.svg.erb', 'source'
|
|
81
|
+
expect( image.type ).to eq :image
|
|
68
82
|
|
|
69
|
-
|
|
70
|
-
|
|
83
|
+
stylesheet = build_subject_asset 'path/to/stylesheet.css.scss', 'source'
|
|
84
|
+
expect( stylesheet.type ).to eq :stylesheet
|
|
71
85
|
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
script = build_subject_asset 'path/to/script.js.coffee', 'source'
|
|
87
|
+
expect( script.type ).to eq :script
|
|
74
88
|
end
|
|
75
89
|
|
|
76
|
-
it '
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
file_path = File.expand_path('source/path/to/images/image.xz')
|
|
80
|
-
|
|
81
|
-
asset = Asset.new(file_path, source_directory: base_path)
|
|
82
|
-
asset.destination_directory = '/images'
|
|
83
|
-
|
|
84
|
-
expect(asset.destination_path.to_s).to eq '/images/image.xz'
|
|
85
|
-
end
|
|
90
|
+
it 'finds type in an unlimited number of extensions' do
|
|
91
|
+
asset = script = build_subject_asset 'path/to/image.asdf.png.asdf.xz', 'source'
|
|
92
|
+
expect( asset.type ).to eq :image
|
|
86
93
|
end
|
|
94
|
+
end
|
|
87
95
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
asset = Asset.new(file_path, source_directory: base_path)
|
|
96
|
+
describe "#source_path" do
|
|
97
|
+
it "returns pathname from sprockets asset" do
|
|
98
|
+
asset = build_subject_asset 'path/to/asset.css', 'source'
|
|
99
|
+
expect( @asset_double ).to receive(:pathname)
|
|
100
|
+
.and_return("sprockets/pathname")
|
|
94
101
|
|
|
95
|
-
|
|
96
|
-
asset.destination_path
|
|
97
|
-
}.to raise_error ::Sprockets::FileNotFound
|
|
98
|
-
end
|
|
102
|
+
expect( asset.source_path ).to eq "sprockets/pathname"
|
|
99
103
|
end
|
|
100
104
|
end
|
|
101
105
|
|
|
102
|
-
|
|
103
|
-
it
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
file_path = File.expand_path('source/path/to/images/image.xz')
|
|
107
|
-
|
|
108
|
-
asset1 = Asset.new(file_path, source_directory: base_path)
|
|
109
|
-
|
|
110
|
-
expect(asset1).to be_match file_path
|
|
111
|
-
end
|
|
106
|
+
describe "#destination_path" do
|
|
107
|
+
it "builds path based on asset type" do
|
|
108
|
+
asset = build_subject_asset 'path/to/image.png', 'source'
|
|
109
|
+
expect( asset.destination_path.to_s ).to eq 'images/path/to/image.png'
|
|
112
110
|
end
|
|
113
111
|
|
|
114
|
-
it
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
file_path = File.expand_path('source/path/to/images/image.xz')
|
|
118
|
-
|
|
119
|
-
asset1 = Asset.new(file_path, source_directory: base_path)
|
|
120
|
-
|
|
121
|
-
expect(asset1).not_to be_match 'asdf'
|
|
122
|
-
end
|
|
112
|
+
it "strips asset type directory from logical path and uses apps asset directory" do
|
|
113
|
+
asset = build_subject_asset 'img/path/to/image.png', 'source'
|
|
114
|
+
expect( asset.destination_path.to_s ).to eq 'images/path/to/image.png'
|
|
123
115
|
end
|
|
124
116
|
end
|
|
117
|
+
|
|
125
118
|
end
|
data/spec/imported_asset_spec.rb
CHANGED
|
@@ -1,72 +1,42 @@
|
|
|
1
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' }
|
|
2
|
+
RSpec.describe Middleman::Sprockets::ImportedAsset do
|
|
6
3
|
|
|
7
|
-
|
|
4
|
+
describe "#initialize" do
|
|
5
|
+
it "sets #logical_path to a pathname based on given path" do
|
|
6
|
+
subject = described_class.new "logical"
|
|
7
|
+
expect( subject.logical_path ).to eq Pathname.new("logical")
|
|
8
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
9
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
it "sets #output_path to nil if no block given" do
|
|
11
|
+
subject = described_class.new "logical"
|
|
12
|
+
expect( subject.output_path ).to be_nil
|
|
23
13
|
end
|
|
24
14
|
|
|
25
|
-
it
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
15
|
+
it "sets #output_path based on return of passed block" do
|
|
16
|
+
subject = described_class.new "logical", -> { "hello" }
|
|
17
|
+
expect( subject.output_path ).to eq Pathname.new("hello")
|
|
38
18
|
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
19
|
|
|
50
|
-
|
|
51
|
-
|
|
20
|
+
it "passes #logical_path to the output_path block if it accepts an argument" do
|
|
21
|
+
output_double = proc { |arg| "hello" }
|
|
22
|
+
expect( output_double ).to receive(:call).with(Pathname.new("logical"))
|
|
52
23
|
|
|
53
|
-
|
|
54
|
-
end
|
|
24
|
+
described_class.new "logical", output_double
|
|
55
25
|
end
|
|
56
26
|
|
|
57
|
-
it
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
file_path = File.expand_path(relative_path)
|
|
27
|
+
it "passes #logical_path to the output_path block if it accepts an argument and has a default", skip: '1.9' do
|
|
28
|
+
output_double = lambda { |arg=3| "hello" }
|
|
29
|
+
expect( output_double ).to receive(:call).with(Pathname.new("logical"))
|
|
61
30
|
|
|
62
|
-
|
|
63
|
-
|
|
31
|
+
described_class.new "logical", output_double
|
|
32
|
+
end
|
|
64
33
|
|
|
65
|
-
|
|
66
|
-
|
|
34
|
+
it "calls output_path block with no args it it accepts none" do
|
|
35
|
+
output_double = -> { "hello" }
|
|
36
|
+
expect( output_double ).to receive(:call).with no_args()
|
|
67
37
|
|
|
68
|
-
|
|
69
|
-
end
|
|
38
|
+
described_class.new "logical", output_double
|
|
70
39
|
end
|
|
71
40
|
end
|
|
41
|
+
|
|
72
42
|
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.
|
|
4
|
+
version: 3.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Reynolds
|
|
@@ -10,62 +10,62 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2014-
|
|
13
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: middleman-core
|
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
|
18
18
|
requirements:
|
|
19
|
-
- -
|
|
19
|
+
- - ">="
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
21
|
version: '3.3'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
25
|
requirements:
|
|
26
|
-
- -
|
|
26
|
+
- - ">="
|
|
27
27
|
- !ruby/object:Gem::Version
|
|
28
28
|
version: '3.3'
|
|
29
29
|
- !ruby/object:Gem::Dependency
|
|
30
30
|
name: sprockets
|
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
|
32
32
|
requirements:
|
|
33
|
-
- - ~>
|
|
33
|
+
- - "~>"
|
|
34
34
|
- !ruby/object:Gem::Version
|
|
35
35
|
version: 2.12.1
|
|
36
36
|
type: :runtime
|
|
37
37
|
prerelease: false
|
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
39
39
|
requirements:
|
|
40
|
-
- - ~>
|
|
40
|
+
- - "~>"
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
42
|
version: 2.12.1
|
|
43
43
|
- !ruby/object:Gem::Dependency
|
|
44
44
|
name: sprockets-sass
|
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements:
|
|
47
|
-
- - ~>
|
|
47
|
+
- - "~>"
|
|
48
48
|
- !ruby/object:Gem::Version
|
|
49
|
-
version: 1.
|
|
49
|
+
version: 1.3.0
|
|
50
50
|
type: :runtime
|
|
51
51
|
prerelease: false
|
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
|
53
53
|
requirements:
|
|
54
|
-
- - ~>
|
|
54
|
+
- - "~>"
|
|
55
55
|
- !ruby/object:Gem::Version
|
|
56
|
-
version: 1.
|
|
56
|
+
version: 1.3.0
|
|
57
57
|
- !ruby/object:Gem::Dependency
|
|
58
58
|
name: sprockets-helpers
|
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
|
60
60
|
requirements:
|
|
61
|
-
- - ~>
|
|
61
|
+
- - "~>"
|
|
62
62
|
- !ruby/object:Gem::Version
|
|
63
63
|
version: 1.1.0
|
|
64
64
|
type: :runtime
|
|
65
65
|
prerelease: false
|
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
|
67
67
|
requirements:
|
|
68
|
-
- - ~>
|
|
68
|
+
- - "~>"
|
|
69
69
|
- !ruby/object:Gem::Version
|
|
70
70
|
version: 1.1.0
|
|
71
71
|
description: Sprockets support for Middleman
|
|
@@ -77,10 +77,10 @@ executables: []
|
|
|
77
77
|
extensions: []
|
|
78
78
|
extra_rdoc_files: []
|
|
79
79
|
files:
|
|
80
|
-
- .gitignore
|
|
81
|
-
- .rspec
|
|
82
|
-
- .simplecov
|
|
83
|
-
- .travis.yml
|
|
80
|
+
- ".gitignore"
|
|
81
|
+
- ".rspec"
|
|
82
|
+
- ".simplecov"
|
|
83
|
+
- ".travis.yml"
|
|
84
84
|
- CHANGELOG.md
|
|
85
85
|
- CONTRIBUTING.md
|
|
86
86
|
- Gemfile
|
|
@@ -212,6 +212,10 @@ files:
|
|
|
212
212
|
- fixtures/sprockets-images-app/source/index.html.erb
|
|
213
213
|
- fixtures/sprockets-images-app/source/library/images/cat.jpg
|
|
214
214
|
- fixtures/sprockets-images-app/vendor/assets/images/cat-2.jpg
|
|
215
|
+
- fixtures/sprockets-imported-asset-path-conflicts-app/config.rb
|
|
216
|
+
- fixtures/sprockets-imported-asset-path-conflicts-app/resources/assets/stylesheets/test.css
|
|
217
|
+
- fixtures/sprockets-imported-assets-match-multiple-paths-app/config.rb
|
|
218
|
+
- fixtures/sprockets-imported-assets-match-multiple-paths-app/vendor/assets/css/test.css
|
|
215
219
|
- fixtures/sprockets-multiple-extensions-app/bower.json
|
|
216
220
|
- fixtures/sprockets-multiple-extensions-app/config.rb
|
|
217
221
|
- fixtures/sprockets-multiple-extensions-app/source/fonts/fontawesome-webfont-source.svg.gz
|
|
@@ -230,16 +234,15 @@ files:
|
|
|
230
234
|
- fixtures/sprockets-svg-font-app/vendor/assets/components/font-awesome/fonts/fontawesome-webfont-bower.ttf.gz
|
|
231
235
|
- lib/middleman-sprockets.rb
|
|
232
236
|
- lib/middleman-sprockets/asset.rb
|
|
233
|
-
- lib/middleman-sprockets/asset_list.rb
|
|
234
237
|
- lib/middleman-sprockets/asset_tag_helpers.rb
|
|
235
238
|
- lib/middleman-sprockets/config_only_environment.rb
|
|
236
239
|
- lib/middleman-sprockets/environment.rb
|
|
237
240
|
- lib/middleman-sprockets/extension.rb
|
|
238
241
|
- lib/middleman-sprockets/imported_asset.rb
|
|
239
242
|
- lib/middleman-sprockets/sass_function_hack.rb
|
|
243
|
+
- lib/middleman-sprockets/sass_utils.rb
|
|
240
244
|
- lib/middleman-sprockets/version.rb
|
|
241
245
|
- middleman-sprockets.gemspec
|
|
242
|
-
- spec/asset_list_spec.rb
|
|
243
246
|
- spec/asset_spec.rb
|
|
244
247
|
- spec/imported_asset_spec.rb
|
|
245
248
|
- spec/spec_helper.rb
|
|
@@ -255,12 +258,12 @@ require_paths:
|
|
|
255
258
|
- lib
|
|
256
259
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
257
260
|
requirements:
|
|
258
|
-
- -
|
|
261
|
+
- - ">="
|
|
259
262
|
- !ruby/object:Gem::Version
|
|
260
263
|
version: '0'
|
|
261
264
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
262
265
|
requirements:
|
|
263
|
-
- -
|
|
266
|
+
- - ">="
|
|
264
267
|
- !ruby/object:Gem::Version
|
|
265
268
|
version: '0'
|
|
266
269
|
requirements: []
|
|
@@ -395,6 +398,10 @@ test_files:
|
|
|
395
398
|
- fixtures/sprockets-images-app/source/index.html.erb
|
|
396
399
|
- fixtures/sprockets-images-app/source/library/images/cat.jpg
|
|
397
400
|
- fixtures/sprockets-images-app/vendor/assets/images/cat-2.jpg
|
|
401
|
+
- fixtures/sprockets-imported-asset-path-conflicts-app/config.rb
|
|
402
|
+
- fixtures/sprockets-imported-asset-path-conflicts-app/resources/assets/stylesheets/test.css
|
|
403
|
+
- fixtures/sprockets-imported-assets-match-multiple-paths-app/config.rb
|
|
404
|
+
- fixtures/sprockets-imported-assets-match-multiple-paths-app/vendor/assets/css/test.css
|
|
398
405
|
- fixtures/sprockets-multiple-extensions-app/bower.json
|
|
399
406
|
- fixtures/sprockets-multiple-extensions-app/config.rb
|
|
400
407
|
- fixtures/sprockets-multiple-extensions-app/source/fonts/fontawesome-webfont-source.svg.gz
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
module Middleman
|
|
3
|
-
module Sprockets
|
|
4
|
-
class AssetList
|
|
5
|
-
attr_reader :assets
|
|
6
|
-
|
|
7
|
-
def initialize(assets = [])
|
|
8
|
-
@assets = Array(assets)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# Find candidate in list
|
|
12
|
-
#
|
|
13
|
-
# @param [#source_path] candidate
|
|
14
|
-
# The candidate to search for
|
|
15
|
-
#
|
|
16
|
-
# @yield
|
|
17
|
-
# This blocks gets the candidate found
|
|
18
|
-
def lookup(candidate, &block)
|
|
19
|
-
found_asset = assets.find { |a| a.match? candidate.source_path }
|
|
20
|
-
|
|
21
|
-
block.call(candidate, found_asset) if block_given? && found_asset
|
|
22
|
-
|
|
23
|
-
found_asset
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Append asset to list
|
|
27
|
-
#
|
|
28
|
-
# @param [Asset]
|
|
29
|
-
# The asset to be appended
|
|
30
|
-
def add(asset)
|
|
31
|
-
assets << asset
|
|
32
|
-
end
|
|
33
|
-
alias_method :<<, :add
|
|
34
|
-
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
data/spec/asset_list_spec.rb
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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
|