jekyll-minibundle 2.2.0 → 3.0.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.
Files changed (56) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +162 -63
  3. data/README.md +62 -57
  4. data/Rakefile +27 -14
  5. data/jekyll-minibundle.gemspec +15 -13
  6. data/lib/jekyll/minibundle.rb +2 -0
  7. data/lib/jekyll/minibundle/asset_bundle.rb +16 -10
  8. data/lib/jekyll/minibundle/asset_file_drop.rb +5 -2
  9. data/lib/jekyll/minibundle/asset_file_properties.rb +2 -0
  10. data/lib/jekyll/minibundle/asset_file_registry.rb +9 -7
  11. data/lib/jekyll/minibundle/asset_stamp.rb +2 -0
  12. data/lib/jekyll/minibundle/asset_tag_markup.rb +6 -4
  13. data/lib/jekyll/minibundle/bundle_file.rb +8 -0
  14. data/lib/jekyll/minibundle/development_file.rb +4 -0
  15. data/lib/jekyll/minibundle/development_file_collection.rb +2 -0
  16. data/lib/jekyll/minibundle/environment.rb +5 -1
  17. data/lib/jekyll/minibundle/exceptions.rb +2 -0
  18. data/lib/jekyll/minibundle/files.rb +2 -0
  19. data/lib/jekyll/minibundle/hashes.rb +3 -0
  20. data/lib/jekyll/minibundle/log.rb +3 -1
  21. data/lib/jekyll/minibundle/mini_bundle_block.rb +8 -1
  22. data/lib/jekyll/minibundle/mini_stamp_tag.rb +3 -1
  23. data/lib/jekyll/minibundle/stamp_file.rb +4 -0
  24. data/lib/jekyll/minibundle/variable_template.rb +15 -12
  25. data/lib/jekyll/minibundle/variable_template_registry.rb +2 -0
  26. data/lib/jekyll/minibundle/version.rb +3 -1
  27. data/test/fixture/site/_bin/remove_comments +1 -0
  28. data/test/fixture/site/_bin/with_count +1 -0
  29. data/test/fixture/site/_config.yml +2 -1
  30. data/test/integration/minibundle_development_mode_test.rb +115 -29
  31. data/test/integration/minibundle_production_mode_test.rb +157 -69
  32. data/test/integration/ministamp_development_mode_test.rb +4 -2
  33. data/test/integration/ministamp_production_mode_test.rb +6 -4
  34. data/test/integration/static_files_as_asset_sources_test.rb +6 -4
  35. data/test/support/assertions.rb +2 -0
  36. data/test/support/fixture_config.rb +14 -12
  37. data/test/support/static_file_config.rb +18 -16
  38. data/test/support/test_case.rb +5 -3
  39. data/test/unit/asset_bundle_test.rb +14 -12
  40. data/test/unit/asset_file_drop_test.rb +4 -3
  41. data/test/unit/asset_file_registry_test.rb +16 -19
  42. data/test/unit/asset_tag_markup_test.rb +8 -6
  43. data/test/unit/bundle_file_properties_test.rb +6 -4
  44. data/test/unit/bundle_file_writing_test.rb +6 -4
  45. data/test/unit/development_file_properties_test.rb +5 -3
  46. data/test/unit/development_file_writing_test.rb +4 -2
  47. data/test/unit/environment_test.rb +6 -4
  48. data/test/unit/files_test.rb +3 -1
  49. data/test/unit/hashes_test.rb +3 -1
  50. data/test/unit/jekyll_static_file_api_test.rb +13 -9
  51. data/test/unit/mini_bundle_block_test.rb +42 -35
  52. data/test/unit/mini_stamp_tag_test.rb +4 -2
  53. data/test/unit/stamp_file_properties_test.rb +5 -3
  54. data/test/unit/stamp_file_writing_test.rb +4 -2
  55. data/test/unit/variable_template_test.rb +8 -8
  56. metadata +13 -14
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cgi/util'
2
4
  require 'jekyll/minibundle/files'
3
5
  require 'jekyll/minibundle/asset_file_registry'
@@ -63,7 +65,7 @@ module Jekyll::Minibundle
63
65
 
64
66
  def parse_structure(args)
65
67
  ::SafeYAML.load(args)
