jekyll-minibundle 3.0.0 → 4.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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +78 -66
  3. data/README.md +117 -101
  4. data/Rakefile +8 -26
  5. data/jekyll-minibundle.gemspec +5 -11
  6. data/lib/jekyll/minibundle/asset_bundle.rb +1 -1
  7. data/lib/jekyll/minibundle/asset_file_drop.rb +1 -3
  8. data/lib/jekyll/minibundle/asset_file_registry.rb +2 -2
  9. data/lib/jekyll/minibundle/asset_tag_markup.rb +1 -1
  10. data/lib/jekyll/minibundle/bundle_file.rb +3 -0
  11. data/lib/jekyll/minibundle/development_file.rb +2 -0
  12. data/lib/jekyll/minibundle/hashes.rb +1 -3
  13. data/lib/jekyll/minibundle/stamp_file.rb +3 -0
  14. data/lib/jekyll/minibundle/variable_template.rb +3 -1
  15. data/lib/jekyll/minibundle/variable_template_registry.rb +2 -2
  16. data/lib/jekyll/minibundle/version.rb +1 -1
  17. metadata +8 -184
  18. data/test/fixture/site/_assets/scripts/app.js +0 -5
  19. data/test/fixture/site/_assets/scripts/dependency.js +0 -4
  20. data/test/fixture/site/_assets/styles/common.css +0 -2
  21. data/test/fixture/site/_assets/styles/reset.css +0 -2
  22. data/test/fixture/site/_bin/remove_comments +0 -4
  23. data/test/fixture/site/_bin/with_count +0 -15
  24. data/test/fixture/site/_config.yml +0 -3
  25. data/test/fixture/site/_layouts/default.html +0 -29
  26. data/test/fixture/site/_tmp/site.css +0 -3
  27. data/test/fixture/site/about.html +0 -4
  28. data/test/fixture/site/assets/site.css +0 -2
  29. data/test/fixture/site/index.html +0 -4
  30. data/test/integration/minibundle_development_mode_test.rb +0 -554
  31. data/test/integration/minibundle_production_mode_test.rb +0 -900
  32. data/test/integration/ministamp_development_mode_test.rb +0 -235
  33. data/test/integration/ministamp_production_mode_test.rb +0 -342
  34. data/test/integration/static_files_as_asset_sources_test.rb +0 -75
  35. data/test/support/assertions.rb +0 -26
  36. data/test/support/fixture_config.rb +0 -20
  37. data/test/support/static_file_config.rb +0 -23
  38. data/test/support/test_case.rb +0 -175
  39. data/test/unit/asset_bundle_test.rb +0 -57
  40. data/test/unit/asset_file_drop_test.rb +0 -66
  41. data/test/unit/asset_file_registry_test.rb +0 -237
  42. data/test/unit/asset_tag_markup_test.rb +0 -46
  43. data/test/unit/bundle_file_properties_test.rb +0 -108
  44. data/test/unit/bundle_file_writing_test.rb +0 -155
  45. data/test/unit/development_file_properties_test.rb +0 -97
  46. data/test/unit/development_file_writing_test.rb +0 -50
  47. data/test/unit/environment_test.rb +0 -29
  48. data/test/unit/files_test.rb +0 -61
  49. data/test/unit/hashes_test.rb +0 -43
  50. data/test/unit/jekyll_static_file_api_test.rb +0 -172
  51. data/test/unit/mini_bundle_block_test.rb +0 -125
  52. data/test/unit/mini_stamp_tag_test.rb +0 -64
  53. data/test/unit/stamp_file_properties_test.rb +0 -98
  54. data/test/unit/stamp_file_writing_test.rb +0 -130
  55. data/test/unit/variable_template_test.rb +0 -121
