jekyll-minibundle 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/README.md +6 -2
  4. data/jekyll-minibundle.gemspec +1 -1
  5. data/lib/jekyll/minibundle/asset_bundle.rb +10 -5
  6. data/lib/jekyll/minibundle/asset_file_properties.rb +1 -5
  7. data/lib/jekyll/minibundle/asset_tag_markup.rb +3 -12
  8. data/lib/jekyll/minibundle/bundle_file.rb +25 -16
  9. data/lib/jekyll/minibundle/development_file.rb +14 -4
  10. data/lib/jekyll/minibundle/files.rb +22 -9
  11. data/lib/jekyll/minibundle/mini_bundle_block.rb +14 -10
  12. data/lib/jekyll/minibundle/mini_stamp_tag.rb +2 -1
  13. data/lib/jekyll/minibundle/stamp_file.rb +21 -9
  14. data/lib/jekyll/minibundle/version.rb +1 -1
  15. data/test/fixture/site/_layouts/default.html +1 -1
  16. data/test/integration/minibundle_development_mode_test.rb +18 -3
  17. data/test/integration/minibundle_production_mode_test.rb +108 -4
  18. data/test/integration/ministamp_development_mode_test.rb +13 -6
  19. data/test/integration/ministamp_production_mode_test.rb +63 -4
  20. data/test/support/static_file_api_config.rb +1 -0
  21. data/test/support/test_case.rb +4 -4
  22. data/test/unit/asset_bundle_test.rb +15 -8
  23. data/test/unit/asset_file_registry_test.rb +3 -3
  24. data/test/unit/asset_tag_markup_test.rb +5 -17
  25. data/test/unit/bundle_file_properties_test.rb +4 -0
  26. data/test/unit/bundle_file_writing_test.rb +54 -18
  27. data/test/unit/development_file_collection_properties_test.rb +5 -0
  28. data/test/unit/development_file_writing_test.rb +39 -0
  29. data/test/unit/environment_test.rb +4 -4
  30. data/test/unit/files_test.rb +13 -0
  31. data/test/unit/jekyll_static_file_api_test.rb +1 -1
  32. data/test/unit/mini_bundle_block_test.rb +1 -1
  33. data/test/unit/mini_stamp_tag_test.rb +1 -1
  34. data/test/unit/stamp_file_properties_test.rb +4 -0
  35. data/test/unit/stamp_file_writing_test.rb +54 -18
  36. metadata +7 -6
  37. data/lib/jekyll/minibundle/asset_file_operations.rb +0 -16
@@ -41,6 +41,10 @@ module Jekyll::Minibundle::Test
41
41
  assert_equal mtime.to_i, @@results.fetch(:mtime)
42
42
  end
43
43
 
44
+ def test_path
45
+ assert_match(%r{/jekyll-minibundle-.+\.js\z}, @@results.fetch(:path))
46
+ end
47
+
44
48
  def test_placeholders
45
49
  assert_equal({}, @@results.fetch(:placeholders))
46
50
  end
@@ -8,35 +8,49 @@ module Jekyll::Minibundle::Test
8
8
 
9
9
  def test_calling_destination_path_for_markup_determines_fingerprint_and_destination_write
10
10
  with_fake_site do |site|
11
- bundle_file = BundleFile.new(site, bundle_config(minifier_cmd_to_remove_comments_and_count))
11
+ bundle_file = make_bundle_file(site)
12
12
  source = source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')
13
13
  old_destination = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
14
14
  org_markup_path, last_markup_path = nil
15
+
16
+ # the call to destination_path_for_markup determines the
17
+ # fingerprint
18
+
15
19
  capture_io { org_markup_path = bundle_file.destination_path_for_markup }
16
20
 
17
- assert bundle_file.write('_site')
21
+ assert write_file(bundle_file)
18
22
 
19
23
  org_mtime = file_mtime_of(old_destination)
20
24
 
21
25
  assert_equal 1, get_minifier_cmd_count
22
26
 
23
27
  last_markup_path = bundle_file.destination_path_for_markup
24
- ensure_file_mtime_changes { File.write(source, '(function() {})()') }
25
28
 
26
- # preserve fingerprint and content seen in last markup phase
27
- refute bundle_file.write('_site')
28
29
  assert_equal org_markup_path, last_markup_path
30
+ assert_equal 1, get_minifier_cmd_count
31
+
32
+ # change content, but don't call destination_path_for_markup yet
33
+
34
+ ensure_file_mtime_changes { File.write(source, '(function() {})()') }
35
+
36
+ # preserve content's fingerprint
37
+
38
+ refute write_file(bundle_file)
39
+
29
40
  assert_equal org_mtime, file_mtime_of(old_destination)