66
- rescue => e
68
+ rescue StandardError => e
67
69
  raise ArgumentError, "Failed parsing ministamp tag argument syntax as YAML: #{args.inspect}. Cause: #{e}"
68
70
  end
69
71
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'jekyll/minibundle/files'
2
4
  require 'jekyll/minibundle/asset_file_properties'
3
5
  require 'jekyll/minibundle/asset_stamp'
@@ -13,7 +15,9 @@ module Jekyll::Minibundle
13
15
  def initialize(site, asset_source_path, asset_destination_path)
14
16
  @site = site
15
17
  @asset_source_path = File.join(@site.source, asset_source_path)
18
+
16
19
  raise ArgumentError, "Stamp source file does not exist: #{@asset_source_path}" unless File.file?(@asset_source_path)
20
+
17
21
  @asset_destination_dir = File.dirname(asset_destination_path)
18
22
  @asset_destination_extension = File.extname(asset_destination_path)
19
23
  @asset_destination_filename_prefix = File.basename(asset_destination_path)[0..-(@asset_destination_extension.size + 1)]
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'strscan'
2
4
 
3
5
  module Jekyll::Minibundle
4
6
  class VariableTemplate
5
- OPEN_TAG = '{{'.freeze
6
- CLOSE_TAG = '}}'.freeze
7
- ESCAPE_CHAR = '\\'.freeze
7
+ OPEN_TAG = '{{'
8
+ CLOSE_TAG = '}}'
9
+ ESCAPE_CHAR = '\\'
8
10
 
9
11
  def initialize(interpolation)
10
12
  instance_eval("def render(variables) #{interpolation} end", __FILE__, __LINE__)
@@ -15,9 +17,10 @@ module Jekyll::Minibundle
15
17
  end
16
18
 
17
19
  class SyntaxError < ArgumentError
18
- CURSOR = '@'.freeze
20
+ CURSOR = '@'
19
21
 
20
22
  def initialize(message, template, position)
23
+ super()
21
24
  @message = message
22
25
  @template = template
23
26
  @position = position
@@ -27,15 +30,14 @@ module Jekyll::Minibundle
27
30
  template_before_pos = @template[0, @position]
28
31
  template_after_pos = @template[@position..-1]
29
32
 
30
- <<-END
31
- #{@message} at position #{@position} in template (position highlighted with "#{CURSOR}"):
32
- #{template_before_pos}#{CURSOR}#{template_after_pos}
33
- END
33
+ <<~MESSAGE
34
+ #{@message} at position #{@position} in template (position highlighted with "#{CURSOR}"):
35
+ #{template_before_pos}#{CURSOR}#{template_after_pos}
36
+ MESSAGE
34
37
  end
35
38
  end
36
39
 
37
40
  module Parser
38
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
39
41
  def self.parse(template)
40
42
  raise ArgumentError, 'Nil template' if template.nil?
41
43
 
@@ -61,7 +63,9 @@ module Jekyll::Minibundle
61
63
  tokens << Token.text(text_buffer)
62
64
  text_buffer = ''
63
65
  close_match = scanner.scan_until(close_regex)
66
+
64
67
  raise SyntaxError.new(%{Missing closing tag ("#{CLOSE_TAG}") for variable opening tag ("#{OPEN_TAG}")}, template, scanner.charpos) unless close_match
68
+
65
69
  tokens << Token.variable(close_match[0..-(CLOSE_TAG.size + 1)].strip)
66
70
  end
67
71
 
@@ -73,7 +77,6 @@ module Jekyll::Minibundle
73
77
 
74
78
  tokens
75
79
  end
76
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
77
80
 
78
81
  def self.make_escape_sequence_regexp
79
82
  escape_chars = (OPEN_TAG + CLOSE_TAG).chars.uniq
@@ -82,7 +85,7 @@ module Jekyll::Minibundle
82
85
  end
83
86
 
84
87
  def self.make_escape_sequence_or_open_tag_regexp
85
- @_escape_sequence_or_open_tag_regexp ||=
88
+ @_make_escape_sequence_or_open_tag_regexp ||=
86
89
  begin
87
90
  regexp = [make_escape_sequence_regexp.join('|'), Regexp.escape(OPEN_TAG)].map { |p| "(#{p})" }.join('|')
88
91
  Regexp.compile(regexp)
@@ -90,7 +93,7 @@ module Jekyll::Minibundle
90
93
  end
