middleman-sprockets 3.3.6 → 3.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,14 +3,7 @@ module Middleman
3
3
  module Sprockets
4
4
  # Asset
5
5
  class Asset
6
-
7
- private
8
-
9
- attr_reader :relative_source_path, :base_name, :destination_directory, :source_directory
10
-
11
- public
12
-
13
- attr_reader :source_path
6
+ attr_reader :source_path, :relative_source_path, :base_name, :destination_directory, :source_directory
14
7
 
15
8
  # Create instance
16
9
  #
@@ -24,12 +17,12 @@ module Middleman
24
17
 
25
18
  fail ArgumentError, 'Missing argument source_directory' unless source_directory
26
19
 
27
- @source_directory = source_directory
20
+ @source_directory = source_directory
28
21
 
29
- @source_path = Pathname.new(source_path)
22
+ @source_path = Pathname.new(source_path)
30
23
  @relative_source_path = @source_path.relative_path_from(Pathname.new(source_directory))
31
- @base_name = @source_path.basename
32
- @import_it = false
24
+ @base_name = @source_path.basename
25
+ @import_it = false
33
26
  end
34
27
 
35
28
  # Should the asset imported?
@@ -58,7 +51,7 @@ module Middleman
58
51
  def destination_path
59
52
  return @destination_path if @destination_path
60
53
 
61
- fail ::Sprockets::FileNotFound, "Couldn't find an appropriate output directory for '#{destination_directory}' - halting because it was explicitly requested via 'import_asset'" unless destination_directory
54
+ fail ::Sprockets::FileNotFound, "Couldn't find an appropriate output directory for '#{source_path}'. Halting because it was explicitly requested via 'import_asset'" unless destination_directory
62
55
 
63
56
  destination_directory + relative_source_path
64
57
  end
@@ -105,17 +98,17 @@ module Middleman
105
98
  end
106
99
 
107
100
  def type
108
- if is_in_images_directory? or is_image?
109
- :image
110
- elsif is_in_scripts_directory? or is_script?
111
- :script
112
- elsif is_in_stylesheets_directory? or is_stylesheet?
113
- :stylesheet
114
- elsif is_in_fonts_directory? or is_font?
115
- :font
116
- else
117
- :unknown
118
- end
101
+ @type ||= if is_image?
102
+ :image
103
+ elsif is_script?
104
+ :script
105
+ elsif is_stylesheet?
106
+ :stylesheet
107
+ elsif is_font?
108
+ :font
109
+ else
110
+ :unknown
111
+ end
119
112
  end
120
113
 
121
114
  def file?
@@ -123,7 +116,7 @@ module Middleman
123
116
  end
124
117
 
125
118
  def partial?
126
- base_name.start_with? '_'
119
+ base_name.to_s.start_with? '_'
127
120
  end
128
121
 
129
122
  # Is it a valid asset
@@ -142,42 +135,66 @@ module Middleman
142
135
  end
143
136
 
144
137
  def extname
145
- source_path.extname
138
+ source_path.basename.to_s[/(\.[^.]+)/]
146
139
  end
147
140
 
148
- def has_real_path?(path)
149
- real_path == path
141
+ def is_image?
142
+ is_image_by_path? || (is_image_by_extension? && !is_font_by_path?)
150
143
  end
151
144
 
152
- def is_in_images_directory?
153
- source_directory.end_with?('images', 'img')
145
+ def is_image_by_path?
146
+ source_directory.to_s.end_with?('images') ||
147
+ source_directory.to_s.end_with?('img') ||
148
+ source_path.dirname.to_s.end_with?('images') ||
149
+ source_path.dirname.to_s.end_with?('img')
154
150
  end
151
+ alias_method :is_in_images_directory?, :is_image_by_path?
155
152
 
156
- def is_in_fonts_directory?
157
- source_directory.end_with?('fonts')
153
+ def is_image_by_extension?
154
+ has_extname? *%w(.gif .png .jpg .jpeg .webp .svg .svgz)
158
155
  end
159
156
 
160
- def is_in_scripts_directory?
161
- source_directory.end_with?('javascripts', 'js')
157
+ def is_stylesheet?
158
+ is_stylesheet_by_path? || is_stylesheet_by_extension?
162
159
  end
163
160
 
164
- def is_in_stylesheets_directory?
165
- source_directory.end_with?('stylesheets', 'css')
161
+ def is_stylesheet_by_extension?
162
+ has_extname? *%w(.css .sass .scss .styl .less)
166
163
  end
167
164
 
168
- def is_image?
169
- has_extname?('.gif', '.png', '.jpg', '.jpeg', '.svg', '.svg.gz')
165
+ def is_stylesheet_by_path?
166
+ source_directory.to_s.end_with?('stylesheets') ||
167
+ source_directory.to_s.end_with?('css') ||
168
+ source_path.dirname.to_s.end_with?('stylesheets') ||
169
+ source_path.dirname.to_s.end_with?('css')
170
170
  end
171
171
 
172
- def is_stylesheet?
173
- has_extname?('.css', '.sass', '.scss', '.styl', '.less')
172
+ def is_font?
173
+ is_font_by_path? || is_font_by_extension?
174
174
  end
175
175
 
176
- def is_font?
177
- has_extname?('.ttf', '.woff', '.eot', '.otf')
176
+ def is_font_by_path?
177
+ source_directory.to_s.end_with?('fonts') ||
178
+ source_path.dirname.to_s.end_with?('fonts')
179
+ end
180
+ alias_method :is_in_fonts_directory?, :is_font_by_path?
181
+
182
+ def is_font_by_extension?
183
+ has_extname? *%w(.ttf .woff .eot .otf .svg .svgz)
178
184
  end
