jekyll-minibundle 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +35 -25
  4. data/Rakefile +6 -6
  5. data/jekyll-minibundle.gemspec +11 -11
  6. data/lib/jekyll/minibundle/asset_bundle.rb +19 -16
  7. data/lib/jekyll/minibundle/asset_file_operations.rb +3 -3
  8. data/lib/jekyll/minibundle/asset_file_paths.rb +2 -6
  9. data/lib/jekyll/minibundle/asset_file_registry.rb +28 -30
  10. data/lib/jekyll/minibundle/asset_stamp.rb +1 -1
  11. data/lib/jekyll/minibundle/asset_tag_markup.rb +16 -14
  12. data/lib/jekyll/minibundle/bundle_file.rb +10 -9
  13. data/lib/jekyll/minibundle/development_file.rb +6 -6
  14. data/lib/jekyll/minibundle/development_file_collection.rb +6 -6
  15. data/lib/jekyll/minibundle/environment.rb +10 -8
  16. data/lib/jekyll/minibundle/mini_bundle_block.rb +4 -4
  17. data/lib/jekyll/minibundle/mini_stamp_tag.rb +2 -2
  18. data/lib/jekyll/minibundle/stamp_file.rb +8 -7
  19. data/lib/jekyll/minibundle/version.rb +1 -1
  20. data/test/fixture/site/_bin/with_count +1 -1
  21. data/test/integration/minibundle_development_mode_test.rb +62 -40
  22. data/test/integration/minibundle_production_mode_test.rb +78 -70
  23. data/test/integration/ministamp_test.rb +23 -23
  24. data/test/integration/static_files_as_asset_sources_test.rb +11 -11
  25. data/test/support/fixture_config.rb +4 -4
  26. data/test/support/test_case.rb +18 -14
  27. data/test/unit/asset_bundle_test.rb +4 -4
  28. data/test/unit/asset_file_registry_test.rb +7 -7
  29. data/test/unit/asset_tag_markup_test.rb +1 -1
  30. data/test/unit/bundle_file_test.rb +43 -33
  31. data/test/unit/development_file_collection_test.rb +44 -0
  32. data/test/unit/stamp_file_test.rb +30 -18
  33. metadata +26 -24
@@ -10,8 +10,8 @@ module Jekyll::Minibundle
10
10
  def initialize(config)
11
11
  @type = config['type']
12
12
  @site_source_dir = config['site_dir']
13
- asset_source_dir = File.join @site_source_dir, config['source_dir']
14
- @assets = config['assets'].map { |asset_path| File.join asset_source_dir, "#{asset_path}.#{@type}" }
13
+ asset_source_dir = File.join(@site_source_dir, config['source_dir'])
14
+ @assets = config['assets'].map { |asset_path| File.join(asset_source_dir, "#{asset_path}.#{@type}") }
15
15
  @destination_path = config['destination_path']
16
16
  @attributes = config['attributes']
17
17
  @stamped_at = nil
@@ -28,7 +28,7 @@ module Jekyll::Minibundle
28
28
  asset_bundle.make_bundle
29
29
  end
30
30
 
31
- AssetTagMarkup.make_markup @type, asset_destination_path, @attributes
31
+ AssetTagMarkup.make_markup(@type, asset_destination_path, @attributes)
32
32
  end
33
33
 
34
34
  def path
@@ -40,7 +40,7 @@ module Jekyll::Minibundle
40
40
  end
41
41
 
42
42
  def destination(site_destination_dir)
43
- File.join site_destination_dir, asset_destination_path
43
+ File.join(site_destination_dir, asset_destination_path)
44
44
  end
45
45
 
46
46
  def mtime
@@ -51,20 +51,21 @@ module Jekyll::Minibundle
51
51
  @stamped_at != mtime
52
52
  end
53
53
 
54
+ # writes destination only after `markup` has been called
54
55
  def write(site_destination_dir)
55
- if File.exists?(destination(site_destination_dir)) && !@is_modified
56
- false
57
- else
58
- write_destination site_destination_dir
56
+ if @is_modified
57
+ write_destination(site_destination_dir)
59
58
  @is_modified = false
60
59
  true
60
+ else
61
+ false
61
62
  end
62
63
  end
63
64
 
64
65
  private
65
66
 
66
67
  def asset_stamp
67
- @_asset_stamp ||= AssetStamp.from_file path
68
+ @_asset_stamp ||= AssetStamp.from_file(path)
68
69
  end
69
70
 
70
71
  def asset_bundle
