sprockets 2.3.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sprockets might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/LICENSE +2 -2
- data/README.md +332 -115
- data/bin/sprockets +8 -0
- data/lib/rake/sprocketstask.rb +25 -13
- data/lib/sprockets/asset.rb +143 -205
- data/lib/sprockets/autoload/closure.rb +7 -0
- data/lib/sprockets/autoload/coffee_script.rb +7 -0
- data/lib/sprockets/autoload/eco.rb +7 -0
- data/lib/sprockets/autoload/ejs.rb +7 -0
- data/lib/sprockets/autoload/sass.rb +7 -0
- data/lib/sprockets/autoload/uglifier.rb +7 -0
- data/lib/sprockets/autoload/yui.rb +7 -0
- data/lib/sprockets/autoload.rb +11 -0
- data/lib/sprockets/base.rb +49 -257
- data/lib/sprockets/bower.rb +58 -0
- data/lib/sprockets/bundle.rb +65 -0
- data/lib/sprockets/cache/file_store.rb +165 -14
- data/lib/sprockets/cache/memory_store.rb +66 -0
- data/lib/sprockets/cache/null_store.rb +46 -0
- data/lib/sprockets/cache.rb +234 -0
- data/lib/sprockets/cached_environment.rb +69 -0
- data/lib/sprockets/closure_compressor.rb +53 -0
- data/lib/sprockets/coffee_script_processor.rb +25 -0
- data/lib/sprockets/coffee_script_template.rb +6 -0
- data/lib/sprockets/compressing.rb +74 -0
- data/lib/sprockets/configuration.rb +83 -0
- data/lib/sprockets/context.rb +125 -131
- data/lib/sprockets/dependencies.rb +73 -0
- data/lib/sprockets/digest_utils.rb +156 -0
- data/lib/sprockets/directive_processor.rb +209 -211
- data/lib/sprockets/eco_processor.rb +32 -0
- data/lib/sprockets/eco_template.rb +3 -35
- data/lib/sprockets/ejs_processor.rb +31 -0
- data/lib/sprockets/ejs_template.rb +3 -34
- data/lib/sprockets/encoding_utils.rb +258 -0
- data/lib/sprockets/engines.rb +45 -38
- data/lib/sprockets/environment.rb +17 -67
- data/lib/sprockets/erb_processor.rb +30 -0
- data/lib/sprockets/erb_template.rb +6 -0
- data/lib/sprockets/errors.rb +6 -13
- data/lib/sprockets/file_reader.rb +15 -0
- data/lib/sprockets/http_utils.rb +115 -0
- data/lib/sprockets/jst_processor.rb +35 -19
- data/lib/sprockets/legacy.rb +314 -0
- data/lib/sprockets/legacy_proc_processor.rb +35 -0
- data/lib/sprockets/legacy_tilt_processor.rb +29 -0
- data/lib/sprockets/loader.rb +176 -0
- data/lib/sprockets/manifest.rb +179 -98
- data/lib/sprockets/manifest_utils.rb +45 -0
- data/lib/sprockets/mime.rb +114 -32
- data/lib/sprockets/path_dependency_utils.rb +85 -0
- data/lib/sprockets/path_digest_utils.rb +47 -0
- data/lib/sprockets/path_utils.rb +282 -0
- data/lib/sprockets/paths.rb +81 -0
- data/lib/sprockets/processing.rb +157 -189
- data/lib/sprockets/processor_utils.rb +103 -0
- data/lib/sprockets/resolve.rb +208 -0
- data/lib/sprockets/sass_cache_store.rb +19 -15
- data/lib/sprockets/sass_compressor.rb +59 -0
- data/lib/sprockets/sass_functions.rb +2 -0
- data/lib/sprockets/sass_importer.rb +2 -29
- data/lib/sprockets/sass_processor.rb +285 -0
- data/lib/sprockets/sass_template.rb +4 -44
- data/lib/sprockets/server.rb +109 -84
- data/lib/sprockets/transformers.rb +145 -0
- data/lib/sprockets/uglifier_compressor.rb +63 -0
- data/lib/sprockets/uri_utils.rb +190 -0
- data/lib/sprockets/utils.rb +193 -44
- data/lib/sprockets/version.rb +1 -1
- data/lib/sprockets/yui_compressor.rb +65 -0
- data/lib/sprockets.rb +144 -53
- metadata +248 -238
- data/lib/sprockets/asset_attributes.rb +0 -126
- data/lib/sprockets/bundled_asset.rb +0 -79
- data/lib/sprockets/caching.rb +0 -96
- data/lib/sprockets/charset_normalizer.rb +0 -41
- data/lib/sprockets/index.rb +0 -99
- data/lib/sprockets/processed_asset.rb +0 -152
- data/lib/sprockets/processor.rb +0 -32
- data/lib/sprockets/safety_colons.rb +0 -28
- data/lib/sprockets/scss_template.rb +0 -13
- data/lib/sprockets/static_asset.rb +0 -57
- data/lib/sprockets/trail.rb +0 -90
@@ -1,7 +1,5 @@
|
|
1
|
-
require '
|
1
|
+
require 'set'
|
2
2
|
require 'shellwords'
|
3
|
-
require 'tilt'
|
4
|
-
require 'yaml'
|
5
3
|
|
6
4
|
module Sprockets
|
7
5
|
# The `DirectiveProcessor` is responsible for parsing and evaluating
|
@@ -20,10 +18,9 @@ module Sprockets
|
|
20
18
|
# *= require "baz"
|
21
19
|
# */
|
22
20
|
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# custom directives or invent your own directive syntax.
|
21
|
+
# This makes it possible to disable or modify the processor to do whatever
|
22
|
+
# you'd like. You could add your own custom directives or invent your own
|
23
|
+
# directive syntax.
|
27
24
|
#
|
28
25
|
# `Environment#processors` includes `DirectiveProcessor` by default.
|
29
26
|
#
|
@@ -36,24 +33,8 @@ module Sprockets
|
|
36
33
|
#
|
37
34
|
# env.register_processor('text/css', MyProcessor)
|
38
35
|
#
|
39
|
-
class DirectiveProcessor
|
40
|
-
|
41
|
-
# of the source file. C style (/* */), JavaScript (//), and
|
42
|
-
# Ruby (#) comments are supported.
|
43
|
-
#
|
44
|
-
# Directives in comments after the first non-whitespace line
|
45
|
-
# of code will not be processed.
|
46
|
-
#
|
47
|
-
HEADER_PATTERN = /
|
48
|
-
\A (
|
49
|
-
(?m:\s*) (
|
50
|
-
(\/\* (?m:.*?) \*\/) |
|
51
|
-
(\#\#\# (?m:.*?) \#\#\#) |
|
52
|
-
(\/\/ .* \n?)+ |
|
53
|
-
(\# .* \n?)+
|
54
|
-
)
|
55
|
-
)+
|
56
|
-
/x
|
36
|
+
class DirectiveProcessor
|
37
|
+
VERSION = '1'
|
57
38
|
|
58
39
|
# Directives are denoted by a `=` followed by the name, then
|
59
40
|
# argument list.
|
@@ -65,77 +46,111 @@ module Sprockets
|
|
65
46
|
# //= require "foo"
|
66
47
|
#
|
67
48
|
DIRECTIVE_PATTERN = /
|
68
|
-
^
|
49
|
+
^ \W* = \s* (\w+.*?) (\*\/)? $
|
69
50
|
/x
|
70
51
|
|
71
|
-
|
72
|
-
|
52
|
+
def self.instance
|
53
|
+
@instance ||= new(
|
54
|
+
# Deprecated: Default to C and Ruby comment styles
|
55
|
+
comments: ["//", ["/*", "*/"]] + ["#", ["###", "###"]]
|
56
|
+
)
|
57
|
+
end
|
73
58
|
|
74
|
-
def
|
75
|
-
|
59
|
+
def self.call(input)
|
60
|
+
instance.call(input)
|
61
|
+
end
|
76
62
|
|
77
|
-
|
78
|
-
@
|
79
|
-
|
80
|
-
@body += "\n" if @body != "" && @body !~ /\n\Z/m
|
63
|
+
def initialize(options = {})
|
64
|
+
@header_pattern = compile_header_pattern(Array(options[:comments]))
|
65
|
+
end
|
81
66
|
|
82
|
-
|
83
|
-
|
67
|
+
def call(input)
|
68
|
+
dup._call(input)
|
84
69
|
end
|
85
70
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
@
|
71
|
+
def _call(input)
|
72
|
+
@environment = input[:environment]
|
73
|
+
@uri = input[:uri]
|
74
|
+
@filename = input[:filename]
|
75
|
+
@dirname = File.dirname(@filename)
|
76
|
+
@content_type = input[:content_type]
|
77
|
+
@required = Set.new(input[:metadata][:required])
|
78
|
+
@stubbed = Set.new(input[:metadata][:stubbed])
|
79
|
+
@links = Set.new(input[:metadata][:links])
|
80
|
+
@dependencies = Set.new(input[:metadata][:dependencies])
|
81
|
+
|
82
|
+
data, directives = process_source(input[:data])
|
83
|
+
process_directives(directives)
|
84
|
+
|
85
|
+
{ data: data,
|
86
|
+
required: @required,
|
87
|
+
stubbed: @stubbed,
|
88
|
+
links: @links,
|
89
|
+
dependencies: @dependencies }
|
90
|
+
end
|
93
91
|
|
94
|
-
|
95
|
-
|
92
|
+
protected
|
93
|
+
# Directives will only be picked up if they are in the header
|
94
|
+
# of the source file. C style (/* */), JavaScript (//), and
|
95
|
+
# Ruby (#) comments are supported.
|
96
|
+
#
|
97
|
+
# Directives in comments after the first non-whitespace line
|
98
|
+
# of code will not be processed.
|
99
|
+
def compile_header_pattern(comments)
|
100
|
+
re = comments.map { |c|
|
101
|
+
case c
|
102
|
+
when String
|
103
|
+
"(?:#{Regexp.escape(c)}.*\\n?)+"
|
104
|
+
when Array
|
105
|
+
"(?:#{Regexp.escape(c[0])}(?m:.*?)#{Regexp.escape(c[1])})"
|
106
|
+
else
|
107
|
+
raise TypeError, "unknown comment type: #{c.class}"
|
108
|
+
end
|
109
|
+
}.join("|")
|
110
|
+
Regexp.compile("\\A(?:(?m:\\s*)(?:#{re}))+")
|
111
|
+
end
|
96
112
|
|
97
|
-
|
98
|
-
|
113
|
+
def process_source(source)
|
114
|
+
header = source[@header_pattern, 0] || ""
|
115
|
+
body = $' || source
|
99
116
|
|
100
|
-
|
101
|
-
end
|
117
|
+
header, directives = extract_directives(header)
|
102
118
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
directives.assoc(lineno) ? "\n" : line
|
110
|
-
}.join.chomp
|
111
|
-
end
|
119
|
+
data = ""
|
120
|
+
data.force_encoding(body.encoding)
|
121
|
+
data << header << "\n" unless header.empty?
|
122
|
+
data << body
|
123
|
+
# Ensure body ends in a new line
|
124
|
+
data << "\n" if data.length > 0 && data[-1] != "\n"
|
112
125
|
|
113
|
-
|
114
|
-
|
115
|
-
@processed_source ||= processed_header + body
|
116
|
-
end
|
126
|
+
return data, directives
|
127
|
+
end
|
117
128
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
# Returns an Array of directive structures. Each structure
|
130
|
+
# is an Array with the line number as the first element, the
|
131
|
+
# directive name as the second element, followed by any
|
132
|
+
# arguments.
|
133
|
+
#
|
134
|
+
# [[1, "require", "foo"], [2, "require", "bar"]]
|
135
|
+
#
|
136
|
+
def extract_directives(header)
|
137
|
+
processed_header = ""
|
138
|
+
directives = []
|
139
|
+
|
140
|
+
header.lines.each_with_index do |line, index|
|
141
|
+
if directive = line[DIRECTIVE_PATTERN, 1]
|
142
|
+
name, *args = Shellwords.shellwords(directive)
|
143
|
+
if respond_to?("process_#{name}_directive", true)
|
144
|
+
directives << [index + 1, name, *args]
|
145
|
+
# Replace directive line with a clean break
|
146
|
+
line = "\n"
|
147
|
+
end
|
131
148
|
end
|
149
|
+
processed_header << line
|
132
150
|
end
|
133
|
-
}.compact
|
134
|
-
end
|
135
151
|
|
136
|
-
|
137
|
-
|
138
|
-
attr_reader :context
|
152
|
+
return processed_header.chomp, directives
|
153
|
+
end
|
139
154
|
|
140
155
|
# Gathers comment directives in the source and processes them.
|
141
156
|
# Any directive method matching `process_*_directive` will
|
@@ -148,7 +163,7 @@ module Sprockets
|
|
148
163
|
#
|
149
164
|
# class DirectiveProcessor < Sprockets::DirectiveProcessor
|
150
165
|
# def process_require_glob_directive
|
151
|
-
# Dir["#{
|
166
|
+
# Dir["#{dirname}/#{glob}"].sort.each do |filename|
|
152
167
|
# require(filename)
|
153
168
|
# end
|
154
169
|
# end
|
@@ -159,29 +174,14 @@ module Sprockets
|
|
159
174
|
# env.unregister_processor('text/css', Sprockets::DirectiveProcessor)
|
160
175
|
# env.register_processor('text/css', DirectiveProcessor)
|
161
176
|
#
|
162
|
-
def process_directives
|
177
|
+
def process_directives(directives)
|
163
178
|
directives.each do |line_number, name, *args|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
def process_source
|
171
|
-
unless @has_written_body || processed_header.empty?
|
172
|
-
@result << processed_header << "\n"
|
173
|
-
end
|
174
|
-
|
175
|
-
included_pathnames.each do |pathname|
|
176
|
-
@result << context.evaluate(pathname)
|
177
|
-
end
|
178
|
-
|
179
|
-
unless @has_written_body
|
180
|
-
@result << body
|
181
|
-
end
|
182
|
-
|
183
|
-
if compat? && constants.any?
|
184
|
-
@result.gsub!(/<%=(.*?)%>/) { constants[$1.strip] }
|
179
|
+
begin
|
180
|
+
send("process_#{name}_directive", *args)
|
181
|
+
rescue Exception => e
|
182
|
+
e.set_backtrace(["#{@filename}:#{line_number}"] + e.backtrace)
|
183
|
+
raise e
|
184
|
+
end
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
@@ -204,22 +204,13 @@ module Sprockets
|
|
204
204
|
# //= require "./bar"
|
205
205
|
#
|
206
206
|
def process_require_directive(path)
|
207
|
-
|
208
|
-
if path =~ /<([^>]+)>/
|
209
|
-
path = $1
|
210
|
-
else
|
211
|
-
path = "./#{path}" unless relative?(path)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
context.require_asset(path)
|
207
|
+
@required << resolve(path, accept: @content_type, pipeline: :self)
|
216
208
|
end
|
217
209
|
|
218
|
-
# `require_self` causes the body of the current file to be
|
219
|
-
#
|
220
|
-
#
|
221
|
-
#
|
222
|
-
# before other dependencies are loaded.
|
210
|
+
# `require_self` causes the body of the current file to be inserted
|
211
|
+
# before any subsequent `require` directives. Useful in CSS files, where
|
212
|
+
# it's common for the index file to contain global styles that need to
|
213
|
+
# be defined before other dependencies are loaded.
|
223
214
|
#
|
224
215
|
# /*= require "reset"
|
225
216
|
# *= require_self
|
@@ -227,26 +218,10 @@ module Sprockets
|
|
227
218
|
# */
|
228
219
|
#
|
229
220
|
def process_require_self_directive
|
230
|
-
if @
|
221
|
+
if @required.include?(@uri)
|
231
222
|
raise ArgumentError, "require_self can only be called once per source file"
|
232
223
|
end
|
233
|
-
|
234
|
-
context.require_asset(pathname)
|
235
|
-
process_source
|
236
|
-
included_pathnames.clear
|
237
|
-
@has_written_body = true
|
238
|
-
end
|
239
|
-
|
240
|
-
# The `include` directive works similar to `require` but
|
241
|
-
# inserts the contents of the dependency even if it already
|
242
|
-
# has been required.
|
243
|
-
#
|
244
|
-
# //= include "header"
|
245
|
-
#
|
246
|
-
def process_include_directive(path)
|
247
|
-
pathname = context.resolve(path)
|
248
|
-
context.depend_on_asset(pathname)
|
249
|
-
included_pathnames << pathname
|
224
|
+
@required << @uri
|
250
225
|
end
|
251
226
|
|
252
227
|
# `require_directory` requires all the files inside a single
|
@@ -256,27 +231,8 @@ module Sprockets
|
|
256
231
|
# //= require_directory "./javascripts"
|
257
232
|
#
|
258
233
|
def process_require_directory_directive(path = ".")
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
unless (stats = stat(root)) && stats.directory?
|
263
|
-
raise ArgumentError, "require_directory argument must be a directory"
|
264
|
-
end
|
265
|
-
|
266
|
-
context.depend_on(root)
|
267
|
-
|
268
|
-
entries(root).each do |pathname|
|
269
|
-
pathname = root.join(pathname)
|
270
|
-
if pathname.to_s == self.file
|
271
|
-
next
|
272
|
-
elsif context.asset_requirable?(pathname)
|
273
|
-
context.require_asset(pathname)
|
274
|
-
end
|
275
|
-
end
|
276
|
-
else
|
277
|
-
# The path must be relative and start with a `./`.
|
278
|
-
raise ArgumentError, "require_directory argument must be a relative path"
|
279
|
-
end
|
234
|
+
path = expand_relative_dirname(:require_directory, path)
|
235
|
+
require_paths(*@environment.stat_directory_with_dependencies(path))
|
280
236
|
end
|
281
237
|
|
282
238
|
# `require_tree` requires all the nested files in a directory.
|
@@ -285,28 +241,8 @@ module Sprockets
|
|
285
241
|
# //= require_tree "./public"
|
286
242
|
#
|
287
243
|
def process_require_tree_directive(path = ".")
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
unless (stats = stat(root)) && stats.directory?
|
292
|
-
raise ArgumentError, "require_tree argument must be a directory"
|
293
|
-
end
|
294
|
-
|
295
|
-
context.depend_on(root)
|
296
|
-
|
297
|
-
each_entry(root) do |pathname|
|
298
|
-
if pathname.to_s == self.file
|
299
|
-
next
|
300
|
-
elsif stat(pathname).directory?
|
301
|
-
context.depend_on(pathname)
|
302
|
-
elsif context.asset_requirable?(pathname)
|
303
|
-
context.require_asset(pathname)
|
304
|
-
end
|
305
|
-
end
|
306
|
-
else
|
307
|
-
# The path must be relative and start with a `./`.
|
308
|
-
raise ArgumentError, "require_tree argument must be a relative path"
|
309
|
-
end
|
244
|
+
path = expand_relative_dirname(:require_tree, path)
|
245
|
+
require_paths(*@environment.stat_sorted_tree_with_dependencies(path))
|
310
246
|
end
|
311
247
|
|
312
248
|
# Allows you to state a dependency on a file without
|
@@ -322,7 +258,7 @@ module Sprockets
|
|
322
258
|
# //= depend_on "foo.png"
|
323
259
|
#
|
324
260
|
def process_depend_on_directive(path)
|
325
|
-
|
261
|
+
resolve(path)
|
326
262
|
end
|
327
263
|
|
328
264
|
# Allows you to state a dependency on an asset without including
|
@@ -337,7 +273,7 @@ module Sprockets
|
|
337
273
|
# //= depend_on_asset "bar.js"
|
338
274
|
#
|
339
275
|
def process_depend_on_asset_directive(path)
|
340
|
-
|
276
|
+
load(resolve(path))
|
341
277
|
end
|
342
278
|
|
343
279
|
# Allows dependency to be excluded from the asset bundle.
|
@@ -349,58 +285,120 @@ module Sprockets
|
|
349
285
|
# //= stub "jquery"
|
350
286
|
#
|
351
287
|
def process_stub_directive(path)
|
352
|
-
|
288
|
+
@stubbed << resolve(path, accept: @content_type, pipeline: :self)
|
353
289
|
end
|
354
290
|
|
355
|
-
#
|
291
|
+
# Declares a linked dependency on the target asset.
|
356
292
|
#
|
357
|
-
#
|
358
|
-
#
|
293
|
+
# The `path` must be a valid asset and should not already be part of the
|
294
|
+
# bundle. Any linked assets will automatically be compiled along with the
|
295
|
+
# current.
|
359
296
|
#
|
360
|
-
#
|
297
|
+
# /*= link "logo.png" */
|
361
298
|
#
|
362
|
-
def
|
363
|
-
@
|
299
|
+
def process_link_directive(path)
|
300
|
+
@links << load(resolve(path)).uri
|
364
301
|
end
|
365
302
|
|
366
|
-
#
|
367
|
-
|
368
|
-
|
303
|
+
# `link_directory` links all the files inside a single
|
304
|
+
# directory. It's similar to `path/*` since it does not follow
|
305
|
+
# nested directories.
|
306
|
+
#
|
307
|
+
# //= link_directory "./fonts"
|
308
|
+
#
|
309
|
+
# Use caution when linking against JS or CSS assets. Include an explicit
|
310
|
+
# extension or content type in these cases
|
311
|
+
#
|
312
|
+
# //= link_directory "./scripts" .js
|
313
|
+
#
|
314
|
+
def process_link_directory_directive(path = ".", accept = nil)
|
315
|
+
path = expand_relative_dirname(:link_directory, path)
|
316
|
+
accept = expand_accept_shorthand(accept)
|
317
|
+
link_paths(*@environment.stat_directory_with_dependencies(path), accept)
|
369
318
|
end
|
370
319
|
|
371
|
-
#
|
372
|
-
#
|
373
|
-
#
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
320
|
+
# `link_tree` links all the nested files in a directory.
|
321
|
+
# Its glob equivalent is `path/**/*`.
|
322
|
+
#
|
323
|
+
# //= link_tree "./images"
|
324
|
+
#
|
325
|
+
# Use caution when linking against JS or CSS assets. Include an explicit
|
326
|
+
# extension or content type in these cases
|
327
|
+
#
|
328
|
+
# //= link_tree "./styles" .css
|
329
|
+
#
|
330
|
+
def process_link_tree_directive(path = ".", accept = nil)
|
331
|
+
path = expand_relative_dirname(:link_tree, path)
|
332
|
+
accept = expand_accept_shorthand(accept)
|
333
|
+
link_paths(*@environment.stat_sorted_tree_with_dependencies(path), accept)
|
334
|
+
end
|
335
|
+
|
336
|
+
private
|
337
|
+
def expand_accept_shorthand(accept)
|
338
|
+
if accept.nil?
|
339
|
+
nil
|
340
|
+
elsif accept.include?("/")
|
341
|
+
accept
|
342
|
+
elsif accept.start_with?(".")
|
343
|
+
@environment.mime_exts[accept]
|
378
344
|
else
|
379
|
-
{}
|
345
|
+
@environment.mime_exts[".#{accept}"]
|
380
346
|
end
|
381
347
|
end
|
382
348
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
349
|
+
def require_paths(paths, deps)
|
350
|
+
resolve_paths(paths, deps, accept: @content_type, pipeline: :self) do |uri|
|
351
|
+
@required << uri
|
352
|
+
end
|
387
353
|
end
|
388
354
|
|
389
|
-
|
390
|
-
|
391
|
-
|
355
|
+
def link_paths(paths, deps, accept)
|
356
|
+
resolve_paths(paths, deps, accept: accept) do |uri|
|
357
|
+
@links << load(uri).uri
|
358
|
+
end
|
392
359
|
end
|
393
360
|
|
394
|
-
def
|
395
|
-
|
361
|
+
def resolve_paths(paths, deps, options = {})
|
362
|
+
@dependencies.merge(deps)
|
363
|
+
paths.each do |subpath, stat|
|
364
|
+
next if subpath == @filename || stat.directory?
|
365
|
+
uri, deps = @environment.resolve(subpath, options.merge(compat: false))
|
366
|
+
@dependencies.merge(deps)
|
367
|
+
yield uri if uri
|
368
|
+
end
|
396
369
|
end
|
397
370
|
|
398
|
-
def
|
399
|
-
|
371
|
+
def expand_relative_dirname(directive, path)
|
372
|
+
if @environment.relative_path?(path)
|
373
|
+
path = File.expand_path(path, @dirname)
|
374
|
+
stat = @environment.stat(path)
|
375
|
+
|
376
|
+
if stat && stat.directory?
|
377
|
+
path
|
378
|
+
else
|
379
|
+
raise ArgumentError, "#{directive} argument must be a directory"
|
380
|
+
end
|
381
|
+
else
|
382
|
+
# The path must be relative and start with a `./`.
|
383
|
+
raise ArgumentError, "#{directive} argument must be a relative path"
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
def load(uri)
|
388
|
+
asset = @environment.load(uri)
|
389
|
+
@dependencies.merge(asset.metadata[:dependencies])
|
390
|
+
asset
|
400
391
|
end
|
401
392
|
|
402
|
-
def
|
403
|
-
|
393
|
+
def resolve(path, options = {})
|
394
|
+
# Prevent absolute paths in directives
|
395
|
+
if @environment.absolute_path?(path)
|
396
|
+
raise FileOutsidePaths, "can't require absolute file: #{path}"
|
397
|
+
end
|
398
|
+
|
399
|
+
uri, deps = @environment.resolve!(path, options.merge(base_path: @dirname))
|
400
|
+
@dependencies.merge(deps)
|
401
|
+
uri
|
404
402
|
end
|
405
403
|
end
|
406
404
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'sprockets/autoload'
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
# Processor engine class for the Eco compiler. Depends on the `eco` gem.
|
5
|
+
#
|
6
|
+
# For more infomation see:
|
7
|
+
#
|
8
|
+
# https://github.com/sstephenson/ruby-eco
|
9
|
+
# https://github.com/sstephenson/eco
|
10
|
+
#
|
11
|
+
module EcoProcessor
|
12
|
+
VERSION = '1'
|
13
|
+
|
14
|
+
def self.cache_key
|
15
|
+
@cache_key ||= [name, Autoload::Eco::Source::VERSION, VERSION].freeze
|
16
|
+
end
|
17
|
+
|
18
|
+
# Compile template data with Eco compiler.
|
19
|
+
#
|
20
|
+
# Returns a JS function definition String. The result should be
|
21
|
+
# assigned to a JS variable.
|
22
|
+
#
|
23
|
+
# # => "function(...) {...}"
|
24
|
+
#
|
25
|
+
def self.call(input)
|
26
|
+
data = input[:data]
|
27
|
+
input[:cache].fetch(cache_key + [data]) do
|
28
|
+
Autoload::Eco.compile(data)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,38 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'sprockets/eco_processor'
|
2
2
|
|
3
3
|
module Sprockets
|
4
|
-
#
|
5
|
-
|
6
|
-
# For more infomation see:
|
7
|
-
#
|
8
|
-
# https://github.com/sstephenson/ruby-eco
|
9
|
-
# https://github.com/sstephenson/eco
|
10
|
-
#
|
11
|
-
class EcoTemplate < Tilt::Template
|
12
|
-
# Check to see if Eco is loaded
|
13
|
-
def self.engine_initialized?
|
14
|
-
defined? ::Eco
|
15
|
-
end
|
16
|
-
|
17
|
-
# Autoload eco library. If the library isn't loaded, Tilt will produce
|
18
|
-
# a thread safetly warning. If you intend to use `.eco` files, you
|
19
|
-
# should explicitly require it.
|
20
|
-
def initialize_engine
|
21
|
-
require_template_library 'eco'
|
22
|
-
end
|
23
|
-
|
24
|
-
def prepare
|
25
|
-
end
|
26
|
-
|
27
|
-
# Compile template data with Eco compiler.
|
28
|
-
#
|
29
|
-
# Returns a JS function definition String. The result should be
|
30
|
-
# assigned to a JS variable.
|
31
|
-
#
|
32
|
-
# # => "function(...) {...}"
|
33
|
-
#
|
34
|
-
def evaluate(scope, locals, &block)
|
35
|
-
Eco.compile(data)
|
36
|
-
end
|
37
|
-
end
|
4
|
+
# Deprecated
|
5
|
+
EcoTemplate = EcoProcessor
|
38
6
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'sprockets/autoload'
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
# Processor engine class for the EJS compiler. Depends on the `ejs` gem.
|
5
|
+
#
|
6
|
+
# For more infomation see:
|
7
|
+
#
|
8
|
+
# https://github.com/sstephenson/ruby-ejs
|
9
|
+
#
|
10
|
+
module EjsProcessor
|
11
|
+
VERSION = '1'
|
12
|
+
|
13
|
+
def self.cache_key
|
14
|
+
@cache_key ||= [name, VERSION].freeze
|
15
|
+
end
|
16
|
+
|
17
|
+
# Compile template data with EJS compiler.
|
18
|
+
#
|
19
|
+
# Returns a JS function definition String. The result should be
|
20
|
+
# assigned to a JS variable.
|
21
|
+
#
|
22
|
+
# # => "function(obj){...}"
|
23
|
+
#
|
24
|
+
def self.call(input)
|
25
|
+
data = input[:data]
|
26
|
+
input[:cache].fetch(cache_key + [data]) do
|
27
|
+
Autoload::EJS.compile(data)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|