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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +96 -42
  3. data/LICENSE.txt +1 -1
  4. data/README.md +232 -52
  5. data/Rakefile +16 -0
  6. data/jekyll-minibundle.gemspec +7 -6
  7. data/lib/jekyll/minibundle/asset_bundle.rb +3 -3
  8. data/lib/jekyll/minibundle/asset_file_drop.rb +45 -0
  9. data/lib/jekyll/minibundle/asset_file_properties.rb +12 -8
  10. data/lib/jekyll/minibundle/asset_file_registry.rb +4 -4
  11. data/lib/jekyll/minibundle/asset_tag_markup.rb +21 -20
  12. data/lib/jekyll/minibundle/bundle_file.rb +6 -1
  13. data/lib/jekyll/minibundle/development_file.rb +2 -1
  14. data/lib/jekyll/minibundle/development_file_collection.rb +2 -2
  15. data/lib/jekyll/minibundle/environment.rb +13 -15
  16. data/lib/jekyll/minibundle/files.rb +16 -18
  17. data/lib/jekyll/minibundle/hashes.rb +10 -12
  18. data/lib/jekyll/minibundle/log.rb +5 -7
  19. data/lib/jekyll/minibundle/mini_bundle_block.rb +35 -12
  20. data/lib/jekyll/minibundle/mini_stamp_tag.rb +108 -16
  21. data/lib/jekyll/minibundle/stamp_file.rb +1 -0
  22. data/lib/jekyll/minibundle/variable_template.rb +145 -0
  23. data/lib/jekyll/minibundle/variable_template_registry.rb +19 -0
  24. data/lib/jekyll/minibundle/version.rb +1 -1
  25. data/test/fixture/site/_bin/with_count +1 -1
  26. data/test/integration/minibundle_development_mode_test.rb +146 -61
  27. data/test/integration/minibundle_production_mode_test.rb +271 -143
  28. data/test/integration/ministamp_development_mode_test.rb +66 -25
  29. data/test/integration/ministamp_production_mode_test.rb +129 -37
  30. data/test/integration/static_files_as_asset_sources_test.rb +10 -10
  31. data/test/support/assertions.rb +1 -1
  32. data/test/support/{static_file_api_config.rb → static_file_config.rb} +6 -3
  33. data/test/support/test_case.rb +7 -4
  34. data/test/unit/asset_bundle_test.rb +6 -6
  35. data/test/unit/asset_file_drop_test.rb +65 -0
  36. data/test/unit/asset_file_registry_test.rb +136 -98
  37. data/test/unit/asset_tag_markup_test.rb +11 -5
  38. data/test/unit/bundle_file_properties_test.rb +44 -23
  39. data/test/unit/bundle_file_writing_test.rb +50 -32
  40. data/test/unit/development_file_properties_test.rb +95 -0
  41. data/test/unit/development_file_writing_test.rb +15 -6
  42. data/test/unit/environment_test.rb +3 -3
  43. data/test/unit/files_test.rb +7 -7
  44. data/test/unit/hashes_test.rb +12 -12
  45. data/test/unit/jekyll_static_file_api_test.rb +91 -20
  46. data/test/unit/mini_bundle_block_test.rb +59 -9
  47. data/test/unit/mini_stamp_tag_test.rb +37 -6
  48. data/test/unit/stamp_file_properties_test.rb +47 -24
  49. data/test/unit/stamp_file_writing_test.rb +33 -24
  50. data/test/unit/variable_template_test.rb +121 -0
  51. metadata +27 -6
  52. data/test/unit/development_file_collection_properties_test.rb +0 -106
@@ -1,48 +1,54 @@
1
1
  require 'support/test_case'
2
2
  require 'support/fixture_config'
3
- require 'support/static_file_api_config'
3
+ require 'support/static_file_config'
4
4
  require 'jekyll/minibundle/stamp_file'
5
5
 
6
6
  module Jekyll::Minibundle::Test
7
7
  class StampFilePropertiesTest < TestCase