@@ -10,18 +10,18 @@ module Jekyll::Minibundle
10
10
 
11
11
  def initialize(asset_source_path, asset_destination_path)
12
12
  @asset_source_path = asset_source_path
13
- @asset_destination_dir = File.dirname asset_destination_path
14
- @asset_destination_basename = File.basename asset_destination_path
13
+ @asset_destination_dir = File.dirname(asset_destination_path)
14
+ @asset_destination_basename = File.basename(asset_destination_path)
15
15
  @stamped_at = nil
16
16
  end
17
17
 
18
18
  def write(site_destination_dir)
19
- if destination_exists?(site_destination_dir) && !modified?
20
- false
21
- else
19
+ if modified?
22
20
  @stamped_at = mtime
23
- write_destination site_destination_dir
21
+ write_destination(site_destination_dir)
24
22
  true
23
+ else
24
+ false
25
25
  end
26
26
  end
27
27
  end
@@ -5,14 +5,14 @@ module Jekyll::Minibundle
5
5
  class DevelopmentFileCollection
6
6
  def initialize(config)
7
7
  @type = config['type']
8
- asset_source_dir = File.join config['site_dir'], config['source_dir']
8
+ asset_source_dir = File.join(config['site_dir'], config['source_dir'])
9
9
  destination_path = config['destination_path']
10
10
 
11
11
  @files = config['assets'].map do |asset_path|
12
12
  asset_basename = "#{asset_path}.#{@type}"
13
- asset_source = File.join asset_source_dir, asset_basename
14
- asset_destination = File.join destination_path, asset_basename
15
- DevelopmentFile.new asset_source, asset_destination
13
+ asset_source = File.join(asset_source_dir, asset_basename)
14
+ asset_destination = File.join(destination_path, asset_basename)
15
+ DevelopmentFile.new(asset_source, asset_destination)
16
16
  end
17
17
 
18
18
  @attributes = config['attributes']
@@ -22,12 +22,12 @@ module Jekyll::Minibundle
22
22
  # NOTE: We could optimize here by iterating over site's static
23
23
  # files only once instead of per each of our file. Seems like a
24
24
  # premature optimization for now, however.
25
- @files.each { |f| f.static_file! site }
25
+ @files.each { |f| f.static_file!(site) }
26
26
  end
27
27
 
28
28
  def markup
29
29
  @files.
30
- map { |f| AssetTagMarkup.make_markup @type, f.asset_destination_path, @attributes }.
30
+ map { |f| AssetTagMarkup.make_markup(@type, f.asset_destination_path, @attributes) }.
31
31
  join("\n")
32
32
  end
33
33
  end
@@ -1,14 +1,16 @@
1
1
  module Jekyll::Minibundle
2
2
  module Environment
3
- def self.command_for(type)
4
- key = "JEKYLL_MINIBUNDLE_CMD_#{type.upcase}"
5
- cmd = ENV[key]
6
- raise "You need to set command for minification in $#{key}" if !cmd
7
- cmd
8
- end
3
+ class << self
4
+ def command_for(type)
5
+ key = "JEKYLL_MINIBUNDLE_CMD_#{type.upcase}"
6
+ cmd = ENV[key]
7
+ fail "You need to set command for minification in $#{key}" if !cmd
8
+ cmd
9
+ end
9
10
 
10
- def self.development?
11
- ENV['JEKYLL_MINIBUNDLE_MODE'] == 'development'
11
+ def development?
12
+ ENV['JEKYLL_MINIBUNDLE_MODE'] == 'development'
13
+ end
12
14
  end
13
15
  end
14
16
  end
@@ -10,9 +10,9 @@ module Jekyll::Minibundle
10
10
 
11
11
  def render(context)
12
12
  site = context.registers[:site]
13
- config = get_current_config YAML.load(super), site
14
- file = AssetFileRegistry.bundle_file config
15
- file.static_file! site
13
+ config = get_current_config(YAML.load(super), site)
14
+ file = AssetFileRegistry.bundle_file(config)
15
+ file.static_file!(site)
16
16
  file.markup
17
17
  end
18
18
 
@@ -30,7 +30,7 @@ module Jekyll::Minibundle
30
30
  def get_current_config(user_config, site)
31
31
  MiniBundleBlock.default_config.
32
32
  merge(user_config).
33
- merge({ 'type' => @type, 'site_dir' => site.source })
33
+ merge('type' => @type, 'site_dir' => site.source)
34
34
  end
35
35
  end
36
36
  end