91
94
 
92
95
  def self.make_close_tag_regexp
93
- @_close_tag_regexp ||= Regexp.compile(Regexp.escape(CLOSE_TAG))
96
+ @_make_close_tag_regexp ||= Regexp.compile(Regexp.escape(CLOSE_TAG))
94
97
  end
95
98
  end
96
99
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'jekyll/minibundle/variable_template'
2
4
 
3
5
  module Jekyll::Minibundle
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module Minibundle
3
- VERSION = '2.2.0'.freeze
5
+ VERSION = '3.0.0'
4
6
  end
5
7
  end
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env sh
2
2
 
3
3
  grep -v '/\*'
4
+ exit 0
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  filename = ARGV.first
4
5
 
@@ -1,2 +1,3 @@
1
- gems: ['jekyll/minibundle']
1
+ plugins:
2
+ - jekyll/minibundle
2
3
  safe: false
@@ -1,12 +1,14 @@
1
- require 'support/test_case'
2
- require 'support/fixture_config'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../support/test_case'
4
+ require_relative '../support/fixture_config'
3
5
 
4
6
  module Jekyll::Minibundle::Test
5
7
  class MinibundleDevelopmentModeTest < TestCase
6
8
  include FixtureConfig
7
9
 
8
- CSS_ASSET_DESTINATION_PATHS = %w{reset common}.map { |f| File.join(CSS_BUNDLE_DESTINATION_PATH, "#{f}.css") }
9
- JS_ASSET_DESTINATION_PATHS = %w{dependency app}.map { |f| File.join(JS_BUNDLE_DESTINATION_PATH, "#{f}.js") }
10
+ CSS_ASSET_DESTINATION_PATHS = %w[reset common].map { |f| File.join(CSS_BUNDLE_DESTINATION_PATH, "#{f}.css") }
11
+ JS_ASSET_DESTINATION_PATHS = %w[dependency app].map { |f| File.join(JS_BUNDLE_DESTINATION_PATH, "#{f}.js") }
10
12
 
11
13
  def test_css_assets_have_tags_in_configured_order
12
14
  with_precompiled_site(:development) do
@@ -23,7 +25,7 @@ module Jekyll::Minibundle::Test
23
25
  def test_css_assets_have_configured_attributes
24
26
  with_precompiled_site(:development) do
25
27
  elements = find_css_elements_from_index.map { |el| [el['id'], el['media']] }.uniq
26
- assert_equal([['my-styles', 'projection']], elements)
28
+ assert_equal([%w[my-styles projection]], elements)
27
29
  end
28
30
  end
29
31
 
@@ -78,15 +80,15 @@ module Jekyll::Minibundle::Test
78
80
  destination = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
79
81
  org_mtime = file_mtime_of(destination)
80
82
 
81
- match_snippet = <<-END
83
+ match_snippet = <<-LIQUID
82
84
  {% minibundle js %}
83
85
  source_dir: _assets/scripts
84
- END
86
+ LIQUID
85
87
 
86
- replacement_snippet = <<-END
88
+ replacement_snippet = <<-LIQUID
87
89
  {% minibundle js %}
88
90
  source_dir: _assets/scripts2
89
- END
91
+ LIQUID
90
92
 
91
93
  ensure_file_mtime_changes do
92
94
  FileUtils.mv(source_path('_assets/scripts'), source_path('_assets/scripts2'))
@@ -105,16 +107,16 @@ module Jekyll::Minibundle::Test
105
107
 
