middleman-sprockets 4.0.0.rc.2 → 4.0.0.rc.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1b6566a77765245f48a875bab984183266a5b33
4
- data.tar.gz: 9554a8e748dd6b8df43f2866340bf755063525c9
3
+ metadata.gz: 51021db335e75bc9e5a93a65b56db0fb1b89fc5e
4
+ data.tar.gz: 7200150e16a3888f9015c759fde9b14e5a65e6be
5
5
  SHA512:
6
- metadata.gz: 78525a45da92cb3f549b564f10be63a3ef9f839eba7104f31acbc5cdc3737e16d2bb11b15e4b397d7051c526c33d6979f50e1544004031203c3179c631bd22db
7
- data.tar.gz: a4080d4ee9f99792c966516f2c76461699ca44b37cca3466d32620c7d2bd778fb791a052844b37ff77dbb59cbf73a83debfee6e096d2837f2a8a1bde494bd813
6
+ metadata.gz: 7272ff377038976d9fe1d314c9b931c5dbefb7b46122a605012a4fc6e9301b4105d0ee6f9ff639f099fa17c400f6e27b422ece03308381ad3ae1ca3c54f67f67
7
+ data.tar.gz: 64cdd14315877463aad4eeb6b987ff1fd44d545a7e0ada7fefad291db366da1debc8036455fbda110014481fa705a4f8e637e8c52ed65e2d7a6e08175f6a443d
@@ -6,29 +6,26 @@ env: TEST=true
6
6
  rvm:
7
7
  - 2.0.0
8
8
  - 2.1
9
- - 2.2
10
- - 2.3.0
9
+ - 2.2.5
10
+ - 2.3.1
11
11
  - ruby-head
12
- - jruby-19mode
13
- - jruby-head
14
12
 
15
13
  gemfile:
16
14
  - gemfiles/middleman-4.1.gemfile
17
15
 
18
16
  matrix:
19
17
  include:
20
- - rvm: 2.2
18
+ - rvm: 2.3.1
21
19
  gemfile: gemfiles/middleman-head.gemfile
22
- - rvm: 2.2
20
+ env: SKIP_ASSET_HASH=true MIDDLEMAN_HEAD=true
21
+ - rvm: 2.3.1
23
22
  gemfile: gemfiles/middleman-4.0.gemfile
24
23
  env: SKIP_ASSET_HASH=true
25
- - rvm: 2.2
24
+ - rvm: 2.3.1
26
25
  gemfile: gemfiles/sprockets-4.0.gemfile
27
26
  env: SKIP_ASSET_HASH=true
28
27
 
29
28
  allow_failures:
30
29
  - rvm: ruby-head
31
- - rvm: jruby-19mode
32
- - rvm: jruby-head
33
- - rvm: 2.2
30
+ - rvm: 2.3.1
34
31
  gemfile: gemfiles/sprockets-4.0.gemfile
data/Gemfile CHANGED
@@ -29,7 +29,13 @@ gem 'ejs', '~> 1.1.1'
29
29
  gem 'eco', '~> 1.0.0'
30
30
  gem 'erubis', '~> 2.7.0'
31
31
  gem 'haml', '~> 4.0', require: false
32
- gem 'sassc', require: false
32
+ gem 'sassc', require: false
33
+
34
+ # catch the version of listen
35
+ # working around bundler not switching the dependency graph itself
36
+ if RUBY_VERSION < '2.2'
37
+ gem 'listen', '~> 3.0.6'
38
+ end
33
39
 
34
40
  # Code Quality
35
41
  group :test do
data/Rakefile CHANGED
@@ -21,6 +21,7 @@ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
21
21
  end
22
22
 
23
23
  exempt_tags.push '--tags ~@asset_hash' if ENV['SKIP_ASSET_HASH'] == 'true'
24
+ exempt_tags.push '--tags ~@middleman_head' unless ENV['MIDDLEMAN_HEAD'] == 'true'
24
25
  t.cucumber_opts = "--color #{exempt_tags.join(' ')} --strict"
25
26
  end
26
27
 