@@ -9,8 +9,8 @@ module Jekyll::Minibundle
9
9
 
10
10
  def render(context)
11
11
  site = context.registers[:site]
12
- file = AssetFileRegistry.stamp_file File.join(site.source, @asset_source), @asset_destination
13
- file.static_file! site
12
+ file = AssetFileRegistry.stamp_file(File.join(site.source, @asset_source), @asset_destination)
13
+ file.static_file!(site)
14
14
  file.markup
15
15
  end
16
16
  end
@@ -12,8 +12,8 @@ module Jekyll::Minibundle
12
12
  def initialize(asset_source_path, asset_destination_path, &basenamer)
13
13
  @basenamer = basenamer
14
14
  @asset_source_path = asset_source_path
15
- @asset_destination_dir = File.dirname asset_destination_path
16
- @asset_destination_extension = File.extname asset_destination_path
15
+ @asset_destination_dir = File.dirname(asset_destination_path)
16
+ @asset_destination_extension = File.extname(asset_destination_path)
17
17
  @asset_destination_base_prefix = File.basename(asset_destination_path)[0 .. -(@asset_destination_extension.size + 1)]
18
18
  @stamped_at = nil
19
19
  @is_modified = false
@@ -32,20 +32,21 @@ module Jekyll::Minibundle
32
32
  asset_destination_path
33
33
  end
34
34
 
35
+ # writes destination only after `markup` has been called
35
36
  def write(site_destination_dir)
36
- if destination_exists?(site_destination_dir) && !@is_modified
37
- false
38
- else
39
- write_destination site_destination_dir
37
+ if @is_modified
38
+ write_destination(site_destination_dir)
40
39
  @is_modified = false
41
40
  true
41
+ else
42
+ false
42
43
  end
43
44
  end
44
45
 
45
46
  private
46
47
 
47
48
  def asset_destination_basename
48
- @basenamer.call @asset_destination_base_prefix, @asset_destination_extension, -> { asset_stamp }
49
+ @basenamer.call(@asset_destination_base_prefix, @asset_destination_extension, -> { asset_stamp })
49
50
  end
50
51
 
51
52
  def asset_stamp
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Minibundle
3
- VERSION = '1.4.2'
3
+ VERSION = '1.4.3'
4
4
  end
5
5
  end
@@ -8,6 +8,6 @@ else
8
8
  0
9
9
  end
10
10
 
11
- File.write filename, "#{count + 1}\n"
11
+ File.write(filename, "#{count + 1}\n")
12
12
 
13
13
  exec(*ARGV[1..-1])
@@ -5,49 +5,63 @@ module Jekyll::Minibundle::Test
5
5
  class MiniBundleDevelopmentModeTest < TestCase
6
6
  include FixtureConfig
7
7
 
8
- EXPECTED_CSS_ASSET_PATHS = %w{reset common}.map { |f| File.join(CSS_BUNDLE_DESTINATION_PATH, "#{f}.css") }
9
- EXPECTED_JS_ASSET_PATHS = %w{dependency app}.map { |f| File.join(JS_BUNDLE_DESTINATION_PATH, "#{f}.js") }
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
10
 
11
11
  def test_css_assets_have_tags_in_configured_order
12
- with_precompiled_site :development do
13
- assert_equal EXPECTED_CSS_ASSET_PATHS, find_css_paths_from_index
12
+ with_precompiled_site(:development) do
13
+ assert_equal CSS_ASSET_DESTINATION_PATHS, find_css_paths_from_index
14
14
  end
15
15
  end
16
16
 
17
17
  def test_js_assets_have_tags_in_configured_order
18
- with_precompiled_site :development do
19
- assert_equal EXPECTED_JS_ASSET_PATHS, find_js_paths_from_index
18
+ with_precompiled_site(:development) do
19
+ assert_equal JS_ASSET_DESTINATION_PATHS, find_js_paths_from_index
20
+ end
21
+ end
22
+
23
+ def test_css_assets_have_configured_attributes
24
+ with_precompiled_site(:development) do
25
+ elements = find_css_elements_from_index.map { |el| [el['id'], el['media']] }.uniq
26
+ assert_equal [['my-styles', 'projection']], elements
27
+ end
28
+ end
29
+
30
+ def test_js_assets_have_configured_attributes
31
+ with_precompiled_site(:development) do
32
+ elements = find_js_elements_from_index.map { |el| el['id'] }.uniq
33
+ assert_equal ['my-scripts'], elements
20
34
  end
21
35
  end