106
108
  org_mtime = file_mtime_of(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js'))
107
109
 
108
- match_snippet = <<-END
110
+ match_snippet = <<-YAML
109
111
  assets:
110
112
  - dependency
111
113
  - app
112
- END
114
+ YAML
113
115
 
114
- replacement_snippet = <<-END
116
+ replacement_snippet = <<-YAML
115
117
  assets:
116
118
  - dependency
117
- END
119
+ YAML
118
120
 
119
121
  ensure_file_mtime_changes do
120
122
  find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
@@ -227,19 +229,19 @@ module Jekyll::Minibundle::Test
227
229
  find_and_gsub_in_file(
228
230
  source_path('_layouts/default.html'),
229
231
  ' {% minibundle css %}',
230
- <<-END
232
+ <<-LIQUID
231
233
  {% minibundle css %}
232
234
  baseurl: '{{ site.baseurl }}/'
233
- END
235
+ LIQUID
234
236
  )
235
237
 
236
238
  find_and_gsub_in_file(
237
239
  source_path('_layouts/default.html'),
238
240
  ' {% minibundle js %}',
239
- <<-END
241
+ <<-LIQUID
240
242
  {% minibundle js %}
241
243
  baseurl: {{ site.baseurl }}/js
242
- END
244
+ LIQUID
243
245
  )
244
246
 
245
247
  generate_site(:development)
@@ -259,17 +261,17 @@ module Jekyll::Minibundle::Test
259
261
  find_and_gsub_in_file(
260
262
  source_path('_layouts/default.html'),
261
263
  ' {% minibundle css %}',
262
- <<-END
264
+ <<-LIQUID
263
265
  {% minibundle css %}
264
266
  baseurl: /ignored
265
267
  destination_baseurl: {{ site.cdn_baseurl }}css/
266
- END
268
+ LIQUID
267
269
  )
268
270
 
269
271
  find_and_gsub_in_file(
270
272
  source_path('_layouts/default.html'),
271
273
  / #{Regexp.escape('{% minibundle js %}')}.*#{Regexp.escape('{% endminibundle %}')}/m,
272
- <<-END
274
+ <<-LIQUID
273
275
  {% minibundle js %}
274
276
  source_dir: _assets/scripts
275
277
  destination_path: static
@@ -279,7 +281,7 @@ module Jekyll::Minibundle::Test
279
281
  - dependency
280
282
  - app
281
283
  {% endminibundle %}
282
- END
284
+ LIQUID
283
285
  )
284
286
 
285
287
  generate_site(:development)
@@ -367,10 +369,10 @@ module Jekyll::Minibundle::Test
367
369
  find_and_gsub_in_file(
368
370
  source_path('_layouts/default.html'),
369
371
  ' {% minibundle js %}',
370
- <<-END
372
+ <<-LIQUID
371
373
  {% minibundle js %}
372
374
  baseurl: /js-root
373
- END
375
+ LIQUID
374
376
  )
375
377
  end
376
378
 
@@ -392,10 +394,10 @@ module Jekyll::Minibundle::Test
392
394
  find_and_gsub_in_file(
393
395
  source_path('_layouts/default.html'),
394
396
  ' {% minibundle js %}',
395
- <<-END
397
+ <<-LIQUID
396
398
  {% minibundle js %}
397
399
  destination_baseurl: /js-root/
398
- END
400
+ LIQUID
399
401
  )
400
402
  end
401
403
 
@@ -422,6 +424,90 @@ module Jekyll::Minibundle::Test
422
424
  end
423
425
  end
424
426
 
427
+ def test_empty_asset_sources_produces_no_destination_assets
428
+ with_site_dir do
429
+ match_snippet = <<-YAML
430
+ assets:
431
+ - dependency
432
+ - app
433
+ YAML
434
+
435
+ replacement_snippet = <<-YAML
436
+ assets: []
437
+ YAML
438
+
439
+ find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
440
+
441
+ generate_site(:development)
442
+
443
+ assert_empty([], find_js_paths_from_index)
444
+ end
445
+ end
446
+
447
+ def test_allows_relative_paths_in_asset_source_files
448
+ with_site_dir do
449
+ match_snippet = <<-LIQUID
450
+ {% minibundle js %}
451
+ source_dir: _assets/scripts
452
+ destination_path: assets/site
453
+ assets:
454
+ - dependency
455
+ - app
456
+ LIQUID
457
+
458
+ replacement_snippet = <<-LIQUID
459
+ {% minibundle js %}
460
+ source_dir: _assets
461
+ destination_path: assets/site
462
+ assets:
463
+ - scripts/dependencies/one
464
+ - ../_app
465
+ LIQUID
466
+
467
+ find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
468
+
469
+ FileUtils.mkdir('_assets/scripts/dependencies')
470
+ FileUtils.mv(source_path('_assets/scripts/dependency.js'), source_path('_assets/scripts/dependencies/one.js'))
471
+ FileUtils.mv(source_path('_assets/scripts/app.js'), source_path('_app.js'))
472
+
473
+ generate_site(:development)
474
+
475
+ assert_equal(['assets/site/scripts/dependencies/one.js', 'assets/site/../_app.js'], find_js_paths_from_index)
476
+ assert(File.file?(destination_path('assets/site/scripts/dependencies/one.js')))
477
+ assert(File.file?(destination_path('assets/_app.js')))
478
+ end
479
+ end
480
+
481
+ def test_allows_root_dir_as_source_dir
482
+ with_site_dir do
483
+ match_snippet = <<-LIQUID
484
+ {% minibundle js %}
485
+ source_dir: _assets/scripts
486
+ destination_path: assets/site
487
+ assets:
488
+ - dependency
489
+ - app
490
+ LIQUID
491
+
492
+ replacement_snippet = <<-LIQUID
493
+ {% minibundle js %}
494
+ source_dir: .
495
+ destination_path: assets/site
496
+ assets:
497
+ - _assets/scripts/dependency
498
+ - _assets/scripts/app
499
+ LIQUID
500
+
501
+ find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
502
+
503
+ generate_site(:development)
504
+
505
+ assert_equal(%w[dependency app].map { |p| File.join(JS_BUNDLE_DESTINATION_PATH, '_assets/scripts', "#{p}.js") }, find_js_paths_from_index)
506
+ assert(File.file?(destination_path(File.join(JS_BUNDLE_DESTINATION_PATH, '_assets/scripts/dependency.js'))))
507
+ assert(File.file?(destination_path(File.join(JS_BUNDLE_DESTINATION_PATH, '_assets/scripts/app.js'))))
508
+ end
509
+ end
510
+
425
511
  private
426
512
 
427
513
  def find_css_elements_from_index
@@ -450,17 +536,17 @@ module Jekyll::Minibundle::Test
450
536
  end
451
537
 
452
538
  def change_destination_path_in_minibundle_block(from, to)
453
- match_snippet = <<-END
539
+ match_snippet = <<-LIQUID
454
540
  {% minibundle js %}
455
541
  source_dir: _assets/scripts
456
542
  destination_path: #{from}
457
- END
543
+ LIQUID
458
544
 
459
- replacement_snippet = <<-END
545
+ replacement_snippet = <<-LIQUID
460
546
  {% minibundle js %}
461
547
  source_dir: _assets/scripts
462
548
  destination_path: #{to}
463
- END
549
+ LIQUID
464
550
 
465
551
  find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
466
552
  end
@@ -1,5 +1,8 @@
1
- require 'support/test_case'
2
- require 'support/fixture_config'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../support/test_case'
4
+ require_relative '../support/fixture_config'
5
+ require 'digest/md5'
3
6
 
4
7
  module Jekyll::Minibundle::Test
5
8
  class MinibundleProductionModeTest < TestCase
@@ -68,7 +71,7 @@ module Jekyll::Minibundle::Test
68
71
 
69
72
  def test_minifies_css_asset_bundle
70
73
  with_precompiled_site(:production) do
71
- source_contents_size = source_assets_size(CSS_BUNDLE_SOURCE_DIR, %w{reset common}, 'css')
74
+ source_contents_size = source_assets_size(CSS_BUNDLE_SOURCE_DIR, %w[reset common], 'css')
72
75
  destination_contents_size = File.read(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)).size