@@ -120,4 +120,4 @@ Feature: Linked assets are included in the sitemap
120
120
  Then the status code should be "200"
121
121
 
122
122
  When I go to "/"
123
- Then I should see '<img src="/assets/logo.png" />'
123
+ Then I should see '<img src="/assets/logo.png"'
@@ -100,13 +100,11 @@ Feature: Access to Middleman helpers
100
100
  Then I should see "console.log('hello');"
101
101
 
102
102
 
103
- Scenario: current_resource is unavailable
103
+ Scenario: current_resource is available
104
104
  Given a fixture app "base-app"
105
105
  And a file named "config.rb" with:
106
106
  """
107
- activate :sprockets do |c|
108
- c.expose_middleman_helpers = true
109
- end
107
+ activate :sprockets
110
108
  """
111
109
  And a file named "source/index.html.erb" with:
112
110
  """
@@ -122,7 +120,7 @@ Feature: Access to Middleman helpers
122
120
  Then I should see "<pre>/</pre>"
123
121
 
124
122
  When going to "/javascripts/site.js" should not raise an exception
125
- And I should see "NoMethodError: undefined method `url' for nil:NilClass"
123
+ And I should see "console.log('/javascripts/site.js');"
126
124
 
127
125
 
128
126
  Scenario: Helpers are not included by default
@@ -10,6 +10,15 @@ Given /^the file "([^\"]*)" content is changed to\:$/ do |name, content|
10
10
  step %Q{a file named "#{name}" with:}, content
11
11
  sleep 1
12
12
  system "touch #{File.join(ENV['MM_ROOT'], name)}"
13
+ step %Q{the filesystem is polled}
14
+ end
15
+
16
+ Then /^the filesystem is polled$/ do
17
+ if @server_inst.files.respond_to?(:poll_once!)
18
+ @server_inst.files.poll_once!
19
+ elsif @server_inst.files.respond_to?(:find_new_files!)
20
+ @server_inst.files.find_new_files!
21
+ end
13
22
  end
14
23
 
15
24
  Then /^sprockets paths should include "([^\"]*)"$/ do |path|
@@ -60,15 +60,15 @@ Feature: Assets get a file hash appended to their URL and references to them are
60
60
  Scenario: Enabling an asset host still produces hashed files and references
61
61
  Given the Server is running at "asset-hash-host-app"
62
62
  When I go to "/"
63
- Then I should see 'href="http://middlemanapp.com/stylesheets/site-a15e24a3.css"'
63
+ Then I should see 'href="http://middlemanapp.com/stylesheets/site-2f4798cc.css"'
64
64
  And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg"'
65
65
  When I go to "/subdir/"
66
- Then I should see 'href="http://middlemanapp.com/stylesheets/site-a15e24a3.css"'
66
+ Then I should see 'href="http://middlemanapp.com/stylesheets/site-2f4798cc.css"'
67
67
  And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg"'
68
68
  When I go to "/other/"
69
- Then I should see 'href="http://middlemanapp.com/stylesheets/site-a15e24a3.css"'
69
+ Then I should see 'href="http://middlemanapp.com/stylesheets/site-2f4798cc.css"'
70
70
  And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg"'
71
- When I go to "/stylesheets/site-a15e24a3.css"
71
+ When I go to "/stylesheets/site-2f4798cc.css"
72
72
  Then I should see 'background-image: url(http://middlemanapp.com/images/100px-5fd6fb90.jpg)'
73
73
 
74
74
  @asset_hash
@@ -37,3 +37,14 @@ Feature: Files with unhandled file extensions are ignored
37
37
 
38
38
  When I go to "/library/js/index.js"
39
39
  Then I should see "alert('why haml?');"
40
+
41
+ Scenario: Json files should be ignored for sprockets 4
42
+ Given a file named "source/file.json.coffee" with:
43
+ """
44
+ data:
45
+ title: "file"
46
+ """
47
+ And the Server is running
48
+
49
+ When I go to "/file.json"
50
+ Then I should see 'title: "file"'
@@ -1,6 +1,6 @@
1
1
  Feature: Throw sane error when Sprockets doesn't find an asset
2
2
 
3
- Background:
3
+ Scenario: When a file is removed, a FileNotFound is caught
4
4
  Given a fixture app "base-app"
5
5
  And a file named "config.rb" with:
6
6
  """
