jekyll-minibundle 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +96 -42
- data/LICENSE.txt +1 -1
- data/README.md +232 -52
- data/Rakefile +16 -0
- data/jekyll-minibundle.gemspec +7 -6
- data/lib/jekyll/minibundle/asset_bundle.rb +3 -3
- data/lib/jekyll/minibundle/asset_file_drop.rb +45 -0
- data/lib/jekyll/minibundle/asset_file_properties.rb +12 -8
- data/lib/jekyll/minibundle/asset_file_registry.rb +4 -4
- data/lib/jekyll/minibundle/asset_tag_markup.rb +21 -20
- data/lib/jekyll/minibundle/bundle_file.rb +6 -1
- data/lib/jekyll/minibundle/development_file.rb +2 -1
- data/lib/jekyll/minibundle/development_file_collection.rb +2 -2
- data/lib/jekyll/minibundle/environment.rb +13 -15
- data/lib/jekyll/minibundle/files.rb +16 -18
- data/lib/jekyll/minibundle/hashes.rb +10 -12
- data/lib/jekyll/minibundle/log.rb +5 -7
- data/lib/jekyll/minibundle/mini_bundle_block.rb +35 -12
- data/lib/jekyll/minibundle/mini_stamp_tag.rb +108 -16
- data/lib/jekyll/minibundle/stamp_file.rb +1 -0
- data/lib/jekyll/minibundle/variable_template.rb +145 -0
- data/lib/jekyll/minibundle/variable_template_registry.rb +19 -0
- data/lib/jekyll/minibundle/version.rb +1 -1
- data/test/fixture/site/_bin/with_count +1 -1
- data/test/integration/minibundle_development_mode_test.rb +146 -61
- data/test/integration/minibundle_production_mode_test.rb +271 -143
- data/test/integration/ministamp_development_mode_test.rb +66 -25
- data/test/integration/ministamp_production_mode_test.rb +129 -37
- data/test/integration/static_files_as_asset_sources_test.rb +10 -10
- data/test/support/assertions.rb +1 -1
- data/test/support/{static_file_api_config.rb → static_file_config.rb} +6 -3
- data/test/support/test_case.rb +7 -4
- data/test/unit/asset_bundle_test.rb +6 -6
- data/test/unit/asset_file_drop_test.rb +65 -0
- data/test/unit/asset_file_registry_test.rb +136 -98
- data/test/unit/asset_tag_markup_test.rb +11 -5
- data/test/unit/bundle_file_properties_test.rb +44 -23
- data/test/unit/bundle_file_writing_test.rb +50 -32
- data/test/unit/development_file_properties_test.rb +95 -0
- data/test/unit/development_file_writing_test.rb +15 -6
- data/test/unit/environment_test.rb +3 -3
- data/test/unit/files_test.rb +7 -7
- data/test/unit/hashes_test.rb +12 -12
- data/test/unit/jekyll_static_file_api_test.rb +91 -20
- data/test/unit/mini_bundle_block_test.rb +59 -9
- data/test/unit/mini_stamp_tag_test.rb +37 -6
- data/test/unit/stamp_file_properties_test.rb +47 -24
- data/test/unit/stamp_file_writing_test.rb +33 -24
- data/test/unit/variable_template_test.rb +121 -0
- metadata +27 -6
- data/test/unit/development_file_collection_properties_test.rb +0 -106
@@ -7,55 +7,55 @@ module Jekyll::Minibundle::Test
|
|
7
7
|
|
8
8
|
def test_css_asset_bundle_has_stamp
|
9
9
|
with_precompiled_site(:production) do
|
10
|
-
assert_equal
|
10
|
+
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_js_asset_bundle_has_stamp
|
15
15
|
with_precompiled_site(:production) do
|
16
|
-
assert_equal
|
16
|
+
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_css_asset_bundle_has_configured_attributes
|
21
21
|
with_precompiled_site(:production) do
|
22
22
|
element = find_css_element_from_index
|
23
|
-
assert_equal
|
24
|
-
assert_equal
|
23
|
+
assert_equal('my-styles', element['id'])
|
24
|
+
assert_equal('projection', element['media'])
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_js_asset_bundle_has_configured_attributes
|
29
29
|
with_precompiled_site(:production) do
|
30
30
|
element = find_js_element_from_index
|
31
|
-
assert_equal
|
32
|
-
assert_equal
|
31
|
+
assert_equal('my-scripts', element['id'])
|
32
|
+
assert_equal('', element['async'])
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_copies_css_asset_bundle_to_destination_dir
|
37
37
|
with_precompiled_site(:production) do
|
38
|
-
assert
|
38
|
+
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_copies_js_asset_bundle_to_destination_dir
|
43
43
|
with_precompiled_site(:production) do
|
44
|
-
assert
|
44
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_concatenates_css_asset_bundle_in_configured_order
|
49
49
|
with_precompiled_site(:production) do
|
50
50
|
bundle = File.read(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
51
|
-
assert_operator
|
51
|
+
assert_operator(bundle.index('html { margin: 0; }'), :<, bundle.index('p { margin: 0; }'))
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_concatenates_js_asset_bundle_in_configured_order
|
56
56
|
with_precompiled_site(:production) do
|
57
57
|
bundle = File.read(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
58
|
-
assert_operator
|
58
|
+
assert_operator(bundle.index('root.dependency = {};'), :<, bundle.index('root.app = {};'))
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -70,7 +70,7 @@ module Jekyll::Minibundle::Test
|
|
70
70
|
with_precompiled_site(:production) do
|
71
71
|
source_contents_size = source_assets_size(CSS_BUNDLE_SOURCE_DIR, %w{reset common}, 'css')
|
72
72
|
destination_contents_size = File.read(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)).size
|
73
|
-
assert_operator
|
73
|
+
assert_operator(destination_contents_size, :<, source_contents_size)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -78,7 +78,7 @@ module Jekyll::Minibundle::Test
|
|
78
78
|
with_precompiled_site(:production) do
|
79
79
|
source_contents_size = source_assets_size(JS_BUNDLE_SOURCE_DIR, %w{dependency app}, 'js')
|
80
80
|
destination_contents_size = File.read(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)).size
|
81
|
-
assert_operator
|
81
|
+
assert_operator(destination_contents_size, :<, source_contents_size)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -90,12 +90,12 @@ module Jekyll::Minibundle::Test
|
|
90
90
|
|
91
91
|
generate_site(:production, clear_cache: false)
|
92
92
|
|
93
|
-
refute
|
93
|
+
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
94
94
|
|
95
95
|
new_destination = 'assets/site-375a0b430b0c5555d0edd2205d26c04d.js'
|
96
96
|
|
97
|
-
assert_equal
|
98
|
-
assert
|
97
|
+
assert_equal(new_destination, find_js_path_from_index)
|
98
|
+
assert(File.file?(destination_path(new_destination)))
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -108,9 +108,9 @@ module Jekyll::Minibundle::Test
|
|
108
108
|
|
109
109
|
generate_site(:production, clear_cache: false)
|
110
110
|
|
111
|
-
assert_equal
|
112
|
-
assert
|
113
|
-
assert_operator
|
111
|
+
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
112
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
113
|
+
assert_operator(file_mtime_of(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)), :>, org_mtime)
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -139,7 +139,7 @@ module Jekyll::Minibundle::Test
|
|
139
139
|
|
140
140
|
new_mtime = file_mtime_of(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
141
141
|
|
142
|
-
assert_operator
|
142
|
+
assert_operator(new_mtime, :>, org_mtime)
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
@@ -147,7 +147,7 @@ module Jekyll::Minibundle::Test
|
|
147
147
|
with_site_dir do
|
148
148
|
generate_site(:production)
|
149
149
|
|
150
|
-
assert
|
150
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
151
151
|
|
152
152
|
match_snippet = <<-END
|
153
153
|
assets:
|
@@ -166,12 +166,12 @@ module Jekyll::Minibundle::Test
|
|
166
166
|
|
167
167
|
generate_site(:production, clear_cache: false)
|
168
168
|
|
169
|
-
refute
|
169
|
+
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
170
170
|
|
171
171
|
new_destination = 'assets/site-71042d0b7c86c04e015fde694dd9f409.js'
|
172
172
|
|
173
|
-
assert_equal
|
174
|
-
assert
|
173
|
+
assert_equal(new_destination, find_js_path_from_index)
|
174
|
+
assert(File.file?(destination_path(new_destination)))
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
@@ -181,7 +181,7 @@ module Jekyll::Minibundle::Test
|
|
181
181
|
|
182
182
|
generate_site(:production)
|
183
183
|
|
184
|
-
assert
|
184
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
185
185
|
|
186
186
|
match_snippet = <<-END
|
187
187
|
assets:
|
@@ -202,8 +202,8 @@ module Jekyll::Minibundle::Test
|
|
202
202
|
|
203
203
|
generate_site(:production, clear_cache: false)
|
204
204
|
|
205
|
-
refute
|
206
|
-
assert
|
205
|
+
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
206
|
+
assert(File.file?(destination_path('assets/site-71042d0b7c86c04e015fde694dd9f409.js')))
|
207
207
|
assert((find_tempfiles('*.js') & old_tempfiles).empty?)
|
208
208
|
end
|
209
209
|
end
|
@@ -212,7 +212,7 @@ module Jekyll::Minibundle::Test
|
|
212
212
|
with_site_dir do
|
213
213
|
generate_site(:production)
|
214
214
|
|
215
|
-
assert
|
215
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
216
216
|
|
217
217
|
ensure_file_mtime_changes do
|
218
218
|
change_destination_path_in_minibundle_block('assets/site', 'assets/site2')
|
@@ -220,12 +220,12 @@ module Jekyll::Minibundle::Test
|
|
220
220
|
|
221
221
|
generate_site(:production, clear_cache: false)
|
222
222
|
|
223
|
-
refute
|
223
|
+
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
224
224
|
|
225
225
|
new_destination = "assets/site2-#{JS_BUNDLE_FINGERPRINT}.js"
|
226
226
|
|
227
|
-
assert_equal
|
228
|
-
assert
|
227
|
+
assert_equal(new_destination, find_js_path_from_index)
|
228
|
+
assert(File.file?(destination_path(new_destination)))
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
@@ -235,7 +235,7 @@ module Jekyll::Minibundle::Test
|
|
235
235
|
|
236
236
|
generate_site(:production)
|
237
237
|
|
238
|
-
assert
|
238
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
239
239
|
|
240
240
|
old_tempfiles = find_tempfiles('*.js') - other_tempfiles
|
241
241
|
|
@@ -245,8 +245,8 @@ module Jekyll::Minibundle::Test
|
|
245
245
|
|
246
246
|
generate_site(:production, clear_cache: false)
|
247
247
|
|
248
|
-
refute
|
249
|
-
assert
|
248
|
+
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
249
|
+
assert(File.file?(destination_path("assets/site2-#{JS_BUNDLE_FINGERPRINT}.js")))
|
250
250
|
assert((find_tempfiles('*.js') & old_tempfiles).empty?)
|
251
251
|
end
|
252
252
|
end
|
@@ -255,7 +255,7 @@ module Jekyll::Minibundle::Test
|
|
255
255
|
with_site_dir do
|
256
256
|
generate_site(:production)
|
257
257
|
|
258
|
-
assert
|
258
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
259
259
|
|
260
260
|
ensure_file_mtime_changes do
|
261
261
|
change_destination_path_in_minibundle_block('assets/site', 'assets/site2')
|
@@ -263,12 +263,12 @@ module Jekyll::Minibundle::Test
|
|
263
263
|
|
264
264
|
generate_site(:production, clear_cache: false)
|
265
265
|
|
266
|
-
refute
|
266
|
+
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
267
267
|
|
268
268
|
new_destination = "assets/site2-#{JS_BUNDLE_FINGERPRINT}.js"
|
269
269
|
|
270
|
-
assert_equal
|
271
|
-
assert
|
270
|
+
assert_equal(new_destination, find_js_path_from_index)
|
271
|
+
assert(File.file?(destination_path(new_destination)))
|
272
272
|
|
273
273
|
ensure_file_mtime_changes do
|
274
274
|
change_destination_path_in_minibundle_block('assets/site2', 'assets/site')
|
@@ -276,9 +276,9 @@ module Jekyll::Minibundle::Test
|
|
276
276
|
|
277
277
|
generate_site(:production, clear_cache: false)
|
278
278
|
|
279
|
-
refute
|
280
|
-
assert_equal
|
281
|
-
assert
|
279
|
+
refute(File.file?(destination_path(new_destination)))
|
280
|
+
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
281
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
282
282
|
end
|
283
283
|
end
|
284
284
|
|
@@ -286,7 +286,7 @@ module Jekyll::Minibundle::Test
|
|
286
286
|
with_site_dir do
|
287
287
|
generate_site(:production)
|
288
288
|
|
289
|
-
assert_equal
|
289
|
+
assert_equal(0, get_minifier_cmd_count)
|
290
290
|
destination = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
291
291
|
org_mtime = file_mtime_of(destination)
|
292
292
|
|
@@ -305,8 +305,8 @@ module Jekyll::Minibundle::Test
|
|
305
305
|
|
306
306
|
generate_site(:production, clear_cache: false)
|
307
307
|
|
308
|
-
assert_equal
|
309
|
-
assert_operator
|
308
|
+
assert_equal(1, get_minifier_cmd_count)
|
309
|
+
assert_operator(file_mtime_of(destination), :>, org_mtime)
|
310
310
|
end
|
311
311
|
end
|
312
312
|
|
@@ -319,11 +319,11 @@ module Jekyll::Minibundle::Test
|
|
319
319
|
org_mtime_css = file_mtime_of(destination_css)
|
320
320
|
org_mtime_js = file_mtime_of(destination_js)
|
321
321
|
|
322
|
-
assert
|
323
|
-
assert
|
322
|
+
assert(File.file?(destination_css))
|
323
|
+
assert(File.file?(destination_js))
|
324
324
|
|
325
|
-
assert_equal
|
326
|
-
assert_equal
|
325
|
+
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
326
|
+
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
327
327
|
|
328
328
|
ensure_file_mtime_changes do
|
329
329
|
find_and_gsub_in_file(
|
@@ -335,94 +335,120 @@ module Jekyll::Minibundle::Test
|
|
335
335
|
|
336
336
|
generate_site(:production, clear_cache: false)
|
337
337
|
|
338
|
-
assert
|
339
|
-
assert
|
340
|
-
assert_equal
|
341
|
-
assert_equal
|
342
|
-
assert_equal
|
343
|
-
assert_equal
|
338
|
+
assert(File.file?(destination_css))
|
339
|
+
assert(File.file?(destination_js))
|
340
|
+
assert_equal(org_mtime_css, file_mtime_of(destination_css))
|
341
|
+
assert_equal(org_mtime_js, file_mtime_of(destination_js))
|
342
|
+
assert_equal("/#{CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_css_path_from_index)
|
343
|
+
assert_equal("/#{JS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_js_path_from_index)
|
344
344
|
end
|
345
345
|
end
|
346
346
|
|
347
347
|
def test_supports_baseurl
|
348
348
|
with_site_dir do
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
generate_site(:production, clear_cache: false)
|
361
|
-
|
362
|
-
assert_equal "/css-root/#{CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_css_path_from_index
|
363
|
-
assert_equal "/js-root/#{JS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_js_path_from_index
|
364
|
-
end
|
365
|
-
end
|
349
|
+
merge_to_yaml_file(source_path('_config.yml'), 'baseurl' => '/root')
|
350
|
+
|
351
|
+
find_and_gsub_in_file(
|
352
|
+
source_path('_layouts/default.html'),
|
353
|
+
' {% minibundle css %}',
|
354
|
+
<<-END
|
355
|
+
{% minibundle css %}
|
356
|
+
baseurl: '{{ site.baseurl }}/'
|
357
|
+
END
|
358
|
+
)
|
366
359
|
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
360
|
+
find_and_gsub_in_file(
|
361
|
+
source_path('_layouts/default.html'),
|
362
|
+
' {% minibundle js %}',
|
363
|
+
<<-END
|
364
|
+
{% minibundle js %}
|
365
|
+
baseurl: {{ site.baseurl }}/js
|
366
|
+
END
|
367
|
+
)
|
372
368
|
|
373
369
|
generate_site(:production)
|
374
370
|
|
375
|
-
assert
|
376
|
-
assert
|
371
|
+
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
372
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
377
373
|
|
378
|
-
assert_equal
|
379
|
-
assert_equal
|
374
|
+
assert_equal("/root/#{CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_css_path_from_index)
|
375
|
+
assert_equal("/root/js/#{JS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_js_path_from_index)
|
380
376
|
end
|
381
377
|
end
|
382
378
|
|
383
379
|
def test_strips_dot_slash_from_dot_baseurl
|
384
380
|
with_site_dir do
|
385
|
-
find_and_gsub_in_file(
|
386
|
-
|
381
|
+
find_and_gsub_in_file(
|
382
|
+
source_path('_layouts/default.html'),
|
383
|
+
' {% minibundle css %}',
|
384
|
+
<<-END
|
385
|
+
{% minibundle css %}
|
386
|
+
baseurl: .
|
387
|
+
END
|
388
|
+
)
|
389
|
+
|
390
|
+
find_and_gsub_in_file(
|
391
|
+
source_path('_layouts/default.html'),
|
392
|
+
' {% minibundle js %}',
|
393
|
+
<<-END
|
394
|
+
{% minibundle js %}
|
395
|
+
baseurl: .
|
396
|
+
END
|
397
|
+
)
|
387
398
|
|
388
399
|
generate_site(:production)
|
389
400
|
|
390
|
-
assert
|
391
|
-
assert
|
401
|
+
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
402
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
392
403
|
|
393
|
-
assert_equal
|
394
|
-
assert_equal
|
404
|
+
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
405
|
+
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
395
406
|
|
396
407
|
generate_site(:production, clear_cache: false)
|
397
408
|
|
398
|
-
assert
|
399
|
-
assert
|
409
|
+
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
410
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
400
411
|
|
401
|
-
assert_equal
|
402
|
-
assert_equal
|
412
|
+
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
413
|
+
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
403
414
|
end
|
404
415
|
end
|
405
416
|
|
406
417
|
def test_strips_dot_slash_from_dot_slash_baseurl
|
407
418
|
with_site_dir do
|
408
|
-
find_and_gsub_in_file(
|
409
|
-
|
419
|
+
find_and_gsub_in_file(
|
420
|
+
source_path('_layouts/default.html'),
|
421
|
+
' {% minibundle css %}',
|
422
|
+
<<-END
|
423
|
+
{% minibundle css %}
|
424
|
+
baseurl: ./
|
425
|
+
END
|
426
|
+
)
|
427
|
+
|
428
|
+
find_and_gsub_in_file(
|
429
|
+
source_path('_layouts/default.html'),
|
430
|
+
' {% minibundle js %}',
|
431
|
+
<<-END
|
432
|
+
{% minibundle js %}
|
433
|
+
baseurl: ./
|
434
|
+
END
|
435
|
+
)
|
410
436
|
|
411
437
|
generate_site(:production)
|
412
438
|
|
413
|
-
assert
|
414
|
-
assert
|
439
|
+
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
440
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
415
441
|
|
416
|
-
assert_equal
|
417
|
-
assert_equal
|
442
|
+
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
443
|
+
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
418
444
|
|
419
445
|
generate_site(:production, clear_cache: false)
|
420
446
|
|
421
|
-
assert
|
422
|
-
assert
|
447
|
+
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
448
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
423
449
|
|
424
|
-
assert_equal
|
425
|
-
assert_equal
|
450
|
+
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
451
|
+
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
426
452
|
end
|
427
453
|
end
|
428
454
|
|
@@ -432,19 +458,19 @@ module Jekyll::Minibundle::Test
|
|
432
458
|
|
433
459
|
generate_site(:production)
|
434
460
|
|
435
|
-
assert
|
436
|
-
assert
|
461
|
+
assert(File.file?(destination_path("site-#{CSS_BUNDLE_FINGERPRINT}.css")))
|
462
|
+
assert(File.file?(destination_path("site-#{JS_BUNDLE_FINGERPRINT}.js")))
|
437
463
|
|
438
|
-
assert_equal
|
439
|
-
assert_equal
|
464
|
+
assert_equal("site-#{CSS_BUNDLE_FINGERPRINT}.css", find_css_path_from_index)
|
465
|
+
assert_equal("site-#{JS_BUNDLE_FINGERPRINT}.js", find_js_path_from_index)
|
440
466
|
|
441
467
|
generate_site(:production, clear_cache: false)
|
442
468
|
|
443
|
-
assert
|
444
|
-
assert
|
469
|
+
assert(File.file?(destination_path("site-#{CSS_BUNDLE_FINGERPRINT}.css")))
|
470
|
+
assert(File.file?(destination_path("site-#{JS_BUNDLE_FINGERPRINT}.js")))
|
445
471
|
|
446
|
-
assert_equal
|
447
|
-
assert_equal
|
472
|
+
assert_equal("site-#{CSS_BUNDLE_FINGERPRINT}.css", find_css_path_from_index)
|
473
|
+
assert_equal("site-#{JS_BUNDLE_FINGERPRINT}.js", find_js_path_from_index)
|
448
474
|
end
|
449
475
|
end
|
450
476
|
|
@@ -454,19 +480,59 @@ module Jekyll::Minibundle::Test
|
|
454
480
|
|
455
481
|
generate_site(:production)
|
456
482
|
|
457
|
-
assert
|
458
|
-
assert
|
483
|
+
assert(File.file?(destination_path("site-#{CSS_BUNDLE_FINGERPRINT}.css")))
|
484
|
+
assert(File.file?(destination_path("site-#{JS_BUNDLE_FINGERPRINT}.js")))
|
459
485
|
|
460
|
-
assert_equal
|
461
|
-
assert_equal
|
486
|
+
assert_equal("site-#{CSS_BUNDLE_FINGERPRINT}.css", find_css_path_from_index)
|
487
|
+
assert_equal("site-#{JS_BUNDLE_FINGERPRINT}.js", find_js_path_from_index)
|
462
488
|
|
463
489
|
generate_site(:production, clear_cache: false)
|
464
490
|
|
465
|
-
assert
|
466
|
-
assert
|
491
|
+
assert(File.file?(destination_path("site-#{CSS_BUNDLE_FINGERPRINT}.css")))
|
492
|
+
assert(File.file?(destination_path("site-#{JS_BUNDLE_FINGERPRINT}.js")))
|
493
|
+
|
494
|
+
assert_equal("site-#{CSS_BUNDLE_FINGERPRINT}.css", find_css_path_from_index)
|
495
|
+
assert_equal("site-#{JS_BUNDLE_FINGERPRINT}.js", find_js_path_from_index)
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
def test_supports_destination_baseurl
|
500
|
+
with_site_dir do
|
501
|
+
merge_to_yaml_file(source_path('_config.yml'), 'cdn_baseurl' => 'https://cdn.example.com/?file=')
|
502
|
+
|
503
|
+
find_and_gsub_in_file(
|
504
|
+
source_path('_layouts/default.html'),
|
505
|
+
' {% minibundle css %}',
|
506
|
+
<<-END
|
507
|
+
{% minibundle css %}
|
508
|
+
baseurl: /ignored
|
509
|
+
destination_baseurl: {{ site.cdn_baseurl }}css/
|
510
|
+
END
|
511
|
+
)
|
512
|
+
|
513
|
+
find_and_gsub_in_file(
|
514
|
+
source_path('_layouts/default.html'),
|
515
|
+
/ #{Regexp.escape('{% minibundle js %}')}.*#{Regexp.escape('{% endminibundle %}')}/m,
|
516
|
+
<<-END
|
517
|
+
{% minibundle js %}
|
518
|
+
source_dir: _assets/scripts
|
519
|
+
destination_path: static
|
520
|
+
baseurl: /ignored
|
521
|
+
destination_baseurl: '{{ site.cdn_baseurl }}'
|
522
|
+
assets:
|
523
|
+
- dependency
|
524
|
+
- app
|
525
|
+
{% endminibundle %}
|
526
|
+
END
|
527
|
+
)
|
528
|
+
|
529
|
+
generate_site(:production)
|
530
|
+
|
531
|
+
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
532
|
+
assert(File.file?(destination_path("static-#{JS_BUNDLE_FINGERPRINT}.js")))
|
467
533
|
|
468
|
-
assert_equal
|
469
|
-
assert_equal
|
534
|
+
assert_equal("https://cdn.example.com/?file=css/site-#{CSS_BUNDLE_FINGERPRINT}.css", find_css_path_from_index)
|
535
|
+
assert_equal("https://cdn.example.com/?file=static-#{JS_BUNDLE_FINGERPRINT}.js", find_js_path_from_index)
|
470
536
|
end
|
471
537
|
end
|
472
538
|
|
@@ -474,23 +540,23 @@ module Jekyll::Minibundle::Test
|
|
474
540
|
with_site_dir do
|
475
541
|
generate_site(:production)
|
476
542
|
|
477
|
-
assert_equal
|
478
|
-
assert_equal
|
543
|
+
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
544
|
+
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
479
545
|
|
480
546
|
find_and_gsub_in_file(source_path('_layouts/default.html'), 'id: my-styles', 'id: my-styles2')
|
481
547
|
find_and_gsub_in_file(source_path('_layouts/default.html'), 'id: my-scripts', 'id: my-scripts2')
|
482
548
|
|
483
549
|
generate_site(:production, clear_cache: false)
|
484
550
|
|
485
|
-
assert_equal
|
486
|
-
assert_equal
|
551
|
+
assert_equal('my-styles2', find_css_element_from_index['id'])
|
552
|
+
assert_equal('my-scripts2', find_js_element_from_index['id'])
|
487
553
|
end
|
488
554
|
end
|
489
555
|
|
490
556
|
def test_bundles_assets_only_once_at_startup
|
491
557
|
with_site_dir do
|
492
558
|
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
493
|
-
assert_equal
|
559
|
+
assert_equal(1, get_minifier_cmd_count)
|
494
560
|
end
|
495
561
|
end
|
496
562
|
|
@@ -501,21 +567,21 @@ module Jekyll::Minibundle::Test
|
|
501
567
|
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
502
568
|
org_mtime = file_mtime_of(expected_js_path)
|
503
569
|
|
504
|
-
assert_equal
|
570
|
+
assert_equal(1, get_minifier_cmd_count)
|
505
571
|
|
506
572
|
ensure_file_mtime_changes { File.write(source_path(CSS_BUNDLE_SOURCE_DIR, 'common.css'), 'h1 {}') }
|
507
573
|
|
508
574
|
generate_site(:production, clear_cache: false, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
509
575
|
|
510
|
-
assert_equal
|
511
|
-
assert_equal
|
576
|
+
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
577
|
+
assert_equal(1, get_minifier_cmd_count)
|
512
578
|
|
513
579
|
ensure_file_mtime_changes { FileUtils.touch('index.html') }
|
514
580
|
|
515
581
|
generate_site(:production, clear_cache: false, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
516
582
|
|
517
|
-
assert_equal
|
518
|
-
assert_equal
|
583
|
+
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
584
|
+
assert_equal(1, get_minifier_cmd_count)
|
519
585
|
end
|
520
586
|
end
|
521
587
|
|
@@ -526,7 +592,7 @@ module Jekyll::Minibundle::Test
|
|
526
592
|
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
527
593
|
org_mtime = file_mtime_of(expected_js_path)
|
528
594
|
|
529
|
-
assert_equal
|
595
|
+
assert_equal(1, get_minifier_cmd_count)
|
530
596
|
|
531
597
|
ensure_file_mtime_changes do
|
532
598
|
find_and_gsub_in_file(source_path('_layouts/default.html'), 'id: my-scripts', 'id: my-scripts2')
|
@@ -534,8 +600,8 @@ module Jekyll::Minibundle::Test
|
|
534
600
|
|
535
601
|
generate_site(:production, clear_cache: false, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
536
602
|
|
537
|
-
assert_equal
|
538
|
-
assert_equal
|
603
|
+
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
604
|
+
assert_equal(1, get_minifier_cmd_count)
|
539
605
|
end
|
540
606
|
end
|
541
607
|
|
@@ -546,16 +612,52 @@ module Jekyll::Minibundle::Test
|
|
546
612
|
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
547
613
|
org_mtime = file_mtime_of(expected_js_path)
|
548
614
|
|
549
|
-
assert_equal
|
615
|
+
assert_equal(1, get_minifier_cmd_count)
|
550
616
|
|
551
617
|
ensure_file_mtime_changes do
|
552
|
-
find_and_gsub_in_file(
|
618
|
+
find_and_gsub_in_file(
|
619
|
+
source_path('_layouts/default.html'),
|
620
|
+
' {% minibundle js %}',
|
621
|
+
<<-END
|
622
|
+
{% minibundle js %}
|
623
|
+
baseurl: /js-root
|
624
|
+
END
|
625
|
+
)
|
553
626
|
end
|
554
627
|
|
555
628
|
generate_site(:production, clear_cache: false, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
556
629
|
|
557
|
-
assert_equal
|
558
|
-
assert_equal
|
630
|
+
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
631
|
+
assert_equal(1, get_minifier_cmd_count)
|
632
|
+
assert_equal("/js-root/#{JS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_js_path_from_index)
|
633
|
+
end
|
634
|
+
end
|
635
|
+
|
636
|
+
def test_does_not_rebundle_assets_when_changing_destination_baseurl
|
637
|
+
with_site_dir do
|
638
|
+
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
639
|
+
|
640
|
+
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
641
|
+
org_mtime = file_mtime_of(expected_js_path)
|
642
|
+
|
643
|
+
assert_equal(1, get_minifier_cmd_count)
|
644
|
+
|
645
|
+
ensure_file_mtime_changes do
|
646
|
+
find_and_gsub_in_file(
|
647
|
+
source_path('_layouts/default.html'),
|
648
|
+
' {% minibundle js %}',
|
649
|
+
<<-END
|
650
|
+
{% minibundle js %}
|
651
|
+
destination_baseurl: /root/
|
652
|
+
END
|
653
|
+
)
|
654
|
+
end
|
655
|
+
|
656
|
+
generate_site(:production, clear_cache: false, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
657
|
+
|
658
|
+
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
659
|
+
assert_equal(1, get_minifier_cmd_count)
|
660
|
+
assert_equal("/root/site-#{JS_BUNDLE_FINGERPRINT}.js", find_js_path_from_index)
|
559
661
|
end
|
560
662
|
end
|
561
663
|
|
@@ -568,9 +670,9 @@ module Jekyll::Minibundle::Test
|
|
568
670
|
|
569
671
|
generate_site(:production, minifier_cmd_js: nil)
|
570
672
|
|
571
|
-
assert_equal
|
572
|
-
assert_equal
|
573
|
-
assert
|
673
|
+
assert_equal(0, get_minifier_cmd_count)
|
674
|
+
assert_equal(1, get_minifier_cmd_count('minifier_cmd_config_count'))
|
675
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
574
676
|
end
|
575
677
|
end
|
576
678
|
|
@@ -583,9 +685,9 @@ module Jekyll::Minibundle::Test
|
|
583
685
|
|
584
686
|
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count('minifier_cmd_env_count'))
|
585
687
|
|
586
|
-
assert_equal
|
587
|
-
assert_equal
|
588
|
-
assert
|
688
|
+
assert_equal(0, get_minifier_cmd_count('minifier_cmd_config_count'))
|
689
|
+
assert_equal(1, get_minifier_cmd_count('minifier_cmd_env_count'))
|
690
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
589
691
|
end
|
590
692
|
end
|
591
693
|
|
@@ -615,11 +717,11 @@ title: Test
|
|
615
717
|
|
616
718
|
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count('minifier_cmd_global_count'))
|
617
719
|
|
618
|
-
assert_equal
|
619
|
-
assert
|
720
|
+
assert_equal(1, get_minifier_cmd_count('minifier_cmd_local_count'))
|
721
|
+
assert(File.file?(destination_path('assets/deps-71042d0b7c86c04e015fde694dd9f409.js')))
|
620
722
|
|
621
|
-
assert_equal
|
622
|
-
assert
|
723
|
+
assert_equal(1, get_minifier_cmd_count('minifier_cmd_global_count'))
|
724
|
+
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
623
725
|
end
|
624
726
|
end
|
625
727
|
|
@@ -627,11 +729,37 @@ title: Test
|
|
627
729
|
with_site_dir do
|
628
730
|
with_umask(0o027) do
|
629
731
|
generate_site(:production)
|
630
|
-
assert_equal
|
732
|
+
assert_equal(0o640, file_permissions_of(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
631
733
|
end
|
632
734
|
end
|
633
735
|
end
|
634
736
|
|
737
|
+
def test_escapes_destination_path_url_and_attributes_in_generated_html_element
|
738
|
+
with_site_dir do
|
739
|
+
find_and_gsub_in_file(
|
740
|
+
source_path('_layouts/default.html'),
|
741
|
+
/ #{Regexp.escape('{% minibundle js %}')}.*#{Regexp.escape('{% endminibundle %}')}/m,
|
742
|
+
<<-END
|
743
|
+
{% minibundle js %}
|
744
|
+
source_dir: _assets/scripts
|
745
|
+
destination_path: 'dst">'
|
746
|
+
assets:
|
747
|
+
- dependency
|
748
|
+
- app
|
749
|
+
attributes:
|
750
|
+
test: '"/><br>'
|
751
|
+
{% endminibundle %}
|
752
|
+
END
|
753
|
+
)
|
754
|
+
|
755
|
+
generate_site(:production)
|
756
|
+
|
757
|
+
assert(File.file?(destination_path(%{dst">-#{JS_BUNDLE_FINGERPRINT}.js})))
|
758
|
+
assert_equal(%{dst">-#{JS_BUNDLE_FINGERPRINT}.js}, find_js_path_from_index)
|
759
|
+
assert_equal('"/><br>', find_js_element_from_index['test'])
|
760
|
+
end
|
761
|
+
end
|
762
|
+
|
635
763
|
private
|
636
764
|
|
637
765
|
def find_css_element_from_index
|