22
36
 
23
37
  def test_copies_css_assets_to_destination_dir
24
- with_precompiled_site :development do
25
- EXPECTED_CSS_ASSET_PATHS.each do |path|
38
+ with_precompiled_site(:development) do
39
+ CSS_ASSET_DESTINATION_PATHS.each do |path|
26
40
  expect_file_exists_and_is_equal_to(destination_path(path), site_fixture_path(CSS_BUNDLE_SOURCE_DIR, File.basename(path)))
27
41
  end
28
42
  end
29
43
  end
30
44
 
31
45
  def test_copies_js_assets_to_destination_dir
32
- with_precompiled_site :development do
33
- EXPECTED_JS_ASSET_PATHS.each do |path|
46
+ with_precompiled_site(:development) do
47
+ JS_ASSET_DESTINATION_PATHS.each do |path|
34
48
  expect_file_exists_and_is_equal_to(destination_path(path), site_fixture_path(JS_BUNDLE_SOURCE_DIR, File.basename(path)))
35
49
  end
36
50
  end
37
51
  end
38
52
 
39
53
  [
40
- {desc: "changing", action: ->(source) { File.write source, 'h1 {}' }},
41
- {desc: "touching", action: ->(source) { FileUtils.touch source }}
54
+ {desc: "changing", action: ->(source) { File.write(source, 'h1 {}') }},
55
+ {desc: "touching", action: ->(source) { FileUtils.touch(source) }}
42
56
  ].each do |spec|
43
57
  define_method :"test_#{spec[:desc]}_css_asset_source_rewrites_destination" do
44
58
  with_site do
45
- generate_site :development
46
- destination = destination_path CSS_BUNDLE_DESTINATION_PATH, 'common.css'
47
- org_mtime = mtime_of destination
48
- source = source_path CSS_BUNDLE_SOURCE_DIR, 'common.css'
59
+ generate_site(:development)
60
+ destination = destination_path(CSS_BUNDLE_DESTINATION_PATH, 'common.css')
61
+ org_mtime = mtime_of(destination)
62
+ source = source_path(CSS_BUNDLE_SOURCE_DIR, 'common.css')
49
63
  ensure_file_mtime_changes { spec[:action].call(source) }
50
- generate_site :development, clear_cache: false
64
+ generate_site(:development, clear_cache: false)
51
65
 
52
66
  assert_equal File.read(destination), File.read(source)
53
67
  assert_operator mtime_of(destination), :>, org_mtime
@@ -56,17 +70,17 @@ module Jekyll::Minibundle::Test
56
70
  end
57
71
 
58
72
  [
59
- {desc: "changing", action: ->(source) { File.write source, '(function() {})()' }},
60
- {desc: "touching", action: ->(source) { FileUtils.touch source }}
73
+ {desc: "changing", action: ->(source) { File.write(source, '(function() {})()') }},
74
+ {desc: "touching", action: ->(source) { FileUtils.touch(source) }}
61
75
  ].each do |spec|
62
76
  define_method :"test_#{spec[:desc]}_js_asset_source_rewrites_destination" do
63
77
  with_site do
64
- generate_site :development
65
- destination = destination_path JS_BUNDLE_DESTINATION_PATH, 'app.js'
66
- org_mtime = mtime_of destination
67
- source = source_path JS_BUNDLE_SOURCE_DIR, 'app.js'
78
+ generate_site(:development)
79
+ destination = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
80
+ org_mtime = mtime_of(destination)
81
+ source = source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')
68
82
  ensure_file_mtime_changes { spec[:action].call(source) }
69
- generate_site :development, clear_cache: false
83
+ generate_site(:development, clear_cache: false)
70
84
 
71
85
  assert_equal File.read(destination), File.read(source)
72
86
  assert_operator mtime_of(destination), :>, org_mtime
@@ -76,17 +90,17 @@ module Jekyll::Minibundle::Test
76
90
 
77
91
  def test_supports_relative_and_absolute_destination_paths
78
92
  with_site do
79
- expected_css_path = destination_path CSS_BUNDLE_DESTINATION_PATH, 'common.css'
80
- expected_js_path = destination_path JS_BUNDLE_DESTINATION_PATH, 'app.js'
81
- generate_site :development
93
+ expected_css_path = destination_path(CSS_BUNDLE_DESTINATION_PATH, 'common.css')
94
+ expected_js_path = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
95
+ generate_site(:development)
82
96
 
83
97
  assert File.exists?(expected_css_path)
84
98
  assert File.exists?(expected_js_path)