@@ -20,12 +20,33 @@ Feature: Throw sane error when Sprockets doesn't find an asset
20
20
  """
21
21
  console.log 'main'
22
22
  """
23
-
24
- Scenario: When a file is removed, a FileNotFound is caught
25
- Given the Server is running
23
+ And the Server is running
26
24
 
27
25
  When I go to "/stylesheets/main.css"
28
26
  Then I should see "Sprockets::FileNotFound: stylesheets/main.css"
29
27
 
30
28
  When I go to "/javascripts/main.js"
31
29
  Then I should see "Sprockets::FileNotFound: javascripts/main.js"
30
+
31
+ Scenario: Importing a missing sass file
32
+ In Sprockets 4, with ruby Sass -- having environment available is required otherwise the printer for load path with fail.
33
+
34
+ Given a fixture app "base-app"
35
+ And a file named "config.rb" with:
36
+ """
37
+ # simulate not having sassc
38
+ # trying to catch a spefic sprockets error
39
+ #
40
+ Object.send :remove_const, :SassC if defined?(SassC)
41
+ activate :sprockets do |c|
42
+ c.expose_middleman_helpers = true
43
+ end
44
+ """
45
+ And a file named "source/stylesheets/site.css.scss" with:
46
+ """
47
+ @import "missing";
48
+ """
49
+ And the Server is running
50
+
51
+ When I go to "/stylesheets/site.css"
52
+ Then I should see "Error: File to import not found or unreadable: missing."
@@ -0,0 +1,22 @@
1
+ Feature: Sitemaps that include StringResource
2
+
3
+ Scenario: No exception is raised determining if the resource is processible
4
+ Given a fixture app "base-app"
5
+ And a file named "config.rb" with:
6
+ """
7
+ class StringResourceGenerator < Middleman::Extension
8
+ def manipulate_resource_list resources
9
+ resources + [Middleman::Sitemap::StringResource.new(app.sitemap, 'stringy/index.html', 'Stringy!')]
10
+ end
11
+ end
12
+
13
+ ::Middleman::Extensions.register(:stringy, StringResourceGenerator)
14
+
15
+ activate :stringy
16
+ activate :sprockets
17
+ """
18
+ And the Server is running
19
+
20
+ When I go to "/stringy"
21
+ Then I should see "Stringy!"
22
+
@@ -0,0 +1,195 @@
1
+ Feature: Detecting linked asset addition and removal
2
+
3
+ Background:
4
+ Given a fixture app "base-app"
5
+ And a file named "config.rb" with:
6
+ """
7
+ config[:watcher_disable] = false
8
+ config[:watcher_force_polling] = true
9
+
10
+ activate :sprockets
11
+ sprockets.append_path File.join(root, 'imports')
12
+ """
13
+ And a file named "imports/a.jpg" with:
14
+ """
15
+ """
16
+ And a file named "imports/b.jpg" with:
17
+ """
18
+ """
19
+
20
+ Scenario: Asset-path helper reference added for an asset
21
+ The linked assets will be added to the sitemap
22
+
23
+ Given a file named "source/stylesheets/manifest.css.scss" with:
24
+ """
25
+ """
26
+ And the Server is running
27
+
28
+ When I go to "/assets/b.jpg"
29
+ Then the status code should be "404"
30
+
31
+ Given the file "source/stylesheets/manifest.css.scss" content is changed to:
32
+ """
33
+ body { background: asset_url('b.jpg'); }
34
+ """
35
+ When I go to "/assets/b.jpg"
36
+ Then the status code should be "200"
37
+
38
+
39
+ Scenario: Link directive added for an asset
40
+ The linked assets will be added to the sitemap
41
+
42
+ Given a file named "source/stylesheets/manifest.css.scss" with:
43
+ """
44
+ """
45
+ And the Server is running
46
+
47
+ When I go to "/assets/a.jpg"
48
+ Then the status code should be "404"
49
+
50
+ Given the file "source/stylesheets/manifest.css.scss" content is changed to:
51
+ """
52
+ //= link a.jpg
53
+ """
54
+
55
+ When I go to "/assets/a.jpg"
56
+ Then the status code should be "200"
57
+
58
+
59
+ Scenario: Link directive removed from file
60
+ The linked assets are removed from the sitemap
61
+
62
+ Given a file named "source/stylesheets/manifest.css.scss" with:
63
+ """
64
+ //= link a.jpg
65
+ """
66
+ And the Server is running
67
+
68
+ When I go to "/assets/a.jpg"
69
+ Then the status code should be "200"
70
+
71
+ Given the file "source/stylesheets/manifest.css.scss" content is changed to:
72
+ """
73
+ """
74
+
75
+ When I go to "/assets/a.jpg"
76
+ Then the status code should be "404"
77
+
78
+
79
+ Scenario: Asset path helper removed from file
80
+ The linked assets are removed from the sitemap
81
+
82
+ Given a file named "source/stylesheets/manifest.css.scss" with:
83
+ """
84
+ body { background: asset_url('b.jpg'); }
85
+ """
86
+ And the Server is running
87
+
88
+ When I go to "/assets/b.jpg"
89
+ Then the status code should be "200"
90
+
91
+ Given the file "source/stylesheets/manifest.css.scss" content is changed to:
92
+ """
93
+ """
94
+
95
+ When I go to "/assets/b.jpg"
96
+ Then the status code should be "404"
97
+
98
+
99
+ Scenario: Asset file with linked assets removed [asset-path helper]
100
+ The linked assets are removed from the sitemap
101
+
102
+ Given a file named "source/stylesheets/manifest.css.scss" with:
103
+ """
104
+ body { background: asset_url('b.jpg'); }
105
+ """
106
+ And the Server is running
107
+
108
+ When I go to "/assets/b.jpg"
109
+ Then the status code should be "200"
110
+
111
+ Given the file "source/stylesheets/manifest.css.scss" is removed
112
+
113
+ When I go to "/assets/b.jpg"
114
+ Then the status code should be "404"
115
+
116
+
117
+ Scenario: Asset file with linked assets removed [directive]
118
+ The linked assets are removed from the sitemap
119
+
120
+ Given a file named "source/stylesheets/manifest.css.scss" with:
121
+ """
122
+ //= link a.jpg
123
+ """
124
+ And the Server is running
125
+
126
+ When I go to "/assets/a.jpg"
127
+ Then the status code should be "200"
128
+
129
+ Given the file "source/stylesheets/manifest.css.scss" is removed
130
+
131
+ When I go to "/assets/a.jpg"
132
+ Then the status code should be "404"
133
+
134
+
135
+ Scenario: Asset file with linked assets added [path helper]
136
+ The linked assets are added to the sitemap
137
+
138
+ Given the Server is running
139
+
140
+ When I go to "/assets/b.jpg"
141
+ Then the status code should be "404"
142
+
143
+ Given a file named "source/stylesheets/manifest.css.scss" with:
144
+ """
145
+ body { background: asset_url('b.jpg'); }
146
+ """
147
+ And the filesystem is polled
148
+
149
+ When I go to "/assets/b.jpg"
150
+ Then the status code should be "200"
151
+
152
+
153
+ Scenario: Asset file with linked assets added [directive]
154
+ The linked assets are added to the sitemap
155
+
156
+ Given the Server is running
157
+
158
+ When I go to "/assets/a.jpg"
159
+ Then the status code should be "404"
160
+
161
+ Given a file named "source/stylesheets/manifest.css.scss" with:
162
+ """
163
+ //= link a.jpg
164
+ """
165
+ And the filesystem is polled
166
+
167
+ When I go to "/assets/a.jpg"
168
+ Then the status code should be "200"
169
+
170
+
171
+ Scenario: Asset file with linked assets (linked in other files) removed
172
+ The linked assets remain in the sitemap
173
+
174
+ Given a file named "source/stylesheets/base.css.scss" with:
175
+ """
176
+ //= link a.jpg
177
+ """
178
+ And a file named "source/stylesheets/manifest.css.scss" with:
179
+ """
180
+ //= link a.jpg
181
+ //= link b.jpg
182
+ """
183
+ And the Server is running
184
+
185
+ When I go to "/assets/a.jpg"
186
+ Then the status code should be "200"
187
+ When I go to "/assets/b.jpg"
188
+ Then the status code should be "200"
189
+
190
+ Given the file "source/stylesheets/manifest.css.scss" is removed
191
+
192
+ When I go to "/assets/a.jpg"
193
+ Then the status code should be "200"
194
+ When I go to "/assets/b.jpg"
195
+ Then the status code should be "404"
@@ -0,0 +1,50 @@
1
+ Feature: Partials can be rendered from a Sprockets Asset
2
+
3
+ Scenario: Rendering a partial in a file in source
4
+ Given a fixture app "base-app"
5
+ And a file named "config.rb" with:
6
+ """
7
+ activate :sprockets do |c|
8
+ c.expose_middleman_helpers = true
9
+ end
10
+ """
11
+ And a file named "source/partials/_maybe_a_js_template.mustache.erb" with:
12
+ """
13
+ <h1>{{ hello }}</h1>
14
+ """
15
+ And a file named "source/javascripts/main.js.erb" with:
16
+ """
17
+ var template = "<%= partial 'partials/maybe_a_js_template.mustache' %>";
18
+ """
19
+ And the Server is running
20
+
21
+ When I go to "/javascripts/main.js"
22
+ Then I should see "<h1>{{ hello }}</h1>"
23
+
24
+ @middleman_head
25
+ Scenario: Rendering a partial in a required file outside source
26
+ This is only possible in middleman 4.1.9+
27
+
28
+ Given a fixture app "base-app"
29
+ And a file named "config.rb" with:
30
+ """
31
+ activate :sprockets do |c|
32
+ c.expose_middleman_helpers = true
33
+ end
34
+ """
35
+ And a file named "source/partials/_template.mustache.erb" with:
36
+ """
37
+ <h1>{{ hello }}</h1>
38
+ """
39
+ And a file named "source/javascripts/_template.js.erb" with:
40
+ """
41
+ var template = "<%= partial 'partials/template.mustache' %>";
42
+ """
43
+ And a file named "source/javascripts/main.js" with:
44
+ """
45
+ //= require '_template'
46
+ """
47
+ And the Server is running
48
+
49
+ When I go to "/javascripts/main.js"
50
+ Then I should see "<h1>{{ hello }}</h1>"
@@ -46,7 +46,7 @@ Feature: Sass should glob partials like sass-rails
46
46
 
