bpm 1.0.0.beta.8 → 1.0.0.beta.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +9 -0
- data/bpm.gemspec +2 -7
- data/lib/bpm/pipeline/generated_asset.rb +19 -21
- data/lib/bpm/pipeline/plugin_context.rb +7 -7
- data/lib/bpm/pipeline/plugin_processor.rb +11 -20
- data/lib/bpm/pipeline/transport_processor.rb +8 -13
- data/lib/bpm/pipeline.rb +47 -42
- data/lib/bpm/project_generator.rb +2 -2
- data/lib/bpm/version.rb +1 -1
- data/lib/bpm.rb +0 -3
- data/spec/cli/init_spec.rb +48 -48
- data/spec/cli/rebuild_spec.rb +30 -30
- data/spec/fixtures/projects/init_app/assets/bpm_libs.js +1 -1
- data/spec/fixtures/projects/init_app/assets/bpm_styles.css +1 -1
- data/spec/fixtures/projects/init_default/assets/bpm_libs.js +1 -1
- data/spec/fixtures/projects/init_default/assets/bpm_styles.css +1 -1
- data/spec/plugins/minifier_spec.rb +8 -8
- data/templates/project/index.html +0 -2
- data/templates/project/{app → lib}/main.js +0 -0
- metadata +24 -209
- data/.gitmodules +0 -3
- data/vendor/sprockets/.gitignore +0 -7
- data/vendor/sprockets/.travis.yml +0 -7
- data/vendor/sprockets/Gemfile +0 -2
- data/vendor/sprockets/LICENSE +0 -20
- data/vendor/sprockets/README.md +0 -22
- data/vendor/sprockets/Rakefile +0 -8
- data/vendor/sprockets/lib/sprockets/asset.rb +0 -198
- data/vendor/sprockets/lib/sprockets/asset_attributes.rb +0 -178
- data/vendor/sprockets/lib/sprockets/base.rb +0 -134
- data/vendor/sprockets/lib/sprockets/bundled_asset.rb +0 -249
- data/vendor/sprockets/lib/sprockets/cache/file_store.rb +0 -41
- data/vendor/sprockets/lib/sprockets/caching.rb +0 -126
- data/vendor/sprockets/lib/sprockets/charset_normalizer.rb +0 -41
- data/vendor/sprockets/lib/sprockets/context.rb +0 -221
- data/vendor/sprockets/lib/sprockets/digest.rb +0 -73
- data/vendor/sprockets/lib/sprockets/directive_processor.rb +0 -397
- data/vendor/sprockets/lib/sprockets/eco_template.rb +0 -38
- data/vendor/sprockets/lib/sprockets/ejs_template.rb +0 -37
- data/vendor/sprockets/lib/sprockets/engines.rb +0 -117
- data/vendor/sprockets/lib/sprockets/environment.rb +0 -94
- data/vendor/sprockets/lib/sprockets/errors.rb +0 -17
- data/vendor/sprockets/lib/sprockets/index.rb +0 -81
- data/vendor/sprockets/lib/sprockets/jst_processor.rb +0 -26
- data/vendor/sprockets/lib/sprockets/mime.rb +0 -38
- data/vendor/sprockets/lib/sprockets/processing.rb +0 -269
- data/vendor/sprockets/lib/sprockets/processor.rb +0 -32
- data/vendor/sprockets/lib/sprockets/safety_colons.rb +0 -28
- data/vendor/sprockets/lib/sprockets/server.rb +0 -270
- data/vendor/sprockets/lib/sprockets/static_asset.rb +0 -86
- data/vendor/sprockets/lib/sprockets/static_compilation.rb +0 -74
- data/vendor/sprockets/lib/sprockets/trail.rb +0 -123
- data/vendor/sprockets/lib/sprockets/utils.rb +0 -67
- data/vendor/sprockets/lib/sprockets/version.rb +0 -3
- data/vendor/sprockets/lib/sprockets.rb +0 -31
- data/vendor/sprockets/sprockets.gemspec +0 -30
- data/vendor/sprockets/test/fixtures/asset/POW.png +0 -0
- data/vendor/sprockets/test/fixtures/asset/application.js +0 -6
- data/vendor/sprockets/test/fixtures/asset/bar-utf8.css +0 -2
- data/vendor/sprockets/test/fixtures/asset/charset.css +0 -2
- data/vendor/sprockets/test/fixtures/asset/circle/a.js +0 -2
- data/vendor/sprockets/test/fixtures/asset/circle/b.js +0 -2
- data/vendor/sprockets/test/fixtures/asset/circle/c.js +0 -2
- data/vendor/sprockets/test/fixtures/asset/compat.js +0 -4
- data/vendor/sprockets/test/fixtures/asset/constants.js +0 -2
- data/vendor/sprockets/test/fixtures/asset/constants.yml +0 -1
- data/vendor/sprockets/test/fixtures/asset/default_mime_type.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/filename.js.erb +0 -1
- data/vendor/sprockets/test/fixtures/asset/foo-utf8.css +0 -2
- data/vendor/sprockets/test/fixtures/asset/included_header.js +0 -4
- data/vendor/sprockets/test/fixtures/asset/jquery.tmpl.min.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/mismatch.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/multiple.js +0 -2
- data/vendor/sprockets/test/fixtures/asset/multipleengine.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/noengine.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/noformat.coffee +0 -1
- data/vendor/sprockets/test/fixtures/asset/one.css +0 -1
- data/vendor/sprockets/test/fixtures/asset/oneengine.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/project.css +0 -1
- data/vendor/sprockets/test/fixtures/asset/project.js.erb +0 -4
- data/vendor/sprockets/test/fixtures/asset/relative/include.js +0 -4
- data/vendor/sprockets/test/fixtures/asset/relative/require.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/relative/require_outside_path.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/require_self.css +0 -9
- data/vendor/sprockets/test/fixtures/asset/require_self_twice.css +0 -8
- data/vendor/sprockets/test/fixtures/asset/semicolons/bar.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/semicolons/index.js +0 -5
- data/vendor/sprockets/test/fixtures/asset/sprite.css.erb +0 -12
- data/vendor/sprockets/test/fixtures/asset/tree/all/b/c/d.js +0 -2
- data/vendor/sprockets/test/fixtures/asset/tree/all/b/c/e.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/all/b/c.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/all/b.css +0 -2
- data/vendor/sprockets/test/fixtures/asset/tree/all/b.js.erb +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/all/d/c.js.coffee +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/all/d/e.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/all_with_require.js +0 -7
- data/vendor/sprockets/test/fixtures/asset/tree/all_with_require_directory.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/all_with_require_tree.js +0 -2
- data/vendor/sprockets/test/fixtures/asset/tree/directory/application.js +0 -2
- data/vendor/sprockets/test/fixtures/asset/tree/directory/bar.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/directory/foo.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/tree/application.js +0 -2
- data/vendor/sprockets/test/fixtures/asset/tree/tree/bar.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/tree/foo.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/with_logical_path/a/a.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/with_logical_path/require_tree_with_logical_path.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/without_argument/a.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/without_argument/b.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/tree/without_argument/require_tree_without_argument.js +0 -1
- data/vendor/sprockets/test/fixtures/asset/two.css +0 -1
- data/vendor/sprockets/test/fixtures/asset/unicode.js +0 -2
- data/vendor/sprockets/test/fixtures/asset/unknownexts.min.js +0 -2
- data/vendor/sprockets/test/fixtures/asset/users.js.erb.str +0 -4
- data/vendor/sprockets/test/fixtures/context/POW.png +0 -0
- data/vendor/sprockets/test/fixtures/context/application.js.yml +0 -3
- data/vendor/sprockets/test/fixtures/context/bar.js +0 -1
- data/vendor/sprockets/test/fixtures/context/foo.js +0 -2
- data/vendor/sprockets/test/fixtures/context/helpers.css.erb +0 -3
- data/vendor/sprockets/test/fixtures/context/properties.js.erb +0 -7
- data/vendor/sprockets/test/fixtures/context/require_glob.js +0 -1
- data/vendor/sprockets/test/fixtures/context/resolve_content_type.js.erb +0 -4
- data/vendor/sprockets/test/fixtures/context/sprite.css.embed +0 -3
- data/vendor/sprockets/test/fixtures/default/application.js.coffee +0 -4
- data/vendor/sprockets/test/fixtures/default/blank.gif +0 -0
- data/vendor/sprockets/test/fixtures/default/coffee/foo.coffee +0 -1
- data/vendor/sprockets/test/fixtures/default/coffee/index.js +0 -3
- data/vendor/sprockets/test/fixtures/default/empty +0 -0
- data/vendor/sprockets/test/fixtures/default/gallery.css.erb +0 -3
- data/vendor/sprockets/test/fixtures/default/gallery.js +0 -1
- data/vendor/sprockets/test/fixtures/default/goodbye.jst.eco +0 -1
- data/vendor/sprockets/test/fixtures/default/hello.jst.ejs +0 -1
- data/vendor/sprockets/test/fixtures/default/hello.txt +0 -1
- data/vendor/sprockets/test/fixtures/default/interpolation.js +0 -1
- data/vendor/sprockets/test/fixtures/default/missing_require.js +0 -1
- data/vendor/sprockets/test/fixtures/default/mobile/a.js +0 -1
- data/vendor/sprockets/test/fixtures/default/mobile/b.js +0 -1
- data/vendor/sprockets/test/fixtures/default/mobile/c.css +0 -1
- data/vendor/sprockets/test/fixtures/default/mobile/d.css +0 -1
- data/vendor/sprockets/test/fixtures/default/mobile/index.css +0 -3
- data/vendor/sprockets/test/fixtures/default/mobile/index.js +0 -1
- data/vendor/sprockets/test/fixtures/default/noreturn.js +0 -1
- data/vendor/sprockets/test/fixtures/default/project.js.coffee.erb +0 -2
- data/vendor/sprockets/test/fixtures/default/with_data_uri.css.erb +0 -3
- data/vendor/sprockets/test/fixtures/directives/code_before_comment +0 -3
- data/vendor/sprockets/test/fixtures/directives/comment_without_directives +0 -6
- data/vendor/sprockets/test/fixtures/directives/directive_word_splitting +0 -6
- data/vendor/sprockets/test/fixtures/directives/directives_after_header +0 -16
- data/vendor/sprockets/test/fixtures/directives/double_slash +0 -9
- data/vendor/sprockets/test/fixtures/directives/hash +0 -8
- data/vendor/sprockets/test/fixtures/directives/no_header +0 -2
- data/vendor/sprockets/test/fixtures/directives/slash_star +0 -10
- data/vendor/sprockets/test/fixtures/directives/slash_star_single +0 -4
- data/vendor/sprockets/test/fixtures/directives/space_between_directive_word +0 -2
- data/vendor/sprockets/test/fixtures/directives/triple_hash +0 -10
- data/vendor/sprockets/test/fixtures/encoding/ascii.js +0 -1
- data/vendor/sprockets/test/fixtures/encoding/ascii_utf8.js +0 -2
- data/vendor/sprockets/test/fixtures/encoding/utf16.js +0 -0
- data/vendor/sprockets/test/fixtures/encoding/utf8.js +0 -1
- data/vendor/sprockets/test/fixtures/encoding/utf8_bom.js +0 -1
- data/vendor/sprockets/test/fixtures/engines/hello.alert +0 -1
- data/vendor/sprockets/test/fixtures/engines/moo.js.str +0 -1
- data/vendor/sprockets/test/fixtures/public/compiled-digest-0aa2105d29558f3eb790d411d7d8fb66.js +0 -3
- data/vendor/sprockets/test/fixtures/public/compiled-digest-1c41eb0cf934a0c76babe875f982f9d1.js +0 -1
- data/vendor/sprockets/test/fixtures/server/app/javascripts/application.js +0 -5
- data/vendor/sprockets/test/fixtures/server/app/javascripts/bar.js +0 -1
- data/vendor/sprockets/test/fixtures/server/app/javascripts/foo.js +0 -1
- data/vendor/sprockets/test/fixtures/server/app/javascripts/hello.txt +0 -2
- data/vendor/sprockets/test/fixtures/server/app/javascripts/tree.js +0 -1
- data/vendor/sprockets/test/fixtures/server/vendor/javascripts/missing_require.js +0 -1
- data/vendor/sprockets/test/fixtures/server/vendor/stylesheets/missing_require.css +0 -1
- data/vendor/sprockets/test/sprockets_test.rb +0 -56
- data/vendor/sprockets/test/test_asset.rb +0 -699
- data/vendor/sprockets/test/test_asset_attributes.rb +0 -150
- data/vendor/sprockets/test/test_caching.rb +0 -62
- data/vendor/sprockets/test/test_context.rb +0 -115
- data/vendor/sprockets/test/test_directive_processor.rb +0 -124
- data/vendor/sprockets/test/test_encoding.rb +0 -65
- data/vendor/sprockets/test/test_engines.rb +0 -73
- data/vendor/sprockets/test/test_environment.rb +0 -587
- data/vendor/sprockets/test/test_server.rb +0 -227
@@ -1,397 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
require 'shellwords'
|
3
|
-
require 'tilt'
|
4
|
-
require 'yaml'
|
5
|
-
|
6
|
-
module Sprockets
|
7
|
-
# The `DirectiveProcessor` is responsible for parsing and evaluating
|
8
|
-
# directive comments in a source file.
|
9
|
-
#
|
10
|
-
# A directive comment starts with a comment prefix, followed by an "=",
|
11
|
-
# then the directive name, then any arguments.
|
12
|
-
#
|
13
|
-
# // JavaScript
|
14
|
-
# //= require "foo"
|
15
|
-
#
|
16
|
-
# # CoffeeScript
|
17
|
-
# #= require "bar"
|
18
|
-
#
|
19
|
-
# /* CSS
|
20
|
-
# *= require "baz"
|
21
|
-
# */
|
22
|
-
#
|
23
|
-
# The Processor is implemented as a `Tilt::Template` and is loosely
|
24
|
-
# coupled to Sprockets. This makes it possible to disable or modify
|
25
|
-
# the processor to do whatever you'd like. You could add your own
|
26
|
-
# custom directives or invent your own directive syntax.
|
27
|
-
#
|
28
|
-
# `Environment#processors` includes `DirectiveProcessor` by default.
|
29
|
-
#
|
30
|
-
# To remove the processor entirely:
|
31
|
-
#
|
32
|
-
# env.unregister_processor('text/css', Sprockets::DirectiveProcessor)
|
33
|
-
# env.unregister_processor('application/javascript', Sprockets::DirectiveProcessor)
|
34
|
-
#
|
35
|
-
# Then inject your own preprocessor:
|
36
|
-
#
|
37
|
-
# env.register_processor('text/css', MyProcessor)
|
38
|
-
#
|
39
|
-
class DirectiveProcessor < Tilt::Template
|
40
|
-
attr_reader :pathname
|
41
|
-
|
42
|
-
def prepare
|
43
|
-
@pathname = Pathname.new(file)
|
44
|
-
|
45
|
-
@directive_parser = Parser.new(data)
|
46
|
-
@included_pathnames = []
|
47
|
-
@compat = false
|
48
|
-
end
|
49
|
-
|
50
|
-
# Implemented for Tilt#render.
|
51
|
-
#
|
52
|
-
# `context` is a `Context` instance with methods that allow you to
|
53
|
-
# access the environment and append to the bundle. See `Context`
|
54
|
-
# for the complete API.
|
55
|
-
def evaluate(context, locals, &block)
|
56
|
-
@context = context
|
57
|
-
|
58
|
-
@result = ""
|
59
|
-
@has_written_body = false
|
60
|
-
|
61
|
-
process_directives
|
62
|
-
process_source
|
63
|
-
|
64
|
-
@result
|
65
|
-
end
|
66
|
-
|
67
|
-
def processed_header
|
68
|
-
@directive_parser.processed_header
|
69
|
-
end
|
70
|
-
|
71
|
-
def processed_body
|
72
|
-
@directive_parser.body
|
73
|
-
end
|
74
|
-
|
75
|
-
def processed_source
|
76
|
-
@directive_parser.processed_source
|
77
|
-
end
|
78
|
-
|
79
|
-
def directives
|
80
|
-
@directive_parser.directives
|
81
|
-
end
|
82
|
-
|
83
|
-
protected
|
84
|
-
class Parser
|
85
|
-
# Directives will only be picked up if they are in the header
|
86
|
-
# of the source file. C style (/* */), JavaScript (//), and
|
87
|
-
# Ruby (#) comments are supported.
|
88
|
-
#
|
89
|
-
# Directives in comments after the first non-whitespace line
|
90
|
-
# of code will not be processed.
|
91
|
-
#
|
92
|
-
HEADER_PATTERN = /
|
93
|
-
\A (
|
94
|
-
(?m:\s*) (
|
95
|
-
(\/\* (?m:.*?) \*\/) |
|
96
|
-
(\#\#\# (?m:.*?) \#\#\#) |
|
97
|
-
(\/\/ .* \n?)+ |
|
98
|
-
(\# .* \n?)+
|
99
|
-
)
|
100
|
-
)+
|
101
|
-
/x
|
102
|
-
|
103
|
-
# Directives are denoted by a `=` followed by the name, then
|
104
|
-
# argument list.
|
105
|
-
#
|
106
|
-
# A few different styles are allowed:
|
107
|
-
#
|
108
|
-
# // =require foo
|
109
|
-
# //= require foo
|
110
|
-
# //= require "foo"
|
111
|
-
#
|
112
|
-
DIRECTIVE_PATTERN = /
|
113
|
-
^ [\W]* = \s* (\w+.*?) (\*\/)? $
|
114
|
-
/x
|
115
|
-
|
116
|
-
attr_reader :source, :header, :body
|
117
|
-
|
118
|
-
def initialize(source)
|
119
|
-
@source = source
|
120
|
-
@header = @source[HEADER_PATTERN, 0] || ""
|
121
|
-
@body = $' || @source
|
122
|
-
|
123
|
-
# Ensure body ends in a new line
|
124
|
-
@body += "\n" if @body != "" && @body !~ /\n\Z/m
|
125
|
-
end
|
126
|
-
|
127
|
-
def header_lines
|
128
|
-
@header_lines ||= header.split("\n")
|
129
|
-
end
|
130
|
-
|
131
|
-
# Returns the header String with any directives stripped.
|
132
|
-
def processed_header
|
133
|
-
header_lines.reject do |line|
|
134
|
-
extract_directive(line)
|
135
|
-
end.join("\n")
|
136
|
-
end
|
137
|
-
|
138
|
-
# Returns the source String with any directives stripped.
|
139
|
-
def processed_source
|
140
|
-
@processed_source ||= processed_header + body
|
141
|
-
end
|
142
|
-
|
143
|
-
# Returns an Array of directive structures. Each structure
|
144
|
-
# is an Array with the line number as the first element, the
|
145
|
-
# directive name as the second element, followed by any
|
146
|
-
# arguments.
|
147
|
-
#
|
148
|
-
# [[1, "require", "foo"], [2, "require", "bar"]]
|
149
|
-
#
|
150
|
-
def directives
|
151
|
-
@directives ||= header_lines.each_with_index.map do |line, index|
|
152
|
-
if directive = extract_directive(line)
|
153
|
-
[index + 1, *Shellwords.shellwords(directive)]
|
154
|
-
end
|
155
|
-
end.compact
|
156
|
-
end
|
157
|
-
|
158
|
-
def extract_directive(line)
|
159
|
-
line[DIRECTIVE_PATTERN, 1]
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
attr_reader :included_pathnames
|
164
|
-
attr_reader :context
|
165
|
-
|
166
|
-
# Gathers comment directives in the source and processes them.
|
167
|
-
# Any directive method matching `process_*_directive` will
|
168
|
-
# automatically be available. This makes it easy to extend the
|
169
|
-
# processor.
|
170
|
-
#
|
171
|
-
# To implement a custom directive called `require_glob`, subclass
|
172
|
-
# `Sprockets::DirectiveProcessor`, then add a method called
|
173
|
-
# `process_require_glob_directive`.
|
174
|
-
#
|
175
|
-
# class DirectiveProcessor < Sprockets::DirectiveProcessor
|
176
|
-
# def process_require_glob_directive
|
177
|
-
# Dir["#{pathname.dirname}/#{glob}"].sort.each do |filename|
|
178
|
-
# require(filename)
|
179
|
-
# end
|
180
|
-
# end
|
181
|
-
# end
|
182
|
-
#
|
183
|
-
# Replace the current processor on the environment with your own:
|
184
|
-
#
|
185
|
-
# env.unregister_processor('text/css', Sprockets::DirectiveProcessor)
|
186
|
-
# env.register_processor('text/css', DirectiveProcessor)
|
187
|
-
#
|
188
|
-
def process_directives
|
189
|
-
directives.each do |line_number, name, *args|
|
190
|
-
context.__LINE__ = line_number
|
191
|
-
send("process_#{name}_directive", *args)
|
192
|
-
context.__LINE__ = nil
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
def process_source
|
197
|
-
unless @has_written_body || processed_header.empty?
|
198
|
-
@result << processed_header << "\n"
|
199
|
-
end
|
200
|
-
|
201
|
-
included_pathnames.each do |pathname|
|
202
|
-
@result << context.evaluate(pathname)
|
203
|
-
end
|
204
|
-
|
205
|
-
unless @has_written_body
|
206
|
-
@result << processed_body
|
207
|
-
end
|
208
|
-
|
209
|
-
if compat? && constants.any?
|
210
|
-
@result.gsub!(/<%=(.*?)%>/) { constants[$1.strip] }
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
# The `require` directive functions similar to Ruby's own `require`.
|
215
|
-
# It provides a way to declare a dependency on a file in your path
|
216
|
-
# and ensures its only loaded once before the source file.
|
217
|
-
#
|
218
|
-
# `require` works with files in the environment path:
|
219
|
-
#
|
220
|
-
# //= require "foo.js"
|
221
|
-
#
|
222
|
-
# Extensions are optional. If your source file is ".js", it
|
223
|
-
# assumes you are requiring another ".js".
|
224
|
-
#
|
225
|
-
# //= require "foo"
|
226
|
-
#
|
227
|
-
# Relative paths work too. Use a leading `./` to denote a relative
|
228
|
-
# path:
|
229
|
-
#
|
230
|
-
# //= require "./bar"
|
231
|
-
#
|
232
|
-
def process_require_directive(path)
|
233
|
-
if @compat
|
234
|
-
if path =~ /<([^>]+)>/
|
235
|
-
path = $1
|
236
|
-
else
|
237
|
-
path = "./#{path}" unless relative?(path)
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
context.require_asset(path)
|
242
|
-
end
|
243
|
-
|
244
|
-
# `require_self` causes the body of the current file to be
|
245
|
-
# inserted before any subsequent `require` or `include`
|
246
|
-
# directives. Useful in CSS files, where it's common for the
|
247
|
-
# index file to contain global styles that need to be defined
|
248
|
-
# before other dependencies are loaded.
|
249
|
-
#
|
250
|
-
# /*= require "reset"
|
251
|
-
# *= require_self
|
252
|
-
# *= require_tree .
|
253
|
-
# */
|
254
|
-
#
|
255
|
-
def process_require_self_directive
|
256
|
-
if @has_written_body
|
257
|
-
raise ArgumentError, "require_self can only be called once per source file"
|
258
|
-
end
|
259
|
-
|
260
|
-
context.require_asset(pathname)
|
261
|
-
process_source
|
262
|
-
included_pathnames.clear
|
263
|
-
@has_written_body = true
|
264
|
-
end
|
265
|
-
|
266
|
-
# The `include` directive works similar to `require` but
|
267
|
-
# inserts the contents of the dependency even if it already
|
268
|
-
# has been required.
|
269
|
-
#
|
270
|
-
# //= include "header"
|
271
|
-
#
|
272
|
-
def process_include_directive(path)
|
273
|
-
pathname = context.resolve(path)
|
274
|
-
context.depend_on_asset(pathname)
|
275
|
-
included_pathnames << pathname
|
276
|
-
end
|
277
|
-
|
278
|
-
# `require_directory` requires all the files inside a single
|
279
|
-
# directory. It's similar to `path/*` since it does not follow
|
280
|
-
# nested directories.
|
281
|
-
#
|
282
|
-
# //= require_directory "./javascripts"
|
283
|
-
#
|
284
|
-
def process_require_directory_directive(path = ".")
|
285
|
-
if relative?(path)
|
286
|
-
root = pathname.dirname.join(path).expand_path
|
287
|
-
context.depend_on(root)
|
288
|
-
|
289
|
-
Dir["#{root}/*"].sort.each do |filename|
|
290
|
-
if filename == self.file
|
291
|
-
next
|
292
|
-
elsif context.asset_requirable?(filename)
|
293
|
-
context.require_asset(filename)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
else
|
297
|
-
# The path must be relative and start with a `./`.
|
298
|
-
raise ArgumentError, "require_directory argument must be a relative path"
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
# `require_tree` requires all the nested files in a directory.
|
303
|
-
# Its glob equivalent is `path/**/*`.
|
304
|
-
#
|
305
|
-
# //= require_tree "./public"
|
306
|
-
#
|
307
|
-
def process_require_tree_directive(path = ".")
|
308
|
-
if relative?(path)
|
309
|
-
root = pathname.dirname.join(path).expand_path
|
310
|
-
context.depend_on(root)
|
311
|
-
|
312
|
-
Dir["#{root}/**/*"].sort.each do |filename|
|
313
|
-
if filename == self.file
|
314
|
-
next
|
315
|
-
elsif File.directory?(filename)
|
316
|
-
context.depend_on(filename)
|
317
|
-
elsif context.asset_requirable?(filename)
|
318
|
-
context.require_asset(filename)
|
319
|
-
end
|
320
|
-
end
|
321
|
-
else
|
322
|
-
# The path must be relative and start with a `./`.
|
323
|
-
raise ArgumentError, "require_tree argument must be a relative path"
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
|
-
# Allows you to state a dependency on a file without
|
328
|
-
# including it.
|
329
|
-
#
|
330
|
-
# This is used for caching purposes. Any changes made to
|
331
|
-
# the dependency file will invalidate the cache of the
|
332
|
-
# source file.
|
333
|
-
#
|
334
|
-
# This is useful if you are using ERB and File.read to pull
|
335
|
-
# in contents from another file.
|
336
|
-
#
|
337
|
-
# //= depend_on "foo.png"
|
338
|
-
#
|
339
|
-
def process_depend_on_directive(path)
|
340
|
-
context.depend_on(path)
|
341
|
-
end
|
342
|
-
|
343
|
-
# Allows you to state a dependency on an asset without including
|
344
|
-
# it.
|
345
|
-
#
|
346
|
-
# This is used for caching purposes. Any changes that would
|
347
|
-
# invalid the asset dependency will invalidate the cache our the
|
348
|
-
# source file.
|
349
|
-
#
|
350
|
-
# Unlike `depend_on`, the path must be a requirable asset.
|
351
|
-
#
|
352
|
-
# //= depend_on_asset "bar.js"
|
353
|
-
#
|
354
|
-
def process_depend_on_asset_directive(path)
|
355
|
-
context.depend_on_asset(path)
|
356
|
-
end
|
357
|
-
|
358
|
-
# Enable Sprockets 1.x compat mode.
|
359
|
-
#
|
360
|
-
# Makes it possible to use the same JavaScript source
|
361
|
-
# file in both Sprockets 1 and 2.
|
362
|
-
#
|
363
|
-
# //= compat
|
364
|
-
#
|
365
|
-
def process_compat_directive
|
366
|
-
@compat = true
|
367
|
-
end
|
368
|
-
|
369
|
-
# Checks if Sprockets 1.x compat mode enabled
|
370
|
-
def compat?
|
371
|
-
@compat
|
372
|
-
end
|
373
|
-
|
374
|
-
# Sprockets 1.x allowed for constant interpolation if a
|
375
|
-
# constants.yml was present. This is only available if
|
376
|
-
# compat mode is on.
|
377
|
-
def constants
|
378
|
-
if compat?
|
379
|
-
path = File.join(context.root_path, "constants.yml")
|
380
|
-
File.exist?(path) ? YAML.load_file(path) : {}
|
381
|
-
else
|
382
|
-
{}
|
383
|
-
end
|
384
|
-
end
|
385
|
-
|
386
|
-
# `provide` is stubbed out for Sprockets 1.x compat.
|
387
|
-
# Mutating the path when an asset is being built is
|
388
|
-
# not permitted.
|
389
|
-
def process_provide_directive(path)
|
390
|
-
end
|
391
|
-
|
392
|
-
private
|
393
|
-
def relative?(path)
|
394
|
-
path =~ /^\.($|\.?\/)/
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'tilt'
|
2
|
-
|
3
|
-
module Sprockets
|
4
|
-
# Tilt 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
|
-
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
|
38
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'tilt'
|
2
|
-
|
3
|
-
module Sprockets
|
4
|
-
# Tilt 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
|
-
class EjsTemplate < Tilt::Template
|
11
|
-
# Check to see if EJS is loaded
|
12
|
-
def self.engine_initialized?
|
13
|
-
defined? ::EJS
|
14
|
-
end
|
15
|
-
|
16
|
-
# Autoload ejs library. If the library isn't loaded, Tilt will produce
|
17
|
-
# a thread safetly warning. If you intend to use `.ejs` files, you
|
18
|
-
# should explicitly require it.
|
19
|
-
def initialize_engine
|
20
|
-
require_template_library 'ejs'
|
21
|
-
end
|
22
|
-
|
23
|
-
def prepare
|
24
|
-
end
|
25
|
-
|
26
|
-
# Compile template data with EJS compiler.
|
27
|
-
#
|
28
|
-
# Returns a JS function definition String. The result should be
|
29
|
-
# assigned to a JS variable.
|
30
|
-
#
|
31
|
-
# # => "function(obj){...}"
|
32
|
-
#
|
33
|
-
def evaluate(scope, locals, &block)
|
34
|
-
EJS.compile(data)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
require 'sprockets/eco_template'
|
2
|
-
require 'sprockets/ejs_template'
|
3
|
-
require 'sprockets/jst_processor'
|
4
|
-
require 'sprockets/mime'
|
5
|
-
require 'sprockets/utils'
|
6
|
-
require 'tilt'
|
7
|
-
|
8
|
-
module Sprockets
|
9
|
-
# `Engines` provides a global and `Environment` instance registry.
|
10
|
-
#
|
11
|
-
# An engine is a type of processor that is bound to an filename
|
12
|
-
# extension. `application.js.coffee` indicates that the
|
13
|
-
# `CoffeeScriptTemplate` engine will be ran on the file.
|
14
|
-
#
|
15
|
-
# Extensions can be stacked and will be evaulated from right to
|
16
|
-
# left. `application.js.coffee.erb` will first run `ERBTemplate`
|
17
|
-
# then `CoffeeScriptTemplate`.
|
18
|
-
#
|
19
|
-
# All `Engine`s must follow the `Tilt::Template` interface. It is
|
20
|
-
# recommended to subclass `Tilt::Template`.
|
21
|
-
#
|
22
|
-
# Its recommended that you register engine changes on your local
|
23
|
-
# `Environment` instance.
|
24
|
-
#
|
25
|
-
# environment.register_engine '.foo', FooProcessor
|
26
|
-
#
|
27
|
-
# The global registry is exposed for plugins to register themselves.
|
28
|
-
#
|
29
|
-
# Sprockets.register_engine '.sass', SassTemplate
|
30
|
-
#
|
31
|
-
module Engines
|
32
|
-
# Returns an `Array` of `Engine`s registered on the
|
33
|
-
# `Environment`. If an `ext` argument is supplied, the `Engine`
|
34
|
-
# register under that extension will be returned.
|
35
|
-
#
|
36
|
-
# environment.engines
|
37
|
-
# # => [CoffeeScriptTemplate, SassTemplate, ...]
|
38
|
-
#
|
39
|
-
# environment.engines('.coffee')
|
40
|
-
# # => CoffeeScriptTemplate
|
41
|
-
#
|
42
|
-
def engines(ext = nil)
|
43
|
-
if ext
|
44
|
-
ext = Sprockets::Utils.normalize_extension(ext)
|
45
|
-
@engines[ext]
|
46
|
-
else
|
47
|
-
@engines.dup
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def engine_formats(ext = nil)
|
52
|
-
if ext
|
53
|
-
ext = Sprockets::Utils.normalize_extension(ext)
|
54
|
-
@engine_formats[ext]
|
55
|
-
else
|
56
|
-
deep_copy_hash(@engine_formats)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Returns an `Array` of engine extension `String`s.
|
61
|
-
#
|
62
|
-
# environment.engine_extensions
|
63
|
-
# # => ['.coffee', '.sass', ...]
|
64
|
-
def engine_extensions
|
65
|
-
@engines.keys
|
66
|
-
end
|
67
|
-
|
68
|
-
# Registers a new Engine `klass` for `ext`. If the `ext` already
|
69
|
-
# has an engine registered, it will be overridden.
|
70
|
-
#
|
71
|
-
# environment.register_engine '.coffee', CoffeeScriptTemplate
|
72
|
-
#
|
73
|
-
def register_engine(ext, klass)
|
74
|
-
ext = Sprockets::Utils.normalize_extension(ext)
|
75
|
-
@engines[ext] = klass
|
76
|
-
|
77
|
-
if klass.respond_to?(:default_mime_type) && klass.default_mime_type
|
78
|
-
if format_ext = extension_for_mime_type(klass.default_mime_type)
|
79
|
-
@engine_formats[format_ext] << ext
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
klass
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
def deep_copy_hash(hash)
|
88
|
-
initial = Hash.new { |h, k| h[k] = [] }
|
89
|
-
hash.inject(initial) { |h, (k, a)| h[k] = a.dup; h }
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# Extend Sprockets module to provide global registry
|
94
|
-
extend Engines
|
95
|
-
@engines = {}
|
96
|
-
@engine_formats = Hash.new { |h, k| h[k] = [] }
|
97
|
-
|
98
|
-
# Cherry pick the default Tilt engines that make sense for
|
99
|
-
# Sprockets. We don't need ones that only generate html like HAML.
|
100
|
-
|
101
|
-
# Mmm, CoffeeScript
|
102
|
-
register_engine '.coffee', Tilt::CoffeeScriptTemplate
|
103
|
-
|
104
|
-
# JST engines
|
105
|
-
register_engine '.jst', JstProcessor
|
106
|
-
register_engine '.eco', EcoTemplate
|
107
|
-
register_engine '.ejs', EjsTemplate
|
108
|
-
|
109
|
-
# CSS engines
|
110
|
-
register_engine '.less', Tilt::LessTemplate
|
111
|
-
register_engine '.sass', Tilt::SassTemplate
|
112
|
-
register_engine '.scss', Tilt::ScssTemplate
|
113
|
-
|
114
|
-
# Other
|
115
|
-
register_engine '.erb', Tilt::ERBTemplate
|
116
|
-
register_engine '.str', Tilt::StringTemplate
|
117
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'sprockets/base'
|
2
|
-
require 'sprockets/charset_normalizer'
|
3
|
-
require 'sprockets/context'
|
4
|
-
require 'sprockets/directive_processor'
|
5
|
-
require 'sprockets/index'
|
6
|
-
require 'sprockets/safety_colons'
|
7
|
-
|
8
|
-
require 'hike'
|
9
|
-
require 'logger'
|
10
|
-
require 'pathname'
|
11
|
-
require 'tilt'
|
12
|
-
|
13
|
-
module Sprockets
|
14
|
-
class Environment < Base
|
15
|
-
# `Environment` should initialized with your application's root
|
16
|
-
# directory. This should be the same as your Rails or Rack root.
|
17
|
-
#
|
18
|
-
# env = Environment.new(Rails.root)
|
19
|
-
#
|
20
|
-
def initialize(root = ".")
|
21
|
-
@trail = Hike::Trail.new(root)
|
22
|
-
|
23
|
-
self.logger = Logger.new($stderr)
|
24
|
-
self.logger.level = Logger::FATAL
|
25
|
-
|
26
|
-
# Create a safe `Context` subclass to mutate
|
27
|
-
@context_class = Class.new(Context)
|
28
|
-
|
29
|
-
# Set MD5 as the default digest
|
30
|
-
require 'digest/md5'
|
31
|
-
@digest_class = ::Digest::MD5
|
32
|
-
@version = ''
|
33
|
-
|
34
|
-
@static_root = nil
|
35
|
-
|
36
|
-
@engines = Sprockets.engines
|
37
|
-
@engine_formats = Sprockets.engine_formats
|
38
|
-
@trail.extensions.replace(engine_extensions)
|
39
|
-
|
40
|
-
@mime_types = {}
|
41
|
-
@preprocessors = Hash.new { |h, k| h[k] = [] }
|
42
|
-
@postprocessors = Hash.new { |h, k| h[k] = [] }
|
43
|
-
@bundle_processors = Hash.new { |h, k| h[k] = [] }
|
44
|
-
|
45
|
-
register_mime_type 'text/css', '.css'
|
46
|
-
register_mime_type 'application/javascript', '.js'
|
47
|
-
|
48
|
-
register_preprocessor 'text/css', DirectiveProcessor
|
49
|
-
register_preprocessor 'application/javascript', DirectiveProcessor
|
50
|
-
|
51
|
-
register_postprocessor 'application/javascript', SafetyColons
|
52
|
-
register_bundle_processor 'text/css', CharsetNormalizer
|
53
|
-
|
54
|
-
expire_index!
|
55
|
-
|
56
|
-
yield self if block_given?
|
57
|
-
end
|
58
|
-
|
59
|
-
# Returns a cached version of the environment.
|
60
|
-
#
|
61
|
-
# All its file system calls are cached which makes `index` much
|
62
|
-
# faster. This behavior is ideal in production since the file
|
63
|
-
# system only changes between deploys.
|
64
|
-
def index
|
65
|
-
Index.new(self)
|
66
|
-
end
|
67
|
-
|
68
|
-
# Cache `find_asset` calls
|
69
|
-
def find_asset(path, options = {})
|
70
|
-
# Ensure inmemory cached assets are still fresh on every lookup
|
71
|
-
if (asset = @assets[path.to_s]) && asset.fresh?
|
72
|
-
asset
|
73
|
-
elsif asset = super
|
74
|
-
@assets[path.to_s] = @assets[asset.pathname.to_s] = asset
|
75
|
-
asset
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
protected
|
80
|
-
# Cache asset building in persisted cache.
|
81
|
-
def build_asset(path, pathname, options)
|
82
|
-
# Persisted cache
|
83
|
-
cache_asset(pathname.to_s) do
|
84
|
-
super
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def expire_index!
|
89
|
-
# Clear digest to be recomputed
|
90
|
-
@digest = nil
|
91
|
-
@assets = {}
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Define some basic Sprockets error classes
|
2
|
-
module Sprockets
|
3
|
-
class Error < StandardError; end
|
4
|
-
class ArgumentError < Error; end
|
5
|
-
class CircularDependencyError < Error; end
|
6
|
-
class ContentTypeMismatch < Error; end
|
7
|
-
class EncodingError < Error; end
|
8
|
-
class FileNotFound < Error; end
|
9
|
-
|
10
|
-
module EngineError
|
11
|
-
attr_accessor :sprockets_annotation
|
12
|
-
|
13
|
-
def message
|
14
|
-
[super, sprockets_annotation].compact.join("\n")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|