85
99
  assert_equal 'assets/site/common.css', find_css_paths_from_index.last
86
100
  assert_equal 'assets/site/app.js', find_js_paths_from_index.last
87
101
 
88
- find_and_gsub_in_file source_path('_layouts/default.html'), 'destination_path: assets/site', 'destination_path: /assets/site'
89
- generate_site :development, clear_cache: false
102
+ find_and_gsub_in_file(source_path('_layouts/default.html'), 'destination_path: assets/site', 'destination_path: /assets/site')
103
+ generate_site(:development, clear_cache: false)
90
104
 
91
105
  assert File.exists?(expected_css_path)
92
106
  assert File.exists?(expected_js_path)
@@ -97,8 +111,8 @@ module Jekyll::Minibundle::Test
97
111
 
98
112
  def test_does_not_require_bundling_commands
99
113
  with_site do
100
- with_env 'JEKYLL_MINIBUNDLE_CMD_CSS' => nil, 'JEKYLL_MINIBUNDLE_CMD_JS' => nil do
101
- generate_site :development
114
+ with_env('JEKYLL_MINIBUNDLE_CMD_CSS' => nil, 'JEKYLL_MINIBUNDLE_CMD_JS' => nil) do
115
+ generate_site(:development)
102
116
  pass
103
117
  end
104
118
  end
@@ -106,16 +120,16 @@ module Jekyll::Minibundle::Test
106
120
 
107
121
  def test_does_not_rewrite_destination_when_nonsource_files_change
108
122
  with_site do
109
- generate_site :development
110
- expected_js_path = destination_path JS_BUNDLE_DESTINATION_PATH, 'app.js'
111
- org_mtime = mtime_of expected_js_path
112
- ensure_file_mtime_changes { File.write source_path(JS_BUNDLE_SOURCE_DIR, 'dependency.js'), '(function() {})()' }
113
- generate_site :development, clear_cache: false
123
+ generate_site(:development)
124
+ expected_js_path = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
125
+ org_mtime = mtime_of(expected_js_path)
126
+ ensure_file_mtime_changes { File.write(source_path(JS_BUNDLE_SOURCE_DIR, 'dependency.js'), '(function() {})()') }
127
+ generate_site(:development, clear_cache: false)
114
128
 
115
129
  assert_equal org_mtime, mtime_of(expected_js_path)
116
130
 
117
- ensure_file_mtime_changes { FileUtils.touch 'index.html' }
118
- generate_site :development, clear_cache: false
131
+ ensure_file_mtime_changes { FileUtils.touch('index.html') }
132
+ generate_site(:development, clear_cache: false)
119
133
 
120
134
  assert_equal org_mtime, mtime_of(expected_js_path)
121
135
  end
@@ -123,12 +137,20 @@ module Jekyll::Minibundle::Test
123
137
 
124
138
  private
125
139
 
140
+ def find_css_elements_from_index
141
+ find_html_elements_from_index('head link[media!="screen"]')
142
+ end
143
+
126
144
  def find_css_paths_from_index
127
- find_html_elements_from_index('head link[media="projection"]').map { |el| el['href'] }
145
+ find_css_elements_from_index.map { |el| el['href'] }
146
+ end
147
+
148
+ def find_js_elements_from_index
149
+ find_html_elements_from_index('body script')
128
150
  end
129
151
 
130
152
  def find_js_paths_from_index
131
- find_html_elements_from_index('body script').map { |el| el['src'] }
153
+ find_js_elements_from_index.map { |el| el['src'] }
132
154
  end
133
155
 
134
156
  def find_html_elements_from_index(css)
@@ -5,90 +5,90 @@ module Jekyll::Minibundle::Test
5
5
  class MiniBundleProductionModeTest < TestCase
6
6
  include FixtureConfig
7
7
 
8
- def test_css_asset_bundle_has_configured_attributes
9
- with_precompiled_site :production do
10
- element = find_html_element_from_index %{head link[href="#{EXPECTED_CSS_BUNDLE_PATH}"]}
11
- assert_equal 'my-styles', element['id']
12
- assert_equal 'projection', element['media']
8
+ def test_css_asset_bundle_has_stamp
9
+ with_precompiled_site(:production) do
10
+ assert_equal CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index
13
11
  end
14
12
  end
15
13
 