47
47
  Given a file named "config.rb" with:
48
48
  """
49
- Object.send :remove_const, :SassC # simulate not having sassc
49
+ Object.send :remove_const, :SassC if defined?(SassC)# simulate not having sassc
50
50
  require 'sass-globbing'
51
51
  activate :sprockets
52
52
  """
@@ -0,0 +1,32 @@
1
+ Feature: Usage of MM's environment method in a Sprockets asset
2
+ In some cases sprockets requires `environment` to return the sprockets environment so we can't overwrite that method in our rendering context. Instead you should use the `environment?` method to test against.
3
+
4
+ If the raw symbol for the environment is required, you can call `app.environment`.
5
+
6
+ Background:
7
+ Given a fixture app "base-app"
8
+ And a file named "config.rb" with:
9
+ """
10
+ activate :sprockets do |c|
11
+ c.expose_middleman_helpers = true
12
+ end
13
+ """
14
+ And a file named "source/javascripts/site.js.erb" with:
15
+ """
16
+ console.log('In development? <%= environment?(:development) ? "yes" : "no" %>');
17
+ console.log('<%= app.environment %>');
18
+ """
19
+
20
+
21
+ Scenario: Should output the sprockets environment on build
22
+ Given a successfully built app
23
+ And I cd to "build"
24
+
25
+ Then the file "javascripts/site.js" should contain "console.log('In development? no');"
26
+
27
+
28
+ Scenario: Should output the environment in preview server calling app.environment
29
+ Given the Server is running
30
+ And I go to "/javascripts/site.js"
31
+
32
+ Then I should see "console.log('development');"
@@ -3,13 +3,15 @@ require 'middleman-core/contracts'
3
3
  require 'middleman-core/sitemap/resource'