179
185
 
180
186
  def is_script?
187
+ is_script_by_path? || is_script_by_extension?
188
+ end
189
+
190
+ def is_script_by_path?
191
+ source_directory.to_s.end_with?('javascripts') ||
192
+ source_directory.to_s.end_with?('js') ||
193
+ source_path.dirname.to_s.end_with?('javascripts') ||
194
+ source_path.dirname.to_s.end_with?('js')
195
+ end
196
+
197
+ def is_script_by_extension?
181
198
  has_extname?('.js', '.coffee')
182
199
  end
183
200
  end
@@ -2,12 +2,8 @@
2
2
  module Middleman
3
3
  module Sprockets
4
4
  class AssetList
5
- private
6
-
7
5
  attr_reader :assets
8
6
 
9
- public
10
-
11
7
  def initialize(assets = [])
12
8
  @assets = Array(assets)
13
9
  end
@@ -1,6 +1,5 @@
1
1
  require "sprockets"
2
2
  require "sprockets-sass"
3
- require "middleman-sprockets/pathname_extensions"
4
3
  require "middleman-sprockets/asset"
5
4
  require "middleman-sprockets/imported_asset"
6
5
  require "middleman-sprockets/asset_list"
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Sprockets
3
- VERSION = "3.3.6"
3
+ VERSION = "3.3.7"
4
4
  end
5
5
  end
data/spec/asset_spec.rb CHANGED
@@ -10,6 +10,11 @@ RSpec.describe Asset do
10
10
  asset = Asset.new('/source/path/to/images/image.xz', source_directory: '/source/path/to/images')
11
11
  expect(asset).to have_type :image
12
12
  end
13
+
14
+ it 'finds type by double extension' do
15
+ asset = Asset.new('/source/path/to/image.png.xz', source_directory: '/source/path/to')
16
+ expect(asset).to have_type :image
17
+ end
13
18
  end
14
19
 
15
20
  context '#import?, #import_it' do
@@ -112,5 +117,4 @@ RSpec.describe Asset do
112
117
  end
113
118
  end
114
119
  end
115
-
116
120
  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.6
4
+ version: 3.3.7
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-08-04 00:00:00.000000000 Z
13
+ date: 2014-08-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: middleman-core
@@ -211,6 +211,15 @@ files:
211
211
  - fixtures/sprockets-images-app/source/index.html.erb
212
212
  - fixtures/sprockets-images-app/source/library/images/cat.jpg
213
213
  - fixtures/sprockets-images-app/vendor/assets/images/cat-2.jpg
214
+ - fixtures/sprockets-svg-font-app/bower.json
215
+ - fixtures/sprockets-svg-font-app/config.rb
216
+ - fixtures/sprockets-svg-font-app/source/fonts/fontawesome-webfont-source.svg
217
+ - fixtures/sprockets-svg-font-app/source/fonts/fontawesome-webfont-source.svg.gz
218
+ - fixtures/sprockets-svg-font-app/source/images/drawing-source.svg
219
+ - fixtures/sprockets-svg-font-app/vendor/assets/components/blub/images/drawing-bower.svg
220
+ - fixtures/sprockets-svg-font-app/vendor/assets/components/font-awesome/fonts/fontawesome-webfont-bower.svg
221
+ - fixtures/sprockets-svg-font-app/vendor/assets/components/font-awesome/fonts/fontawesome-webfont-bower.svg.gz
222
+ - fixtures/sprockets-svg-font-app/vendor/assets/components/font-awesome/fonts/fontawesome-webfont-bower.ttf.gz
214
223
  - lib/middleman-sprockets.rb
215
224
  - lib/middleman-sprockets/asset.rb
216
225
  - lib/middleman-sprockets/asset_list.rb
@@ -219,7 +228,6 @@ files:
219
228
  - lib/middleman-sprockets/environment.rb
220
229
  - lib/middleman-sprockets/extension.rb
221
230
  - lib/middleman-sprockets/imported_asset.rb
222
- - lib/middleman-sprockets/pathname_extensions.rb
223
231
  - lib/middleman-sprockets/sass_function_hack.rb
224
232
  - lib/middleman-sprockets/version.rb
225
233
  - middleman-sprockets.gemspec
@@ -378,4 +386,13 @@ test_files:
378
386
  - fixtures/sprockets-images-app/source/index.html.erb
379
387
  - fixtures/sprockets-images-app/source/library/images/cat.jpg
380
388
  - fixtures/sprockets-images-app/vendor/assets/images/cat-2.jpg
389
+ - fixtures/sprockets-svg-font-app/bower.json
390
+ - fixtures/sprockets-svg-font-app/config.rb
391
+ - fixtures/sprockets-svg-font-app/source/fonts/fontawesome-webfont-source.svg
392
+ - fixtures/sprockets-svg-font-app/source/fonts/fontawesome-webfont-source.svg.gz
393
+ - fixtures/sprockets-svg-font-app/source/images/drawing-source.svg
394
+ - fixtures/sprockets-svg-font-app/vendor/assets/components/blub/images/drawing-bower.svg
395
+ - fixtures/sprockets-svg-font-app/vendor/assets/components/font-awesome/fonts/fontawesome-webfont-bower.svg
396
+ - fixtures/sprockets-svg-font-app/vendor/assets/components/font-awesome/fonts/fontawesome-webfont-bower.svg.gz
397
+ - fixtures/sprockets-svg-font-app/vendor/assets/components/font-awesome/fonts/fontawesome-webfont-bower.ttf.gz
381
398
  has_rdoc:
@@ -1,10 +0,0 @@
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