73
76
  assert_operator(destination_contents_size, :<, source_contents_size)
74
77
  end
@@ -76,7 +79,7 @@ module Jekyll::Minibundle::Test
76
79
 
77
80
  def test_minifies_js_asset_bundle
78
81
  with_precompiled_site(:production) do
79
- source_contents_size = source_assets_size(JS_BUNDLE_SOURCE_DIR, %w{dependency app}, 'js')
82
+ source_contents_size = source_assets_size(JS_BUNDLE_SOURCE_DIR, %w[dependency app], 'js')
80
83
  destination_contents_size = File.read(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)).size
81
84
  assert_operator(destination_contents_size, :<, source_contents_size)
82
85
  end
@@ -120,15 +123,15 @@ module Jekyll::Minibundle::Test
120
123
 
121
124
  org_mtime = file_mtime_of(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
122
125
 
123
- match_snippet = <<-END
126
+ match_snippet = <<-LIQUID
124
127
  {% minibundle js %}
125
128
  source_dir: _assets/scripts
126
- END
129
+ LIQUID
127
130
 
128
- replacement_snippet = <<-END
131
+ replacement_snippet = <<-LIQUID
129
132
  {% minibundle js %}
130
133
  source_dir: _assets/scripts2
131
- END
134
+ LIQUID
132
135
 
133
136
  ensure_file_mtime_changes do
134
137
  FileUtils.mv(source_path('_assets/scripts'), source_path('_assets/scripts2'))
@@ -149,16 +152,16 @@ module Jekyll::Minibundle::Test
149
152
 
150
153
  assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
151
154
 
152
- match_snippet = <<-END
155
+ match_snippet = <<-YAML
153
156
  assets:
154
157
  - dependency
155
158
  - app
156
- END
159
+ YAML
157
160
 
158
- replacement_snippet = <<-END
161
+ replacement_snippet = <<-YAML
159
162
  assets:
160
163
  - dependency
161
- END
164
+ YAML
162
165
 
163
166
  ensure_file_mtime_changes do
164
167
  find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
@@ -183,16 +186,16 @@ module Jekyll::Minibundle::Test
183
186
 
184
187
  assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
185
188
 
186
- match_snippet = <<-END
189
+ match_snippet = <<-YAML
187
190
  assets:
188
191
  - dependency
189
192
  - app
190
- END
193
+ YAML
191
194
 
192
- replacement_snippet = <<-END
195
+ replacement_snippet = <<-YAML
193
196
  assets:
194
197
  - dependency
195
- END
198
+ YAML
196
199
 
197
200
  old_tempfiles = find_tempfiles('*.js') - other_tempfiles
198
201
 
@@ -290,14 +293,14 @@ module Jekyll::Minibundle::Test
290
293
  destination = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
291
294
  org_mtime = file_mtime_of(destination)
292
295
 
293
- match_snippet = <<-END
296
+ match_snippet = <<-LIQUID
294
297
  {% minibundle js %}
295
- END
298
+ LIQUID
296
299
 
297
- replacement_snippet = <<-END
300
+ replacement_snippet = <<-LIQUID
298
301
  {% minibundle js %}
299
302
  minifier_cmd: #{minifier_cmd_to_remove_comments_and_count}
300
- END
303
+ LIQUID
301
304
 
302
305
  ensure_file_mtime_changes do
303
306
  find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
@@ -351,19 +354,19 @@ module Jekyll::Minibundle::Test
351
354
  find_and_gsub_in_file(
352
355
  source_path('_layouts/default.html'),
353
356
  ' {% minibundle css %}',
354
- <<-END
357
+ <<-LIQUID
355
358
  {% minibundle css %}
356
359
  baseurl: '{{ site.baseurl }}/'
357
- END
360
+ LIQUID
358
361
  )
359
362
 
360
363
  find_and_gsub_in_file(
361
364
  source_path('_layouts/default.html'),
362
365
  ' {% minibundle js %}',
363
- <<-END
366
+ <<-LIQUID
364
367
  {% minibundle js %}
365
368
  baseurl: {{ site.baseurl }}/js
366
- END
369
+ LIQUID
367
370
  )
368
371
 
369
372
  generate_site(:production)
@@ -381,19 +384,19 @@ module Jekyll::Minibundle::Test
381
384
  find_and_gsub_in_file(
382
385
  source_path('_layouts/default.html'),
383
386
  ' {% minibundle css %}',
384
- <<-END
387
+ <<-LIQUID
385
388
  {% minibundle css %}
386
389
  baseurl: .
387
- END
390
+ LIQUID
388
391
  )
389
392
 
390
393
  find_and_gsub_in_file(
391
394
  source_path('_layouts/default.html'),
392
395
  ' {% minibundle js %}',
393
- <<-END
396
+ <<-LIQUID
394
397
  {% minibundle js %}
395
398
  baseurl: .
396
- END
399
+ LIQUID
397
400
  )
398
401
 
399
402
  generate_site(:production)
@@ -419,19 +422,19 @@ module Jekyll::Minibundle::Test
419
422
  find_and_gsub_in_file(
420
423
  source_path('_layouts/default.html'),
421
424
  ' {% minibundle css %}',
422
- <<-END
425
+ <<-LIQUID
423
426
  {% minibundle css %}
424
427
  baseurl: ./
425
- END
428
+ LIQUID
426
429
  )
427
430
 
428
431
  find_and_gsub_in_file(
429
432
  source_path('_layouts/default.html'),
430
433
  ' {% minibundle js %}',
431
- <<-END
434
+ <<-LIQUID
432
435
  {% minibundle js %}
433
436
  baseurl: ./
434
- END
437
+ LIQUID
435
438
  )
436
439
 
437
440
  generate_site(:production)
@@ -503,17 +506,17 @@ module Jekyll::Minibundle::Test
503
506
  find_and_gsub_in_file(
504
507
  source_path('_layouts/default.html'),
505
508
  ' {% minibundle css %}',
506
- <<-END
509
+ <<-LIQUID
507
510
  {% minibundle css %}
508
511
  baseurl: /ignored
509
512
  destination_baseurl: {{ site.cdn_baseurl }}css/
510
- END
513
+ LIQUID
511
514
  )
512
515
 
513
516
  find_and_gsub_in_file(
514
517
  source_path('_layouts/default.html'),
515
518
  / #{Regexp.escape('{% minibundle js %}')}.*#{Regexp.escape('{% endminibundle %}')}/m,
516
- <<-END
519
+ <<-LIQUID
517
520
  {% minibundle js %}
518
521
  source_dir: _assets/scripts
519
522
  destination_path: static
@@ -523,7 +526,7 @@ module Jekyll::Minibundle::Test
523
526
  - dependency
524
527
  - app
525
528
  {% endminibundle %}
526
- END
529
+ LIQUID
527
530
  )
528
531
 
529
532
  generate_site(:production)
@@ -618,10 +621,10 @@ module Jekyll::Minibundle::Test
618
621
  find_and_gsub_in_file(
619
622
  source_path('_layouts/default.html'),
620
623
  ' {% minibundle js %}',
621
- <<-END
624
+ <<-LIQUID
622
625
  {% minibundle js %}
623
626
  baseurl: /js-root
624
- END
627
+ LIQUID
625
628
  )
626
629
  end
627
630
 
@@ -646,10 +649,10 @@ module Jekyll::Minibundle::Test
646
649
  find_and_gsub_in_file(
647
650
  source_path('_layouts/default.html'),
648
651
  ' {% minibundle js %}',
649
- <<-END
652
+ <<-LIQUID
650
653
  {% minibundle js %}
651
654
  destination_baseurl: /root/
652
- END
655
+ LIQUID
653
656
  )
654
657
  end
655
658
 
@@ -693,27 +696,27 @@ module Jekyll::Minibundle::Test
693
696
 
694
697
  def test_minifier_command_in_local_block_overrides_command_from_environment
695
698
  with_site_dir do
696
- IO.write('test.html', <<-END)
697
- ---
698
- layout: override
699
- title: Test
700
- ---
701
- END
702
-
703
- IO.write('_layouts/override.html', <<-END)
704
- <!DOCTYPE html>
705
- <html>
706
- <body>
707
- {% minibundle js %}
708
- source_dir: _assets/scripts
709
- destination_path: assets/deps
710
- assets:
711
- - dependency
712
- minifier_cmd: #{minifier_cmd_to_remove_comments_and_count('minifier_cmd_local_count')}
713
- {% endminibundle %}
714
- </body>
715
- </html>
716
- END
699
+ IO.write('test.html', <<~YAML)
700
+ ---
701
+ layout: override
702
+ title: Test
703
+ ---
704
+ YAML
705
+
706
+ IO.write('_layouts/override.html', <<~LIQUID)
707
+ <!DOCTYPE html>
708
+ <html>
709
+ <body>
710
+ {% minibundle js %}
711
+ source_dir: _assets/scripts
712
+ destination_path: assets/deps
713
+ assets:
714
+ - dependency
715
+ minifier_cmd: #{minifier_cmd_to_remove_comments_and_count('minifier_cmd_local_count')}
716
+ {% endminibundle %}
717
+ </body>
718
+ </html>
719
+ LIQUID
717
720
 
718
721
  generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count('minifier_cmd_global_count'))