30
41
  assert_equal 1, get_minifier_cmd_count
31
42
 
43
+ # see content's fingerprint to update after calling
44
+ # destination_path_for_markup
45
+
32
46
  capture_io { last_markup_path = bundle_file.destination_path_for_markup }
33
47
 
34
- assert bundle_file.write('_site')
48
+ refute_equal org_markup_path, last_markup_path
49
+
50
+ assert write_file(bundle_file)
35
51
 
36
52
  new_destination = destination_path('assets/site-375a0b430b0c5555d0edd2205d26c04d.js')
37
53
 
38
- # see updated fingerprint in the next round
39
- refute_equal org_markup_path, last_markup_path
40
54
  assert_operator file_mtime_of(new_destination), :>, org_mtime
41
55
  assert_equal 2, get_minifier_cmd_count
42
56
  end
@@ -44,14 +58,14 @@ module Jekyll::Minibundle::Test
44
58
 
45
59
  def test_many_consecutive_destination_path_for_markup_calls_trigger_one_destination_write
46
60
  with_fake_site do |site|
47
- bundle_file = BundleFile.new(site, bundle_config(minifier_cmd_to_remove_comments_and_count))
61
+ bundle_file = make_bundle_file(site)
48
62
  source = source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')
49
63
  destination = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
50
64
  org_markup_path, last_markup_path = nil
51
65
  capture_io { org_markup_path = bundle_file.destination_path_for_markup }
52
66
  bundle_file.destination_path_for_markup
53
67
 
54
- assert bundle_file.write('_site')
68
+ assert write_file(bundle_file)
55
69
 
56
70
  org_mtime = file_mtime_of(destination)
57
71
 
@@ -61,7 +75,7 @@ module Jekyll::Minibundle::Test
61
75
  capture_io { last_markup_path = bundle_file.destination_path_for_markup }
62
76
  bundle_file.destination_path_for_markup
63
77
 
64
- assert bundle_file.write('_site')
78
+ assert write_file(bundle_file)
65
79
  assert_equal org_markup_path, last_markup_path
66
80
  assert_operator file_mtime_of(destination), :>, org_mtime
67
81
  assert_equal 2, get_minifier_cmd_count
@@ -70,30 +84,52 @@ module Jekyll::Minibundle::Test
70
84
 
71
85
  def test_calling_write_before_destination_path_for_markup_has_no_effect
72
86
  with_fake_site do |site|
73
- bundle_file = BundleFile.new(site, bundle_config(minifier_cmd_to_remove_comments_and_count))
87
+ bundle_file = make_bundle_file(site)
74
88
 
75
- refute bundle_file.write('_site')
89
+ refute write_file(bundle_file)
76
90
  assert_empty Dir[destination_path('assets/*.js')]
77
91
  assert_equal 0, get_minifier_cmd_count
78
92
 
79
93
  capture_io { bundle_file.destination_path_for_markup }
80
94
 
81
- assert bundle_file.write('_site')
95
+ assert write_file(bundle_file)
82
96
  assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
83
97
  assert_equal 1, get_minifier_cmd_count
84
98
  end
85
99
  end
86
100
 
101
+ def test_modified_property_determines_if_write_would_succeed
102
+ with_fake_site do |site|
103
+ bundle_file = make_bundle_file(site)
104
+
105
+ refute bundle_file.modified?
106
+ refute write_file(bundle_file)
107
+
108
+ capture_io { bundle_file.destination_path_for_markup }
109
+
110
+ assert bundle_file.modified?
111
+ assert write_file(bundle_file)
112
+
113
+ refute bundle_file.modified?
114
+ refute write_file(bundle_file)
115
+ end
116
+ end
117
+
87
118
  private
88
119
 
89
- def bundle_config(minifier_cmd)
90
- {
120
+ def make_bundle_file(site)
121
+ BundleFile.new(
122
+ site,
91
123
  'type' => :js,
92
124
  'source_dir' => JS_BUNDLE_SOURCE_DIR,
93
125
  'assets' => %w{dependency app},
94
126
  'destination_path' => JS_BUNDLE_DESTINATION_PATH,
95
- 'minifier_cmd' => minifier_cmd
96
- }
127
+ 'minifier_cmd' => minifier_cmd_to_remove_comments_and_count
128
+ )
129
+ end
130
+
131
+ def write_file(file)
132
+ file.write(File.join(Dir.pwd, '_site'))
97
133
  end
98
134
  end
99
135
  end
