jekyll-minibundle 1.4.4 → 1.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27c6e3e700c2d0f5767edcebbb8df218df565536
4
- data.tar.gz: 1fc68af34209d4556fcb726088fca486a318a33a
3
+ metadata.gz: c57552878f3ad0d964086ad33177b243dcf74586
4
+ data.tar.gz: c784618a1d7e99af9e26a8f62b0ea507f013d6f3
5
5
  SHA512:
6
- metadata.gz: c68cdff97eecd9343ea90498ff73e0c04987ef7020ee360d0c9a7c74d28782877e996cedd3e8ab8d1cdfbc5a9279bc8b18842c34a62d5206ff7320b46a056563
7
- data.tar.gz: 6f6873bc41f2bfde2e7d38b5e4091672fb3a59cff7d026e2d18580ea706527920c035c5b27d6833773ebdce9eeb2d4687b76aebab42b0b02317d00ac3613a230
6
+ metadata.gz: bfa016f615363e82e82a300d5a1a441ceef2467f167fbeb284f1850b88497c3573ef4e11ef37a09a99e0d51a59e1b71780d2fb05928f495a25aaadd6a3d808c0
7
+ data.tar.gz: 6d78b169081c7fa690d21efcda81dc5a7f3f60ae5aefa50d604d2623fc6d33959892c0a4770fc705516230c876bc17bbe4e0c57d5b0254959f0f74bc96082e46
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 1.4.5 / 2014-05-10
2
+
3
+ * Use SafeYAML to load user input from `minibundle` block for
4
+ consistent behavior with Jekyll and for security
5
+ * Clean log messages: show relative paths when bundling assets
6
+ * Add missing implementations of `relative_path` and `to_liquid`
7
+ methods from Jekyll's StaticFile API (introduced in Jekyll v1.5.0),
8
+ allowing Minibundle to behave better with other Jekyll plugins (#3,
9
+ @mmistakes)
10
+ * Fix Ruby deprecation warnings (use `File.exist?` instead of
11
+ `File.exists?`)
12
+
1
13
  # 1.4.4 / 2014-01-16
2
14
 
3
15
  * Conserve memory when calculating fingerprint for an asset.
data/README.md CHANGED
@@ -12,7 +12,8 @@ Tested with Ruby MRI 1.9.3, 2.0, and 2.1. Ruby 1.8 is *not* supported.
12
12
 
13
13
  The plugin works with Jekyll's watch (auto-regeneration) mode.
14
14
 
