middleman-sprockets 3.2.0 → 3.3.0
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/.gitignore +1 -0
- data/CHANGELOG.md +16 -3
- data/Gemfile +1 -1
- data/features/bower.feature +8 -1
- data/fixtures/bower-app/config.rb +3 -1
- data/fixtures/bower-json-app/config.rb +1 -0
- data/fixtures/bower-json-app/source/javascripts/application.js.coffee +1 -0
- data/fixtures/bower-json-app/source/javascripts/bower.json +5 -0
- data/lib/middleman-sprockets.rb +1 -1
- data/lib/middleman-sprockets/asset_tag_helpers.rb +59 -0
- data/lib/middleman-sprockets/environment.rb +201 -0
- data/lib/middleman-sprockets/extension.rb +62 -309
- data/lib/middleman-sprockets/sass_function_hack.rb +16 -14
- data/lib/middleman-sprockets/version.rb +2 -2
- data/middleman-sprockets.gemspec +4 -4
- metadata +25 -16
- data/lib/middleman_extension.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2706ab113d91037dbef37ebada72f4d62a8cdc50
|
4
|
+
data.tar.gz: db48cea1c6e261cdbe473842e1982ffeba658598
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dae92a7bca105c4fd757d307210f782240bd1f177b7cbae5e33e640d0c4a796d956b14ec96adcccec42fc4d26cbeb919bb6619391a5c46c9ac6641e098b77a93
|
7
|
+
data.tar.gz: 2261c1d32d5e6f4bb363bdb53dee89171644248785b165533e227dab2e653406e6fa2e7520d899d2ef2954697c37d5191f1fb983c8253e414107e1fe2f75e73b
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,20 @@
|
|
1
|
-
|
1
|
+
3.3.0
|
2
2
|
===
|
3
3
|
|
4
|
+
* Prep work for Middleman v4.
|
5
|
+
* Work around sstephenson/sprockets#533 by serving bower.json directly, skipping Sprockets.
|
6
|
+
* Only attempt to patch up Sass if Sass is present.
|
7
|
+
* :bower_dir is deprecated in favor of just adding your bower_components folder to the sprockets load path.
|
8
|
+
* Convert to a new-style Middleman extension. #48
|
9
|
+
* Use a file-based cache to persist compiled assets between sessions #47
|
10
|
+
|
11
|
+
3.2.0
|
12
|
+
===
|
13
|
+
|
14
|
+
* Require Middleman 3.2 or later.
|
15
|
+
* No longer require 'middleman-more'
|
16
|
+
* Fix import_asset. #38
|
17
|
+
|
4
18
|
3.1.3
|
5
19
|
===
|
6
20
|
|
@@ -37,11 +51,10 @@ master
|
|
37
51
|
* When `:debug_assets` is on, do not add `?body=1` multiple times. #24
|
38
52
|
* :js_assets_paths configuration is deprecated in favor of just calling sprockets.append_path. #22
|
39
53
|
* Sprockets integration, especially with regard to helper methods, is significantly improved. #22
|
40
|
-
* Images and fonts from gems added to the Sprockets load path will now be copied to the build output. #22
|
54
|
+
* Images and fonts from gems added to the Sprockets load path will now be copied to the build output. #22
|
41
55
|
* Compatibility with newer Sprockets versions.
|
42
56
|
|
43
57
|
3.0.10
|
44
58
|
===
|
45
59
|
|
46
60
|
* No longer expire Sprockets index in development mode. #18
|
47
|
-
|
data/Gemfile
CHANGED
data/features/bower.feature
CHANGED
@@ -9,4 +9,11 @@ Feature: Bower
|
|
9
9
|
When I cd to "build"
|
10
10
|
Then the following files should exist:
|
11
11
|
| javascripts/get_jquery.js |
|
12
|
-
And the file "javascripts/get_jquery.js" should contain "window.jQuery ="
|
12
|
+
And the file "javascripts/get_jquery.js" should contain "window.jQuery ="
|
13
|
+
|
14
|
+
Scenario: Sprockets should not mess with bower.json
|
15
|
+
Given a successfully built app at "bower-json-app"
|
16
|
+
When I cd to "build"
|
17
|
+
Then the following files should exist:
|
18
|
+
| javascripts/bower.json |
|
19
|
+
And the file "javascripts/bower.json" should contain '"name": "my-project",'
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
# foo
|
data/lib/middleman-sprockets.rb
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Middleman
|
2
|
+
module Sprockets
|
3
|
+
module AssetTagHelpers
|
4
|
+
|
5
|
+
# extend padrinos javascript_include_tag with debug functionality
|
6
|
+
# splits up script dependencies in individual files when
|
7
|
+
# configuration variable :debug_assets is set to true
|
8
|
+
def javascript_include_tag(*sources)
|
9
|
+
if debug_assets?
|
10
|
+
options = sources.extract_options!.symbolize_keys
|
11
|
+
sources.map do |source|
|
12
|
+
super(dependencies_paths('.js', source), options)
|
13
|
+
end.join("").gsub("body=1.js", "body=1")
|
14
|
+
else
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# extend padrinos stylesheet_link_tag with debug functionality
|
20
|
+
# splits up stylesheets dependencies in individual files when
|
21
|
+
# configuration variable :debug_assets is set to true
|
22
|
+
def stylesheet_link_tag(*sources)
|
23
|
+
if debug_assets?
|
24
|
+
options = sources.extract_options!.symbolize_keys
|
25
|
+
sources.map do |source|
|
26
|
+
super(dependencies_paths('.css', source), options)
|
27
|
+
end.join("").gsub("body=1.css", "body=1")
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# Should we "debug assets" by outputting each as an individual script tag instead of combining them?
|
36
|
+
def debug_assets?
|
37
|
+
!build? && (sprockets.options.debug_assets || (respond_to?(:debug_assets) && debug_assets))
|
38
|
+
end
|
39
|
+
|
40
|
+
# Find the paths for all the dependencies of a given source file.
|
41
|
+
def dependencies_paths(extension, source)
|
42
|
+
source_file_name = source.to_s
|
43
|
+
|
44
|
+
if source_file_name.start_with?('//', 'http')
|
45
|
+
# Don't touch external sources
|
46
|
+
source_file_name
|
47
|
+
else
|
48
|
+
source_file_name << extension unless source_file_name.end_with?(extension)
|
49
|
+
|
50
|
+
dependencies_paths = sprockets[source_file_name].to_a.map do |dependency|
|
51
|
+
# if sprockets sees "?body=1" it only gives back the body
|
52
|
+
# of the script without the dependencies included
|
53
|
+
dependency.logical_path + "?body=1"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
module Middleman
|
2
|
+
module Sprockets
|
3
|
+
# Generic Middleman Sprockets env
|
4
|
+
class Environment < ::Sprockets::Environment
|
5
|
+
attr_accessor :options
|
6
|
+
|
7
|
+
# Setup
|
8
|
+
def initialize(app)
|
9
|
+
@imported_assets = []
|
10
|
+
@app = app
|
11
|
+
@options = {}
|
12
|
+
|
13
|
+
super app.source_dir
|
14
|
+
|
15
|
+
# By default, sprockets has no cache! Give it a file-based cache so that
|
16
|
+
# the cache is persisted between sessions
|
17
|
+
@cache = ::Sprockets::Cache::FileStore.new(File.join app.root, '.cache')
|
18
|
+
|
19
|
+
enhance_context_class!
|
20
|
+
|
21
|
+
# Remove compressors, we handle these with middleware
|
22
|
+
unregister_bundle_processor 'application/javascript', :js_compressor
|
23
|
+
unregister_bundle_processor 'text/css', :css_compressor
|
24
|
+
|
25
|
+
# configure search paths
|
26
|
+
append_path app.config[:js_dir]
|
27
|
+
append_path app.config[:css_dir]
|
28
|
+
append_path app.config[:images_dir]
|
29
|
+
append_path app.config[:fonts_dir]
|
30
|
+
|
31
|
+
if app.config.respond_to?(:bower_dir)
|
32
|
+
warn ":bower_dir is deprecated. Call sprockets.append_path from a 'ready' block instead."
|
33
|
+
append_path app.config[:bower_dir]
|
34
|
+
end
|
35
|
+
|
36
|
+
# add custom assets paths to the scope
|
37
|
+
app.config[:js_assets_paths].each do |p|
|
38
|
+
warn ":js_assets_paths is deprecated. Call sprockets.append_path from a 'ready' block instead."
|
39
|
+
append_path p
|
40
|
+
end if app.config.respond_to?(:js_assets_paths)
|
41
|
+
|
42
|
+
# Stylus support
|
43
|
+
if defined?(::Stylus)
|
44
|
+
require 'stylus/sprockets'
|
45
|
+
::Stylus.setup(self, app.config[:styl])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Add our own customizations to the Sprockets context class
|
50
|
+
def enhance_context_class!
|
51
|
+
app = @app
|
52
|
+
|
53
|
+
# Make the app context available to Sprockets
|
54
|
+
context_class.send(:define_method, :app) { app }
|
55
|
+
|
56
|
+
context_class.class_eval do
|
57
|
+
def asset_path(path, options={})
|
58
|
+
# Handle people calling with the Middleman/Padrino asset path signature
|
59
|
+
if path.is_a?(::Symbol) && !options.is_a?(::Hash)
|
60
|
+
return app.asset_path(path, options)
|
61
|
+
end
|
62
|
+
|
63
|
+
kind = case options[:type]
|
64
|
+
when :image then :images
|
65
|
+
when :font then :fonts
|
66
|
+
when :javascript then :js
|
67
|
+
when :stylesheet then :css
|
68
|
+
else options[:type]
|
69
|
+
end
|
70
|
+
|
71
|
+
app.asset_path(kind, path)
|
72
|
+
end
|
73
|
+
|
74
|
+
# These helpers are already defined in later versions of Sprockets, but we define
|
75
|
+
# them ourself to help older versions and to provide extra options that Sass wants.
|
76
|
+
|
77
|
+
# Expand logical image asset path.
|
78
|
+
def image_path(path, options={})
|
79
|
+
asset_path(path, :type => :image)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Expand logical font asset path.
|
83
|
+
def font_path(path, options={})
|
84
|
+
# Knock .fonts off the end, because Middleman < 3.1 doesn't handle fonts
|
85
|
+
# in asset_path
|
86
|
+
asset_path(path, :type => :font).sub(/\.fonts$/, '')
|
87
|
+
end
|
88
|
+
|
89
|
+
# Expand logical javascript asset path.
|
90
|
+
def javascript_path(path, options={})
|
91
|
+
asset_path(path, :type => :javascript)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Expand logical stylesheet asset path.
|
95
|
+
def stylesheet_path(path, options={})
|
96
|
+
asset_path(path, :type => :stylesheet)
|
97
|
+
end
|
98
|
+
|
99
|
+
def method_missing(*args)
|
100
|
+
name = args.first
|
101
|
+
if app.respond_to?(name)
|
102
|
+
app.send(*args)
|
103
|
+
else
|
104
|
+
super
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Needed so that method_missing makes sense
|
109
|
+
def respond_to?(method, include_private = false)
|
110
|
+
super || app.respond_to?(method, include_private)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
private :enhance_context_class!
|
115
|
+
|
116
|
+
# Override Sprockets' default digest function to *not*
|
117
|
+
# change depending on the exact Sprockets version. It still takes
|
118
|
+
# into account "version" which is a user-suppliable version
|
119
|
+
# number that can be used to force assets to have a new
|
120
|
+
# hash.
|
121
|
+
def digest
|
122
|
+
@digest ||= Digest::SHA1.new.update(version.to_s)
|
123
|
+
@digest.dup
|
124
|
+
end
|
125
|
+
|
126
|
+
# Strip our custom 8-char hex/sha
|
127
|
+
def path_fingerprint(path)
|
128
|
+
path[/-([0-9a-f]{8})\.[^.]+$/, 1]
|
129
|
+
end
|
130
|
+
|
131
|
+
# Invalidate sitemap when users mess with the sprockets load paths
|
132
|
+
def append_path(*args)
|
133
|
+
@app.sitemap.rebuild_resource_list!(:sprockets_paths)
|
134
|
+
super
|
135
|
+
end
|
136
|
+
|
137
|
+
def prepend_path(*args)
|
138
|
+
@app.sitemap.rebuild_resource_list!(:sprockets_paths)
|
139
|
+
super
|
140
|
+
end
|
141
|
+
|
142
|
+
def clear_paths
|
143
|
+
@app.sitemap.rebuild_resource_list!(:sprockets_paths)
|
144
|
+
super
|
145
|
+
end
|
146
|
+
|
147
|
+
def css_exception_response(exception)
|
148
|
+
raise exception if @app.build?
|
149
|
+
super
|
150
|
+
end
|
151
|
+
|
152
|
+
def javascript_exception_response(exception)
|
153
|
+
raise exception if @app.build?
|
154
|
+
super
|
155
|
+
end
|
156
|
+
|
157
|
+
def call(env)
|
158
|
+
# Set the app current path based on the full URL so that helpers work
|
159
|
+
request_path = URI.decode(File.join(env['SCRIPT_NAME'], env['PATH_INFO']))
|
160
|
+
if request_path.respond_to? :force_encoding
|
161
|
+
request_path.force_encoding('UTF-8')
|
162
|
+
end
|
163
|
+
resource = @app.sitemap.find_resource_by_destination_path(request_path)
|
164
|
+
|
165
|
+
debug_assets = !@app.build? && (@options.debug_assets || (@app.respond_to?(:debug_assets) && @app.debug_assets))
|
166
|
+
if !resource && !debug_assets
|
167
|
+
response = ::Rack::Response.new
|
168
|
+
response.status = 404
|
169
|
+
response.write """<html><body><h1>File Not Found</h1><p>#{request_path}</p>
|
170
|
+
<p>If this is an an asset from a gem, add <tt>sprockets.import_asset '#{File.basename(request_path)}'</tt>
|
171
|
+
to your <tt>config.rb</tt>.</body>"""
|
172
|
+
return response.finish
|
173
|
+
end
|
174
|
+
|
175
|
+
if @app.respond_to?(:current_path=)
|
176
|
+
@app.current_path = request_path
|
177
|
+
end
|
178
|
+
|
179
|
+
# Fix https://github.com/sstephenson/sprockets/issues/533
|
180
|
+
if resource && File.basename(resource.path) == 'bower.json'
|
181
|
+
file = ::Rack::File.new nil
|
182
|
+
file.path = resource.source_file
|
183
|
+
response = file.serving({})
|
184
|
+
response[1]['Content-Type'] = resource.content_type
|
185
|
+
return response
|
186
|
+
end
|
187
|
+
|
188
|
+
super
|
189
|
+
end
|
190
|
+
|
191
|
+
# A list of Sprockets logical paths for assets that should be brought into the
|
192
|
+
# Middleman application and built.
|
193
|
+
attr_accessor :imported_assets
|
194
|
+
|
195
|
+
# Tell Middleman to build this asset, referenced as a logical path.
|
196
|
+
def import_asset(asset_logical_path)
|
197
|
+
imported_assets << asset_logical_path
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
@@ -1,337 +1,90 @@
|
|
1
1
|
require "sprockets"
|
2
2
|
require "sprockets-sass"
|
3
|
-
require "middleman-sprockets/
|
3
|
+
require "middleman-sprockets/environment"
|
4
|
+
require "middleman-sprockets/asset_tag_helpers"
|
4
5
|
|
5
6
|
# Sprockets extension
|
6
|
-
module Middleman
|
7
|
+
module Middleman
|
8
|
+
class SprocketsExtension < Extension
|
9
|
+
option :debug_assets, false, 'Split up each required asset into its own script/style tag instead of combining them (development only)'
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
def initialize(klass, options_hash={}, &block)
|
12
|
+
require "middleman-sprockets/sass_function_hack"
|
10
13
|
|
11
|
-
|
12
|
-
def registered(app)
|
13
|
-
# Add class methods to context
|
14
|
-
app.send :include, InstanceMethods
|
15
|
-
|
16
|
-
app.helpers JavascriptTagHelper
|
17
|
-
app.helpers StylesheetTagHelper
|
18
|
-
|
19
|
-
::Tilt.register ::Sprockets::EjsTemplate, 'ejs'
|
20
|
-
::Tilt.register ::Sprockets::EcoTemplate, 'eco'
|
21
|
-
::Tilt.register ::Sprockets::JstProcessor, 'jst'
|
22
|
-
|
23
|
-
app.after_configuration do
|
24
|
-
template_extensions :jst => :js, :eco => :js, :ejs => :js
|
25
|
-
|
26
|
-
sitemap.rebuild_resource_list!
|
27
|
-
|
28
|
-
# Add any gems with (vendor|app|.)/assets/javascripts to paths
|
29
|
-
# also add similar directories from project root (like in rails)
|
30
|
-
try_paths = [
|
31
|
-
%w{ assets },
|
32
|
-
%w{ app },
|
33
|
-
%w{ app assets },
|
34
|
-
%w{ vendor },
|
35
|
-
%w{ vendor assets },
|
36
|
-
%w{ lib },
|
37
|
-
%w{ lib assets }
|
38
|
-
].inject([]) do |sum, v|
|
39
|
-
sum + [
|
40
|
-
File.join(v, 'javascripts'),
|
41
|
-
File.join(v, 'stylesheets'),
|
42
|
-
File.join(v, 'images'),
|
43
|
-
File.join(v, 'fonts')
|
44
|
-
]
|
45
|
-
end
|
46
|
-
|
47
|
-
([root] + ::Middleman.rubygems_latest_specs.map(&:full_gem_path)).each do |root_path|
|
48
|
-
try_paths.map {|p| File.join(root_path, p) }.
|
49
|
-
select {|p| File.directory?(p) }.
|
50
|
-
each {|path| sprockets.append_path(path) }
|
51
|
-
end
|
52
|
-
|
53
|
-
# Setup Sprockets Sass options
|
54
|
-
sass.each { |k, v| ::Sprockets::Sass.options[k] = v }
|
55
|
-
|
56
|
-
# Intercept requests to /javascripts and /stylesheets and pass to sprockets
|
57
|
-
our_sprockets = sprockets
|
58
|
-
|
59
|
-
map("/#{js_dir}") { run our_sprockets }
|
60
|
-
map("/#{css_dir}") { run our_sprockets }
|
61
|
-
map("/#{images_dir}") { run our_sprockets }
|
62
|
-
map("/#{fonts_dir}") { run our_sprockets }
|
63
|
-
|
64
|
-
# register resource list manipulator to add assets_load_paths to sitemap
|
65
|
-
sitemap.register_resource_list_manipulator(:assets_load_paths, SitemapExtension.new(self), false)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
alias :included :registered
|
69
|
-
end
|
70
|
-
|
71
|
-
module InstanceMethods
|
72
|
-
# @return [Middleman::CoreExtensions::Sprockets::MiddlemanSprocketsEnvironment]
|
73
|
-
def sprockets
|
74
|
-
@sprockets ||= MiddlemanSprocketsEnvironment.new(self)
|
14
|
+
super
|
75
15
|
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# Generic Middleman Sprockets env
|
79
|
-
class MiddlemanSprocketsEnvironment < ::Sprockets::Environment
|
80
|
-
# Setup
|
81
|
-
def initialize(app)
|
82
|
-
@imported_assets = []
|
83
|
-
@app = app
|
84
|
-
|
85
|
-
super app.source_dir
|
86
16
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
# Remove compressors, we handle these with middleware
|
93
|
-
unregister_bundle_processor 'application/javascript', :js_compressor
|
94
|
-
unregister_bundle_processor 'text/css', :css_compressor
|
95
|
-
|
96
|
-
# configure search paths
|
97
|
-
append_path app.js_dir
|
98
|
-
append_path app.css_dir
|
99
|
-
append_path app.images_dir
|
100
|
-
append_path app.fonts_dir
|
101
|
-
append_path app.bower_dir if app.respond_to?(:bower_dir)
|
102
|
-
|
103
|
-
# add custom assets paths to the scope
|
104
|
-
app.js_assets_paths.each do |p|
|
105
|
-
warn ":js_assets_paths is deprecated. Call sprockets.append_path instead."
|
106
|
-
append_path p
|
107
|
-
end if app.respond_to?(:js_assets_paths)
|
108
|
-
|
109
|
-
# Stylus support
|
110
|
-
if defined?(::Stylus)
|
111
|
-
require 'stylus/sprockets'
|
112
|
-
::Stylus.setup(self, app.styl)
|
17
|
+
helpers do
|
18
|
+
# The sprockets environment
|
19
|
+
# @return [Middleman::MiddlemanSprocketsEnvironment]
|
20
|
+
def sprockets
|
21
|
+
extensions[:sprockets].environment
|
113
22
|
end
|
114
|
-
end
|
115
23
|
|
116
|
-
|
117
|
-
def enhance_context_class!
|
118
|
-
app = @app
|
119
|
-
|
120
|
-
# Make the app context available to Sprockets
|
121
|
-
context_class.send(:define_method, :app) { app }
|
122
|
-
|
123
|
-
context_class.class_eval do
|
124
|
-
def asset_path(path, options={})
|
125
|
-
# Handle people calling with the Middleman/Padrino asset path signature
|
126
|
-
if path.is_a?(::Symbol) && !options.is_a?(::Hash)
|
127
|
-
return app.asset_path(path, options)
|
128
|
-
end
|
129
|
-
|
130
|
-
kind = case options[:type]
|
131
|
-
when :image then :images
|
132
|
-
when :font then :fonts
|
133
|
-
when :javascript then :js
|
134
|
-
when :stylesheet then :css
|
135
|
-
else options[:type]
|
136
|
-
end
|
137
|
-
|
138
|
-
app.asset_path(kind, path)
|
139
|
-
end
|
140
|
-
|
141
|
-
# These helpers are already defined in later versions of Sprockets, but we define
|
142
|
-
# them ourself to help older versions and to provide extra options that Sass wants.
|
143
|
-
|
144
|
-
# Expand logical image asset path.
|
145
|
-
def image_path(path, options={})
|
146
|
-
asset_path(path, :type => :image)
|
147
|
-
end
|
148
|
-
|
149
|
-
# Expand logical font asset path.
|
150
|
-
def font_path(path, options={})
|
151
|
-
# Knock .fonts off the end, because Middleman < 3.1 doesn't handle fonts
|
152
|
-
# in asset_path
|
153
|
-
asset_path(path, :type => :font).sub(/\.fonts$/, '')
|
154
|
-
end
|
155
|
-
|
156
|
-
# Expand logical javascript asset path.
|
157
|
-
def javascript_path(path, options={})
|
158
|
-
asset_path(path, :type => :javascript)
|
159
|
-
end
|
160
|
-
|
161
|
-
# Expand logical stylesheet asset path.
|
162
|
-
def stylesheet_path(path, options={})
|
163
|
-
asset_path(path, :type => :stylesheet)
|
164
|
-
end
|
165
|
-
|
166
|
-
def method_missing(*args)
|
167
|
-
name = args.first
|
168
|
-
if app.respond_to?(name)
|
169
|
-
app.send(*args)
|
170
|
-
else
|
171
|
-
super
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
# Needed so that method_missing makes sense
|
176
|
-
def respond_to?(method, include_private = false)
|
177
|
-
super || app.respond_to?(method, include_private)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
private :enhance_context_class!
|
182
|
-
|
183
|
-
# Override Sprockets' default digest function to *not*
|
184
|
-
# change depending on the exact Sprockets version. It still takes
|
185
|
-
# into account "version" which is a user-suppliable version
|
186
|
-
# number that can be used to force assets to have a new
|
187
|
-
# hash.
|
188
|
-
def digest
|
189
|
-
@digest ||= Digest::SHA1.new.update(version.to_s)
|
190
|
-
@digest.dup
|
24
|
+
include ::Middleman::Sprockets::AssetTagHelpers
|
191
25
|
end
|
192
26
|
|
193
|
-
|
194
|
-
|
195
|
-
path[/-([0-9a-f]{8})\.[^.]+$/, 1]
|
196
|
-
end
|
197
|
-
|
198
|
-
# Invalidate sitemap when users mess with the sprockets load paths
|
199
|
-
def append_path(*args)
|
200
|
-
@app.sitemap.rebuild_resource_list!(:sprockets_paths)
|
201
|
-
super
|
202
|
-
end
|
203
|
-
|
204
|
-
def prepend_path(*args)
|
205
|
-
@app.sitemap.rebuild_resource_list!(:sprockets_paths)
|
206
|
-
super
|
27
|
+
def environment
|
28
|
+
@sprockets ||= ::Middleman::Sprockets::Environment.new(app)
|
207
29
|
end
|
208
30
|
|
209
|
-
def
|
210
|
-
|
211
|
-
|
31
|
+
def instance_available
|
32
|
+
if defined?(::Middleman::ConfigContext)
|
33
|
+
app.add_to_config_context :sprockets, &method(:environment)
|
34
|
+
end
|
212
35
|
end
|
213
36
|
|
214
|
-
def
|
215
|
-
|
216
|
-
super
|
217
|
-
end
|
37
|
+
def after_configuration
|
38
|
+
self.environment.options = options
|
218
39
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
40
|
+
::Tilt.register ::Sprockets::EjsTemplate, 'ejs'
|
41
|
+
::Tilt.register ::Sprockets::EcoTemplate, 'eco'
|
42
|
+
::Tilt.register ::Sprockets::JstProcessor, 'jst'
|
43
|
+
app.template_extensions :jst => :js, :eco => :js, :ejs => :js
|
44
|
+
|
45
|
+
app.sitemap.rebuild_resource_list!
|
46
|
+
|
47
|
+
# Add any gems with (vendor|app|.)/assets/javascripts to paths
|
48
|
+
# also add similar directories from project root (like in rails)
|
49
|
+
try_paths = [
|
50
|
+
%w{ assets },
|
51
|
+
%w{ app },
|
52
|
+
%w{ app assets },
|
53
|
+
%w{ vendor },
|
54
|
+
%w{ vendor assets },
|
55
|
+
%w{ lib },
|
56
|
+
%w{ lib assets }
|
57
|
+
].inject([]) do |sum, v|
|
58
|
+
sum + [
|
59
|
+
File.join(v, 'javascripts'),
|
60
|
+
File.join(v, 'stylesheets'),
|
61
|
+
File.join(v, 'images'),
|
62
|
+
File.join(v, 'fonts')
|
63
|
+
]
|
229
64
|
end
|
230
|
-
resource = @app.sitemap.find_resource_by_destination_path(request_path)
|
231
65
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
response.write """<html><body><h1>File Not Found</h1><p>#{request_path}</p>
|
237
|
-
<p>If this is an an asset from a gem, add <tt>sprockets.import_asset '#{File.basename(request_path)}'</tt>
|
238
|
-
to your <tt>config.rb</tt>.</body>"""
|
239
|
-
return response.finish
|
66
|
+
([app.root] + ::Middleman.rubygems_latest_specs.map(&:full_gem_path)).each do |root_path|
|
67
|
+
try_paths.map {|p| File.join(root_path, p) }.
|
68
|
+
select {|p| File.directory?(p) }.
|
69
|
+
each {|path| self.environment.append_path(path) }
|
240
70
|
end
|
241
71
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
end
|
246
|
-
|
247
|
-
# A list of Sprockets logical paths for assets that should be brought into the
|
248
|
-
# Middleman application and built.
|
249
|
-
attr_accessor :imported_assets
|
250
|
-
|
251
|
-
# Tell Middleman to build this asset, referenced as a logical path.
|
252
|
-
def import_asset(asset_logical_path)
|
253
|
-
imported_assets << asset_logical_path
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
module JavascriptTagHelper
|
258
|
-
|
259
|
-
# extend padrinos javascript_include_tag with debug functionality
|
260
|
-
# splits up script dependencies in individual files when
|
261
|
-
# configuration variable :debug_assets is set to true
|
262
|
-
def javascript_include_tag(*sources)
|
263
|
-
if respond_to?(:debug_assets) && debug_assets && !build?
|
264
|
-
options = sources.extract_options!.symbolize_keys
|
265
|
-
|
266
|
-
# loop through all sources and the dependencies and
|
267
|
-
# output each as script tag in the correct order
|
268
|
-
sources.map do |source|
|
269
|
-
source_file_name = source.to_s
|
270
|
-
|
271
|
-
dependencies_paths = if source_file_name.start_with?('//', 'http')
|
272
|
-
# Don't touch external sources
|
273
|
-
source_file_name
|
274
|
-
else
|
275
|
-
source_file_name << ".js" unless source_file_name.end_with?(".js")
|
276
|
-
|
277
|
-
sprockets[source_file_name].to_a.map do |dependency|
|
278
|
-
# if sprockets sees "?body=1" it only gives back the body
|
279
|
-
# of the script without the dependencies included
|
280
|
-
dependency.logical_path + "?body=1"
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
super(dependencies_paths, options)
|
285
|
-
end.join("").gsub("body=1.js", "body=1")
|
286
|
-
else
|
287
|
-
super
|
72
|
+
# Setup Sprockets Sass options
|
73
|
+
if app.config.respond_to?(:sass)
|
74
|
+
app.config[:sass].each { |k, v| ::Sprockets::Sass.options[k] = v }
|
288
75
|
end
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
module StylesheetTagHelper
|
293
|
-
|
294
|
-
# extend padrinos stylesheet_link_tag with debug functionality
|
295
|
-
# splits up stylesheets dependencies in individual files when
|
296
|
-
# configuration variable :debug_assets is set to true
|
297
|
-
def stylesheet_link_tag(*sources)
|
298
|
-
if respond_to?(:debug_assets) && debug_assets && !build?
|
299
|
-
options = sources.extract_options!.symbolize_keys
|
300
|
-
# loop through all sources and the dependencies and
|
301
|
-
# output each as script tag in the correct order
|
302
|
-
|
303
|
-
sources.map do |source|
|
304
|
-
source_file_name = source.to_s
|
305
76
|
|
306
|
-
|
307
|
-
|
308
|
-
source_file_name
|
309
|
-
else
|
310
|
-
source_file_name << ".css" unless source_file_name.end_with?(".css")
|
77
|
+
# Intercept requests to /javascripts and /stylesheets and pass to sprockets
|
78
|
+
our_sprockets = self.environment
|
311
79
|
|
312
|
-
|
313
|
-
|
314
|
-
# of the script without the dependencies included
|
315
|
-
dependency.logical_path + "?body=1"
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
super(dependencies_paths, options)
|
320
|
-
end.join("").gsub("body=1.css", "body=1")
|
321
|
-
else
|
322
|
-
super
|
80
|
+
[app.config[:js_dir], app.config[:css_dir], app.config[:images_dir], app.config[:fonts_dir]].each do |dir|
|
81
|
+
app.map("/#{dir}") { run our_sprockets }
|
323
82
|
end
|
324
83
|
end
|
325
|
-
end
|
326
|
-
|
327
|
-
class SitemapExtension
|
328
|
-
def initialize(app)
|
329
|
-
@app = app
|
330
|
-
end
|
331
84
|
|
332
85
|
# Add sitemap resource for every image in the sprockets load path
|
333
86
|
def manipulate_resource_list(resources)
|
334
|
-
sprockets =
|
87
|
+
sprockets = self.environment
|
335
88
|
|
336
89
|
imported_assets = []
|
337
90
|
sprockets.imported_assets.each do |asset_logical_path|
|
@@ -349,15 +102,15 @@ module Middleman::Sprockets
|
|
349
102
|
output_dir = nil
|
350
103
|
export_all = false
|
351
104
|
if load_path.end_with?('/images')
|
352
|
-
output_dir = @app.images_dir
|
105
|
+
output_dir = @app.config[:images_dir]
|
353
106
|
export_all = true
|
354
107
|
elsif load_path.end_with?('/fonts')
|
355
|
-
output_dir = @app.fonts_dir
|
108
|
+
output_dir = @app.config[:fonts_dir]
|
356
109
|
export_all = true
|
357
110
|
elsif load_path.end_with?('/stylesheets')
|
358
|
-
output_dir = @app.css_dir
|
111
|
+
output_dir = @app.config[:css_dir]
|
359
112
|
elsif load_path.end_with?('/javascripts')
|
360
|
-
output_dir = @app.js_dir
|
113
|
+
output_dir = @app.config[:js_dir]
|
361
114
|
end
|
362
115
|
|
363
116
|
if output_dir
|
@@ -4,22 +4,24 @@
|
|
4
4
|
#
|
5
5
|
# See https://github.com/middleman/middleman/issues/864 for more info.
|
6
6
|
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
if defined?(Sass)
|
8
|
+
module Sass::Script::Functions
|
9
|
+
def image_url(source, options = {}, cache_buster = nil)
|
10
|
+
# Work with the Compass #image_url API
|
11
|
+
if options.respond_to? :value
|
12
|
+
case options.value
|
13
|
+
when true
|
14
|
+
return ::Sass::Script::String.new sprockets_context.image_path(source.value).to_s, :string
|
15
|
+
else
|
16
|
+
options = {}
|
17
|
+
end
|
16
18
|
end
|
19
|
+
::Sass::Script::String.new "url(\"#{sprockets_context.image_path(source.value, map_options(options)).to_s}\")"
|
17
20
|
end
|
18
|
-
::Sass::Script::String.new "url(\"#{sprockets_context.image_path(source.value, map_options(options)).to_s}\")"
|
19
|
-
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
# Also override generated_image_url to use Sprockets a la https://github.com/Compass/compass-rails/blob/98e4b115c8bb6395a1c3351926d574321396778b/lib/compass-rails/patches/3_1.rb
|
23
|
+
def generated_image_url(path, only_path = nil)
|
24
|
+
asset_url(path, Sass::Script::String.new("image"))
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
data/middleman-sprockets.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "middleman-sprockets"
|
7
7
|
s.version = Middleman::Sprockets::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Thomas Reynolds"]
|
10
|
-
s.email = ["me@tdreyno.com"]
|
9
|
+
s.authors = ["Thomas Reynolds", "Ben Hollis"]
|
10
|
+
s.email = ["me@tdreyno.com", "ben@benhollis.net"]
|
11
11
|
s.homepage = "https://github.com/middleman/middleman-sprockets"
|
12
12
|
s.summary = %q{Sprockets support for Middleman}
|
13
13
|
s.description = %q{Sprockets support for Middleman}
|
@@ -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.2"])
|
19
19
|
s.add_dependency("sprockets", ["~> 2.1"])
|
20
20
|
s.add_dependency("sprockets-sass", ["~> 1.0.0"])
|
21
21
|
s.add_dependency("sprockets-helpers", ["~> 1.0.0"])
|
22
|
-
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,80 +1,82 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-sprockets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Reynolds
|
8
|
+
- Ben Hollis
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: middleman-core
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- -
|
18
|
+
- - ">="
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: '3.2'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
|
-
- -
|
25
|
+
- - ">="
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '3.2'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: sprockets
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- - ~>
|
32
|
+
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: '2.1'
|
34
35
|
type: :runtime
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- - ~>
|
39
|
+
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '2.1'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: sprockets-sass
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
|
-
- - ~>
|
46
|
+
- - "~>"
|
46
47
|
- !ruby/object:Gem::Version
|
47
48
|
version: 1.0.0
|
48
49
|
type: :runtime
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
|
-
- - ~>
|
53
|
+
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: 1.0.0
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: sprockets-helpers
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
|
-
- - ~>
|
60
|
+
- - "~>"
|
60
61
|
- !ruby/object:Gem::Version
|
61
62
|
version: 1.0.0
|
62
63
|
type: :runtime
|
63
64
|
prerelease: false
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
|
-
- - ~>
|
67
|
+
- - "~>"
|
67
68
|
- !ruby/object:Gem::Version
|
68
69
|
version: 1.0.0
|
69
70
|
description: Sprockets support for Middleman
|
70
71
|
email:
|
71
72
|
- me@tdreyno.com
|
73
|
+
- ben@benhollis.net
|
72
74
|
executables: []
|
73
75
|
extensions: []
|
74
76
|
extra_rdoc_files: []
|
75
77
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .travis.yml
|
78
|
+
- ".gitignore"
|
79
|
+
- ".travis.yml"
|
78
80
|
- CHANGELOG.md
|
79
81
|
- CONTRIBUTING.md
|
80
82
|
- Gemfile
|
@@ -133,6 +135,9 @@ files:
|
|
133
135
|
- fixtures/bower-app/components/jquery/package.json
|
134
136
|
- fixtures/bower-app/config.rb
|
135
137
|
- fixtures/bower-app/source/javascripts/get_jquery.js
|
138
|
+
- fixtures/bower-json-app/config.rb
|
139
|
+
- fixtures/bower-json-app/source/javascripts/application.js.coffee
|
140
|
+
- fixtures/bower-json-app/source/javascripts/bower.json
|
136
141
|
- fixtures/glob-app/config.rb
|
137
142
|
- fixtures/glob-app/source/stylesheets/main.css.scss
|
138
143
|
- fixtures/glob-app/source/stylesheets/module1/_i-am-mod.scss
|
@@ -193,10 +198,11 @@ files:
|
|
193
198
|
- fixtures/sprockets-images-app/source/library/images/cat.jpg
|
194
199
|
- fixtures/sprockets-images-app/vendor/assets/images/cat-2.jpg
|
195
200
|
- lib/middleman-sprockets.rb
|
201
|
+
- lib/middleman-sprockets/asset_tag_helpers.rb
|
202
|
+
- lib/middleman-sprockets/environment.rb
|
196
203
|
- lib/middleman-sprockets/extension.rb
|
197
204
|
- lib/middleman-sprockets/sass_function_hack.rb
|
198
205
|
- lib/middleman-sprockets/version.rb
|
199
|
-
- lib/middleman_extension.rb
|
200
206
|
- middleman-sprockets.gemspec
|
201
207
|
homepage: https://github.com/middleman/middleman-sprockets
|
202
208
|
licenses:
|
@@ -208,17 +214,17 @@ require_paths:
|
|
208
214
|
- lib
|
209
215
|
required_ruby_version: !ruby/object:Gem::Requirement
|
210
216
|
requirements:
|
211
|
-
- -
|
217
|
+
- - ">="
|
212
218
|
- !ruby/object:Gem::Version
|
213
219
|
version: '0'
|
214
220
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
221
|
requirements:
|
216
|
-
- -
|
222
|
+
- - ">="
|
217
223
|
- !ruby/object:Gem::Version
|
218
224
|
version: '0'
|
219
225
|
requirements: []
|
220
226
|
rubyforge_project:
|
221
|
-
rubygems_version: 2.
|
227
|
+
rubygems_version: 2.2.2
|
222
228
|
signing_key:
|
223
229
|
specification_version: 4
|
224
230
|
summary: Sprockets support for Middleman
|
@@ -275,6 +281,9 @@ test_files:
|
|
275
281
|
- fixtures/bower-app/components/jquery/package.json
|
276
282
|
- fixtures/bower-app/config.rb
|
277
283
|
- fixtures/bower-app/source/javascripts/get_jquery.js
|
284
|
+
- fixtures/bower-json-app/config.rb
|
285
|
+
- fixtures/bower-json-app/source/javascripts/application.js.coffee
|
286
|
+
- fixtures/bower-json-app/source/javascripts/bower.json
|
278
287
|
- fixtures/glob-app/config.rb
|
279
288
|
- fixtures/glob-app/source/stylesheets/main.css.scss
|
280
289
|
- fixtures/glob-app/source/stylesheets/module1/_i-am-mod.scss
|
data/lib/middleman_extension.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "middleman-sprockets"
|