4
4
 
5
5
  require_relative 'resource'
6
+ require_relative 'resource_store'
6
7
  require_relative 'interface'
7
8
 
8
9
  module Middleman
9
10
  module Sprockets
10
11
  class Extension < Extension
11
12
  attr_reader :environment,
12
- :interface
13
+ :interface,
14
+ :resources
13
15
 
14
16
  expose_to_config sprockets: :environment
15
17
  expose_to_template sprockets: :environment
@@ -22,9 +24,9 @@ module Middleman
22
24
  def initialize app, options_hash={}, &block
23
25
  super
24
26
 
25
- @inline_asset_references = Set.new
26
- @environment = ::Sprockets::Environment.new
27
- @interface = Interface.new options, @environment
27
+ @resources = ResourceStore.new
28
+ @environment = ::Sprockets::Environment.new
29
+ @interface = Interface.new options, @environment
28
30
 
29
31
  use_sassc_if_available
30
32
  end
@@ -45,6 +47,14 @@ module Middleman
45
47
  @environment.context_class.send(:define_method, :env) { the_env }
46
48
 
47
49
  @environment.context_class.class_eval do
50
+ def current_resource
51
+ app.extensions[:sprockets].resources.find_by_path(filename)
52
+ end
53
+
54
+ def current_path
55
+ current_resource.destination_path if current_resource
56
+ end
57
+
48
58
  def asset_path path, options={}