15
- [![Build Status](https://secure.travis-ci.org/tkareine/jekyll-minibundle.png)](http://travis-ci.org/tkareine/jekyll-minibundle)
15
+ [![Gem Version](https://badge.fury.io/rb/jekyll-minibundle.svg)](http://badge.fury.io/rb/jekyll-minibundle)
16
+ [![Build Status](https://secure.travis-ci.org/tkareine/jekyll-minibundle.svg)](http://travis-ci.org/tkareine/jekyll-minibundle)
16
17
 
17
18
  # Features
18
19
 
data/Rakefile CHANGED
@@ -40,13 +40,13 @@ namespace :gem do
40
40
  end
41
41
  end
42
42
 
43
- desc 'Run tests; envars: tests=<test_path> to select a particular suite, debug=1 to require Pry and PP'
43
+ desc 'Run tests; envars: tests=<test_path> to select a particular suite, debug=1 to require Pry and PP and enable warnings'
44
44
  task :test do
45
45
  glob = ENV.fetch('tests', 'test/{unit,integration}/*_test.rb')
46
46
  files = Dir[glob].
47
47
  map { |file| %r{^test/(.+)\.rb$}.match(file)[1] }.
48
48
  shelljoin
49
- opts = ENV['debug'] ? '-rpp -rpry' : ''
49
+ opts = ENV['debug'] ? '-w -rpp -rpry' : ''
50
50
  eval = %{-e 'ARGV.each { |f| require f }'}
51
51
  cmd = "ruby #{opts} #{eval} #{files}"
52
52
  env = get_minibundle_env('RUBYLIB' => 'lib:test')
@@ -27,10 +27,10 @@ minification tool (not even other gems).
27
27
 
28
28
  s.test_files = `git ls-files -- test`.split("\n")
29
29
 
30
- s.add_development_dependency 'jekyll', '~> 1.4'
31
- s.add_development_dependency 'minitest', '~> 5.2'
30
+ s.add_development_dependency 'jekyll', '~> 2.0'
31
+ s.add_development_dependency 'minitest', '~> 5.3'
32
32
  s.add_development_dependency 'nokogiri', '~> 1.6'
33
- s.add_development_dependency 'rake', '~> 10.1'
33
+ s.add_development_dependency 'rake', '~> 10.3'
34
34
 
35
35
  s.required_ruby_version = '>= 1.9.3'
36
36
 
@@ -3,8 +3,8 @@ require 'jekyll/minibundle/environment'
3
3
 
4
4
  module Jekyll::Minibundle
5
5
  class AssetBundle
6
- def initialize(type, assets, site_dir)
7
- @type, @assets, @site_dir = type, assets, site_dir
6
+ def initialize(type, asset_paths, site_dir)
7
+ @type, @asset_paths, @site_dir = type, asset_paths, site_dir
8
8
  @temp_file = Tempfile.new("jekyll-minibundle-#{@type}-")
9
9
  at_exit { @temp_file.close! }
10
10
  end
@@ -18,8 +18,8 @@ module Jekyll::Minibundle
18
18
  exit_status = spawn_minifier(cmd) do |input|
19
19
  $stdout.puts # place newline after "(Re)generating..." log messages
20
20
  log("Bundling #{@type} assets:")
21
- @assets.each do |asset|
22
- log(asset)
21
+ @asset_paths.each do |asset|
22
+ log(relative_path_from(asset, @site_dir))
23
23
  IO.foreach(asset) { |line| input.write(line) }
24
24
  input.puts(';') if @type == :js
25
25
  end
@@ -40,6 +40,10 @@ module Jekyll::Minibundle
40
40
  end
41
41
  end
42
42
 
43
+ def relative_path_from(path, base)
44
+ path.sub(/\A#{base}\//, '')
45
+ end
46
+
43
47
  def get_minifier_cmd
44
48
  Environment.command_for(@type)
45
49
  end
@@ -2,7 +2,9 @@ require 'fileutils'
2
2
 
3
3
  module Jekyll::Minibundle
4
4
  module AssetFileOperations
5
- def static_file!(site)
5
+ def add_as_static_file_to(site)
6
+ # NOTE: Rely on explicit site parameter (not on self's @site) so
7
+ # that we can utilize asset registry clearing for tests.
6
8
  unless site.static_files.include? self
7
9
  site.static_files << self
8
10
  end
@@ -4,6 +4,10 @@ module Jekyll::Minibundle
4
4
  asset_source_path
5
5
  end
6
6
 
7
+ def relative_path
8
+ path.sub(/\A#{@site.source}/, '')
9
+ end
10
+
7
11
  def asset_destination_path
8
12
  File.join(asset_destination_dir, asset_destination_basename)
9
13
  end
@@ -19,5 +23,13 @@ module Jekyll::Minibundle
19
23
  def modified?
20
24
  stamped_at != mtime
21
25
  end
26
+
27
+ def to_liquid
28
+ {
29
+ 'path' => relative_path,
30
+ 'modified_time' => mtime.to_s,
31
+ 'extname' => File.extname(relative_path)
32
+ }
33
+ end
22
34
  end
23
35
  end
@@ -10,27 +10,27 @@ module Jekyll::Minibundle
10
10
  @_instances = {}
11
11
  end
12
12
 
13
- def bundle_file(config)
13
+ def bundle_file(site, config)
14
14
  asset_destination_path = "#{config.fetch('destination_path')}.#{config.fetch('type')}"
15
- @_instances[asset_destination_path] ||= register_bundle_file(config)
15
+ @_instances[asset_destination_path] ||= register_bundle_file(site, config)
16
16
  end
17
17
 
18
- def stamp_file(asset_source_path, asset_destination_path)
19
- @_instances[asset_destination_path] ||= register_stamp_file(asset_source_path, asset_destination_path)
18
+ def stamp_file(site, asset_source_path, asset_destination_path)
19
+ @_instances[asset_destination_path] ||= register_stamp_file(site, asset_source_path, asset_destination_path)
20
20
  end
21
21
 
22
22
  private
23
23
 
24
- def register_bundle_file(config)
24
+ def register_bundle_file(site, config)
25
25
  if Environment.development?
26
- DevelopmentFileCollection.new(config)
26
+ DevelopmentFileCollection.new(site, config)
27
27
  else
28
- BundleFile.new(config)
28
+ BundleFile.new(site, config)
29
29
  end
30
30
  end
31
31
 
32
- def register_stamp_file(asset_source_path, asset_destination_path)
33
- StampFile.new(asset_source_path, asset_destination_path, &get_stamp_file_basenamer)
32
+ def register_stamp_file(site, asset_source_path, asset_destination_path)
33
+ StampFile.new(site, asset_source_path, asset_destination_path, &get_stamp_file_basenamer)
34
34
  end
35
35
 
36
36
  def get_stamp_file_basenamer
@@ -6,19 +6,22 @@ require 'jekyll/minibundle/asset_tag_markup'
6
6
  module Jekyll::Minibundle
7
7
  class BundleFile
8
8
  include AssetFileOperations
9
+ include AssetFilePaths
9
10
 
10
- def initialize(config)
11
+ attr_reader :stamped_at
12
+
13
+ def initialize(site, config)
14
+ @site = site
11
15
  @type = config.fetch('type')
12
- @site_source_dir = config.fetch('site_dir')
13
- asset_source_dir = File.join(@site_source_dir, config.fetch('source_dir'))
14
- @assets = config.fetch('assets').map { |asset_path| File.join(asset_source_dir, "#{asset_path}.#{@type}") }
16
+ asset_source_dir = File.join(@site.source, config.fetch('source_dir'))
17
+ @asset_paths = config.fetch('assets').map { |asset_path| File.join(asset_source_dir, "#{asset_path}.#{@type}") }
15
18
  @destination_path = config.fetch('destination_path')
16
19
  @attributes = config.fetch('attributes')
17
20
  @stamped_at = nil
18
21
  @is_modified = false
19
22
  end
20
23
 
21
- def markup
24
+ def destination_path_for_markup
22
25
  # we must rebundle here, if at all, in order to make sure the
23
26
  # markup and generated file have the same fingerprint
24
27
  if modified?
@@ -39,19 +42,12 @@ module Jekyll::Minibundle
39
42
  "#{@destination_path}-#{asset_stamp}.#{@type}"
40
43
  end
41
44
 
42
- def destination(site_destination_dir)
43
- File.join(site_destination_dir, asset_destination_path)
44
- end
45
-
46
45
  def mtime
47
- @assets.map { |f| File.stat(f).mtime.to_i }.max
48
- end
49
-
50
- def modified?
51
- @stamped_at != mtime
46
+ @asset_paths.map { |f| File.stat(f).mtime.to_i }.max
52
47
  end
53
48
 
54
- # writes destination only after `markup` has been called
49
+ # writes destination only after `destination_path_for_markup` has
50
+ # been called
55
51
  def write(site_destination_dir)
56
52
  if @is_modified
57
53
  write_destination(site_destination_dir)
@@ -69,7 +65,7 @@ module Jekyll::Minibundle
69
65
  end
70
66
 
71
67
  def asset_bundle
72
- @_asset_bundle ||= AssetBundle.new(@type, @assets, @site_source_dir)
68
+ @_asset_bundle ||= AssetBundle.new(@type, @asset_paths, @site.source)
73
69
  end
74
70
  end
75
71
  end
@@ -8,7 +8,8 @@ module Jekyll::Minibundle
8
8
 
9
9
  attr_reader :asset_source_path, :asset_destination_dir, :asset_destination_basename, :stamped_at
10
10
 
11
- def initialize(asset_source_path, asset_destination_path)
11
+ def initialize(site, asset_source_path, asset_destination_path)
12
+ @site = site
12
13
  @asset_source_path = asset_source_path
13
14
  @asset_destination_dir = File.dirname(asset_destination_path)
14
15
  @asset_destination_basename = File.basename(asset_destination_path)
@@ -3,29 +3,29 @@ require 'jekyll/minibundle/development_file'
3
3
 
4
4
  module Jekyll::Minibundle
5
5
  class DevelopmentFileCollection
6
- def initialize(config)
6
+ def initialize(site, config)
7
7
  @type = config.fetch('type')
8
- asset_source_dir = File.join(config.fetch('site_dir'), config.fetch('source_dir'))
8
+ asset_source_dir = File.join(site.source, config.fetch('source_dir'))
9
9
  destination_path = config.fetch('destination_path')
10
10
 
11
11
  @files = config.fetch('assets').map do |asset_path|
12
12
  asset_basename = "#{asset_path}.#{@type}"
13
13
  asset_source = File.join(asset_source_dir, asset_basename)
14
14
  asset_destination = File.join(destination_path, asset_basename)
15
- DevelopmentFile.new(asset_source, asset_destination)
15
+ DevelopmentFile.new(site, asset_source, asset_destination)
16
16
  end
17
17
 
18
18
  @attributes = config.fetch('attributes')
19
19
  end
20
20
 
21
- def static_file!(site)
21
+ def add_as_static_file_to(site)
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.add_as_static_file_to(site) }
26
26
  end
27
27
 
28
- def markup
28
+ def destination_path_for_markup
29
29
  @files.
30
30
  map { |f| AssetTagMarkup.make_markup(@type, f.asset_destination_path, @attributes) }.
31
31
  join("\n")
@@ -1,4 +1,4 @@
1
- require 'yaml'
1
+ require 'safe_yaml/load'
2
2
  require 'jekyll/minibundle/asset_file_registry'
3
3
 
4
4
  module Jekyll::Minibundle
@@ -10,10 +10,10 @@ module Jekyll::Minibundle
10
10
 
11
11
  def render(context)
12
12
  site = context.registers.fetch(:site)
13
- config = get_current_config(YAML.load(super), site)
14
- file = AssetFileRegistry.bundle_file(config)
15
- file.static_file!(site)
16
- file.markup
13
+ config = get_current_config(SafeYAML.load(super), site)
14
+ file = AssetFileRegistry.bundle_file(site, config)
15
+ file.add_as_static_file_to(site)
16
+ file.destination_path_for_markup
17
17
  end
18
18
 
19
19
  def self.default_config
@@ -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)
34
34
  end
35
35
  end
36
36
  end
@@ -9,9 +9,9 @@ module Jekyll::Minibundle
9
9
 
10
10
  def render(context)
11
11
  site = context.registers.fetch(:site)
12
- file = AssetFileRegistry.stamp_file(File.join(site.source, @asset_source), @asset_destination)
13
- file.static_file!(site)
14
- file.markup
12
+ file = AssetFileRegistry.stamp_file(site, @asset_source, @asset_destination)
13
+ file.add_as_static_file_to(site)
14
+ file.destination_path_for_markup
15
15
  end
16
16
  end
17
17
  end
@@ -9,9 +9,10 @@ module Jekyll::Minibundle
9
9
 
10
10
  attr_reader :asset_source_path, :asset_destination_dir, :stamped_at
11
11
 
12
- def initialize(asset_source_path, asset_destination_path, &basenamer)
12
+ def initialize(site, asset_source_path, asset_destination_path, &basenamer)
13
+ @site = site
13
14
  @basenamer = basenamer
14
- @asset_source_path = asset_source_path
15
+ @asset_source_path = File.join(@site.source, asset_source_path)
15
16
  @asset_destination_dir = File.dirname(asset_destination_path)
16
17
  @asset_destination_extension = File.extname(asset_destination_path)
17
18
  @asset_destination_base_prefix = File.basename(asset_destination_path)[0 .. -(@asset_destination_extension.size + 1)]
@@ -19,7 +20,7 @@ module Jekyll::Minibundle
19
20
  @is_modified = false
20
21
  end
21
22
 
22
- def markup
23
+ def destination_path_for_markup
23
24
  # we must regenerate the fingerprint here, if at all, in order
24
25
  # to make sure the markup and generated file have the same
25
26
  # fingerprint
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Minibundle
3
- VERSION = '1.4.4'
3
+ VERSION = '1.4.5'
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  filename = ARGV.first
4
4
 
5
- count = if File.exists? filename
5
+ count = if File.exist?(filename)
6
6
  File.read(filename).strip.to_i
7
7
  else
8
8
  0
@@ -55,7 +55,7 @@ module Jekyll::Minibundle::Test
55
55
  {desc: "touching", action: ->(source) { FileUtils.touch(source) }}
56
56
  ].each do |spec|
57
57
  define_method :"test_#{spec.fetch(:desc)}_css_asset_source_rewrites_destination" do
58
- with_site do
58
+ with_site_dir do
59
59
  generate_site(:development)
60
60
  destination = destination_path(CSS_BUNDLE_DESTINATION_PATH, 'common.css')
61
61
  org_mtime = mtime_of(destination)
@@ -74,7 +74,7 @@ module Jekyll::Minibundle::Test
74
74
  {desc: "touching", action: ->(source) { FileUtils.touch(source) }}
75
75
  ].each do |spec|
76
76
  define_method :"test_#{spec.fetch(:desc)}_js_asset_source_rewrites_destination" do
77
- with_site do
77
+ with_site_dir do
78
78
  generate_site(:development)
79
79
  destination = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
80
80
  org_mtime = mtime_of(destination)
@@ -89,28 +89,28 @@ module Jekyll::Minibundle::Test
89
89
  end
90
90
 
91
91
  def test_supports_relative_and_absolute_destination_paths
92
- with_site do
92
+ with_site_dir do
93
93
  expected_css_path = destination_path(CSS_BUNDLE_DESTINATION_PATH, 'common.css')
94
94
  expected_js_path = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
95
95
  generate_site(:development)
96
96
 
97
- assert File.exists?(expected_css_path)
98
- assert File.exists?(expected_js_path)
97
+ assert File.exist?(expected_css_path)
98
+ assert File.exist?(expected_js_path)
99
99
  assert_equal 'assets/site/common.css', find_css_paths_from_index.last
100
100
  assert_equal 'assets/site/app.js', find_js_paths_from_index.last
101
101
 
102
102
  find_and_gsub_in_file(source_path('_layouts/default.html'), 'destination_path: assets/site', 'destination_path: /assets/site')
103
103
  generate_site(:development, clear_cache: false)
104
104
 
105
- assert File.exists?(expected_css_path)
106
- assert File.exists?(expected_js_path)
105
+ assert File.exist?(expected_css_path)
106
+ assert File.exist?(expected_js_path)
107
107
  assert_equal '/assets/site/common.css', find_css_paths_from_index.last
108
108
  assert_equal '/assets/site/app.js', find_js_paths_from_index.last
109
109
  end
110
110
  end
111
111
 
112
112
  def test_does_not_require_bundling_commands
113
- with_site do
113
+ with_site_dir do
114
114
  with_env('JEKYLL_MINIBUNDLE_CMD_CSS' => nil, 'JEKYLL_MINIBUNDLE_CMD_JS' => nil) do
115
115
  generate_site(:development)
116
116
  pass
@@ -119,7 +119,7 @@ module Jekyll::Minibundle::Test
119
119
  end
120
120
 
121
121
  def test_does_not_rewrite_destination_when_nonsource_files_change
122
- with_site do
122
+ with_site_dir do
123
123
  generate_site(:development)
124
124
  expected_js_path = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
125
125
  org_mtime = mtime_of(expected_js_path)
@@ -158,7 +158,7 @@ module Jekyll::Minibundle::Test
158
158
  end
159
159
 
160
160
  def expect_file_exists_and_is_equal_to(actual, expected)
161
- assert File.exists?(actual)
161
+ assert File.exist?(actual)
162
162
  assert_equal File.read(expected), File.read(actual)
163
163
  end
164
164
  end
@@ -34,13 +34,13 @@ module Jekyll::Minibundle::Test
34
34
 
35
35
  def test_copies_css_asset_bundle_to_destination_dir
36
36
  with_precompiled_site(:production) do
37
- assert File.exists?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
37
+ assert File.exist?(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
42
  with_precompiled_site(:production) do
43
- assert File.exists?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
43
+ assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
44
44
  end
45
45
  end
46
46
 
@@ -82,41 +82,41 @@ module Jekyll::Minibundle::Test
82
82
  end
83
83
 
84
84
  def test_changing_css_asset_source_rewrites_destination
85
- with_site do
85
+ with_site_dir do
86
86
  generate_site(:production)
87
87
  org_mtime = mtime_of(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
88
88
  ensure_file_mtime_changes { File.write(source_path(CSS_BUNDLE_SOURCE_DIR, 'common.css'), 'h1 {}') }
89
89
  generate_site(:production, clear_cache: false)
90
90
 
91
- refute File.exists?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
91
+ refute File.exist?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
92
92
 
93
93
  new_destination = 'assets/site-9fd3995d6f0fce425db81c3691dfe93f.css'
94
94
 
95
95
  assert_equal new_destination, find_css_path_from_index
96
- assert File.exists?(destination_path(new_destination))
96
+ assert File.exist?(destination_path(new_destination))
97
97
  assert_operator mtime_of(destination_path(new_destination)), :>, org_mtime
98
98
  end
99
99
  end
100
100
 
101
101
  def test_changing_js_asset_source_rewrites_destination
102
- with_site do
102
+ with_site_dir do
103
103
  generate_site(:production)
104
104
  org_mtime = mtime_of(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
105
105
  ensure_file_mtime_changes { File.write(source_path(JS_BUNDLE_SOURCE_DIR, 'app.js'), '(function() {})()') }
106
106
  generate_site(:production, clear_cache: false)
107
107
 
108
- refute File.exists?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
108
+ refute File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
109
109
 
110
110
  new_destination = 'assets/site-375a0b430b0c5555d0edd2205d26c04d.js'
111
111
 
112
112
  assert_equal new_destination, find_js_path_from_index
113
- assert File.exists?(destination_path(new_destination))
113
+ assert File.exist?(destination_path(new_destination))
114
114
  assert_operator mtime_of(destination_path(new_destination)), :>, org_mtime
115
115
  end
116
116
  end
117
117
 
118
118
  def test_touching_css_asset_source_rewrites_destination
119
- with_site do
119
+ with_site_dir do
120
120
  generate_site(:production)
121
121
  destination = CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH
122
122
  org_mtime = mtime_of(destination_path(destination))
@@ -124,13 +124,13 @@ module Jekyll::Minibundle::Test
124
124
  generate_site(:production, clear_cache: false)
125
125
 
126
126
  assert_equal destination, find_css_path_from_index
127
- assert File.exists?(destination_path(destination))
127
+ assert File.exist?(destination_path(destination))
128
128
  assert_operator mtime_of(destination_path(destination)), :>, org_mtime
129
129
  end
130
130
  end
131
131
 
132
132
  def test_touching_js_asset_source_rewrites_destination
133
- with_site do
133
+ with_site_dir do
134
134
  generate_site(:production)
135
135
  destination = JS_BUNDLE_DESTINATION_FINGERPRINT_PATH
136
136
  org_mtime = mtime_of(destination_path(destination))
@@ -138,34 +138,34 @@ module Jekyll::Minibundle::Test
138
138
  generate_site(:production, clear_cache: false)
139
139
 
140
140
  assert_equal destination, find_js_path_from_index
141
- assert File.exists?(destination_path(destination))
141
+ assert File.exist?(destination_path(destination))
142
142
  assert_operator mtime_of(destination_path(destination)), :>, org_mtime
143
143
  end
144
144
  end
145
145
 
146
146
  def test_supports_relative_and_absolute_destination_paths
147
- with_site do
147
+ with_site_dir do
148
148
  generate_site(:production)
149
149
  expected_css_path = destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
150
150
  expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
151
151
 
152
- assert File.exists?(expected_css_path)
153
- assert File.exists?(expected_js_path)
152
+ assert File.exist?(expected_css_path)
153
+ assert File.exist?(expected_js_path)
154
154
  assert_equal CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index
155
155
  assert_equal JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index
156
156
 
157
157
  find_and_gsub_in_file(source_path('_layouts/default.html'), 'destination_path: assets/site', 'destination_path: /assets/site')
158
158
  generate_site(:production, clear_cache: false)
159
159
 
160
- assert File.exists?(expected_css_path)
161
- assert File.exists?(expected_js_path)
160
+ assert File.exist?(expected_css_path)
161
+ assert File.exist?(expected_js_path)
162
162
  assert_equal "/#{CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_css_path_from_index
163
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
- with_site do
168
+ with_site_dir do
169
169
  with_env('JEKYLL_MINIBUNDLE_CMD_JS' => cmd_to_remove_comments_and_count) do
170
170
  generate_site(:production)
171
171
  end
@@ -174,7 +174,7 @@ module Jekyll::Minibundle::Test
174
174
  end
175
175
 
176
176
  def test_does_not_rebundle_assets_when_nonsource_files_change
177
- with_site do
177
+ with_site_dir do
178
178
  with_env('JEKYLL_MINIBUNDLE_CMD_JS' => cmd_to_remove_comments_and_count) do
179
179
  generate_site(:production)
180
180
  expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
@@ -8,14 +8,14 @@ module Jekyll::Minibundle::Test
8
8
  def test_asset_destination_path_has_no_stamp_in_development_mode
9
9
  with_precompiled_site(:development) do
10
10
  assert_equal STAMP_DESTINATION_PATH, find_css_path_from_index
11
- assert File.exists?(destination_path(STAMP_DESTINATION_PATH))
11
+ assert File.exist?(destination_path(STAMP_DESTINATION_PATH))
12
12
  end
13
13
  end
14
14
 
15
15
  def test_asset_destination_path_has_stamp_in_production_mode
16
16
  with_precompiled_site(:production) do
17
17
  assert_equal STAMP_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index
18
- assert File.exists?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
18
+ assert File.exist?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
19
19
  end
20
20
  end
21
21
 
@@ -28,24 +28,24 @@ module Jekyll::Minibundle::Test
28
28
  end
29
29
 
30
30
  def test_changing_asset_source_rewrites_destination
31
- with_site do
31
+ with_site_dir do
32
32
  generate_site(:production)
33
33
  org_mtime = mtime_of(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
34
34
  ensure_file_mtime_changes { File.write(source_path(STAMP_SOURCE_PATH), 'h1 {}') }
35
35
  generate_site(:production, clear_cache: false)
36
36
 
37
- refute File.exists?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
37
+ refute File.exist?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
38
38
 
39
39
  new_destination = 'assets/screen-0f5dbd1e527a2bee267e85007b08d2a5.css'
40
40
 
41
41
  assert_equal new_destination, find_css_path_from_index
42
- assert File.exists?(destination_path(new_destination))
42
+ assert File.exist?(destination_path(new_destination))
43
43
  assert_operator mtime_of(destination_path(new_destination)), :>, org_mtime
44
44
  end
45
45
  end
46
46
 
47
47
  def test_touching_asset_source_rewrites_destination
48
- with_site do
48
+ with_site_dir do
49
49
  generate_site(:production)
50
50
  destination = STAMP_DESTINATION_FINGERPRINT_PATH
51
51
  org_mtime = mtime_of(destination_path(destination))
@@ -53,29 +53,29 @@ module Jekyll::Minibundle::Test
53
53
  generate_site(:production, clear_cache: false)
54
54
 
55
55
  assert_equal destination, find_css_path_from_index
56
- assert File.exists?(destination_path(destination))
56
+ assert File.exist?(destination_path(destination))
57
57
  assert_operator mtime_of(destination_path(destination)), :>, org_mtime
58
58
  end
59
59
  end
60
60
 
61
61
  def test_supports_relative_and_absolute_destination_paths
62
- with_site do
62
+ with_site_dir do
63
63
  generate_site(:production)
64
64
  expected_path = destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)
65
65
 
66
- assert File.exists?(expected_path)
66
+ assert File.exist?(expected_path)
67
67
  assert_equal STAMP_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index
68
68
 
69
69
  find_and_gsub_in_file(source_path('_layouts/default.html'), %r{assets/screen.css}, '/\0')
70
70
  generate_site(:production, clear_cache: false)
71
71
 
72
- assert File.exists?(expected_path)
72
+ assert File.exist?(expected_path)
73
73
  assert_equal "/#{STAMP_DESTINATION_FINGERPRINT_PATH}", find_css_path_from_index
74
74
  end
75
75
  end
76
76
 
77
77
  def test_does_not_rewrite_destination_when_nonsource_files_change
78
- with_site do
78
+ with_site_dir do
79
79
  generate_site(:production)
80
80
  expected_path = destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)
81
81
  org_mtime = mtime_of(expected_path)
@@ -19,7 +19,7 @@ module Jekyll::Minibundle::Test
19
19
 
20
20
  [:development, :production].each do |env|
21
21
  define_method :"test_ministamp_allows_using_static_file_as_asset_source_in_#{env}_mode" do
22
- with_site do
22
+ with_site_dir do
23
23
  contents = 'h2 {}'
24
24
  File.write(source_path('assets/shared.css'), contents)
25
25
  find_and_gsub_in_file(source_path('_layouts/default.html'), 'ministamp _tmp/site.css', 'ministamp assets/shared.css')
@@ -35,7 +35,7 @@ module Jekyll::Minibundle::Test
35
35
  end
36
36
 
37
37
  def test_minibundle_allows_using_static_file_as_asset_source_in_development_mode
38
- with_site do
38
+ with_site_dir do
39
39
  dep_contents = 'console.log("lol")'
40
40
  app_contents = 'console.log("balal")'
41
41
  File.write(source_path('assets/dependency.js'), dep_contents)
@@ -49,7 +49,7 @@ module Jekyll::Minibundle::Test
49
49
  end
50
50
 
51
51
  def test_minibundle_allows_using_static_file_as_asset_source_in_production_mode
52
- with_site do
52
+ with_site_dir do
53
53
  dep_contents = 'console.log("lol")'
54
54
  app_contents = 'console.log("balal")'
55
55
  bundled_contents = "#{dep_contents};\n#{app_contents};\n"
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'ostruct'
2
3
  require 'tempfile'
3
4
  require 'minitest/autorun'
4
5
  require 'nokogiri'
@@ -48,7 +49,7 @@ module Jekyll::Minibundle::Test
48
49
  org_env.each { |k, v| ENV[k] = v }
49
50
  end
50
51
 
51
- def with_site(&block)
52
+ def with_site_dir(&block)
52
53
  Dir.mktmpdir("jekyll-minibundle-test-site-") do |dir|
53
54
  Dir.chdir(dir) do
54
55
  _copy_fixture_site_dir(Dir.pwd)
@@ -57,6 +58,24 @@ module Jekyll::Minibundle::Test
57
58
  end
58
59
  end
59
60
 
61
+ def new_fake_site(dir)
62
+ OpenStruct.new(:source => dir)
63
+ end
64
+
65
+ def new_real_site
66
+ config = nil
67
+ capture_io do
68
+ config = Jekyll.configuration(TestCase.site_generation_jekyll_options)
69
+ end
70
+ Jekyll::Site.new(config)
71
+ end
72
+
73
+ def with_fake_site(&block)
74
+ with_site_dir do |dir|
75
+ yield new_fake_site(dir)
76
+ end
77
+ end
78
+
60
79
  def with_precompiled_site(mode, &block)
61
80
  Dir.chdir(_get_precompiled_site(mode), &block)
62
81
  end
@@ -77,7 +96,7 @@ module Jekyll::Minibundle::Test
77
96
  end
78
97
 
79
98
  def get_cmd_count
80
- if File.exists?('count')
99
+ if File.exist?('count')
81
100
  File.read('count').to_i
82
101
  else
83
102
  0
@@ -109,10 +128,8 @@ module Jekyll::Minibundle::Test
109
128
 
110
129
  def _generate_site(test_options)
111
130
  AssetFileRegistry.clear if test_options.fetch(:clear_cache)
112
-
113
- capture_io do
114
- Jekyll::Site.new(Jekyll.configuration(TestCase.site_generation_jekyll_options)).process
115
- end
131
+ site = new_real_site
132
+ capture_io { site.process }
116
133
  end
117
134
 
118
135
  def _get_site_generation_test_options(options)
@@ -8,22 +8,22 @@ module Jekyll::Minibundle::Test
8
8
  end
9
9
 
10
10
  def test_returns_same_stamp_file_instance_for_same_destination_path
11
- first = AssetFileRegistry.stamp_file('_assets/src1.css', 'assets/dest.css')
12
- second = AssetFileRegistry.stamp_file('_assets/src2.css', 'assets/dest.css')
11
+ first = AssetFileRegistry.stamp_file(site, '_assets/src1.css', 'assets/dest.css')
12
+ second = AssetFileRegistry.stamp_file(site, '_assets/src2.css', 'assets/dest.css')
13
13
  assert_same first, second
14
14
  assert_equal 1, asset_file_registry_size
15
15
  end
16
16
 
17
17
  def test_returns_same_bundle_file_instance_for_same_destination_path_and_type
18
- first = AssetFileRegistry.bundle_file(bundle_config.merge('assets' => %w{a1 a2}))
19
- second = AssetFileRegistry.bundle_file(bundle_config.merge('assets' => %w{b1 b2}))
18
+ first = AssetFileRegistry.bundle_file(site, bundle_config.merge('assets' => %w{a1 a2}))
19
+ second = AssetFileRegistry.bundle_file(site, bundle_config.merge('assets' => %w{b1 b2}))
20
20
  assert_same first, second
21
21
  assert_equal 1, asset_file_registry_size
22
22
  end
23
23
 
24
24
  def test_bundle_files_allow_same_path_for_different_types
25
- AssetFileRegistry.bundle_file(bundle_config.merge('type' => :css))
26
- AssetFileRegistry.bundle_file(bundle_config.merge('type' => :js))
25
+ AssetFileRegistry.bundle_file(site, bundle_config.merge('type' => :css))
26
+ AssetFileRegistry.bundle_file(site, bundle_config.merge('type' => :js))
27
27
  assert_equal 2, asset_file_registry_size
28
28
  end
29
29
 
@@ -32,7 +32,6 @@ module Jekyll::Minibundle::Test
32
32
  def bundle_config
33
33
  {
34
34
  'type' => :css,
35
- 'site_dir' => '.',
36
35
  'source_dir' => '_assets/styles',
37
36
  'assets' => %w{dependency app},
38
37
  'destination_path' => 'assets/site',
@@ -43,5 +42,9 @@ module Jekyll::Minibundle::Test
43
42
  def asset_file_registry_size
44
43
  AssetFileRegistry.instance_variable_get(:@_instances).size
45
44
  end
45
+
46
+ def site
47
+ OpenStruct.new(:source => '.')
48
+ end
46
49
  end
47
50
  end
@@ -7,13 +7,13 @@ module Jekyll::Minibundle::Test
7
7
  include FixtureConfig
8
8
 
9
9
  def test_calling_markup_determines_fingerprint_and_destination_write
10
- with_site do
10
+ with_fake_site do |site|
11
11
  with_env('JEKYLL_MINIBUNDLE_CMD_JS' => cmd_to_remove_comments_and_count) do
12
- bundle_file = BundleFile.new(bundle_config)
12
+ bundle_file = BundleFile.new(site, bundle_config)
13
13
  source = source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')
14
14
  old_destination = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
15
15
  org_markup, last_markup = nil
16
- capture_io { org_markup = bundle_file.markup }
16
+ capture_io { org_markup = bundle_file.destination_path_for_markup }
17
17
 
18
18
  assert bundle_file.write('_site')
19
19
 
@@ -21,7 +21,7 @@ module Jekyll::Minibundle::Test
21
21
 
22
22
  assert_equal 1, get_cmd_count
23
23
 
24
- last_markup = bundle_file.markup
24
+ last_markup = bundle_file.destination_path_for_markup
25
25
  ensure_file_mtime_changes { File.write(source, '(function() {})()') }
26
26
 
27
27
  # preserve fingerprint and content seen in last markup phase
@@ -30,7 +30,7 @@ module Jekyll::Minibundle::Test
30
30
  assert_equal org_mtime, mtime_of(old_destination)
31
31
  assert_equal 1, get_cmd_count
32
32
 
33
- capture_io { last_markup = bundle_file.markup }
33
+ capture_io { last_markup = bundle_file.destination_path_for_markup }
34
34
 
35
35
  assert bundle_file.write('_site')
36
36
 
@@ -45,14 +45,14 @@ module Jekyll::Minibundle::Test
45
45
  end
46
46
 
47
47
  def test_many_consecutive_markup_calls_trigger_one_destination_write
48
- with_site do
48
+ with_fake_site do |site|
49
49
  with_env('JEKYLL_MINIBUNDLE_CMD_JS' => cmd_to_remove_comments_and_count) do
50
- bundle_file = BundleFile.new(bundle_config)
50
+ bundle_file = BundleFile.new(site, bundle_config)
51
51
  source = source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')
52
52
  destination = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
53
53
  org_markup, last_markup = nil
54
- capture_io { org_markup = bundle_file.markup }
55
- bundle_file.markup
54
+ capture_io { org_markup = bundle_file.destination_path_for_markup }
55
+ bundle_file.destination_path_for_markup
56
56
 
57
57
  assert bundle_file.write('_site')
58
58
 
@@ -61,8 +61,8 @@ module Jekyll::Minibundle::Test
61
61
  assert_equal 1, get_cmd_count
62
62
 
63
63
  ensure_file_mtime_changes { FileUtils.touch(source) }
64
- capture_io { last_markup = bundle_file.markup }
65
- bundle_file.markup
64
+ capture_io { last_markup = bundle_file.destination_path_for_markup }
65
+ bundle_file.destination_path_for_markup
66
66
 
67
67
  assert bundle_file.write('_site')
68
68
  assert_equal org_markup, last_markup
@@ -72,30 +72,37 @@ module Jekyll::Minibundle::Test
72
72
  end
73
73
  end
74
74
 
75
- def test_calling_write_before_markup_has_no_effect
76
- with_site do
75
+ def test_calling_write_before_destination_path_for_markup_has_no_effect
76
+ with_fake_site do |site|
77
77
  with_env('JEKYLL_MINIBUNDLE_CMD_JS' => cmd_to_remove_comments_and_count) do
78
- bundle_file = BundleFile.new(bundle_config)
78
+ bundle_file = BundleFile.new(site, bundle_config)
79
79
 
80
80
  refute bundle_file.write('_site')
81
81
  assert_empty Dir[destination_path('assets/*.js')]
82
82
  assert_equal 0, get_cmd_count
83
83
 
84
- capture_io { bundle_file.markup }
84
+ capture_io { bundle_file.destination_path_for_markup }
85
85
 
86
86
  assert bundle_file.write('_site')
87
- assert File.exists?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
87
+ assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
88
88
  assert_equal 1, get_cmd_count
89
89
  end
90
90
  end
91
91
  end
92
92
 
93
+ def test_to_liquid
94
+ with_fake_site do |site|
95
+ hash = BundleFile.new(site, bundle_config).to_liquid
96
+ assert_match(/jekyll-minibundle-js-/, hash['path'])
97
+ refute_empty hash['modified_time']
98
+ end
99
+ end
100
+
93
101
  private
94
102
 
95
103
  def bundle_config
96
104
  {
97
105
  'type' => :js,
98
- 'site_dir' => '.',
99
106
  'source_dir' => JS_BUNDLE_SOURCE_DIR,
100
107
  'assets' => %w{dependency app},
101
108
  'destination_path' => JS_BUNDLE_DESTINATION_PATH,
@@ -6,30 +6,49 @@ module Jekyll::Minibundle::Test
6
6
  class DevelopmentFileCollectionTest < TestCase
7
7
  include FixtureConfig
8
8
 
9
- def test_calling_write_before_markup_writes_destination
10
- with_site do
11
- dev_files = DevelopmentFileCollection.new(bundle_config)
9
+ def test_calling_write_before_destination_path_for_markup_writes_destination
10
+ with_fake_site do |site|
11
+ dev_files = DevelopmentFileCollection.new(site, bundle_config)
12
12
 
13
13
  assert first_file_of(dev_files).write('_site')
14
14
 
15
15
  destination_file = destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js')
16
16
 
17
- assert File.exists?(destination_file)
17
+ assert File.exist?(destination_file)
18
18
 
19
19
  org_mtime = mtime_of(destination_file)
20
- dev_files.markup
20
+ dev_files.destination_path_for_markup
21
21
 
22
22
  refute first_file_of(dev_files).write('_site')
23
23
  assert_equal org_mtime, mtime_of(destination_file)
24
24
  end
25
25
  end
26
26
 
27
+ def test_to_liquid
28
+ with_fake_site do |site|
29
+ files = DevelopmentFileCollection.new(site, bundle_config).
30
+ instance_variable_get('@files').
31
+ sort_by { |f| f.path }
32
+
33
+ hash = files[0].to_liquid
34
+
35
+ assert_equal "/#{JS_BUNDLE_SOURCE_DIR}/app.js", hash['path']
36
+ refute_empty hash['modified_time']
37
+ assert_equal '.js', hash['extname']
38
+
39
+ hash = files[1].to_liquid
40
+
41
+ assert_equal "/#{JS_BUNDLE_SOURCE_DIR}/dependency.js", hash['path']
42
+ refute_empty hash['modified_time']
43
+ assert_equal '.js', hash['extname']
44
+ end
45
+ end
46
+
27
47
  private
28
48
 
29
49
  def bundle_config
30
50
  {
31
51
  'type' => :js,
32
- 'site_dir' => '.',
33
52
  'source_dir' => JS_BUNDLE_SOURCE_DIR,
34
53
  'assets' => %w{dependency app},
35
54
  'destination_path' => JS_BUNDLE_DESTINATION_PATH,
@@ -0,0 +1,63 @@
1
+ require 'support/test_case'
2
+ require 'support/fixture_config'
3
+ require 'jekyll/minibundle/development_file_collection'
4
+ require 'jekyll/minibundle/bundle_file'
5
+ require 'jekyll/minibundle/stamp_file'
6
+
7
+ module Jekyll::Minibundle::Test
8
+ class JekyllPayloadTest < TestCase
9
+ include FixtureConfig
10
+
11
+ def test_sorts_stamp_files_in_site_payload
12
+ with_site do |site|
13
+ file = StampFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH, &stamp_basenamer)
14
+ run_site_payload(site, file)
15
+ end
16
+ end
17
+
18
+ def test_sorts_bundle_files_in_site_payload
19
+ with_site do |site|
20
+ file = BundleFile.new(site, bundle_config)
21
+ run_site_payload(site, file)
22
+ end
23
+ end
24
+
25
+ def test_sorts_development_files_in_site_payload
26
+ with_site do |site|
27
+ file = DevelopmentFileCollection.new(site, bundle_config)
28
+ run_site_payload(site, file)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def with_site(&block)
35
+ with_site_dir do
36
+ yield new_real_site
37
+ end
38
+ end
39
+
40
+ def run_site_payload(site, file)
41
+ file.add_as_static_file_to(site)
42
+
43
+ static_file = Jekyll::StaticFile.new(site, '.', 'dir', 'name.css')
44
+ site.static_files << static_file
45
+
46
+ site.site_payload
47
+ end
48
+
49
+ def stamp_basenamer
50
+ ->(base, ext, stamper) { "#{base}-#{stamper.call}#{ext}" }
51
+ end
52
+
53
+ def bundle_config
54
+ {
55
+ 'type' => :js,
56
+ 'source_dir' => JS_BUNDLE_SOURCE_DIR,
57
+ 'assets' => %w{dependency app},
58
+ 'destination_path' => JS_BUNDLE_DESTINATION_PATH,
59
+ 'attributes' => {}
60
+ }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,26 @@
1
+ require 'support/test_case'
2
+ require 'jekyll/minibundle/development_file'
3
+ require 'jekyll/minibundle/bundle_file'
4
+ require 'jekyll/minibundle/stamp_file'
5
+
6
+ module Jekyll::Minibundle::Test
7
+ class JekyllStaticFileAPITest < TestCase
8
+ def test_development_file_conforms_to_static_file_api
9
+ assert_empty missing_api_methods(DevelopmentFile)
10
+ end
11
+
12
+ def test_bundle_file_conforms_to_static_file_api
13
+ assert_empty missing_api_methods(BundleFile)
14
+ end
15
+
16
+ def test_stamp_file_conforms_to_static_file_api
17
+ assert_empty missing_api_methods(StampFile)
18
+ end
19
+
20
+ private
21
+
22
+ def missing_api_methods(clazz)
23
+ Jekyll::StaticFile.public_instance_methods - clazz.public_instance_methods
24
+ end
25
+ end
26
+ end
@@ -6,17 +6,17 @@ module Jekyll::Minibundle::Test
6
6
  class StampFileTest < TestCase
7
7
  include FixtureConfig
8
8
 
9
- def test_calling_markup_determines_fingerprint_and_destination_write
10
- with_site do
11
- stamp_file = StampFile.new(STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH, &stamp_basenamer)
9
+ def test_calling_destination_path_for_markup_determines_fingerprint_and_destination_write
10
+ with_fake_site do |site|
11
+ stamp_file = StampFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH, &stamp_basenamer)
12
12
  source = source_path(STAMP_SOURCE_PATH)
13
13
  old_destination = destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)
14
- org_markup = stamp_file.markup
14
+ org_markup = stamp_file.destination_path_for_markup
15
15
 
16
16
  assert stamp_file.write('_site')
17
17
 
18
18
  org_mtime = mtime_of(old_destination)
19
- last_markup = stamp_file.markup
19
+ last_markup = stamp_file.destination_path_for_markup
20
20
  ensure_file_mtime_changes { File.write(source, 'h1 {}') }
21
21
 
22
22
  # preserve fingerprint and content seen in last markup phase
@@ -25,7 +25,7 @@ module Jekyll::Minibundle::Test
25
25
  assert_equal org_mtime, mtime_of(old_destination)
26
26
  assert_equal File.read(site_fixture_path(STAMP_SOURCE_PATH)), File.read(old_destination)
27
27
 
28
- last_markup = stamp_file.markup
28
+ last_markup = stamp_file.destination_path_for_markup
29
29
 
30
30
  assert stamp_file.write('_site')
31
31
 
@@ -38,20 +38,20 @@ module Jekyll::Minibundle::Test
38
38
  end
39
39
  end
40
40
 
41
- def test_many_consecutive_markup_calls_trigger_one_destination_write
42
- with_site do
43
- stamp_file = StampFile.new(STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH, &stamp_basenamer)
41
+ def test_many_consecutive_destination_path_for_markup_calls_trigger_one_destination_write
42
+ with_fake_site do |site|
43
+ stamp_file = StampFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH, &stamp_basenamer)
44
44
  source = source_path(STAMP_SOURCE_PATH)
45
45
  destination = destination_path(STAMP_DESTINATION_FINGERPRINT_PATH)
46
- org_markup = stamp_file.markup
47
- stamp_file.markup
46
+ org_markup = stamp_file.destination_path_for_markup
47
+ stamp_file.destination_path_for_markup
48
48
 
49
49
  assert stamp_file.write('_site')
50
50
 
51
51
  org_mtime = mtime_of(destination)
52
52
  ensure_file_mtime_changes { FileUtils.touch(source) }
53
- last_markup = stamp_file.markup
54
- stamp_file.markup
53
+ last_markup = stamp_file.destination_path_for_markup
54
+ stamp_file.destination_path_for_markup
55
55
 
56
56
  assert stamp_file.write('_site')
57
57
  assert_equal org_markup, last_markup
@@ -60,17 +60,26 @@ module Jekyll::Minibundle::Test
60
60
  end
61
61
  end
62
62
 
63
- def test_calling_write_before_markup_has_no_effect
64
- with_site do
65
- stamp_file = StampFile.new(STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH, &stamp_basenamer)
63
+ def test_calling_write_before_destination_path_for_markup_has_no_effect
64
+ with_fake_site do |site|
65
+ stamp_file = StampFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH, &stamp_basenamer)
66
66
 
67
67
  refute stamp_file.write('_site')
68
68
  assert_empty Dir[destination_path('assets/*.css')]
69
69
 
70
- stamp_file.markup
70
+ stamp_file.destination_path_for_markup
71
71
 
72
72
  assert stamp_file.write('_site')
73
- assert File.exists?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
73
+ assert File.exist?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
74
+ end
75
+ end
76
+
77
+ def test_to_liquid
78
+ with_fake_site do |site|
79
+ hash = StampFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH, &stamp_basenamer).to_liquid
80
+ assert_equal "/#{STAMP_SOURCE_PATH}", hash['path']
81
+ refute_empty hash['modified_time']
82
+ assert_equal '.css', hash['extname']
74
83
  end
75
84
  end
76
85
 
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: 1.4.4
4
+ version: 1.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tuomas Kareinen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-16 00:00:00.000000000 Z
11
+ date: 2014-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.4'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.4'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.2'
33
+ version: '5.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.2'
40
+ version: '5.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.1'
61
+ version: '10.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.1'
68
+ version: '10.3'
69
69
  description: |
70
70
  A straightforward asset bundling plugin for Jekyll, utilizing external
71
71
  minification tool of your choice. It provides asset concatenation for
@@ -121,6 +121,8 @@ files:
121
121
  - test/unit/asset_tag_markup_test.rb
122
122
  - test/unit/bundle_file_test.rb
123
123
  - test/unit/development_file_collection_test.rb
124
+ - test/unit/jekyll_payload_test.rb
125
+ - test/unit/jekyll_static_file_api_test.rb
124
126
  - test/unit/stamp_file_test.rb
125
127
  homepage: https://github.com/tkareine/jekyll-minibundle
126
128
  licenses:
@@ -147,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
149
  version: '0'
148
150
  requirements: []
149
151
  rubyforge_project:
150
- rubygems_version: 2.2.1
152
+ rubygems_version: 2.2.2
151
153
  signing_key:
152
154
  specification_version: 4
153
155
  summary: A minimalistic asset bundling plugin for Jekyll
@@ -176,4 +178,6 @@ test_files:
176
178
  - test/unit/asset_tag_markup_test.rb
177
179
  - test/unit/bundle_file_test.rb
178
180
  - test/unit/development_file_collection_test.rb
181
+ - test/unit/jekyll_payload_test.rb
182
+ - test/unit/jekyll_static_file_api_test.rb
179
183
  - test/unit/stamp_file_test.rb