@@ -1,235 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../support/test_case'
4
- require_relative '../support/fixture_config'
5
-
6
- module Jekyll::Minibundle::Test
7
- class MinistampDevelopmentModeTest < TestCase
8
- include FixtureConfig
9
-
10
- def test_asset_destination_path_has_no_stamp
11
- with_precompiled_site(:development) do
12
- assert_equal(STAMP_DESTINATION_PATH, find_css_path_from_index)
13
- assert(File.file?(destination_path(STAMP_DESTINATION_PATH)))
14
- end
15
- end
16
-
17
- def test_contents_of_asset_destination_are_equal_to_source
18
- with_precompiled_site(:development) do
19
- source_contents = File.read(site_fixture_path(STAMP_SOURCE_PATH))
20
- destination_contents = File.read(destination_path(STAMP_DESTINATION_PATH))
21
- assert_equal(source_contents, destination_contents)
22
- end
23
- end
24
-
25
- def test_changing_asset_source_file_rewrites_destination
26
- with_site_dir do
27
- generate_site(:development)
28
-
29
- org_mtime = file_mtime_of(destination_path(STAMP_DESTINATION_PATH))
30
- ensure_file_mtime_changes { File.write(source_path(STAMP_SOURCE_PATH), 'h1 {}') }
31
-
32
- generate_site(:development, clear_cache: false)
33
-
34
- new_mtime = file_mtime_of(destination_path(STAMP_DESTINATION_PATH))
35
- assert_operator(new_mtime, :>, org_mtime)
36
- end
37
- end
38
-
39
- def test_touching_asset_source_file_rewrites_destination
40
- with_site_dir do
41
- generate_site(:development)
42
-
43
- org_mtime = file_mtime_of(destination_path(STAMP_DESTINATION_PATH))
44
- ensure_file_mtime_changes { FileUtils.touch(source_path(STAMP_SOURCE_PATH)) }
45
-
46
- generate_site(:development, clear_cache: false)
47
-
48
- new_mtime = file_mtime_of(destination_path(STAMP_DESTINATION_PATH))
49
- assert_operator(new_mtime, :>, org_mtime)
50
- end
51
- end
52
-
53
- def test_changing_asset_source_path_rewrites_destination
54
- with_site_dir do
55
- generate_site(:development)
56
-
57
- org_mtime = file_mtime_of(destination_path(STAMP_DESTINATION_PATH))
58
-
59
- ensure_file_mtime_changes do
60
- FileUtils.mv(source_path('_tmp/site.css'), source_path('_tmp/site2.css'))
61
-
62
- find_and_gsub_in_file(
63
- source_path('_layouts/default.html'),
64
- '{% ministamp _tmp/site.css assets/screen.css',
65
- '{% ministamp _tmp/site2.css assets/screen.css'
66
- )
67
- end
68
-
69
- generate_site(:development, clear_cache: false)
70
-
71
- new_mtime = file_mtime_of(destination_path(STAMP_DESTINATION_PATH))
72
-
73
- assert_operator(new_mtime, :>, org_mtime)
74
- end
75
- end
76
-
77
- def test_changing_asset_destination_path_rewrites_destination
78
- with_site_dir do
79
- generate_site(:development)
80
-
81
- assert(File.file?(destination_path(STAMP_DESTINATION_PATH)))
82
-
83
- ensure_file_mtime_changes do
84
- find_and_gsub_in_file(
85
- source_path('_layouts/default.html'),
86
- '{% ministamp _tmp/site.css assets/screen.css',
87
- '{% ministamp _tmp/site.css assets/screen2.css'
88
- )
89
- end
90
-
91
- generate_site(:development, clear_cache: false)
92
-
93
- refute(File.file?(destination_path(STAMP_DESTINATION_PATH)))
94
-
95
- new_destination = 'assets/screen2.css'
96
-
97
- assert_equal(new_destination, find_css_path_from_index)
98
- assert(File.file?(destination_path(new_destination)))
99
- end
100
- end
101
-
102
- def test_changing_asset_destination_path_to_new_value_and_back_to_original_rewrites_destination
103
- with_site_dir do
104
- generate_site(:development)
105
-
106
- assert(File.file?(destination_path(STAMP_DESTINATION_PATH)))
107
-
108
- ensure_file_mtime_changes do
109
- find_and_gsub_in_file(
110
- source_path('_layouts/default.html'),
111
- '{% ministamp _tmp/site.css assets/screen.css',
112
- '{% ministamp _tmp/site.css assets/screen2.css'
113
- )
114
- end
115
-
116
- generate_site(:development, clear_cache: false)
117
-
118
- refute(File.file?(destination_path(STAMP_DESTINATION_PATH)))
119
-
120
- new_destination = 'assets/screen2.css'
121
-
122
- assert_equal(new_destination, find_css_path_from_index)
123
- assert(File.file?(destination_path(new_destination)))
124
-
125
- ensure_file_mtime_changes do
126
- find_and_gsub_in_file(
127
- source_path('_layouts/default.html'),
128
- '{% ministamp _tmp/site.css assets/screen2.css',
129
- '{% ministamp _tmp/site.css assets/screen.css'
130
- )
131
- end
132
-
133
- generate_site(:development, clear_cache: false)
134
-
135
- refute(File.file?(destination_path(new_destination)))
136
-
137
- assert_equal(STAMP_DESTINATION_PATH, find_css_path_from_index)
138
- assert(File.file?(destination_path(STAMP_DESTINATION_PATH)))
139
- end
140
- end
141
-
142
- def test_supports_relative_and_absolute_destination_paths
143
- with_site_dir do
144
- generate_site(:development)
145
-
146
- destination = destination_path(STAMP_DESTINATION_PATH)
147
- org_mtime = file_mtime_of(destination)
148
-
149
- assert(File.file?(destination))
150
- assert_equal(STAMP_DESTINATION_PATH, find_css_path_from_index)
151
-
152
- ensure_file_mtime_changes do
153
- find_and_gsub_in_file(
154
- source_path('_layouts/default.html'),
155
- '{% ministamp _tmp/site.css assets/screen.css',
156
- '{% ministamp _tmp/site.css /assets/screen.css'
157
- )
158
- end
159
-
160
- generate_site(:development, clear_cache: false)
161
-
162
- assert(File.file?(destination))
163
- assert_equal(org_mtime, file_mtime_of(destination))
164
- assert_equal("/#{STAMP_DESTINATION_PATH}", find_css_path_from_index)
165
- end
166
- end
167
-
168
- def test_supports_yaml_hash_argument_with_render_basename_only_option
169
- with_site_dir do
170
- find_and_gsub_in_file(
171
- source_path('_layouts/default.html'),
172
- '{% ministamp _tmp/site.css assets/screen.css',
173
- %({% ministamp { source_path: _tmp/site.css, destination_path: /assets/screen.css, render_basename_only: true })
174
- )
175
-
176
- generate_site(:development)
177
-
178
- assert(File.file?(destination_path(STAMP_DESTINATION_PATH)))
179
- assert_equal('screen.css', find_css_path_from_index)
180
- end
181
- end
182
-
183
- def test_does_not_rewrite_destination_when_changing_nonsource_files
184
- with_site_dir do
185
- generate_site(:development)
186
-
187
- expected_path = destination_path(STAMP_DESTINATION_PATH)
188
- org_mtime = file_mtime_of(expected_path)
189
- ensure_file_mtime_changes { File.write(source_path(JS_BUNDLE_SOURCE_DIR, 'dependency.js'), '(function() {})()') }
190
-
191
- generate_site(:development, clear_cache: false)
192
-
193
- assert_equal(org_mtime, file_mtime_of(expected_path))
194
-
195
- ensure_file_mtime_changes { FileUtils.touch('index.html') }
196
-
197
- generate_site(:development, clear_cache: false)
198
-
199
- assert_equal(org_mtime, file_mtime_of(expected_path))
200
- end
201
- end
202
-
203
- def test_does_not_rewrite_destination_when_changing_render_basename_only_option
204
- with_site_dir do
205
- generate_site(:development)
206
-
207
- destination = destination_path(STAMP_DESTINATION_PATH)
208
- org_mtime = file_mtime_of(destination)
209
-
210
- assert(File.file?(destination))
211
- assert_equal(STAMP_DESTINATION_PATH, find_css_path_from_index)
212
-
213
- ensure_file_mtime_changes do
214
- find_and_gsub_in_file(
215
- source_path('_layouts/default.html'),
216
- '<link rel="stylesheet" href="{% ministamp _tmp/site.css assets/screen.css %}" media="screen">',
217
- %(<link rel="stylesheet" href="{% ministamp { source_path: _tmp/site.css, destination_path: assets/screen.css, render_basename_only: true } %}" media="screen">)
218
- )
219
- end
220
-
221
- generate_site(:development, clear_cache: false)
222
-
223
- assert(File.file?(destination))
224
- assert_equal(org_mtime, file_mtime_of(destination))
225
- assert_equal('screen.css', find_css_path_from_index)
226
- end
227
- end
228
-
229
- private
230
-
231
- def find_css_path_from_index
232
- find_html_element(File.read(destination_path('index.html')), 'head link').first['href']
233
- end
234
- end
235
- end
@@ -1,342 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../support/test_case'
4
- require_relative '../support/fixture_config'
5
-
6
- module Jekyll::Minibundle::Test
7
- class MinistampProductionModeTest < TestCase
8
- include FixtureConfig
9
-
10
- def test_asset_destination_path_has_stamp
11
- with_precompiled_site(:production) do
12
- assert_equal(STAMP_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
13
- assert(File.file?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)))
14
- end
15
- end
16
-
17
- def test_contents_of_asset_destination_are_equal_to_source
18
- with_precompiled_site(:production) do
19
- source_contents = File.read(site_fixture_path(STAMP_SOURCE_PATH))
20
- destination_contents = File.read(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
21
- assert_equal(source_contents, destination_contents)
22
- end
23
- end
24
-
25
- def test_changing_asset_source_file_rewrites_destination
26
- with_site_dir do
27
- generate_site(:production)
28
-
29
- ensure_file_mtime_changes { File.write(source_path(STAMP_SOURCE_PATH), 'h1 {}') }
30
-
31
- generate_site(:production, clear_cache: false)
32
-
33
- refute(File.file?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)))
34
-
35
- new_destination = 'assets/screen-0f5dbd1e527a2bee267e85007b08d2a5.css'
36
-
37
- assert_equal(new_destination, find_css_path_from_index)
38
- assert(File.file?(destination_path(new_destination)))
39
- end
40
- end
41
-
42
- def test_touching_asset_source_file_rewrites_destination
43
- with_site_dir do
44
- generate_site(:production)
45
-
46
- org_mtime = file_mtime_of(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
47
- ensure_file_mtime_changes { FileUtils.touch(source_path(STAMP_SOURCE_PATH)) }
48
- generate_site(:production, clear_cache: false)
49
-
50
- assert_equal(STAMP_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
51
-
52
- new_mtime = file_mtime_of(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
53
- assert_operator(new_mtime, :>, org_mtime)
54
- end
55
- end
56
-
57
- def test_changing_asset_source_path_rewrites_destination
58
- with_site_dir do
59
- generate_site(:production)
60
-
61
- org_mtime = file_mtime_of(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
62
-
63
- ensure_file_mtime_changes do
64
- FileUtils.mv(source_path('_tmp/site.css'), source_path('_tmp/site2.css'))
65
-
66
- find_and_gsub_in_file(
67
- source_path('_layouts/default.html'),
68
- '{% ministamp _tmp/site.css assets/screen.css',
69
- '{% ministamp _tmp/site2.css assets/screen.css'
70
- )
71
- end
72
-
73
- generate_site(:production, clear_cache: false)
74
-
75
- new_mtime = file_mtime_of(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
76
-
77
- assert_operator(new_mtime, :>, org_mtime)
78
- end
79
- end
80
-
81
- def test_changing_asset_destination_path_rewrites_destination
82
- with_site_dir do
83
- generate_site(:production)
84
-
85
- assert(File.file?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)))
86
-
87
- ensure_file_mtime_changes do
88
- find_and_gsub_in_file(
89
- source_path('_layouts/default.html'),
90
- '{% ministamp _tmp/site.css assets/screen.css',
91
- '{% ministamp _tmp/site.css assets/screen2.css'
92
- )
93
- end
94
-
95
- generate_site(:production, clear_cache: false)
96
-
97
- refute(File.file?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)))
98
-
99
- new_destination = "assets/screen2-#{STAMP_FINGERPRINT}.css"
100
-
101
- assert_equal(new_destination, find_css_path_from_index)
102
- assert(File.file?(destination_path(new_destination)))
103
- end
104
- end
105
-
106
- def test_changing_asset_destination_path_to_new_value_and_back_to_original_rewrites_destination
107
- with_site_dir do
108
- generate_site(:production)
109
-
110
- assert(File.file?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)))
111
-
112
- ensure_file_mtime_changes do
113
- find_and_gsub_in_file(
114
- source_path('_layouts/default.html'),
115
- '{% ministamp _tmp/site.css assets/screen.css',
116
- '{% ministamp _tmp/site.css assets/screen2.css'
117
- )
118
- end
119
-
120
- generate_site(:production, clear_cache: false)
121
-
122
- refute(File.file?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)))
123
-
124
- new_destination = "assets/screen2-#{STAMP_FINGERPRINT}.css"
125
-
126
- assert_equal(new_destination, find_css_path_from_index)
127
- assert(File.file?(destination_path(new_destination)))
128
-
129
- ensure_file_mtime_changes do
130
- find_and_gsub_in_file(
131
- source_path('_layouts/default.html'),
132
- '{% ministamp _tmp/site.css assets/screen2.css',
133
- '{% ministamp _tmp/site.css assets/screen.css'
134
- )
135
- end
136
-
137
- generate_site(:production, clear_cache: false)
138
-
139
- refute(File.file?(destination_path(new_destination)))
140
-
141
- assert_equal(STAMP_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
142
- assert(File.file?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)))
143
- end
144
- end
145
-
146
- def test_supports_relative_and_absolute_destination_paths
147
- with_site_dir do
148
- generate_site(:production)
149
-
150
- destination = destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)
151
- org_mtime = file_mtime_of(destination)
152
-
153
- assert(File.file?(destination))
154
- assert_equal(STAMP_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
155
-
156
- ensure_file_mtime_changes do
157
- find_and_gsub_in_file(
158
- source_path('_layouts/default.html'),
159
- '{% ministamp _tmp/site.css assets/screen.css',
160
- '{% ministamp _tmp/site.css /assets/screen.css'
161
- )
162
- end
163
-
164
- generate_site(:production, clear_cache: false)
165
-
166
- assert(File.file?(destination))
167
- assert_equal(org_mtime, file_mtime_of(destination))
168
- assert_equal("/#{STAMP_DESTINATION_FINGERPRINT_PATH}", find_css_path_from_index)
169
- end
170
- end
171
-
172
- def test_strips_dot_slash_from_relative_destination_path
173
- with_site_dir do
174
- find_and_gsub_in_file(
175
- source_path('_layouts/default.html'),
176
- '{% ministamp _tmp/site.css assets/screen.css',
177
- '{% ministamp _tmp/site.css screen.css'
178
- )
179
-
180
- generate_site(:production)
181
-
182
- destination = destination_path("screen-#{STAMP_FINGERPRINT}.css")
183
- org_mtime = file_mtime_of(destination)
184
-
185
- assert(File.file?(destination))
186
- assert_equal("screen-#{STAMP_FINGERPRINT}.css", find_css_path_from_index)
187
-
188
- ensure_file_mtime_changes do
189
- generate_site(:production, clear_cache: false)
190
- end
191
-
192
- assert(File.file?(destination))
193
- assert_equal(org_mtime, file_mtime_of(destination))
194
- assert_equal("screen-#{STAMP_FINGERPRINT}.css", find_css_path_from_index)
195
- end
196
- end
197
-
198
- def test_strips_dot_slash_from_destination_path
199
- with_site_dir do
200
- find_and_gsub_in_file(
201
- source_path('_layouts/default.html'),
202
- '{% ministamp _tmp/site.css assets/screen.css',
203
- '{% ministamp _tmp/site.css ./screen.css'
204
- )
205
-
206
- generate_site(:production)
207
-
208
- destination = destination_path("screen-#{STAMP_FINGERPRINT}.css")
209
- org_mtime = file_mtime_of(destination)
210
-
211
- assert(File.file?(destination))
212
- assert_equal("screen-#{STAMP_FINGERPRINT}.css", find_css_path_from_index)
213
-
214
- ensure_file_mtime_changes do
215
- generate_site(:production, clear_cache: false)
216
- end
217
-
218
- assert(File.file?(destination))
219
- assert_equal(org_mtime, file_mtime_of(destination))
220
- assert_equal("screen-#{STAMP_FINGERPRINT}.css", find_css_path_from_index)
221
- end
222
- end
223
-
224
- def test_supports_yaml_hash_argument_with_source_and_destination_paths
225
- with_site_dir do
226
- find_and_gsub_in_file(
227
- source_path('_layouts/default.html'),
228
- '<link rel="stylesheet" href="{% ministamp _tmp/site.css assets/screen.css %}" media="screen">',
229
- %(<link rel="stylesheet" href="{% ministamp { source_path: _tmp/site.css, destination_path: assets/screen.css } %}" media="screen">)
230
- )
231
-
232
- generate_site(:production)
233
-
234
- assert(File.file?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)))
235
- assert_equal(STAMP_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
236
- end
237
- end
238
-
239
- def test_supports_yaml_hash_argument_with_source_and_destination_paths_with_liquid_variables
240
- with_site_dir do
241
- find_and_gsub_in_file(
242
- source_path('_layouts/default.html'),
243
- ' <link rel="stylesheet" href="{% ministamp _tmp/site.css assets/screen.css %}" media="screen">',
244
- <<-LIQUID
245
- {% assign stamp_source_filename = 'site' %}
246
- {% assign stamp_destination_url = 'assets/screen.css' %}
247
- <link rel="stylesheet" href="{% ministamp { source_path: '_tmp/{{ stamp_source_filename }}.css', destination_path: '{{ stamp_destination_url }}' } %}" media="screen">
248
- LIQUID
249
- )
250
-
251
- generate_site(:production)
252
-
253
- assert(File.file?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)))
254
- assert_equal(STAMP_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
255
- end
256
- end
257
-
258
- def test_supports_yaml_hash_argument_with_render_basename_only_option
259
- with_site_dir do
260
- find_and_gsub_in_file(
261
- source_path('_layouts/default.html'),
262
- '{% ministamp _tmp/site.css assets/screen.css',
263
- %({% ministamp { source_path: _tmp/site.css, destination_path: /assets/screen.css, render_basename_only: true })
264
- )
265
-
266
- generate_site(:production)
267
-
268
- assert(File.file?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)))
269
- assert_equal("screen-#{STAMP_FINGERPRINT}.css", find_css_path_from_index)
270
- end
271
- end
272
-
273
- def test_does_not_rewrite_destination_when_changing_nonsource_files
274
- with_site_dir do
275
- generate_site(:production)
276
-
277
- expected_path = destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)
278
- org_mtime = file_mtime_of(expected_path)
279
- ensure_file_mtime_changes { File.write(source_path(JS_BUNDLE_SOURCE_DIR, 'dependency.js'), '(function() {})()') }
280
-
281
- generate_site(:production, clear_cache: false)
282
-
283
- assert_equal(org_mtime, file_mtime_of(expected_path))
284
-
285
- ensure_file_mtime_changes { FileUtils.touch('index.html') }
286
-
287
- generate_site(:production, clear_cache: false)
288
-
289
- assert_equal(org_mtime, file_mtime_of(expected_path))
290
- end
291
- end
292
-
293
- def test_does_not_rewrite_destination_when_changing_render_basename_only_option
294
- with_site_dir do
295
- generate_site(:production)
296
-
297
- destination = destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)
298
- org_mtime = file_mtime_of(destination)
299
-
300
- assert(File.file?(destination))
301
- assert_equal(STAMP_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
302
-
303
- ensure_file_mtime_changes do
304
- find_and_gsub_in_file(
305
- source_path('_layouts/default.html'),
306
- '<link rel="stylesheet" href="{% ministamp _tmp/site.css assets/screen.css %}" media="screen">',
307
- %(<link rel="stylesheet" href="{% ministamp { source_path: _tmp/site.css, destination_path: assets/screen.css, render_basename_only: true } %}" media="screen">)
308
- )
309
- end
310
-
311
- generate_site(:production, clear_cache: false)
312
-
313
- assert(File.file?(destination))
314
- assert_equal(org_mtime, file_mtime_of(destination))
315
- assert_equal("screen-#{STAMP_FINGERPRINT}.css", find_css_path_from_index)
316
- end
317
- end
318
-
319
- def test_escapes_generated_url
320
- with_site_dir do
321
- find_and_gsub_in_file(
322
- source_path('_layouts/default.html'),
323
- '{% ministamp _tmp/site.css assets/screen.css %}',
324
- %({% ministamp { source_path: '_tmp/site.css', destination_path: 'scre">en.css' } %})
325
- )
326
-
327
- generate_site(:production)
328
-
329
- filename = %(scre">en-#{STAMP_FINGERPRINT}.css)
330
-
331
- assert(File.file?(destination_path(filename)))
332
- assert_equal(filename, find_css_path_from_index)
333
- end
334
- end
335
-
336
- private
337
-
338
- def find_css_path_from_index
339
- find_html_element(File.read(destination_path('index.html')), 'head link').first['href']
340
- end
341
- end
342
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../support/test_case'
4
- require_relative '../support/fixture_config'
5
-
6
- module Jekyll::Minibundle::Test
7
- class StaticFilesAsAssetSourcesTest < TestCase
8
- include FixtureConfig
9
-
10
- def test_asset_and_static_files_with_same_destination_paths_can_coexist
11
- with_precompiled_site(:production) do
12
- actual = Dir[destination_path('assets/site*.*')].sort
13
- expected = [
14
- destination_path('assets/site.css'),
15
- destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH),
16
- destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
17
- ].sort
18
- assert_equal(expected, actual)
19
- end
20
- end
21
-
22
- %i[development production].each do |env|
23
- define_method :"test_ministamp_allows_using_static_file_as_asset_source_in_#{env}_mode" do
24
- with_site_dir do
25
- contents = 'h2 {}'
26
- File.write(source_path('assets/shared.css'), contents)
27
- find_and_gsub_in_file(source_path('_layouts/default.html'), 'ministamp _tmp/site.css', 'ministamp assets/shared.css')
28
-
29
- generate_site(env)
30
-
31
- asset_files = Dir["#{destination_path('assets')}/screen*.css"]
32
-
33
- assert_equal(1, asset_files.size)
34
- assert_equal(contents, File.read(destination_path('assets/shared.css')))
35
- assert_equal(contents, File.read(asset_files.first))
36
- end
37
- end
38
- end
39
-
40
- def test_minibundle_allows_using_static_file_as_asset_source_in_development_mode
41
- with_site_dir do
42
- dep_contents = 'console.log("lol")'
43
- app_contents = 'console.log("balal")'
44
- File.write(source_path('assets/dependency.js'), dep_contents)
45
- File.write(source_path('assets/app.js'), app_contents)
46
- find_and_gsub_in_file(source_path('_layouts/default.html'), 'source_dir: _assets/scripts', 'source_dir: assets')
47
-
48
- generate_site(:development)
49
-
50
- assert_equal(dep_contents, File.read(destination_path('assets/dependency.js')))
51
- assert_equal(app_contents, File.read(destination_path('assets/app.js')))
52
- end
53
- end
54
-
55
- def test_minibundle_allows_using_static_file_as_asset_source_in_production_mode
56
- with_site_dir do
57
- dep_contents = 'console.log("lol")'
58
- app_contents = 'console.log("balal")'
59
- bundled_contents = "#{dep_contents};\n#{app_contents};\n"
60
- File.write(source_path('assets/dependency.js'), dep_contents)
61
- File.write(source_path('assets/app.js'), app_contents)
62
- find_and_gsub_in_file(source_path('_layouts/default.html'), 'source_dir: _assets/scripts', 'source_dir: assets')
63
-
64
- generate_site(:production)
65
-
66
- asset_files = Dir[destination_path('assets/site-*.js')]
67
-
68
- assert_equal(1, asset_files.size)
69
- assert_equal(dep_contents, File.read(destination_path('assets/dependency.js')))
70
- assert_equal(app_contents, File.read(destination_path('assets/app.js')))
71
- assert_equal(bundled_contents, File.read(asset_files.first))
72
- end
73
- end
74
- end
75
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll::Minibundle::Test
4
- module Assertions
5
- def assert_contains_only(collection, expected_elements)
6
- assert_respond_to collection, :size
7
-
8
- collection_size = collection.size
9
- expected_elements_size = expected_elements.size
10
-
11
- assert_equal(expected_elements_size, collection_size, lambda do
12
- "Expected #{mu_pp(collection)} to have size #{expected_elements_size} instead of #{collection_size}"
13
- end)
14
-
15
- remaining = collection.dup.to_a
16
- expected_elements.each do |e|
17
- index = remaining.index(e)
18
- remaining.delete_at(index) if index
19
- end
20
-
21
- assert(remaining.empty?, lambda do
22
- "Expected\n\n#{mu_pp(collection)}\n\nto include only\n\n#{mu_pp(expected_elements)}"
23
- end)
24
- end
25
- end
26
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll::Minibundle::Test
4
- module FixtureConfig
5
- STAMP_SOURCE_PATH = '_tmp/site.css'
6
- STAMP_DESTINATION_PATH = 'assets/screen.css'
7
- STAMP_FINGERPRINT = 'd57c1404fe726e66d57128a1bd190cbb'
8
- STAMP_DESTINATION_FINGERPRINT_PATH = "assets/screen-#{STAMP_FINGERPRINT}.css"
9
-
10
- CSS_BUNDLE_SOURCE_DIR = '_assets/styles'
11
- CSS_BUNDLE_DESTINATION_PATH = 'assets/site'
12
- CSS_BUNDLE_FINGERPRINT = 'b2e0ecc1c100effc2c7353caad20c327'
13
- CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH = "#{CSS_BUNDLE_DESTINATION_PATH}-#{CSS_BUNDLE_FINGERPRINT}.css"
14
-
15
- JS_BUNDLE_SOURCE_DIR = '_assets/scripts'
16
- JS_BUNDLE_DESTINATION_PATH = 'assets/site'
17
- JS_BUNDLE_FINGERPRINT = '4782a1f67803038d4f8351051e67deb8'
18
- JS_BUNDLE_DESTINATION_FINGERPRINT_PATH = "#{JS_BUNDLE_DESTINATION_PATH}-#{JS_BUNDLE_FINGERPRINT}.js"
19
- end
20
- end