49
59
  # Handle people calling with the Middleman/Padrino asset path signature
50
60
  if path.is_a?(::Symbol) && !options.is_a?(::Hash)
@@ -64,7 +74,8 @@ module Middleman
64
74
  end
65
75
 
66
76
  if app.extensions[:sprockets].check_asset(path)
67
- app.extensions[:sprockets].sprockets_asset_path(environment[path]).sub(/^\/?/, '/')
77
+ link_asset(path)
78
+ app.extensions[:sprockets].sprockets_asset_path(env[path]).sub(/^\/?/, '/')
68
79
  else
69
80
  app.asset_path(kind, path)
70
81
  end
@@ -76,37 +87,30 @@ module Middleman
76
87
 
77
88
  Contract ResourceList => ResourceList
78
89
  def manipulate_resource_list resources
79
- sprockets_resources = ::Middleman::Util.instrument 'sprockets', name: 'manipulator.sprockets_resources' do
80
- resources.map do |resource|
81
- process_candidate_sprockets_resource(resource)
82
- end
83
- end
84
-
85
- linked_resources = ::Middleman::Util.instrument 'sprockets', name: 'manipulator.linked_resources' do
86
- @inline_asset_references.map do |path|
87
- asset = environment[path]
88
- generate_resource(sprockets_asset_path(asset), asset.filename, asset.logical_path)
89
- end
90
+ sprockets_resources, base_resources = resources.partition(&method(:processible?))
91
+ ::Middleman::Util.instrument 'sprockets', name: 'manipulator.sprockets_resources' do
92
+ sprockets_resources.map!(&method(:process_sprockets_resource))
90
93
  end
91
94
 
92
95
  ::Middleman::Util.instrument 'sprockets', name: 'manipulator.ignore_resources' do
96
+ all_resources = base_resources + sprockets_resources + linked_resources!.to_a
97
+
93
98
  if app.extensions[:sitemap_ignore].respond_to?(:manipulate_resource_list)
94
- app.extensions[:sitemap_ignore].manipulate_resource_list sprockets_resources + linked_resources
99
+ app.extensions[:sitemap_ignore].manipulate_resource_list all_resources
95
100
  else
96
- sprockets_resources + linked_resources
101
+ all_resources
97
102
  end
98
103
  end
99
104
  end