16
- def test_js_asset_bundle_has_configured_attributes
17
- with_precompiled_site :production do
18
- element = find_html_element_from_index %{body script[src="#{EXPECTED_JS_BUNDLE_PATH}"]}
19
- assert_equal 'my-scripts', element['id']
14
+ def test_js_asset_bundle_has_stamp
15
+ with_precompiled_site(:production) do
16
+ assert_equal JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index
20
17
  end
21
18
  end
22
19
 
23
- def test_css_asset_bundle_has_stamp
24
- with_precompiled_site :production do
25
- assert_equal EXPECTED_CSS_BUNDLE_PATH, find_css_path_from_index
20
+ def test_css_asset_bundle_has_configured_attributes
21
+ with_precompiled_site(:production) do
22
+ element = find_css_element_from_index
23
+ assert_equal 'my-styles', element['id']
24
+ assert_equal 'projection', element['media']
26
25
  end
27
26
  end
28
27
 
29
- def test_js_asset_bundle_has_stamp
30
- with_precompiled_site :production do
31
- assert_equal EXPECTED_JS_BUNDLE_PATH, find_js_path_from_index
28
+ def test_js_asset_bundle_has_configured_attributes
29
+ with_precompiled_site(:production) do
30
+ element = find_js_element_from_index
31
+ assert_equal 'my-scripts', element['id']
32
32
  end
33
33
  end
34
34
 
35
35
  def test_copies_css_asset_bundle_to_destination_dir
36
- with_precompiled_site :production do
37
- assert File.exists?(destination_path(EXPECTED_CSS_BUNDLE_PATH))
36
+ with_precompiled_site(:production) do
37
+ assert File.exists?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
38
38
  end
39
39
  end
40
40
 
41
41
  def test_copies_js_asset_bundle_to_destination_dir
42
- with_precompiled_site :production do
43
- assert File.exists?(destination_path(EXPECTED_JS_BUNDLE_PATH))
42
+ with_precompiled_site(:production) do
43
+ assert File.exists?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
44
44
  end
45
45
  end
46
46
 
47
47
  def test_concatenates_css_asset_bundle_in_configured_order
48
- with_precompiled_site :production do
49
- bundle = File.read(destination_path(EXPECTED_CSS_BUNDLE_PATH))
48
+ with_precompiled_site(:production) do
49
+ bundle = File.read(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
50
50
  assert_operator bundle.index('html { margin: 0; }'), :<, bundle.index('p { margin: 0; }')
51
51
  end
52
52
  end
53
53
 
54
54
  def test_concatenates_js_asset_bundle_in_configured_order
55
- with_precompiled_site :production do
56
- bundle = File.read(destination_path(EXPECTED_JS_BUNDLE_PATH))
55
+ with_precompiled_site(:production) do
56
+ bundle = File.read(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
57
57
  assert_operator bundle.index('root.dependency = {};'), :<, bundle.index('root.app = {};')
58
58
  end
59
59
  end
60
60
 
61
61
  def test_inserts_semicolons_between_js_assets
62
- with_precompiled_site :production do
63
- bundle = File.read(destination_path(EXPECTED_JS_BUNDLE_PATH))
62
+ with_precompiled_site(:production) do
63
+ bundle = File.read(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
64
64
  assert_match(%r|}\)\(window\)\n;\n\(function|, bundle)
65
65
  end
66
66
  end
67
67
 
68
68
  def test_minifies_css_asset_bundle
69
- with_precompiled_site :production do
69
+ with_precompiled_site(:production) do
70
70
  source_contents_size = source_assets_size(CSS_BUNDLE_SOURCE_DIR, %w{reset common}, 'css')
71
- destination_contents_size = File.read(destination_path(EXPECTED_CSS_BUNDLE_PATH)).size
71
+ destination_contents_size = File.read(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)).size
72
72
  assert_operator destination_contents_size, :<, source_contents_size
73
73
  end
74
74
  end
75
75
 
76
76
  def test_minifies_js_asset_bundle
77
- with_precompiled_site :production do
77
+ with_precompiled_site(:production) do
78
78
  source_contents_size = source_assets_size(JS_BUNDLE_SOURCE_DIR, %w{dependency app}, 'js')
79
- destination_contents_size = File.read(destination_path(EXPECTED_JS_BUNDLE_PATH)).size
79
+ destination_contents_size = File.read(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)).size
80
80
  assert_operator destination_contents_size, :<, source_contents_size
81
81
  end
82
82
  end
83
83
 
84
84
  def test_changing_css_asset_source_rewrites_destination
85
85
  with_site do
