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,587 +0,0 @@
|
|
1
|
-
require 'sprockets_test'
|
2
|
-
require 'rack/mock'
|
3
|
-
require 'execjs'
|
4
|
-
|
5
|
-
module EnvironmentTests
|
6
|
-
def self.test(name, &block)
|
7
|
-
define_method("test #{name.inspect}", &block)
|
8
|
-
end
|
9
|
-
|
10
|
-
test "working directory is the default root" do
|
11
|
-
assert_equal Dir.pwd, @env.root
|
12
|
-
end
|
13
|
-
|
14
|
-
test "default logger level is set to fatal" do
|
15
|
-
assert_equal Logger::FATAL, @env.logger.level
|
16
|
-
end
|
17
|
-
|
18
|
-
test "active css compressor" do
|
19
|
-
assert_nil @env.css_compressor
|
20
|
-
end
|
21
|
-
|
22
|
-
test "active js compressor" do
|
23
|
-
assert_nil @env.js_compressor
|
24
|
-
end
|
25
|
-
|
26
|
-
test "current static root" do
|
27
|
-
assert_equal fixture_path("public"), @env.static_root.to_s
|
28
|
-
end
|
29
|
-
|
30
|
-
test "paths" do
|
31
|
-
assert_equal [fixture_path("default")], @env.paths.to_a
|
32
|
-
end
|
33
|
-
|
34
|
-
test "extensions" do
|
35
|
-
["coffee", "erb", "less", "sass", "scss", "str", "css", "js"].each do |ext|
|
36
|
-
assert @env.extensions.to_a.include?(".#{ext}")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
test "engine extensions" do
|
41
|
-
["coffee", "erb", "less", "sass", "scss", "str"].each do |ext|
|
42
|
-
assert @env.engine_extensions.include?(".#{ext}")
|
43
|
-
end
|
44
|
-
["css", "js"].each do |ext|
|
45
|
-
assert !@env.engine_extensions.include?(".#{ext}")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
test "format extensions" do
|
50
|
-
["css", "js"].each do |ext|
|
51
|
-
assert @env.format_extensions.include?(".#{ext}")
|
52
|
-
end
|
53
|
-
["coffee", "erb", "less", "sass", "scss", "str"].each do |ext|
|
54
|
-
assert !@env.format_extensions.include?(".#{ext}")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
test "eco templates" do
|
59
|
-
asset = @env["goodbye.jst"]
|
60
|
-
context = ExecJS.compile(asset)
|
61
|
-
assert_equal "Goodbye world\n", context.call("JST['goodbye']", :name => "world")
|
62
|
-
end
|
63
|
-
|
64
|
-
test "ejs templates" do
|
65
|
-
asset = @env["hello.jst"]
|
66
|
-
context = ExecJS.compile(asset)
|
67
|
-
assert_equal "hello: world\n", context.call("JST['hello']", :name => "world")
|
68
|
-
end
|
69
|
-
|
70
|
-
test "asset_data_uri helper" do
|
71
|
-
asset = @env["with_data_uri.css"]
|
72
|
-
assert_equal "body {\n background-image: url(data:image/gif;base64,R0lGODlhAQABAIAAAP%2F%2F%2FwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D) no-repeat;\n}\n", asset.to_s
|
73
|
-
assert asset.send(:dependency_paths).find { |dependency| dependency["path"] == fixture_path("default/blank.gif") }
|
74
|
-
end
|
75
|
-
|
76
|
-
test "lookup mime type" do
|
77
|
-
assert_equal "application/javascript", @env.mime_types(".js")
|
78
|
-
assert_equal "application/javascript", @env.mime_types("js")
|
79
|
-
assert_equal "text/css", @env.mime_types(:css)
|
80
|
-
assert_equal nil, @env.mime_types("foo")
|
81
|
-
assert_equal nil, @env.mime_types("foo")
|
82
|
-
end
|
83
|
-
|
84
|
-
test "lookup bundle processors" do
|
85
|
-
assert_equal [], @env.bundle_processors('application/javascript')
|
86
|
-
assert_equal [Sprockets::CharsetNormalizer], @env.bundle_processors('text/css')
|
87
|
-
end
|
88
|
-
|
89
|
-
test "resolve in environment" do
|
90
|
-
assert_equal fixture_path('default/gallery.js'),
|
91
|
-
@env.resolve("gallery.js").to_s
|
92
|
-
assert_equal fixture_path('default/gallery.js'),
|
93
|
-
@env.resolve(Pathname.new("gallery.js")).to_s
|
94
|
-
assert_equal fixture_path('default/coffee/foo.coffee'),
|
95
|
-
@env.resolve("coffee/foo.js").to_s
|
96
|
-
end
|
97
|
-
|
98
|
-
test "missing file raises an exception" do
|
99
|
-
assert_raises(Sprockets::FileNotFound) do
|
100
|
-
@env.resolve("null")
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
test "find bundled asset in environment" do
|
105
|
-
assert_equal "var Gallery = {};\n", @env["gallery.js"].to_s
|
106
|
-
end
|
107
|
-
|
108
|
-
test "find bundled asset with absolute path environment" do
|
109
|
-
assert_equal "var Gallery = {};\n", @env[fixture_path("default/gallery.js")].to_s
|
110
|
-
end
|
111
|
-
|
112
|
-
test "find bundled asset with implicit format" do
|
113
|
-
assert_equal "(function() {\n var foo;\n foo = 'hello';\n}).call(this);\n",
|
114
|
-
@env["coffee/foo.js"].to_s
|
115
|
-
end
|
116
|
-
|
117
|
-
test "find static asset in environment" do
|
118
|
-
assert_equal "Hello world\n", @env["hello.txt"].to_s
|
119
|
-
end
|
120
|
-
|
121
|
-
test "find static asset with leading slash in environment" do
|
122
|
-
assert_equal "Hello world\n", @env[fixture_path("default/hello.txt")].to_s
|
123
|
-
end
|
124
|
-
|
125
|
-
test "find asset with digest" do
|
126
|
-
digest = @env["hello.txt"].digest
|
127
|
-
assert_equal "Hello world\n", @env["hello-#{digest}.txt"].to_s
|
128
|
-
end
|
129
|
-
|
130
|
-
test "find asset with invalid digest" do
|
131
|
-
assert_nil @env["hello-ffffffff.txt"]
|
132
|
-
end
|
133
|
-
|
134
|
-
test "find index.js in directory" do
|
135
|
-
assert_equal "var A;\nvar B;\n", @env["mobile.js"].to_s
|
136
|
-
end
|
137
|
-
|
138
|
-
test "find index.css in directory" do
|
139
|
-
assert_equal ".c {}\n.d {}\n/*\n */\n\n", @env["mobile.css"].to_s
|
140
|
-
end
|
141
|
-
|
142
|
-
test "missing static path returns nil" do
|
143
|
-
assert_nil @env[fixture_path("default/missing.png")]
|
144
|
-
end
|
145
|
-
|
146
|
-
test "find static directory returns nil" do
|
147
|
-
assert_nil @env["images"]
|
148
|
-
end
|
149
|
-
|
150
|
-
test "missing asset returns nil" do
|
151
|
-
assert_equal nil, @env["missing.js"]
|
152
|
-
end
|
153
|
-
|
154
|
-
test "missing asset path returns nil" do
|
155
|
-
assert_nil @env[fixture_path("default/missing.js")]
|
156
|
-
end
|
157
|
-
|
158
|
-
test "asset with missing requires raises an exception" do
|
159
|
-
assert_raises Sprockets::FileNotFound do
|
160
|
-
@env["missing_require.js"]
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
test "asset logical path for absolute path" do
|
165
|
-
assert_equal "gallery.js",
|
166
|
-
@env[fixture_path("default/gallery.js")].logical_path
|
167
|
-
assert_equal "application.js",
|
168
|
-
@env[fixture_path("default/application.js.coffee")].logical_path
|
169
|
-
assert_equal "mobile/a.js",
|
170
|
-
@env[fixture_path("default/mobile/a.js")].logical_path
|
171
|
-
end
|
172
|
-
|
173
|
-
test "path for asset" do
|
174
|
-
digest = @env["gallery.js"].digest
|
175
|
-
assert_equal "/gallery-#{digest}.js", @env.path("gallery.js")
|
176
|
-
assert_equal "/gallery.js", @env.path("gallery.js", false)
|
177
|
-
assert_equal "/gallery-#{digest}.js", @env.path("/gallery.js")
|
178
|
-
assert_equal "/assets/gallery-#{digest}.js",
|
179
|
-
@env.path("gallery.js", true, "/assets")
|
180
|
-
end
|
181
|
-
|
182
|
-
test "url for asset" do
|
183
|
-
env = Rack::MockRequest.env_for("/")
|
184
|
-
digest = @env["gallery.js"].digest
|
185
|
-
|
186
|
-
assert_equal "http://example.org/gallery-#{digest}.js",
|
187
|
-
@env.url(env, "gallery.js")
|
188
|
-
assert_equal "http://example.org/gallery.js",
|
189
|
-
@env.url(env, "gallery.js", false)
|
190
|
-
assert_equal "http://example.org/gallery-#{digest}.js",
|
191
|
-
@env.url(env, "/gallery.js")
|
192
|
-
assert_equal "http://example.org/assets/gallery-#{digest}.js",
|
193
|
-
@env.url(env, "gallery.js", true, "assets")
|
194
|
-
end
|
195
|
-
|
196
|
-
test "missing path for asset" do
|
197
|
-
assert_equal "/missing.js", @env.path("missing.js")
|
198
|
-
end
|
199
|
-
|
200
|
-
test "precompile" do
|
201
|
-
digest = @env["gallery.js"].digest
|
202
|
-
filename = fixture_path("public/gallery-#{digest}.js")
|
203
|
-
filename_gz = "#{filename}.gz"
|
204
|
-
|
205
|
-
sandbox filename, filename_gz do
|
206
|
-
assert !File.exist?(filename)
|
207
|
-
@env.precompile("gallery.js")
|
208
|
-
assert File.exist?(filename)
|
209
|
-
assert File.exist?(filename_gz)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
test "precompile glob" do
|
214
|
-
dirname = fixture_path("public/mobile")
|
215
|
-
|
216
|
-
a_digest = @env["mobile/a.js"].digest
|
217
|
-
b_digest = @env["mobile/b.js"].digest
|
218
|
-
c_digest = @env["mobile/c.css"].digest
|
219
|
-
|
220
|
-
sandbox dirname do
|
221
|
-
assert !File.exist?(dirname)
|
222
|
-
@env.precompile("mobile/*")
|
223
|
-
|
224
|
-
assert File.exist?(dirname)
|
225
|
-
[nil, '.gz'].each do |gzipped|
|
226
|
-
assert File.exist?(File.join(dirname, "a-#{a_digest}.js#{gzipped}"))
|
227
|
-
assert File.exist?(File.join(dirname, "b-#{b_digest}.js#{gzipped}"))
|
228
|
-
assert File.exist?(File.join(dirname, "c-#{c_digest}.css#{gzipped}"))
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
test "precompile regexp" do
|
234
|
-
dirname = fixture_path("public/mobile")
|
235
|
-
|
236
|
-
a_digest = @env["mobile/a.js"].digest
|
237
|
-
b_digest = @env["mobile/b.js"].digest
|
238
|
-
c_digest = @env["mobile/c.css"].digest
|
239
|
-
|
240
|
-
sandbox dirname do
|
241
|
-
assert !File.exist?(dirname)
|
242
|
-
@env.precompile(/mobile\/.*/)
|
243
|
-
|
244
|
-
assert File.exist?(dirname)
|
245
|
-
[nil, '.gz'].each do |gzipped|
|
246
|
-
assert File.exist?(File.join(dirname, "a-#{a_digest}.js#{gzipped}"))
|
247
|
-
assert File.exist?(File.join(dirname, "b-#{b_digest}.js#{gzipped}"))
|
248
|
-
assert File.exist?(File.join(dirname, "c-#{c_digest}.css#{gzipped}"))
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
test "precompile static asset" do
|
254
|
-
digest = @env["hello.txt"].digest
|
255
|
-
filename = fixture_path("public/hello-#{digest}.txt")
|
256
|
-
|
257
|
-
sandbox filename do
|
258
|
-
assert !File.exist?(filename)
|
259
|
-
@env.precompile("hello.txt")
|
260
|
-
assert File.exist?(filename)
|
261
|
-
assert !File.exist?("#{filename}.gz")
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
test "CoffeeScript files are compiled in a closure" do
|
266
|
-
script = @env["coffee"].to_s
|
267
|
-
assert_equal "undefined", ExecJS.exec(script)
|
268
|
-
end
|
269
|
-
|
270
|
-
test "assets environment reference is its caller" do
|
271
|
-
assert_equal @env, @env["gallery.js"].environment
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
class WhitespaceCompressor
|
276
|
-
def self.compress(source)
|
277
|
-
source.gsub(/\s+/, "")
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
class TestEnvironment < Sprockets::TestCase
|
282
|
-
include EnvironmentTests
|
283
|
-
|
284
|
-
def new_environment
|
285
|
-
Sprockets::Environment.new(".") do |env|
|
286
|
-
env.append_path(fixture_path('default'))
|
287
|
-
env.static_root = fixture_path('public')
|
288
|
-
env.cache = {}
|
289
|
-
yield env if block_given?
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
def setup
|
294
|
-
@env = new_environment
|
295
|
-
end
|
296
|
-
|
297
|
-
test "changing logger" do
|
298
|
-
@env.logger = Logger.new($stderr)
|
299
|
-
end
|
300
|
-
|
301
|
-
test "changing paths" do
|
302
|
-
old_digest = @env.digest
|
303
|
-
|
304
|
-
@env.clear_paths
|
305
|
-
@env.append_path(fixture_path('asset'))
|
306
|
-
|
307
|
-
assert_not_equal old_digest, @env.digest
|
308
|
-
end
|
309
|
-
|
310
|
-
test "register mime type" do
|
311
|
-
assert !@env.mime_types("jst")
|
312
|
-
@env.register_mime_type("application/javascript", "jst")
|
313
|
-
assert_equal "application/javascript", @env.mime_types("jst")
|
314
|
-
end
|
315
|
-
|
316
|
-
test "register bundle processor" do
|
317
|
-
assert !@env.bundle_processors('text/css').include?(WhitespaceCompressor)
|
318
|
-
@env.register_bundle_processor 'text/css', WhitespaceCompressor
|
319
|
-
assert @env.bundle_processors('text/css').include?(WhitespaceCompressor)
|
320
|
-
end
|
321
|
-
|
322
|
-
test "unregister custom block preprocessor" do
|
323
|
-
old_size = @env.preprocessors('text/css').size
|
324
|
-
@env.register_preprocessor('text/css', :foo) { |context, data| data }
|
325
|
-
assert_equal old_size+1, @env.preprocessors('text/css').size
|
326
|
-
@env.unregister_preprocessor('text/css', :foo)
|
327
|
-
assert_equal old_size, @env.preprocessors('text/css').size
|
328
|
-
end
|
329
|
-
|
330
|
-
test "unregister custom block postprocessor" do
|
331
|
-
old_size = @env.postprocessors('text/css').size
|
332
|
-
@env.register_postprocessor('text/css', :foo) { |context, data| data }
|
333
|
-
assert_equal old_size+1, @env.postprocessors('text/css').size
|
334
|
-
@env.unregister_postprocessor('text/css', :foo)
|
335
|
-
assert_equal old_size, @env.postprocessors('text/css').size
|
336
|
-
end
|
337
|
-
|
338
|
-
test "unregister custom block bundle processor" do
|
339
|
-
old_size = @env.bundle_processors('text/css').size
|
340
|
-
@env.register_bundle_processor('text/css', :foo) { |context, data| data }
|
341
|
-
assert_equal old_size+1, @env.bundle_processors('text/css').size
|
342
|
-
@env.unregister_bundle_processor('text/css', :foo)
|
343
|
-
assert_equal old_size, @env.bundle_processors('text/css').size
|
344
|
-
end
|
345
|
-
|
346
|
-
test "setting css compressor to nil clears current compressor" do
|
347
|
-
old_digest = @env.digest
|
348
|
-
@env.css_compressor = WhitespaceCompressor
|
349
|
-
assert @env.css_compressor
|
350
|
-
@env.css_compressor = nil
|
351
|
-
assert_nil @env.css_compressor
|
352
|
-
end
|
353
|
-
|
354
|
-
test "setting js compressor to nil clears current compressor" do
|
355
|
-
@env.js_compressor = WhitespaceCompressor
|
356
|
-
assert @env.js_compressor
|
357
|
-
@env.js_compressor = nil
|
358
|
-
assert_nil @env.js_compressor
|
359
|
-
end
|
360
|
-
|
361
|
-
test "changing paths expires old assets" do
|
362
|
-
old_digest = @env.digest
|
363
|
-
assert @env["gallery.css"]
|
364
|
-
|
365
|
-
@env.clear_paths
|
366
|
-
|
367
|
-
assert_not_equal old_digest, @env.digest
|
368
|
-
assert_nil @env["gallery.css"]
|
369
|
-
end
|
370
|
-
|
371
|
-
test "changing digest implementation class" do
|
372
|
-
old_digest = @env.digest
|
373
|
-
old_asset_digest = @env["gallery.js"].digest
|
374
|
-
|
375
|
-
require 'digest/sha1'
|
376
|
-
@env.digest_class = Digest::SHA1
|
377
|
-
|
378
|
-
assert_not_equal old_digest, @env.digest
|
379
|
-
assert_not_equal old_asset_digest, @env["gallery.js"].digest
|
380
|
-
end
|
381
|
-
|
382
|
-
test "changing digest version" do
|
383
|
-
old_digest = @env.digest
|
384
|
-
old_asset_digest = @env["gallery.js"].digest
|
385
|
-
|
386
|
-
@env.version = 'v2'
|
387
|
-
|
388
|
-
assert_not_equal old_digest, @env.digest
|
389
|
-
assert_not_equal old_asset_digest, @env["gallery.js"].digest
|
390
|
-
end
|
391
|
-
|
392
|
-
test "bundled asset is stale if its mtime is updated or deleted" do
|
393
|
-
filename = File.join(fixture_path("default"), "tmp.js")
|
394
|
-
|
395
|
-
sandbox filename do
|
396
|
-
assert_nil @env["tmp.js"]
|
397
|
-
|
398
|
-
File.open(filename, 'w') { |f| f.puts "foo;" }
|
399
|
-
assert_equal "foo;\n", @env["tmp.js"].to_s
|
400
|
-
|
401
|
-
File.open(filename, 'w') { |f| f.puts "bar;" }
|
402
|
-
time = Time.now + 60
|
403
|
-
File.utime(time, time, filename)
|
404
|
-
assert_equal "bar;\n", @env["tmp.js"].to_s
|
405
|
-
|
406
|
-
File.unlink(filename)
|
407
|
-
assert_nil @env["tmp.js"]
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
test "static asset is stale if its mtime is updated or deleted" do
|
412
|
-
filename = File.join(fixture_path("default"), "tmp.png")
|
413
|
-
|
414
|
-
sandbox filename do
|
415
|
-
assert_nil @env["tmp.png"]
|
416
|
-
|
417
|
-
File.open(filename, 'w') { |f| f.puts "foo" }
|
418
|
-
assert_equal "foo\n", @env["tmp.png"].to_s
|
419
|
-
|
420
|
-
File.open(filename, 'w') { |f| f.puts "bar" }
|
421
|
-
time = Time.now + 60
|
422
|
-
File.utime(time, time, filename)
|
423
|
-
assert_equal "bar\n", @env["tmp.png"].to_s
|
424
|
-
|
425
|
-
File.unlink(filename)
|
426
|
-
assert_nil @env["tmp.png"]
|
427
|
-
end
|
428
|
-
end
|
429
|
-
|
430
|
-
test "seperate contexts classes for each instance" do
|
431
|
-
e1 = new_environment
|
432
|
-
e2 = new_environment
|
433
|
-
|
434
|
-
assert_raises(NameError) { e1.context_class.instance_method(:foo) }
|
435
|
-
assert_raises(NameError) { e2.context_class.instance_method(:foo) }
|
436
|
-
|
437
|
-
e1.context_class.class_eval do
|
438
|
-
def foo; end
|
439
|
-
end
|
440
|
-
|
441
|
-
assert_nothing_raised(NameError) { e1.context_class.instance_method(:foo) }
|
442
|
-
assert_raises(NameError) { e2.context_class.instance_method(:foo) }
|
443
|
-
end
|
444
|
-
|
445
|
-
test "registering engine adds to the environments extensions" do
|
446
|
-
assert !@env.engines[".foo"]
|
447
|
-
assert !@env.extensions.include?(".foo")
|
448
|
-
|
449
|
-
@env.register_engine ".foo", Tilt::StringTemplate
|
450
|
-
|
451
|
-
assert @env.engines[".foo"]
|
452
|
-
assert @env.extensions.include?(".foo")
|
453
|
-
end
|
454
|
-
|
455
|
-
test "seperate engines for each instance" do
|
456
|
-
e1 = new_environment
|
457
|
-
e2 = new_environment
|
458
|
-
|
459
|
-
assert_nil e1.engines[".foo"]
|
460
|
-
assert_nil e2.engines[".foo"]
|
461
|
-
|
462
|
-
e1.register_engine ".foo", Tilt::StringTemplate
|
463
|
-
|
464
|
-
assert e1.engines[".foo"]
|
465
|
-
assert_nil e2.engines[".foo"]
|
466
|
-
end
|
467
|
-
|
468
|
-
test "disabling default directive preprocessor" do
|
469
|
-
@env.unregister_preprocessor('application/javascript', Sprockets::DirectiveProcessor)
|
470
|
-
assert_equal "// =require \"notfound\"\n;\n", @env["missing_require.js"].to_s
|
471
|
-
end
|
472
|
-
end
|
473
|
-
|
474
|
-
class TestIndex < Sprockets::TestCase
|
475
|
-
include EnvironmentTests
|
476
|
-
|
477
|
-
def new_environment
|
478
|
-
Sprockets::Environment.new(".") do |env|
|
479
|
-
env.append_path(fixture_path('default'))
|
480
|
-
env.static_root = fixture_path('public')
|
481
|
-
env.cache = {}
|
482
|
-
yield env if block_given?
|
483
|
-
end.index
|
484
|
-
end
|
485
|
-
|
486
|
-
def setup
|
487
|
-
@env = new_environment
|
488
|
-
end
|
489
|
-
|
490
|
-
test "does not allow static root to be changed" do
|
491
|
-
assert_raises TypeError do
|
492
|
-
@env.static_root = fixture_path('public')
|
493
|
-
end
|
494
|
-
end
|
495
|
-
|
496
|
-
test "does not allow new mime types to be added" do
|
497
|
-
assert_raises TypeError do
|
498
|
-
@env.register_mime_type "application/javascript", ".jst"
|
499
|
-
end
|
500
|
-
end
|
501
|
-
|
502
|
-
test "change in environment mime types does not affect index" do
|
503
|
-
env = Sprockets::Environment.new(".")
|
504
|
-
env.register_mime_type "application/javascript", ".jst"
|
505
|
-
index = env.index
|
506
|
-
|
507
|
-
assert_equal "application/javascript", index.mime_types("jst")
|
508
|
-
env.register_mime_type nil, ".jst"
|
509
|
-
assert_equal "application/javascript", index.mime_types("jst")
|
510
|
-
end
|
511
|
-
|
512
|
-
test "does not allow new bundle processors to be added" do
|
513
|
-
assert_raises TypeError do
|
514
|
-
@env.register_bundle_processor 'text/css', WhitespaceCompressor
|
515
|
-
end
|
516
|
-
end
|
517
|
-
|
518
|
-
test "does not allow bundle processors to be removed" do
|
519
|
-
assert_raises TypeError do
|
520
|
-
@env.unregister_bundle_processor 'text/css', WhitespaceCompressor
|
521
|
-
end
|
522
|
-
end
|
523
|
-
|
524
|
-
test "change in environment bundle_processors does not affect index" do
|
525
|
-
env = Sprockets::Environment.new(".")
|
526
|
-
index = env.index
|
527
|
-
|
528
|
-
assert !index.bundle_processors('text/css').include?(WhitespaceCompressor)
|
529
|
-
env.register_bundle_processor 'text/css', WhitespaceCompressor
|
530
|
-
assert !index.bundle_processors('text/css').include?(WhitespaceCompressor)
|
531
|
-
end
|
532
|
-
|
533
|
-
test "change in environment static root does not affect index" do
|
534
|
-
env = Sprockets::Environment.new(".")
|
535
|
-
env.static_root = fixture_path('public')
|
536
|
-
index = env.index
|
537
|
-
|
538
|
-
assert_equal fixture_path('public'), index.static_root.to_s
|
539
|
-
env.static_root = fixture_path('static')
|
540
|
-
assert_equal fixture_path('public'), index.static_root.to_s
|
541
|
-
end
|
542
|
-
|
543
|
-
test "does not allow css compressor to be changed" do
|
544
|
-
assert_raises TypeError do
|
545
|
-
@env.css_compressor = WhitespaceCompressor
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
test "change in environment css compressor does not affect index" do
|
550
|
-
env = Sprockets::Environment.new(".")
|
551
|
-
env.css_compressor = WhitespaceCompressor
|
552
|
-
index = env.index
|
553
|
-
|
554
|
-
assert index.css_compressor
|
555
|
-
env.css_compressor = nil
|
556
|
-
assert index.css_compressor
|
557
|
-
end
|
558
|
-
|
559
|
-
test "does not allow js compressor to be changed" do
|
560
|
-
assert_raises TypeError do
|
561
|
-
@env.js_compressor = WhitespaceCompressor
|
562
|
-
end
|
563
|
-
end
|
564
|
-
|
565
|
-
test "change in environment js compressor does not affect index" do
|
566
|
-
env = Sprockets::Environment.new(".")
|
567
|
-
env.js_compressor = WhitespaceCompressor
|
568
|
-
index = env.index
|
569
|
-
|
570
|
-
assert index.js_compressor
|
571
|
-
env.js_compressor = nil
|
572
|
-
assert index.js_compressor
|
573
|
-
end
|
574
|
-
|
575
|
-
test "change in environment engines does not affect index" do
|
576
|
-
env = Sprockets::Environment.new
|
577
|
-
index = env.index
|
578
|
-
|
579
|
-
assert_nil env.engines[".foo"]
|
580
|
-
assert_nil index.engines[".foo"]
|
581
|
-
|
582
|
-
env.register_engine ".foo", Tilt::StringTemplate
|
583
|
-
|
584
|
-
assert env.engines[".foo"]
|
585
|
-
assert_nil index.engines[".foo"]
|
586
|
-
end
|
587
|
-
end
|