8
8
  include FixtureConfig
9
- include StaticFileAPIConfig
9
+ include StaticFileConfig
10
10
 
11
11
  def setup
12
- @@results ||= with_fake_site do |site|
13
- file = StampFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH)
14
- file.destination_path_for_markup
15
- get_send_results(file, STATIC_FILE_API_PROPERTIES)
12
+ @@results ||= with_stamp_file do |file|
13
+ get_send_results(file, STATIC_FILE_PROPERTIES)
16
14
  end
17
15
  end
18
16
 
17
+ def test_basename
18
+ assert_equal("screen-#{STAMP_FINGERPRINT}", @@results.fetch(:basename))
19
+ end
20
+
21
+ def test_data
22
+ assert_equal({}, @@results.fetch(:data))
23
+ end
24
+
19
25
  def test_defaults
20
26
  assert_equal({}, @@results.fetch(:defaults))
21
27
  end
22
28
 
23
29
  def test_destination_rel_dir
24
- assert_equal 'assets', @@results.fetch(:destination_rel_dir)
25
- end
26
-
27
- def test_name
28
- assert_equal "screen-#{STAMP_FINGERPRINT}.css", @@results.fetch(:name)
30
+ assert_equal('/assets', @@results.fetch(:destination_rel_dir))
29
31
  end
30
32
 
31
33
  def test_extname
32
- assert_equal '.css', @@results.fetch(:extname)
34
+ assert_equal('.css', @@results.fetch(:extname))
33
35
  end
34
36
 
35
37
  def test_modified_time
36
- assert_instance_of Time, @@results.fetch(:modified_time)
38
+ assert_instance_of(Time, @@results.fetch(:modified_time))
37
39
  end
38
40
 
39
41
  def test_mtime
40
42
  mtime = @@results.fetch(:modified_time)
41
- assert_equal mtime.to_i, @@results.fetch(:mtime)
43
+ assert_equal(mtime.to_i, @@results.fetch(:mtime))
44
+ end
45
+
46
+ def test_name
47
+ assert_equal("screen-#{STAMP_FINGERPRINT}.css", @@results.fetch(:name))
42
48
  end
43
49
 
44
50
  def test_path