86
- generate_site :production
87
- org_mtime = mtime_of destination_path(EXPECTED_CSS_BUNDLE_PATH)
88
- ensure_file_mtime_changes { File.write source_path(CSS_BUNDLE_SOURCE_DIR, 'common.css'), 'h1 {}' }
89
- generate_site :production, clear_cache: false
86
+ generate_site(:production)
87
+ org_mtime = mtime_of(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
88
+ ensure_file_mtime_changes { File.write(source_path(CSS_BUNDLE_SOURCE_DIR, 'common.css'), 'h1 {}') }
89
+ generate_site(:production, clear_cache: false)
90
90
 
91
- refute File.exists?(destination_path(EXPECTED_CSS_BUNDLE_PATH))
91
+ refute File.exists?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
92
92
 
93
93
  new_destination = 'assets/site-9fd3995d6f0fce425db81c3691dfe93f.css'
94
94
 
@@ -100,12 +100,12 @@ module Jekyll::Minibundle::Test
100
100
 
101
101
  def test_changing_js_asset_source_rewrites_destination
102
102
  with_site do
103
- generate_site :production
104
- org_mtime = mtime_of destination_path(EXPECTED_JS_BUNDLE_PATH)
105
- ensure_file_mtime_changes { File.write source_path(JS_BUNDLE_SOURCE_DIR, 'app.js'), '(function() {})()' }
106
- generate_site :production, clear_cache: false
103
+ generate_site(:production)
104
+ org_mtime = mtime_of(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
105
+ ensure_file_mtime_changes { File.write(source_path(JS_BUNDLE_SOURCE_DIR, 'app.js'), '(function() {})()') }
106
+ generate_site(:production, clear_cache: false)
107
107
 
108
- refute File.exists?(destination_path(EXPECTED_JS_BUNDLE_PATH))
108
+ refute File.exists?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
109
109
 
110
110
  new_destination = 'assets/site-375a0b430b0c5555d0edd2205d26c04d.js'
111
111
 
@@ -117,11 +117,11 @@ module Jekyll::Minibundle::Test
117
117
 
118
118
  def test_touching_css_asset_source_rewrites_destination
119
119
  with_site do
120
- generate_site :production
121
- destination = EXPECTED_CSS_BUNDLE_PATH
122
- org_mtime = mtime_of destination_path(destination)
123
- ensure_file_mtime_changes { FileUtils.touch source_path(CSS_BUNDLE_SOURCE_DIR, 'common.css') }
124
- generate_site :production, clear_cache: false
120
+ generate_site(:production)
121
+ destination = CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH
122
+ org_mtime = mtime_of(destination_path(destination))
123
+ ensure_file_mtime_changes { FileUtils.touch(source_path(CSS_BUNDLE_SOURCE_DIR, 'common.css')) }
124
+ generate_site(:production, clear_cache: false)
125
125
 
126
126
  assert_equal destination, find_css_path_from_index
127
127
  assert File.exists?(destination_path(destination))
@@ -131,11 +131,11 @@ module Jekyll::Minibundle::Test
131
131
 
132
132
  def test_touching_js_asset_source_rewrites_destination
133
133
  with_site do
134
- generate_site :production
135
- destination = EXPECTED_JS_BUNDLE_PATH
136
- org_mtime = mtime_of destination_path(destination)
137
- ensure_file_mtime_changes { FileUtils.touch source_path(JS_BUNDLE_SOURCE_DIR, 'app.js') }
138
- generate_site :production, clear_cache: false
134
+ generate_site(:production)
135
+ destination = JS_BUNDLE_DESTINATION_FINGERPRINT_PATH
136
+ org_mtime = mtime_of(destination_path(destination))
137
+ ensure_file_mtime_changes { FileUtils.touch(source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')) }
138
+ generate_site(:production, clear_cache: false)
139
139
 
140
140
  assert_equal destination, find_js_path_from_index
141
141
  assert File.exists?(destination_path(destination))
@@ -145,29 +145,29 @@ module Jekyll::Minibundle::Test
145
145
 
146
146
  def test_supports_relative_and_absolute_destination_paths
147
147
  with_site do
148
- generate_site :production
149
- expected_css_path = destination_path EXPECTED_CSS_BUNDLE_PATH
150
- expected_js_path = destination_path EXPECTED_JS_BUNDLE_PATH
148
+ generate_site(:production)
149
+ expected_css_path = destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
150
+ expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
151
151
 
152
152
  assert File.exists?(expected_css_path)
153
153
  assert File.exists?(expected_js_path)
154
- assert_equal EXPECTED_CSS_BUNDLE_PATH, find_css_path_from_index
155
- assert_equal EXPECTED_JS_BUNDLE_PATH, find_js_path_from_index
154
+ assert_equal CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index
155
+ assert_equal JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index
156
156
 
157
- find_and_gsub_in_file source_path('_layouts/default.html'), 'destination_path: assets/site', 'destination_path: /assets/site'
158
- generate_site :production, clear_cache: false
157
+ find_and_gsub_in_file(source_path('_layouts/default.html'), 'destination_path: assets/site', 'destination_path: /assets/site')
158
+ generate_site(:production, clear_cache: false)
159
159
 
160
160
  assert File.exists?(expected_css_path)
161
161
  assert File.exists?(expected_js_path)
162
- assert_equal "/#{EXPECTED_CSS_BUNDLE_PATH}", find_css_path_from_index
163
- assert_equal "/#{EXPECTED_JS_BUNDLE_PATH}", find_js_path_from_index
162
+ assert_equal "/#{CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_css_path_from_index
163
+ assert_equal "/#{JS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_js_path_from_index
164
164
  end
165
165
  end
166
166
 
167
167
  def test_bundles_assets_only_once_at_startup
168
168
  with_site do
169
- with_env 'JEKYLL_MINIBUNDLE_CMD_JS' => cmd_to_remove_comments_and_count do
170
- generate_site :production
169
+ with_env('JEKYLL_MINIBUNDLE_CMD_JS' => cmd_to_remove_comments_and_count) do
170
+ generate_site(:production)
171
171
  end
172
172
  assert_equal 1, get_cmd_count
173
173
  end
@@ -175,20 +175,20 @@ module Jekyll::Minibundle::Test
175
175
 
176
176
  def test_does_not_rebundle_assets_when_nonsource_files_change
177
177
  with_site do
178
- with_env 'JEKYLL_MINIBUNDLE_CMD_JS' => cmd_to_remove_comments_and_count do
179
- generate_site :production
180
- expected_js_path = destination_path EXPECTED_JS_BUNDLE_PATH
181
- last_mtime = mtime_of expected_js_path
178
+ with_env('JEKYLL_MINIBUNDLE_CMD_JS' => cmd_to_remove_comments_and_count) do
179
+ generate_site(:production)
180
+ expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
181
+ last_mtime = mtime_of(expected_js_path)
182
182
 
183
183
  assert_equal 1, get_cmd_count
184
184
 
185
- ensure_file_mtime_changes { File.write source_path(CSS_BUNDLE_SOURCE_DIR, 'common.css'), 'h1 {}' }
186
- generate_site :production, clear_cache: false
185
+ ensure_file_mtime_changes { File.write(source_path(CSS_BUNDLE_SOURCE_DIR, 'common.css'), 'h1 {}') }
186
+ generate_site(:production, clear_cache: false)
187
187
 
188
188
  assert_equal last_mtime, mtime_of(expected_js_path)
189
189
  assert_equal 1, get_cmd_count
190
190
 
191
- ensure_file_mtime_changes { FileUtils.touch 'index.html' }
191
+ ensure_file_mtime_changes { FileUtils.touch('index.html') }
192
192
  generate_site :production, clear_cache: false
193
193
 
194
194
  assert_equal last_mtime, mtime_of(expected_js_path)
@@ -199,12 +199,20 @@ module Jekyll::Minibundle::Test
199
199
 
200
200
  private
201
201
 
202
+ def find_css_element_from_index
203
+ find_html_element_from_index('head link[media!="screen"]')
204
+ end
205
+
202
206
  def find_css_path_from_index
203
- find_html_element_from_index('head link[media="projection"]')['href']
207
+ find_css_element_from_index['href']
208
+ end
209
+
210
+ def find_js_element_from_index
211
+ find_html_element_from_index('body script')
204
212
  end
205
213
 
206
214
  def find_js_path_from_index
207
- find_html_element_from_index('body script')['src']
215
+ find_js_element_from_index['src']
208
216
  end
209
217
 
210
218
  def find_html_element_from_index(css)
@@ -213,7 +221,7 @@ module Jekyll::Minibundle::Test
213
221
 
214
222
  def source_assets_size(source_subdir, assets, type)
215
223
  assets.
216
- map { |f| File.read site_fixture_path(source_subdir, "#{f}.#{type}") }.
224
+ map { |f| File.read(site_fixture_path(source_subdir, "#{f}.#{type}")) }.
217
225
  join('').
218
226
  size
219
227
  end