middleman-sprockets 3.3.4 → 3.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.simplecov +9 -0
- data/Gemfile +2 -2
- data/README.md +47 -2
- data/Rakefile +4 -1
- data/features/bower.feature +7 -0
- data/features/support/env.rb +10 -0
- data/fixtures/bower-individual-outputdir-app/bower.json +7 -0
- data/fixtures/bower-individual-outputdir-app/bower_components/underscore/bower.json +8 -0
- data/fixtures/bower-individual-outputdir-app/bower_components/underscore/underscore.js +1343 -0
- data/fixtures/bower-individual-outputdir-app/config.rb +6 -0
- data/fixtures/bower-individual-outputdir-app/source/javascripts/application.js +1 -0
- data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/.bower.json +34 -0
- data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/bower.json +26 -0
- data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/img/close.png +0 -0
- data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/js/lightbox.js +2 -0
- data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/package.json +37 -0
- data/lib/middleman-sprockets/asset.rb +185 -0
- data/lib/middleman-sprockets/asset_list.rb +41 -0
- data/lib/middleman-sprockets/config_only_environment.rb +4 -4
- data/lib/middleman-sprockets/environment.rb +7 -2
- data/lib/middleman-sprockets/extension.rb +32 -52
- data/lib/middleman-sprockets/imported_asset.rb +57 -0
- data/lib/middleman-sprockets/pathname_extensions.rb +10 -0
- data/lib/middleman-sprockets/version.rb +1 -1
- data/spec/asset_list_spec.rb +38 -0
- data/spec/asset_spec.rb +116 -0
- data/spec/imported_asset_spec.rb +72 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/aruba.rb +18 -0
- data/spec/support/rspec.rb +17 -0
- metadata +34 -2
@@ -0,0 +1,6 @@
|
|
1
|
+
sprockets.append_path File.join(root, 'bower_components')
|
2
|
+
|
3
|
+
sprockets.append_path File.join(root, 'vendor/assets/components')
|
4
|
+
sprockets.import_asset('underscore/underscore.js') { 'underscore.js' }
|
5
|
+
sprockets.import_asset('lightbox2/img/close.png') { |logical_path| Pathname.new('hello_world') + logical_path }
|
6
|
+
sprockets.import_asset('lightbox2/js/lightbox.js')
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require underscore/underscore
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"name": "lightbox",
|
3
|
+
"homepage": "http://lokeshdhakar.com/projects/lightbox2/",
|
4
|
+
"authors": [
|
5
|
+
"Lokesh Dhakar <lokesh.dhakar@gmail.com>"
|
6
|
+
],
|
7
|
+
"description": "The original Lightbox script. Uses jQuery.",
|
8
|
+
"main": "js/lightbox.js",
|
9
|
+
"keywords": [
|
10
|
+
"lightbox",
|
11
|
+
"overlay",
|
12
|
+
"jquery",
|
13
|
+
"gallery",
|
14
|
+
"images"
|
15
|
+
],
|
16
|
+
"license": "CC BY 2.5",
|
17
|
+
"ignore": [
|
18
|
+
"**/.*",
|
19
|
+
"Gruntfile.js",
|
20
|
+
"node_modules",
|
21
|
+
"bower_components",
|
22
|
+
"test",
|
23
|
+
"tests"
|
24
|
+
],
|
25
|
+
"_release": "05ffb8e6d5",
|
26
|
+
"_resolution": {
|
27
|
+
"type": "branch",
|
28
|
+
"branch": "master",
|
29
|
+
"commit": "05ffb8e6d524762ded286b0c33cebab5347cf34a"
|
30
|
+
},
|
31
|
+
"_source": "https://github.com/dg-vrnetze/revealjs-lightbox2.git",
|
32
|
+
"_target": "*",
|
33
|
+
"_originalSource": "https://github.com/dg-vrnetze/revealjs-lightbox2.git"
|
34
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"name": "lightbox",
|
3
|
+
"version": "2.7.1",
|
4
|
+
"homepage": "http://lokeshdhakar.com/projects/lightbox2/",
|
5
|
+
"authors": [
|
6
|
+
"Lokesh Dhakar <lokesh.dhakar@gmail.com>"
|
7
|
+
],
|
8
|
+
"description": "The original Lightbox script. Uses jQuery.",
|
9
|
+
"main": "js/lightbox.js",
|
10
|
+
"keywords": [
|
11
|
+
"lightbox",
|
12
|
+
"overlay",
|
13
|
+
"jquery",
|
14
|
+
"gallery",
|
15
|
+
"images"
|
16
|
+
],
|
17
|
+
"license": "CC BY 2.5",
|
18
|
+
"ignore": [
|
19
|
+
"**/.*",
|
20
|
+
"Gruntfile.js",
|
21
|
+
"node_modules",
|
22
|
+
"bower_components",
|
23
|
+
"test",
|
24
|
+
"tests"
|
25
|
+
]
|
26
|
+
}
|
Binary file
|
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"name": "lightbox",
|
3
|
+
"version": "2.7.1",
|
4
|
+
"author": "Lokesh Dhakar",
|
5
|
+
"description": "Lightbox is small javascript library used to overlay images on top of the current page. It's a snap to setup and works on all modern browsers.",
|
6
|
+
"keywords": [
|
7
|
+
"lightbox",
|
8
|
+
"lightbox2",
|
9
|
+
"overlay",
|
10
|
+
"image",
|
11
|
+
"gallery"
|
12
|
+
],
|
13
|
+
"homepage": "http://lokeshdhakar.com/projects/lightbox2/",
|
14
|
+
"repository": {
|
15
|
+
"type": "git",
|
16
|
+
"url": "https://github.com/lokesh/lightbox2.git"
|
17
|
+
},
|
18
|
+
"bugs": {
|
19
|
+
"url": "https://github.com/lokesh/lightbox2/issues"
|
20
|
+
},
|
21
|
+
"licenses": [
|
22
|
+
{
|
23
|
+
"type": "Creative Commons Attribution 2.5 License",
|
24
|
+
"url": "http://creativecommons.org/licenses/by/2.5/"
|
25
|
+
}
|
26
|
+
],
|
27
|
+
"devDependencies": {
|
28
|
+
"grunt": "~0.4.2",
|
29
|
+
"grunt-contrib-compass": "^0.7.2",
|
30
|
+
"grunt-contrib-watch": "^0.5.3",
|
31
|
+
"grunt-contrib-connect": "^0.7.1",
|
32
|
+
"grunt-ftp-deploy": "^0.1.1",
|
33
|
+
"grunt-contrib-uglify": "~0.4.0",
|
34
|
+
"grunt-contrib-jshint": "~0.9.2",
|
35
|
+
"grunt-exec": "~0.4.5"
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,185 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Middleman
|
3
|
+
module Sprockets
|
4
|
+
# Asset
|
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
|
14
|
+
|
15
|
+
# Create instance
|
16
|
+
#
|
17
|
+
# @param [Pathname] logical_path
|
18
|
+
# The logical path to the asset given in config.rb
|
19
|
+
#
|
20
|
+
# @param [proc] output_dir
|
21
|
+
# An individual output directory for that particular asset
|
22
|
+
def initialize(source_path, options)
|
23
|
+
source_directory = options.fetch(:source_directory, nil)
|
24
|
+
|
25
|
+
fail ArgumentError, 'Missing argument source_directory' unless source_directory
|
26
|
+
|
27
|
+
@source_directory = source_directory
|
28
|
+
|
29
|
+
@source_path = Pathname.new(source_path)
|
30
|
+
@relative_source_path = @source_path.relative_path_from(Pathname.new(source_directory))
|
31
|
+
@base_name = @source_path.basename
|
32
|
+
@import_it = false
|
33
|
+
end
|
34
|
+
|
35
|
+
# Should the asset imported?
|
36
|
+
#
|
37
|
+
# @return [true, false]
|
38
|
+
# Is true if it should be imported
|
39
|
+
def import?
|
40
|
+
valid? && (in_trusted_source_directory? || import_it?)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Check on file type
|
44
|
+
#
|
45
|
+
# @return [true, false]
|
46
|
+
# Is true if has type
|
47
|
+
def has_type?(t)
|
48
|
+
type == t
|
49
|
+
end
|
50
|
+
|
51
|
+
# Path where the asset should be stored
|
52
|
+
#
|
53
|
+
# @return [Pathname]
|
54
|
+
# Returns `destination_path` if set, otherwise build result: destination_directory + relative_source_path
|
55
|
+
#
|
56
|
+
# @raise [::Sprockets::FileNotFound]
|
57
|
+
# Raise error if destination_directory was not set previously from outside
|
58
|
+
def destination_path
|
59
|
+
return @destination_path if @destination_path
|
60
|
+
|
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
|
62
|
+
|
63
|
+
destination_directory + relative_source_path
|
64
|
+
end
|
65
|
+
|
66
|
+
# Sets the destination_path
|
67
|
+
#
|
68
|
+
# @param [String,Pathname] path
|
69
|
+
# The output path for asset as string or pathname. It will be converted
|
70
|
+
# to `Pathname`.
|
71
|
+
def destination_path=(path)
|
72
|
+
@destination_path = Pathname.new path
|
73
|
+
end
|
74
|
+
|
75
|
+
# Set destination directory
|
76
|
+
#
|
77
|
+
# @param [String] path
|
78
|
+
# The path to the destination directory
|
79
|
+
#
|
80
|
+
# @return [Pathname]
|
81
|
+
# The path as pathname
|
82
|
+
def destination_directory=(path)
|
83
|
+
@destination_directory = Pathname.new path
|
84
|
+
end
|
85
|
+
|
86
|
+
# Check if given path matches source_path
|
87
|
+
#
|
88
|
+
# @param [String] path
|
89
|
+
# The path to be checked
|
90
|
+
# @return [true, false]
|
91
|
+
# The result of check
|
92
|
+
def match?(path)
|
93
|
+
source_path == Pathname.new(path)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Tell asset that it is importable
|
97
|
+
def import_it
|
98
|
+
@import_it = true # single =
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def in_trusted_source_directory?
|
104
|
+
is_in_images_directory? || is_in_fonts_directory?
|
105
|
+
end
|
106
|
+
|
107
|
+
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
|
119
|
+
end
|
120
|
+
|
121
|
+
def file?
|
122
|
+
source_path.file?
|
123
|
+
end
|
124
|
+
|
125
|
+
def partial?
|
126
|
+
base_name.start_with? '_'
|
127
|
+
end
|
128
|
+
|
129
|
+
# Is it a valid asset
|
130
|
+
# @return [true, false]
|
131
|
+
# If the asset is valid return true
|
132
|
+
def valid?
|
133
|
+
file? && !partial?
|
134
|
+
end
|
135
|
+
|
136
|
+
def import_it?
|
137
|
+
@import_it == true # double =
|
138
|
+
end
|
139
|
+
|
140
|
+
def has_extname?(*exts)
|
141
|
+
exts.any? { |e| extname == e }
|
142
|
+
end
|
143
|
+
|
144
|
+
def extname
|
145
|
+
source_path.extname
|
146
|
+
end
|
147
|
+
|
148
|
+
def has_real_path?(path)
|
149
|
+
real_path == path
|
150
|
+
end
|
151
|
+
|
152
|
+
def is_in_images_directory?
|
153
|
+
source_directory.end_with?('images', 'img')
|
154
|
+
end
|
155
|
+
|
156
|
+
def is_in_fonts_directory?
|
157
|
+
source_directory.end_with?('fonts')
|
158
|
+
end
|
159
|
+
|
160
|
+
def is_in_scripts_directory?
|
161
|
+
source_directory.end_with?('javascripts', 'js')
|
162
|
+
end
|
163
|
+
|
164
|
+
def is_in_stylesheets_directory?
|
165
|
+
source_directory.end_with?('stylesheets', 'css')
|
166
|
+
end
|
167
|
+
|
168
|
+
def is_image?
|
169
|
+
has_extname?('.gif', '.png', '.jpg', '.jpeg', '.svg', '.svg.gz')
|
170
|
+
end
|
171
|
+
|
172
|
+
def is_stylesheet?
|
173
|
+
has_extname?('.css', '.sass', '.scss', '.styl', '.less')
|
174
|
+
end
|
175
|
+
|
176
|
+
def is_font?
|
177
|
+
has_extname?('.ttf', '.woff', '.eot', '.otf')
|
178
|
+
end
|
179
|
+
|
180
|
+
def is_script?
|
181
|
+
has_extname?('.js', '.coffee')
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Middleman
|
3
|
+
module Sprockets
|
4
|
+
class AssetList
|
5
|
+
private
|
6
|
+
|
7
|
+
attr_reader :assets
|
8
|
+
|
9
|
+
public
|
10
|
+
|
11
|
+
def initialize(assets = [])
|
12
|
+
@assets = Array(assets)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Find candidate in list
|
16
|
+
#
|
17
|
+
# @param [#source_path] candidate
|
18
|
+
# The candidate to search for
|
19
|
+
#
|
20
|
+
# @yield
|
21
|
+
# This blocks gets the candidate found
|
22
|
+
def lookup(candidate, &block)
|
23
|
+
found_asset = assets.find { |a| a.match? candidate.source_path }
|
24
|
+
|
25
|
+
block.call(candidate, found_asset) if block_given? && found_asset
|
26
|
+
|
27
|
+
found_asset
|
28
|
+
end
|
29
|
+
|
30
|
+
# Append asset to list
|
31
|
+
#
|
32
|
+
# @param [Asset]
|
33
|
+
# The asset to be appended
|
34
|
+
def add(asset)
|
35
|
+
assets << asset
|
36
|
+
end
|
37
|
+
alias_method :<<, :add
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -21,8 +21,8 @@ module Middleman
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def apply_to_environment(environment)
|
24
|
-
@imported_assets.each do |
|
25
|
-
environment.import_asset
|
24
|
+
@imported_assets.each do |(path, directory)|
|
25
|
+
environment.import_asset path, &directory
|
26
26
|
end
|
27
27
|
|
28
28
|
@appended_paths.each do |path|
|
@@ -34,8 +34,8 @@ module Middleman
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def import_asset(asset_logical_path)
|
38
|
-
@imported_assets << asset_logical_path
|
37
|
+
def import_asset(asset_logical_path, &output_directory)
|
38
|
+
@imported_assets << [asset_logical_path, output_directory]
|
39
39
|
end
|
40
40
|
|
41
41
|
def append_path(path)
|
@@ -214,8 +214,13 @@ module Middleman
|
|
214
214
|
end
|
215
215
|
|
216
216
|
# Tell Middleman to build this asset, referenced as a logical path.
|
217
|
-
def import_asset(asset_logical_path)
|
218
|
-
|
217
|
+
def import_asset(asset_logical_path, &determine_output_dir)
|
218
|
+
args = []
|
219
|
+
args << asset_logical_path
|
220
|
+
args << determine_output_dir if block_given?
|
221
|
+
|
222
|
+
imported_assets << ImportedAsset.new(*args)
|
223
|
+
|
219
224
|
@app.sitemap.rebuild_resource_list!(:sprockets_import_asset)
|
220
225
|
end
|
221
226
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
require "sprockets"
|
2
2
|
require "sprockets-sass"
|
3
|
+
require "middleman-sprockets/pathname_extensions"
|
4
|
+
require "middleman-sprockets/asset"
|
5
|
+
require "middleman-sprockets/imported_asset"
|
6
|
+
require "middleman-sprockets/asset_list"
|
3
7
|
require "middleman-sprockets/config_only_environment"
|
4
8
|
require "middleman-sprockets/environment"
|
5
9
|
require "middleman-sprockets/asset_tag_helpers"
|
@@ -53,7 +57,7 @@ module Middleman
|
|
53
57
|
@environment = ::Middleman::Sprockets::Environment.new(app, :debug_assets => debug_assets)
|
54
58
|
config_environment.apply_to_environment(@environment)
|
55
59
|
|
56
|
-
|
60
|
+
append_paths_from_gems
|
57
61
|
|
58
62
|
# Setup Sprockets Sass options
|
59
63
|
if app.config.defines_setting?(:sass)
|
@@ -70,64 +74,40 @@ module Middleman
|
|
70
74
|
|
71
75
|
# Add sitemap resource for every image in the sprockets load path
|
72
76
|
def manipulate_resource_list(resources)
|
73
|
-
imported_assets =
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
raise ::Sprockets::FileNotFound, "couldn't find asset '#{asset_logical_path}'" if assets.empty?
|
81
|
-
imported_assets += assets
|
77
|
+
imported_assets = Middleman::Sprockets::AssetList.new
|
78
|
+
|
79
|
+
environment.imported_assets.each do |asset|
|
80
|
+
asset.resolve_path_with environment
|
81
|
+
@app.logger.debug "== Importing Sprockets asset #{asset.real_path}"
|
82
|
+
|
83
|
+
imported_assets << asset
|
82
84
|
end
|
83
85
|
|
84
86
|
resources_list = []
|
85
87
|
environment.paths.each do |load_path|
|
86
|
-
candidate_dir = nil
|
87
|
-
export_all = false
|
88
|
-
if load_path.end_with?('/images')
|
89
|
-
candidate_dir = @app.config[:images_dir]
|
90
|
-
export_all = true
|
91
|
-
elsif load_path.end_with?('/fonts')
|
92
|
-
candidate_dir = @app.config[:fonts_dir]
|
93
|
-
export_all = true
|
94
|
-
elsif load_path.end_with?('/stylesheets')
|
95
|
-
candidate_dir = @app.config[:css_dir]
|
96
|
-
elsif load_path.end_with?('/javascripts')
|
97
|
-
candidate_dir = @app.config[:js_dir]
|
98
|
-
end
|
99
|
-
|
100
88
|
environment.each_entry(load_path) do |path|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
when '.ttf', '.woff', '.eot', '.otf'
|
119
|
-
@app.config[:fonts_dir]
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
if !output_dir
|
124
|
-
raise ::Sprockets::FileNotFound, "couldn't find an appropriate output directory for '#{path}' - halting because it was explicitly requested via 'import_asset'"
|
89
|
+
asset = Middleman::Sprockets::Asset.new(path, source_directory: load_path)
|
90
|
+
|
91
|
+
imported_assets.lookup(asset) do |candidate, found_asset|
|
92
|
+
candidate.destination_path = found_asset.output_path if found_asset.output_path
|
93
|
+
candidate.import_it
|
94
|
+
end
|
95
|
+
|
96
|
+
next unless asset.import?
|
97
|
+
|
98
|
+
if asset.has_type? :image
|
99
|
+
asset.destination_directory = @app.config[:images_dir]
|
100
|
+
elsif asset.has_type? :script
|
101
|
+
asset.destination_directory = @app.config[:js_dir]
|
102
|
+
elsif asset.has_type? :font
|
103
|
+
asset.destination_directory = @app.config[:fonts_dir]
|
104
|
+
elsif asset.has_type? :stylesheet
|
105
|
+
asset.destination_directory = @app.config[:css_dir]
|
125
106
|
end
|
126
107
|
|
127
|
-
|
128
|
-
new_path = @app.sitemap.extensionless_path(File.join(output_dir, base_path))
|
108
|
+
new_path = @app.sitemap.extensionless_path(asset.destination_path.to_s)
|
129
109
|
|
130
|
-
next if @app.sitemap.find_resource_by_destination_path(new_path)
|
110
|
+
next if @app.sitemap.find_resource_by_destination_path(new_path.to_s)
|
131
111
|
resources_list << ::Middleman::Sitemap::Resource.new(@app.sitemap, new_path.to_s, path.to_s)
|
132
112
|
end
|
133
113
|
end
|
@@ -137,7 +117,7 @@ module Middleman
|
|
137
117
|
private
|
138
118
|
|
139
119
|
# Add any directories from gems with Rails-like paths to sprockets load path
|
140
|
-
def
|
120
|
+
def append_paths_from_gems
|
141
121
|
try_paths = [
|
142
122
|
%w{ assets },
|
143
123
|
%w{ app },
|