100
105
 
101
106
  Contract ::Middleman::Sitemap::Resource => Bool
102
107
  def processible? r
103
- !r.is_a?(Resource) && interface.processible?(r.source_file)
108
+ !r.is_a?(Resource) && !r.file_descriptor.nil? && interface.processible?(r.source_file)
104
109
  end
105
110
 
106
111
  Contract String => Bool
107
112
  def check_asset path
108
113
  if environment[path]
109
- @inline_asset_references << path
110
114
  true
111
115
  else
112
116
  false
@@ -120,15 +124,28 @@ module Middleman
120
124
 
121
125
  private
122
126
 
127
+ def linked_resources
128
+ @_linked_resources ||= (@resources.resources
129
+ .map(&:sprockets_asset)
130
+ .map(&:links)
131
+ .reduce(&:merge) || Set.new())
132
+ .map do |path|
133
+ asset = environment[path]
134
+ generate_resource(sprockets_asset_path(asset),
135
+ asset.filename,
136
+ asset.logical_path)
137
+ end
138
+ end
139
+
140
+ def linked_resources!
141
+ @_linked_resources = nil
142
+ linked_resources
143
+ end
144
+
123
145
  def expose_app_helpers_to_sprockets!
124
146
  @environment.context_class.class_eval do
125
- def current_resource
126
- logger.error "The use of `current_resource` in sprockets assets isn't currently implemented"
127
- nil
128
- end
129
-
130
147
  def mm_context
131
- @_mm_context ||= app.template_context_class.new(app)
148
+ @_mm_context ||= app.template_context_class.new(app, current_path: current_path)
132
149
  end
133
150
 
134
151
  def method_missing method, *args, &block
@@ -146,15 +163,10 @@ module Middleman
146
163
  end
147
164
 
148
165
  Contract ::Middleman::Sitemap::Resource => Or[::Middleman::Sitemap::Resource, Resource]
149
- def process_candidate_sprockets_resource resource
150
- return resource unless processible?(resource)
151
-
166
+ def process_sprockets_resource resource
152
167
  ::Middleman::Util.instrument 'sprockets', name: 'process_resource', resource: resource do
153
168
  sprockets_resource = generate_resource(resource.path, resource.source_file, resource.path)
154
-
155
- if sprockets_resource.respond_to?(:sprockets_asset) && !sprockets_resource.errored?
156
- @inline_asset_references.merge sprockets_resource.sprockets_asset.links
157
- end
169
+ @resources.add sprockets_resource
158
170
 
159
171
  sprockets_resource
160
172
  end
@@ -36,7 +36,8 @@ module Middleman
36
36
  Contract String => Bool
37
37
  def processible? filename
38
38
  file_ext, _mime = ::Sprockets::PathUtils.match_path_extname(filename, environment.config[:mime_exts])
39
- extensions.include?(file_ext)
39
+ *template_exts, target_ext = Middleman::Util.collect_extensions(filename)
40
+ options[:supported_output_extensions].include?(target_ext) && extensions.include?(file_ext)
40
41
  end
41
42
  end
42
43
 
@@ -56,9 +56,9 @@ module Middleman
56
56
  @ext = ext
57
57
  end
58
58
 
59
- Contract Array
59
+ Contract Set
60
60
  def links
61
- []
61
+ Set.new
62
62
  end
63
63
 
64
64
  Contract String
@@ -0,0 +1,39 @@
1
+ module Middleman
2
+ module Sprockets
3
+ class ResourceStore
4
+ include Contracts
5
+
6
+ attr_reader :store
7
+
8
+ def initialize
9
+ @store = {}
10
+ end
11
+
12
+ Contract IsA['::Middleman::Sprockets::Resource'] => Any
13
+ def add resource
14
+ store[resource.file_descriptor.full_path] = resource
15
+ end
16
+
17
+ Contract ArrayOf[IsA['::Middleman::Sprockets::Resource']]
18
+ def resources
19
+ store.values
20
+ end
21
+
22
+ Contract ArrayOf[Pathname]
23
+ def paths
24
+ store.keys
25
+ end
26
+
27
+ Contract Pathname => Bool
28
+ def matching_path? path
29
+ paths.include?(path)
30
+ end
31
+
32
+ Contract Or[String, Pathname] => Maybe[IsA['::Middleman::Sprockets::Resource']]
33
+ def find_by_path path
34
+ path = Pathname.new(path) unless path.is_a?(Pathname)
35
+ store.fetch path, nil
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Sprockets
3
- VERSION = '4.0.0.rc.2'.freeze
3
+ VERSION = '4.0.0.rc.3'.freeze
4
4
  end