719
722
 
@@ -739,7 +742,7 @@ title: Test
739
742
  find_and_gsub_in_file(
740
743
  source_path('_layouts/default.html'),
741
744
  / #{Regexp.escape('{% minibundle js %}')}.*#{Regexp.escape('{% endminibundle %}')}/m,
742
- <<-END
745
+ <<-LIQUID
743
746
  {% minibundle js %}
744
747
  source_dir: _assets/scripts
745
748
  destination_path: 'dst">'
@@ -749,17 +752,102 @@ title: Test
749
752
  attributes:
750
753
  test: '"/><br>'
751
754
  {% endminibundle %}
752
- END
755
+ LIQUID
753
756
  )
754
757
 
755
758
  generate_site(:production)
756
759
 
757
- assert(File.file?(destination_path(%{dst">-#{JS_BUNDLE_FINGERPRINT}.js})))
758
- assert_equal(%{dst">-#{JS_BUNDLE_FINGERPRINT}.js}, find_js_path_from_index)
760
+ assert(File.file?(destination_path(%(dst">-#{JS_BUNDLE_FINGERPRINT}.js))))
761
+ assert_equal(%(dst">-#{JS_BUNDLE_FINGERPRINT}.js), find_js_path_from_index)
759
762
  assert_equal('"/><br>', find_js_element_from_index['test'])
760
763
  end
761
764
  end
762
765
 
766
+ def test_empty_asset_sources_produces_empty_bundle
767
+ with_site_dir do
768
+ match_snippet = <<-YAML
769
+ assets:
770
+ - dependency
771
+ - app
772
+ YAML
773
+
774
+ replacement_snippet = <<-YAML
775
+ assets: []
776
+ YAML
777
+
778
+ find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
779
+
780
+ generate_site(:production)
781
+
782
+ destination = "assets/site-#{Digest::MD5.hexdigest('')}.js"
783
+
784
+ assert_equal(destination, find_js_path_from_index)
785
+ assert(File.file?(destination_path(destination)))
786
+ end
787
+ end
788
+
789
+ def test_allows_relative_paths_in_asset_source_files
790
+ with_site_dir do
791
+ match_snippet = <<-LIQUID
792
+ {% minibundle js %}
793
+ source_dir: _assets/scripts
794
+ destination_path: assets/site
795
+ assets:
796
+ - dependency
797
+ - app
798
+ LIQUID
799
+
800
+ replacement_snippet = <<-LIQUID
801
+ {% minibundle js %}
802
+ source_dir: _assets
803
+ destination_path: assets/site
804
+ assets:
805
+ - scripts/dependencies/one
806
+ - ../_app
807
+ LIQUID
808
+
809
+ find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
810
+
811
+ FileUtils.mkdir('_assets/scripts/dependencies')
812
+ FileUtils.mv(source_path('_assets/scripts/dependency.js'), source_path('_assets/scripts/dependencies/one.js'))
813
+ FileUtils.mv(source_path('_assets/scripts/app.js'), source_path('_app.js'))
814
+
815
+ generate_site(:production)
816
+
817
+ assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
818
+ assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
819
+ end
820
+ end
821
+
822
+ def test_allows_root_dir_as_source_dir
823
+ with_site_dir do
824
+ match_snippet = <<-LIQUID
825
+ {% minibundle js %}
826
+ source_dir: _assets/scripts
827
+ destination_path: assets/site
828
+ assets:
829
+ - dependency
830
+ - app
831
+ LIQUID
832
+
833
+ replacement_snippet = <<-LIQUID
834
+ {% minibundle js %}
835
+ source_dir: .
836
+ destination_path: assets/site
837
+ assets:
838
+ - _assets/scripts/dependency
839
+ - _assets/scripts/app
840
+ LIQUID
841
+
842
+ find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
843
+
844
+ generate_site(:production)
845
+
846
+ assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
847
+ assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
848
+ end
849
+ end
850
+
763
851
  private
764
852
 
765
853
  def find_css_element_from_index
@@ -790,17 +878,17 @@ title: Test
790
878
  end
791
879
 
792
880
  def change_destination_path_in_minibundle_block(from, to)
793
- match_snippet = <<-END
881
+ match_snippet = <<-LIQUID
794
882
  {% minibundle js %}
795
883
  source_dir: _assets/scripts
796
884
  destination_path: #{from}
797
- END
885
+ LIQUID
798
886
 
799
- replacement_snippet = <<-END
887
+ replacement_snippet = <<-LIQUID
800
888
  {% minibundle js %}
801
889
  source_dir: _assets/scripts
802
890
  destination_path: #{to}
803
- END
891
+ LIQUID
804
892
 
805
893
  find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
806
894
  end