45
- assert_match(%r{/#{STAMP_SOURCE_PATH}\z}, @@results.fetch(:path))
51
+ assert_match(%r{\A/.+/#{STAMP_SOURCE_PATH}\z}, @@results.fetch(:path))
46
52
  end
47
53
 
48
54
  def test_placeholders
@@ -50,24 +56,41 @@ module Jekyll::Minibundle::Test
50
56
  end
51
57
 
52
58
  def test_relative_path
53
- assert_equal "/#{STAMP_SOURCE_PATH}", @@results.fetch(:relative_path)
59
+ assert_equal("/#{STAMP_SOURCE_PATH}", @@results.fetch(:relative_path))
54
60
  end
55
61
 
56
62
  def test_to_liquid
57
- hash = @@results.fetch(:to_liquid)
58
- assert_equal "screen-#{STAMP_FINGERPRINT}", hash.fetch('basename')
59
- assert_equal "screen-#{STAMP_FINGERPRINT}.css", hash.fetch('name')
60
- assert_equal '.css', hash.fetch('extname')
61
- assert_instance_of Time, hash.fetch('modified_time')
62
- assert_equal "/#{STAMP_SOURCE_PATH}", hash.fetch('path')
63
+ with_stamp_file do |file|
64
+ drop = file.to_liquid
65
+ assert_equal("screen-#{STAMP_FINGERPRINT}.css", drop.name)
66
+ assert_equal('.css', drop.extname)
67
+ assert_equal("screen-#{STAMP_FINGERPRINT}", drop.basename)
68
+ assert_instance_of(Time, drop.modified_time)
69
+ assert_equal("/#{STAMP_SOURCE_PATH}", drop.path)
70
+ assert_nil(drop.collection)
71
+ end
63
72
  end
64
73
 
65
74
  def test_type
66
- assert_nil @@results.fetch(:type)
75
+ assert_nil(@@results.fetch(:type))
76
+ end
77
+
78
+ def test_url
79
+ assert_equal(STAMP_DESTINATION_FINGERPRINT_PATH, @@results.fetch(:url))
67
80
  end
68
81
 
69
82
  def test_write?
70
- assert @@results.fetch(:write?)
83
+ assert(@@results.fetch(:write?))
84
+ end
85
+
86
+ private
87
+
88
+ def with_stamp_file(&block)
89
+ with_fake_site do |site|
90
+ file = StampFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH)
91
+ file.destination_path_for_markup
92
+ block.call(file)
93
+ end
71
94
  end
72
95
  end
73
96
  end
@@ -6,6 +6,15 @@ module Jekyll::Minibundle::Test
6
6
  class StampFileWritingTest < TestCase
7
7
  include FixtureConfig
8
8
 
9
+ def test_raise_error_if_source_file_does_not_exist
10
+ err = assert_raises(ArgumentError) do
11
+ with_fake_site do |site|
12
+ StampFile.new(site, '_tmp', STAMP_DESTINATION_PATH)
13
+ end
14
+ end
15
+ assert_match(%r{\AStamp source file does not exist: .+/_tmp\z}, err.to_s)
16
+ end
17
+
9
18
  def test_calling_destination_path_for_markup_determines_fingerprint_and_destination_write
10
19
  with_fake_site do |site|
11
20
  stamp_file = make_stamp_file(site)
@@ -17,13 +26,13 @@ module Jekyll::Minibundle::Test
17
26
 
18
27
  org_markup_path = stamp_file.destination_path_for_markup
19
28
 
20
- assert write_file(stamp_file)
29
+ assert(write_file(stamp_file))
21
30
 
22
31
  org_mtime = file_mtime_of(old_destination)
23
32
 
24
33
  last_markup_path = stamp_file.destination_path_for_markup
25
34
 
26
- assert_equal org_markup_path, last_markup_path
35
+ assert_equal(org_markup_path, last_markup_path)
27
36
 
28
37
  # change content, but don't call destination_path_for_markup yet
29
38
 
@@ -31,11 +40,11 @@ module Jekyll::Minibundle::Test
31
40
 
32
41
  # preserve content's fingerprint
33
42
 
34
- refute write_file(stamp_file)
43
+ refute(write_file(stamp_file))
35
44
 
36
- assert_equal org_markup_path, last_markup_path
37
- assert_equal org_mtime, file_mtime_of(old_destination)
38
- assert_equal File.read(site_fixture_path(STAMP_SOURCE_PATH)), File.read(old_destination)
45
+ assert_equal(org_markup_path, last_markup_path)
46
+ assert_equal(org_mtime, file_mtime_of(old_destination))
47
+ assert_equal(File.read(site_fixture_path(STAMP_SOURCE_PATH)), File.read(old_destination))
39
48
 
40
49
  # see content's fingerprint to update after calling
41
50
  # destination_path_for_markup
@@ -44,12 +53,12 @@ module Jekyll::Minibundle::Test
44
53
 
45
54
  refute_equal org_markup_path, last_markup_path
46
55
 
47
- assert write_file(stamp_file)
56
+ assert(write_file(stamp_file))
48
57
 
49
58
  new_destination = destination_path('assets/screen-0f5dbd1e527a2bee267e85007b08d2a5.css')
50
59
 
51
- assert_operator file_mtime_of(new_destination), :>, org_mtime
52
- assert_equal File.read(source), File.read(new_destination)
60
+ assert_operator(file_mtime_of(new_destination), :>, org_mtime)
61
+ assert_equal(File.read(source), File.read(new_destination))
53
62
  end
54
63
  end
55
64
 
@@ -61,17 +70,17 @@ module Jekyll::Minibundle::Test
61
70
  org_markup = stamp_file.destination_path_for_markup
62
71
  stamp_file.destination_path_for_markup
63
72
 
64
- assert write_file(stamp_file)
73
+ assert(write_file(stamp_file))
65
74
 
66
75
  org_mtime = file_mtime_of(destination)
67
76
  ensure_file_mtime_changes { FileUtils.touch(source) }
68
77
  last_markup = stamp_file.destination_path_for_markup
69
78
  stamp_file.destination_path_for_markup
70
79
 
71
- assert write_file(stamp_file)
72
- assert_equal org_markup, last_markup
73
- assert_operator file_mtime_of(destination), :>, org_mtime
74
- assert_equal File.read(source), File.read(destination)
80
+ assert(write_file(stamp_file))
81
+ assert_equal(org_markup, last_markup)
82
+ assert_operator(file_mtime_of(destination), :>, org_mtime)
83
+ assert_equal(File.read(source), File.read(destination))
75
84
  end
76
85
  end
77
86
 
@@ -79,13 +88,13 @@ module Jekyll::Minibundle::Test
79
88
  with_fake_site do |site|
80
89
  stamp_file = make_stamp_file(site)
81
90
 
82
- refute write_file(stamp_file)
83
- assert_empty Dir[destination_path('assets/*.css')]
91
+ refute(write_file(stamp_file))
92
+ assert_empty(Dir[destination_path('assets/*.css')])
84
93
 
85
94
  stamp_file.destination_path_for_markup
86
95
 
87
- assert write_file(stamp_file)
88
- assert File.exist?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
96
+ assert(write_file(stamp_file))
97
+ assert(File.file?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)))
89
98
  end
90
99
  end
91
100
 
@@ -93,16 +102,16 @@ module Jekyll::Minibundle::Test
93
102
  with_fake_site do |site|
94
103
  stamp_file = make_stamp_file(site)
95
104
 
96
- refute stamp_file.modified?
97
- refute write_file(stamp_file)
105
+ refute(stamp_file.modified?)
106
+ refute(write_file(stamp_file))
98
107
 
99
108
  stamp_file.destination_path_for_markup
100
109
 
101
- assert stamp_file.modified?
102
- assert write_file(stamp_file)
110
+ assert(stamp_file.modified?)
111
+ assert(write_file(stamp_file))
103
112
 
104
- refute stamp_file.modified?
105
- refute write_file(stamp_file)
113
+ refute(stamp_file.modified?)
114
+ refute(write_file(stamp_file))
106
115
  end
107
116
  end
108
117
 
@@ -0,0 +1,121 @@
1
+ # coding: utf-8
2
+
3
+ require 'support/test_case'
4
+ require 'jekyll/minibundle/variable_template'
5
+
6
+ module Jekyll::Minibundle::Test
7
+ class VariableTemplateTest < TestCase
8
+ VARIABLES = {
9
+ 'var1' => 41,
10
+ 'var2' => '42',
11
+ 'var3' => 43
12
+ }.freeze
13
+
14
+ def test_render_single_variable
15
+ assert_equal('41', render('{{var1}}', VARIABLES))
16
+ assert_equal('abc 41 zz', render('abc {{var1}} zz', VARIABLES))
17
+ end
18
+
19
+ def test_render_many_variables
20
+ assert_equal('414243', render('{{var1}}{{var2}}{{var3}}', VARIABLES))
21
+ assert_equal('abc 41 42efg43hij', render('abc {{var1}} {{var2}}efg{{var3}}hij', VARIABLES))
22
+ end
23
+
24
+ def test_render_single_variable_many_times
25
+ assert_equal('4141', render('{{var1}}{{var1}}', VARIABLES))
26
+ end
27
+
28
+ def test_strip_whitespace_around_variable_name
29
+ assert_equal('41 42', render("{{ var1\t}} {{ \n var2\n}}", VARIABLES))
30
+ end
31
+
32
+ def test_render_empty_string_for_nil_variable
33
+ assert_equal('', render('{{nosuch}}', VARIABLES))
34
+ end
35
+
36
+ def test_variable_name_can_be_anything_but_closing_tag
37
+ assert_equal('42', render('{{ foo {{ 3… } bar }}', 'foo {{ 3… } bar' => 42))
38
+ end
39
+
40
+ def test_return_template_without_variables_as_is
41
+ assert_equal('', render('', VARIABLES))
42
+ assert_equal('abc', render('abc', VARIABLES))
43
+ end
44
+
45
+ def test_raise_error_if_nil_template
46
+ err = assert_raises(ArgumentError) { VariableTemplate.compile(nil) }
47
+ assert_equal('Nil template', err.to_s)
48
+ end
49
+
50
+ def test_raise_error_if_unclosed_open_tag
51
+ err = assert_raises(VariableTemplate::SyntaxError) { VariableTemplate.compile('beg{{var}end') }
52
+ expected = <<-END
53
+ Missing closing tag ("}}") for variable opening tag ("{{") at position 5 in template (position highlighted with "@"):
54
+ beg{{@var}end
55
+ END
56
+ assert_equal(expected, err.to_s)
57
+ end
58
+
59
+ def test_application_to_same_compiled_template_many_times
60
+ template = VariableTemplate.compile('the answer is {{var}}, obviously')
61
+ assert_equal('the answer is 42, obviously', template.render('var' => 42))
62
+ assert_equal('the answer is 21, obviously', template.render('var' => 21))
63
+ end
64
+
65
+ def test_nonascii_template_and_variables
66
+ variables = {
67
+ '…first' => 'after first…',
68
+ 'yötön yö' => 'yö'
69
+ }
70
+ actual = render('begin… {{ …first }} middle {{yötön yö}} …end', variables)
71
+ expected = 'begin… after first… middle yö …end'
72
+ assert_equal(expected, actual)
73
+ end
74
+
75
+ def test_escapes_with_backslash
76
+ assert_equal('\\', render('\\\\', VARIABLES))
77
+ assert_equal('{', render('\\{', VARIABLES))
78
+ assert_equal('}', render('\\}', VARIABLES))
79
+ assert_equal('\\a', render('\\a', VARIABLES))
80
+ assert_equal('{{var1}}', render('\{{var1}}', VARIABLES))
81
+ assert_equal('{{var1}}', render('{\{var1}}', VARIABLES))
82
+ assert_equal('{{var1}}', render('\{{var1\}}', VARIABLES))
83
+ assert_equal('{{var1}}', render('\{{var1}\}', VARIABLES))
84
+ assert_equal('bar', render('{{foo\\}}', 'foo\\' => 'bar'))
85
+ end
86
+
87
+ def test_generator_escapes_text_token
88
+ assert_equal('#{}', render('#{}', {}))
89
+ assert_equal('"hey"', render('"hey"', {}))
90
+ assert_equal("'hey'", render("'hey'", {}))
91
+ end
92
+
93
+ def test_generator_escapes_variable_token
94
+ assert_equal('42', render('{{ \\ }}', '\\' => 42))
95
+ assert_equal('42', render("{{ ' }}", "'" => 42))
96
+ assert_equal('42', render('{{ " }}', '"' => 42))
97
+ assert_equal('42', render('{{ #{} }}', '#{}' => 42))
98
+ assert_equal("beg'42'end", render("beg'{{ 'var' }}'end", "'var'" => 42))
99
+ end
100
+
101
+ def test_complex_template
102
+ variables = {
103
+ 'integer' => 42,
104
+ 'string' => 'a rather long string',
105
+ 'sneaky… \\' => 'clever…'
106
+ }
107
+
108
+ template = 'begin "ä\\{\\ö\\\\{{integer}}middle \{{trap}} and {{ string }} also {{ sneaky… \\}} end'
109
+ expected = 'begin "ä{\\ö\\42middle {{trap}} and a rather long string also clever… end'
110
+ actual = render(template, variables)
111
+
112
+ assert_equal(expected, actual)
113
+ end
114
+
115
+ private
116
+
117
+ def render(template, values)
118
+ VariableTemplate.compile(template).render(values)
119
+ end
120
+ end
121
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-minibundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
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-02-28 00:00:00.000000000 Z
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: benchmark-ips
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: jekyll
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -112,6 +126,7 @@ files:
112
126
  - jekyll-minibundle.gemspec
113
127
  - lib/jekyll/minibundle.rb
114
128
  - lib/jekyll/minibundle/asset_bundle.rb
129
+ - lib/jekyll/minibundle/asset_file_drop.rb
115
130
  - lib/jekyll/minibundle/asset_file_properties.rb
116
131
  - lib/jekyll/minibundle/asset_file_registry.rb
117
132
  - lib/jekyll/minibundle/asset_stamp.rb
@@ -127,6 +142,8 @@ files:
127
142
  - lib/jekyll/minibundle/mini_bundle_block.rb
128
143
  - lib/jekyll/minibundle/mini_stamp_tag.rb
129
144
  - lib/jekyll/minibundle/stamp_file.rb
145
+ - lib/jekyll/minibundle/variable_template.rb
146
+ - lib/jekyll/minibundle/variable_template_registry.rb
130
147
  - lib/jekyll/minibundle/version.rb
131
148
  - test/fixture/site/_assets/scripts/app.js
132
149
  - test/fixture/site/_assets/scripts/dependency.js
@@ -147,14 +164,15 @@ files:
147
164
  - test/integration/static_files_as_asset_sources_test.rb
148
165
  - test/support/assertions.rb
149
166
  - test/support/fixture_config.rb
150
- - test/support/static_file_api_config.rb
167
+ - test/support/static_file_config.rb
151
168
  - test/support/test_case.rb
152
169
  - test/unit/asset_bundle_test.rb
170
+ - test/unit/asset_file_drop_test.rb
153
171
  - test/unit/asset_file_registry_test.rb
154
172
  - test/unit/asset_tag_markup_test.rb
155
173
  - test/unit/bundle_file_properties_test.rb
156
174
  - test/unit/bundle_file_writing_test.rb
157
- - test/unit/development_file_collection_properties_test.rb
175
+ - test/unit/development_file_properties_test.rb
158
176
  - test/unit/development_file_writing_test.rb
159
177
  - test/unit/environment_test.rb
160
178
  - test/unit/files_test.rb
@@ -164,6 +182,7 @@ files:
164
182
  - test/unit/mini_stamp_tag_test.rb
165
183
  - test/unit/stamp_file_properties_test.rb
166
184
  - test/unit/stamp_file_writing_test.rb
185
+ - test/unit/variable_template_test.rb
167
186
  homepage: https://github.com/tkareine/jekyll-minibundle
168
187
  licenses:
169
188
  - MIT
@@ -213,14 +232,15 @@ test_files:
213
232
  - test/integration/static_files_as_asset_sources_test.rb
214
233
  - test/support/assertions.rb
215
234
  - test/support/fixture_config.rb
216
- - test/support/static_file_api_config.rb
235
+ - test/support/static_file_config.rb
217
236
  - test/support/test_case.rb
218
237
  - test/unit/asset_bundle_test.rb
238
+ - test/unit/asset_file_drop_test.rb
219
239
  - test/unit/asset_file_registry_test.rb
220
240
  - test/unit/asset_tag_markup_test.rb
221
241
  - test/unit/bundle_file_properties_test.rb
222
242
  - test/unit/bundle_file_writing_test.rb
223
- - test/unit/development_file_collection_properties_test.rb
243
+ - test/unit/development_file_properties_test.rb
224
244
  - test/unit/development_file_writing_test.rb
225
245
  - test/unit/environment_test.rb
226
246
  - test/unit/files_test.rb
@@ -230,3 +250,4 @@ test_files:
230
250
  - test/unit/mini_stamp_tag_test.rb
231
251
  - test/unit/stamp_file_properties_test.rb
232
252
  - test/unit/stamp_file_writing_test.rb
253
+ - test/unit/variable_template_test.rb