5
5
  end
@@ -18,4 +18,6 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.add_dependency 'middleman-core', ['~> 4.0']
20
20
  s.add_dependency 'sprockets', ['>= 3.0']
21
+
22
+ s.add_development_dependency 'capybara', ['~> 2.5.0']
21
23
  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: 4.0.0.rc.2
4
+ version: 4.0.0.rc.3
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: 2016-04-09 00:00:00.000000000 Z
13
+ date: 2016-05-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: middleman-core
@@ -40,6 +40,20 @@ dependencies:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '3.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: capybara
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 2.5.0
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: 2.5.0
43
57
  description: Sprockets support for Middleman
44
58
  email:
45
59
  - me@tdreyno.com
@@ -74,15 +88,19 @@ files:
74
88
  - features/test_cases/exception_response.feature
75
89
  - features/test_cases/excluded_file_extensions.feature
76
90
  - features/test_cases/file_not_found.feature
91
+ - features/test_cases/handles_string_resource.feature
77
92
  - features/test_cases/ignore_directive_is_respected.feature
78
93
  - features/test_cases/imported_asset_extensions.feature
79
94
  - features/test_cases/jst.feature
95
+ - features/test_cases/linked_asset_addition_and_removal.feature
80
96
  - features/test_cases/long_filenames.feature
97
+ - features/test_cases/partial_rendering.feature
81
98
  - features/test_cases/path_helpers.feature
82
99
  - features/test_cases/processible_outside_asset_dir.feature
83
100
  - features/test_cases/sass_globs.feature
84
101
  - features/test_cases/sass_partials.feature
85
102
  - features/test_cases/sassc.feature
103
+ - features/test_cases/usage_of_environment.feature
86
104
  - features/test_cases/use_from_templates.feature
87
105
  - features/test_cases/using_assets_gem_assets.feature
88
106
  - fixtures/asset-hash-app/config.rb
@@ -127,6 +145,7 @@ files:
127
145
  - lib/middleman-sprockets/extension.rb
128
146
  - lib/middleman-sprockets/interface.rb
129
147
  - lib/middleman-sprockets/resource.rb
148
+ - lib/middleman-sprockets/resource_store.rb
130
149
  - lib/middleman-sprockets/version.rb
131
150
  - middleman-sprockets.gemspec
132
151
  - spec/spec_helper.rb
@@ -170,15 +189,19 @@ test_files:
170
189
  - features/test_cases/exception_response.feature
171
190
  - features/test_cases/excluded_file_extensions.feature
172
191
  - features/test_cases/file_not_found.feature
192
+ - features/test_cases/handles_string_resource.feature
173
193
  - features/test_cases/ignore_directive_is_respected.feature
174
194
  - features/test_cases/imported_asset_extensions.feature
175
195
  - features/test_cases/jst.feature
196
+ - features/test_cases/linked_asset_addition_and_removal.feature
176
197
  - features/test_cases/long_filenames.feature
198
+ - features/test_cases/partial_rendering.feature
177
199
  - features/test_cases/path_helpers.feature
178
200
  - features/test_cases/processible_outside_asset_dir.feature
179
201
  - features/test_cases/sass_globs.feature
180
202
  - features/test_cases/sass_partials.feature
181
203
  - features/test_cases/sassc.feature
204
+ - features/test_cases/usage_of_environment.feature
182
205
  - features/test_cases/use_from_templates.feature
183
206
  - features/test_cases/using_assets_gem_assets.feature
184
207
  - fixtures/asset-hash-app/config.rb