@@ -51,6 +51,11 @@ module Jekyll::Minibundle::Test
51
51
  assert_equal app_mtime.to_i, @@results.fetch(:app).fetch(:mtime)
52
52
  end
53
53
 
54
+ def test_path
55
+ assert_match(%r{/#{JS_BUNDLE_SOURCE_DIR}/dependency.js\z}, @@results.fetch(:dependency).fetch(:relative_path))
56
+ assert_match(%r{/#{JS_BUNDLE_SOURCE_DIR}/app.js\z}, @@results.fetch(:app).fetch(:relative_path))
57
+ end
58
+
54
59
  def test_placeholders
55
60
  assert_equal({}, @@results.fetch(:dependency).fetch(:placeholders))
56
61
  assert_equal({}, @@results.fetch(:app).fetch(:placeholders))
@@ -0,0 +1,39 @@
1
+ require 'support/test_case'
2
+ require 'support/fixture_config'
3
+ require 'jekyll/minibundle/development_file'
4
+
5
+ module Jekyll::Minibundle::Test
6
+ class DevelopmentFileWritingTest < TestCase
7
+ include FixtureConfig
8
+
9
+ def test_modify_property_determines_if_write_would_succeed
10
+ with_fake_site do |site|
11
+ dev_file = make_development_file(site)
12
+ source = source_path(STAMP_SOURCE_PATH)
13
+
14
+ assert dev_file.modified?
15
+ assert write_file(dev_file)
16
+
17
+ ensure_file_mtime_changes do
18
+ FileUtils.touch(source)
19
+ end
20
+
21
+ assert dev_file.modified?
22
+ assert write_file(dev_file)
23
+
24
+ refute dev_file.modified?
25
+ refute write_file(dev_file)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def make_development_file(site)
32
+ DevelopmentFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH)
33
+ end
34
+
35
+ def write_file(file)
36
+ file.write(File.join(Dir.pwd, '_site'))
37
+ end
38
+ end
39
+ end
@@ -4,23 +4,23 @@ require 'jekyll/minibundle/environment'
4
4
  module Jekyll::Minibundle::Test
5
5
  class EnvironmentTest < TestCase
6
6
  def test_find_site_config_returns_value_when_found
7
- assert_equal 1, Environment.find_site_config(new_site(top: {leaf: 1}), [:top, :leaf], Integer)
7
+ assert_equal 1, Environment.find_site_config(make_site(top: {leaf: 1}), [:top, :leaf], Integer)
8
8
  end
9
9
 
10
10
  def test_find_site_config_returns_nil_when_not_found
11
- assert_nil Environment.find_site_config(new_site, [:top, :leaf], Integer)
11
+ assert_nil Environment.find_site_config(make_site, [:top, :leaf], Integer)
12
12
  end
13
13
 
14
14
  def test_find_site_config_raises_exception_if_found_value_is_of_unexpected_type
15
15
  err = assert_raises(RuntimeError) do
16
- Environment.find_site_config(new_site(top: {leaf: '1'}), [:top, :leaf], Integer)
16
+ Environment.find_site_config(make_site(top: {leaf: '1'}), [:top, :leaf], Integer)
17
17
  end
18
18
  assert_equal 'Invalid site configuration for key top.leaf; expecting type Integer', err.to_s
19
19
  end
20
20
 
21
21
  private
22
22
 
23
- def new_site(config = {})
23
+ def make_site(config = {})
24
24
  OpenStruct.new(config: config)
25
25
  end
26
26
  end
@@ -3,6 +3,15 @@ require 'jekyll/minibundle/files'
3
3
 
4
4
  module Jekyll::Minibundle::Test
5
5
  class FilesTest < TestCase
6
+ def test_copy_p
7
+ with_tmp_dir do
8
+ File.write('foo', 'content')
9
+ Files.copy_p('foo', 'bar/zap')
10
+ copied = File.read('bar/zap')
11
+ assert_equal 'content', copied
12
+ end
13
+ end
14
+
6
15
  def test_read_last_with_non_existing_file_raises_exception
7
16
  assert_raises(Errno::ENOENT) { Files.read_last('no-such-file', 4) }
8
17
  end
@@ -42,5 +51,9 @@ module Jekyll::Minibundle::Test
42
51
  assert_equal '', Files.read_last(file.path, -1)
43
52
  end
44
53
  end
54
+
55
+ def test_strip_dot_slash_from_path_start
56
+ assert_equal 'path', Files.strip_dot_slash_from_path_start('./path')
57
+ end
45
58
  end
46
59
  end
@@ -62,7 +62,7 @@ module Jekyll::Minibundle::Test
62
62
 
63
63
  def with_empty_site(&block)
64
64
  with_tmp_dir do |dir|
65
- block.call(new_fake_site(dir))
65
+ block.call(make_fake_site(dir))
66
66
  end
67
67
  end
68
68
 
@@ -57,7 +57,7 @@ minifier_cmd: #{minifier_cmd_to_remove_comments}
57
57
 
58
58
  actual_output = nil
59
59
  capture_io do
60
- actual_output = template.render({}, registers: {site: new_fake_site(site_fixture_path)})
60
+ actual_output = template.render({}, registers: {site: make_fake_site(site_fixture_path)})
61
61
  end
62
62
  expected_output = %{<link rel="stylesheet" href="#{spec.fetch(:expected_asset_url)}">\n}
63
63
 
@@ -24,7 +24,7 @@ module Jekyll::Minibundle::Test
24
24
  AssetFileRegistry.clear_all
25
25
  output = Liquid::Template
26
26
  .parse("{% ministamp #{STAMP_SOURCE_PATH} #{STAMP_DESTINATION_PATH} rest %}")
27
- .render({}, registers: {site: new_fake_site(site_fixture_path)})
27
+ .render({}, registers: {site: make_fake_site(site_fixture_path)})
28
28
  assert_equal STAMP_DESTINATION_FINGERPRINT_PATH, output
29
29
  end
30
30
  end
@@ -41,6 +41,10 @@ module Jekyll::Minibundle::Test
41
41
  assert_equal mtime.to_i, @@results.fetch(:mtime)
42
42
  end
43
43
 
44
+ def test_path
45
+ assert_match(%r{/#{STAMP_SOURCE_PATH}\z}, @@results.fetch(:path))
46
+ end
47
+
44
48
  def test_placeholders
45
49
  assert_equal({}, @@results.fetch(:placeholders))
46
50
  end
@@ -8,31 +8,46 @@ module Jekyll::Minibundle::Test
8
8
 
9
9
  def test_calling_destination_path_for_markup_determines_fingerprint_and_destination_write
10
10
  with_fake_site do |site|
11
- stamp_file = new_stamp_file(site)
11
+ stamp_file = make_stamp_file(site)
12
12
  source = source_path(STAMP_SOURCE_PATH)
13
13
  old_destination = destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)
14
- org_markup = stamp_file.destination_path_for_markup
15
14
 
16
- assert stamp_file.write('_site')
15
+ # the call to destination_path_for_markup determines the
16
+ # fingerprint
17
+
18
+ org_markup_path = stamp_file.destination_path_for_markup
19
+
20
+ assert write_file(stamp_file)
17
21
 
18
22
  org_mtime = file_mtime_of(old_destination)
19
- last_markup = stamp_file.destination_path_for_markup
23
+
24
+ last_markup_path = stamp_file.destination_path_for_markup
25
+
26
+ assert_equal org_markup_path, last_markup_path
27
+
28
+ # change content, but don't call destination_path_for_markup yet
29
+
20
30
  ensure_file_mtime_changes { File.write(source, 'h1 {}') }
21
31
 
22
- # preserve fingerprint and content seen in last markup phase
23
- refute stamp_file.write('_site')
24
- assert_equal org_markup, last_markup
32
+ # preserve content's fingerprint
33
+
34
+ refute write_file(stamp_file)
35
+
36
+ assert_equal org_markup_path, last_markup_path
25
37
  assert_equal org_mtime, file_mtime_of(old_destination)
26
38
  assert_equal File.read(site_fixture_path(STAMP_SOURCE_PATH)), File.read(old_destination)
27
39
 
28
- last_markup = stamp_file.destination_path_for_markup
40
+ # see content's fingerprint to update after calling
41
+ # destination_path_for_markup
42
+
43
+ last_markup_path = stamp_file.destination_path_for_markup
29
44
 
30
- assert stamp_file.write('_site')
45
+ refute_equal org_markup_path, last_markup_path
46
+
47
+ assert write_file(stamp_file)
31
48
 
32
49
  new_destination = destination_path('assets/screen-0f5dbd1e527a2bee267e85007b08d2a5.css')
33
50
 
34
- # see updated fingerprint in the next round
35
- refute_equal org_markup, last_markup
36
51
  assert_operator file_mtime_of(new_destination), :>, org_mtime
37
52
  assert_equal File.read(source), File.read(new_destination)
38
53
  end
@@ -40,20 +55,20 @@ module Jekyll::Minibundle::Test
40
55
 
41
56
  def test_many_consecutive_destination_path_for_markup_calls_trigger_one_destination_write
42
57
  with_fake_site do |site|
43
- stamp_file = new_stamp_file(site)
58
+ stamp_file = make_stamp_file(site)
44
59
  source = source_path(STAMP_SOURCE_PATH)
45
60
  destination = destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)
46
61
  org_markup = stamp_file.destination_path_for_markup
47
62
  stamp_file.destination_path_for_markup
48
63
 
49
- assert stamp_file.write('_site')
64
+ assert write_file(stamp_file)
50
65
 
51
66
  org_mtime = file_mtime_of(destination)
52
67
  ensure_file_mtime_changes { FileUtils.touch(source) }
53
68
  last_markup = stamp_file.destination_path_for_markup
54
69
  stamp_file.destination_path_for_markup
55
70
 
56
- assert stamp_file.write('_site')
71
+ assert write_file(stamp_file)
57
72
  assert_equal org_markup, last_markup
58
73
  assert_operator file_mtime_of(destination), :>, org_mtime
59
74
  assert_equal File.read(source), File.read(destination)
@@ -62,22 +77,43 @@ module Jekyll::Minibundle::Test
62
77
 
63
78
  def test_calling_write_before_destination_path_for_markup_has_no_effect
64
79
  with_fake_site do |site|
65
- stamp_file = new_stamp_file(site)
80
+ stamp_file = make_stamp_file(site)
66
81
 
67
- refute stamp_file.write('_site')
82
+ refute write_file(stamp_file)
68
83
  assert_empty Dir[destination_path('assets/*.css')]
69
84
 
70
85
  stamp_file.destination_path_for_markup
71
86
 
72
- assert stamp_file.write('_site')
87
+ assert write_file(stamp_file)
73
88
  assert File.exist?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
74
89
  end
75
90
  end
76
91
 
92
+ def test_modified_property_determines_if_write_would_succeed
93
+ with_fake_site do |site|
94
+ stamp_file = make_stamp_file(site)
95
+
96
+ refute stamp_file.modified?
97
+ refute write_file(stamp_file)
98
+
99
+ stamp_file.destination_path_for_markup
100
+
101
+ assert stamp_file.modified?
102
+ assert write_file(stamp_file)
103
+
104
+ refute stamp_file.modified?
105
+ refute write_file(stamp_file)
106
+ end
107
+ end
108
+
77
109
  private
78
110
 
79
- def new_stamp_file(site)
111
+ def make_stamp_file(site)
80
112
  StampFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH)
81
113
  end
114
+
115
+ def write_file(file)
116
+ file.write(File.join(Dir.pwd, '_site'))
117
+ end
82
118
  end
83
119
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-minibundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tuomas Kareinen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-14 00:00:00.000000000 Z
11
+ date: 2017-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.46.0
89
+ version: 0.47.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.46.0
96
+ version: 0.47.0
97
97
  description: |
98
98
  A straightforward asset bundling plugin for Jekyll, utilizing external
99
99
  minification tool of your choice. It provides asset concatenation for
@@ -112,7 +112,6 @@ files:
112
112
  - jekyll-minibundle.gemspec
113
113
  - lib/jekyll/minibundle.rb
114
114
  - lib/jekyll/minibundle/asset_bundle.rb
115
- - lib/jekyll/minibundle/asset_file_operations.rb
116
115
  - lib/jekyll/minibundle/asset_file_properties.rb
117
116
  - lib/jekyll/minibundle/asset_file_registry.rb
118
117
  - lib/jekyll/minibundle/asset_stamp.rb
@@ -156,6 +155,7 @@ files:
156
155
  - test/unit/bundle_file_properties_test.rb
157
156
  - test/unit/bundle_file_writing_test.rb
158
157
  - test/unit/development_file_collection_properties_test.rb
158
+ - test/unit/development_file_writing_test.rb
159
159
  - test/unit/environment_test.rb
160
160
  - test/unit/files_test.rb
161
161
  - test/unit/hashes_test.rb
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  version: '0'
190
190
  requirements: []
191
191
  rubyforge_project:
192
- rubygems_version: 2.6.8
192
+ rubygems_version: 2.6.10
193
193
  signing_key:
194
194
  specification_version: 4
195
195
  summary: A minimalistic asset bundling plugin for Jekyll
@@ -221,6 +221,7 @@ test_files:
221
221
  - test/unit/bundle_file_properties_test.rb
222
222
  - test/unit/bundle_file_writing_test.rb
223
223
  - test/unit/development_file_collection_properties_test.rb
224
+ - test/unit/development_file_writing_test.rb
224
225
  - test/unit/environment_test.rb
225
226
  - test/unit/files_test.rb
226
227
  - test/unit/hashes_test.rb