jekyll-minibundle 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/README.md +6 -2
  4. data/jekyll-minibundle.gemspec +1 -1
  5. data/lib/jekyll/minibundle/asset_bundle.rb +10 -5
  6. data/lib/jekyll/minibundle/asset_file_properties.rb +1 -5
  7. data/lib/jekyll/minibundle/asset_tag_markup.rb +3 -12
  8. data/lib/jekyll/minibundle/bundle_file.rb +25 -16
  9. data/lib/jekyll/minibundle/development_file.rb +14 -4
  10. data/lib/jekyll/minibundle/files.rb +22 -9
  11. data/lib/jekyll/minibundle/mini_bundle_block.rb +14 -10
  12. data/lib/jekyll/minibundle/mini_stamp_tag.rb +2 -1
  13. data/lib/jekyll/minibundle/stamp_file.rb +21 -9
  14. data/lib/jekyll/minibundle/version.rb +1 -1
  15. data/test/fixture/site/_layouts/default.html +1 -1
  16. data/test/integration/minibundle_development_mode_test.rb +18 -3
  17. data/test/integration/minibundle_production_mode_test.rb +108 -4
  18. data/test/integration/ministamp_development_mode_test.rb +13 -6
  19. data/test/integration/ministamp_production_mode_test.rb +63 -4
  20. data/test/support/static_file_api_config.rb +1 -0
  21. data/test/support/test_case.rb +4 -4
  22. data/test/unit/asset_bundle_test.rb +15 -8
  23. data/test/unit/asset_file_registry_test.rb +3 -3
  24. data/test/unit/asset_tag_markup_test.rb +5 -17
  25. data/test/unit/bundle_file_properties_test.rb +4 -0
  26. data/test/unit/bundle_file_writing_test.rb +54 -18
  27. data/test/unit/development_file_collection_properties_test.rb +5 -0
  28. data/test/unit/development_file_writing_test.rb +39 -0
  29. data/test/unit/environment_test.rb +4 -4
  30. data/test/unit/files_test.rb +13 -0
  31. data/test/unit/jekyll_static_file_api_test.rb +1 -1
  32. data/test/unit/mini_bundle_block_test.rb +1 -1
  33. data/test/unit/mini_stamp_tag_test.rb +1 -1
  34. data/test/unit/stamp_file_properties_test.rb +4 -0
  35. data/test/unit/stamp_file_writing_test.rb +54 -18
  36. metadata +7 -6
  37. data/lib/jekyll/minibundle/asset_file_operations.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c07644674d4019624ae3cd17463a8dc961df66ba
4
- data.tar.gz: f512236902087572a1d618620ac87184f8590b28
3
+ metadata.gz: 8c11f2890adfcdd3cc6902ddf8f1449f3e1b1721
4
+ data.tar.gz: 8676586c08adf47c8962dcee2214cfba11eeff55
5
5
  SHA512:
6
- metadata.gz: 3886e4b0a47bfa8d9aa720c0b5630952fd876835f29b9cfe55b5df11bb726ff51f9ff91defd338e64e9b7e44687f692b069aeb246f21be126793b3f139963428
7
- data.tar.gz: 320e44f066004bf6a701ea26a0bdc42a507211656d9f446ea20da84cb67b5f5c0468afe2d7b2e70ac4919a34cad2a41b773c3f6c8319faa03f7667a8abe1bb07
6
+ metadata.gz: 3915fc23411307ba14bf2e700fe40ab7197aa155397027b6bcd65a3cb31efaa631df9aea43545b5584bf55e0ed63f33376e5e0f6a3344db4a3d55fa627cd37e3
7
+ data.tar.gz: d159b2a770dd15d261bdf6b2a6661a866ea73f3a76188d2a85bb62e061f875809558f53d46e0726e494ca2a0cad68ce7a12c006a5d0488c3f9b673f81588db61
data/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ # 2.1.2 / 2017-02-28
2
+
3
+ * Bug fix: remove unnecessary '.' path component from asset destination
4
+ path. This manifested when the asset destination had no subdirectory.
5
+ Affects `ministamp` tag and `minibundle` block.
6
+
7
+ Example situation:
8
+
9
+ ```
10
+ <link href="{{ site.baseurl }}/{% ministamp _assets/site.css site.css %}" rel="stylesheet">
11
+ ```
12
+
13
+ Generation result, before the fix:
14
+
15
+ ```
16
+ <link href="/./site-6a204bd89f3c8348afd5c77c717a097a.css" rel="stylesheet">
17
+ ```
18
+
19
+ Generation result, after the fix:
20
+
21
+ ```
22
+ <link href="/site-6a204bd89f3c8348afd5c77c717a097a.css" rel="stylesheet">
23
+ ```
24
+
25
+ * Bug fix (related to above): don't let Jekyll's watch mode
26
+ (auto-regenration) remove asset from generated site directory when
27
+ asset destination path has no subdirectory.
28
+ * Show bundle destination path in bundling log message
29
+
1
30
  # 2.1.1 / 2017-01-14
2
31
 
3
32
  * Fix the file permissions of `minibundle` block's output file to
data/README.md CHANGED
@@ -303,8 +303,12 @@ See the sources of [an example site][JekyllMinibundleExampleSite].
303
303
 
304
304
  ## Known caveats
305
305
 
306
- The plugin does not work with Jekyll's incremental rebuild feature
307
- (Jekyll option `--incremental`).
306
+ 1. The plugin does not work with Jekyll's incremental rebuild feature
307
+ (Jekyll option `--incremental`).
308
+
309
+ 2. `ministamp` tag does not interpret Liquid variables, as the tag just
310
+ takes in string literals. Improving this would require new syntax for
311
+ tag arguments.
308
312
 
309
313
  ## License
310
314
 
@@ -32,7 +32,7 @@ There are no other runtime dependencies besides the minification tool
32
32
  s.add_development_dependency 'nokogiri', '~> 1.6'
33
33
  s.add_development_dependency 'pry', '~> 0.10'
34
34
  s.add_development_dependency 'rake', '~> 12.0'
35
- s.add_development_dependency 'rubocop', '~> 0.46.0'
35
+ s.add_development_dependency 'rubocop', '~> 0.47.0'
36
36
 
37
37
  s.required_ruby_version = '>= 2.0.0'
38
38
 
@@ -10,12 +10,13 @@ module Jekyll::Minibundle
10
10
  def initialize(config)
11
11
  @type = config.fetch(:type)
12
12
  @asset_paths = config.fetch(:asset_paths)
13
+ @destination_path = config.fetch(:destination_path)
13
14
  @site_dir = config.fetch(:site_dir)
14
15
  @minifier_cmd = config.fetch(:minifier_cmd)
15
16
 
16
17
  unless @minifier_cmd
17
18
  raise <<-END
18
- Missing minification command for bundling #{@type} assets. Specify it in
19
+ Missing minification command for bundling #{bundle_destination_path}. Specify it in
19
20
  1) minibundle.minifier_commands.#{@type} setting in _config.yml,
20
21
  2) $JEKYLL_MINIBUNDLE_CMD_#{@type.to_s.upcase} environment variable, or
21
22
  3) minifier_cmd setting inside minibundle block.
@@ -39,15 +40,15 @@ Missing minification command for bundling #{@type} assets. Specify it in
39
40
  raise IllegalStateError, 'Cannot make bundle with closed AssetBundle' unless @tempfile
40
41
  exit_status = spawn_minifier(@minifier_cmd) do |input|
41
42
  $stdout.puts # place newline after "(Re)generating..." log messages
42
- Log.info("Bundling #{@type} assets:")
43
+ Log.info("Bundling #{bundle_destination_path}:")
43
44
  @asset_paths.each do |asset|
44
- Log.info(relative_path_from(asset, @site_dir))
45
+ Log.info(' ' + relative_path_from(asset, @site_dir))
45
46
  IO.foreach(asset) { |line| input.write(line) }
46
47
  input.puts(';') if @type == :js
47
48
  end
48
49
  end
49
50
  if exit_status != 0
50
- msg = "Bundling #{@type} assets failed with exit status #{exit_status}, command: '#{@minifier_cmd}'"
51
+ msg = "Bundling #{bundle_destination_path} failed with exit status #{exit_status}, command: '#{@minifier_cmd}'"
51
52
  log_minifier_error(msg)
52
53
  raise msg
53
54
  end
@@ -72,7 +73,7 @@ Missing minification command for bundling #{@type} assets. Specify it in
72
73
  _, status = Process.waitpid2(pid)
73
74
  status.exitstatus
74
75
  rescue => e
75
- raise "Bundling #{@type} assets failed: #{e}"
76
+ raise "Bundling #{bundle_destination_path} failed: #{e}"
76
77
  ensure
77
78
  [rd, wr].each { |io| io.close unless io.closed? }
78
79
  end
@@ -89,5 +90,9 @@ Missing minification command for bundling #{@type} assets. Specify it in
89
90
  .split("\n")
90
91
  .each { |line| Log.error(line) }
91
92
  end
93
+
94
+ def bundle_destination_path
95
+ "#{@destination_path}.#{@type}"
96
+ end
92
97
  end
93
98
  end
@@ -15,7 +15,7 @@ module Jekyll::Minibundle
15
15
  end
16
16
 
17
17
  def destination(site_destination_dir)
18
- File.join(site_destination_dir, asset_destination_path)
18
+ File.expand_path(File.join(site_destination_dir, asset_destination_path), '/')
19
19
  end
20
20
 
21
21
  def url
@@ -34,10 +34,6 @@ module Jekyll::Minibundle
34
34
  modified_time.to_i
35
35
  end
36
36
 
37
- def modified?
38
- stamped_at != mtime
39
- end
40
-
41
37
  def destination_rel_dir
42
38
  asset_destination_dir
43
39
  end
@@ -3,13 +3,12 @@ require 'cgi'
3
3
  module Jekyll::Minibundle
4
4
  module AssetTagMarkup
5
5
  class << self
6
- def make_markup(type, baseurl, path, attributes)
7
- url = make_url(baseurl, path)
6
+ def make_markup(type, path, attributes)
8
7
  case type
9
8
  when :js
10
- %{<script type="text/javascript" src="#{url}"#{make_attributes(attributes)}></script>}
9
+ %{<script type="text/javascript" src="#{path}"#{make_attributes(attributes)}></script>}
11
10
  when :css
12
- %{<link rel="stylesheet" href="#{url}"#{make_attributes(attributes)}>}
11
+ %{<link rel="stylesheet" href="#{path}"#{make_attributes(attributes)}>}
13
12
  else
14
13
  raise ArgumentError, "Unknown type for generating bundle markup: #{type}, #{path}"
15
14
  end
@@ -26,14 +25,6 @@ module Jekyll::Minibundle
26
25
  %{ #{name}="#{CGI.escape_html(value.to_s)}"}
27
26
  end
28
27
  end
29
-
30
- def make_url(baseurl, path)
31
- if baseurl.empty?
32
- path
33
- else
34
- File.join(baseurl, path)
35
- end
36
- end
37
28
  end
38
29
  end
39
30
  end
@@ -1,23 +1,23 @@
1
+ require 'jekyll/minibundle/files'
1
2
  require 'jekyll/minibundle/asset_bundle'
2
- require 'jekyll/minibundle/asset_file_operations'
3
3
  require 'jekyll/minibundle/asset_file_properties'
4
4
  require 'jekyll/minibundle/asset_stamp'
5
5
 
6
6
  module Jekyll::Minibundle
7
7
  class BundleFile
8
- include AssetFileOperations
9
8
  include AssetFileProperties
10
9
 
11
- attr_reader :asset_destination_dir, :stamped_at
10
+ attr_reader :asset_destination_dir,
11
+ :stamped_at
12
12
 
13
13
  def initialize(site, config)
14
14
  @site = site
15
15
  @type = config.fetch('type')
16
16
  asset_source_dir = File.join(@site.source, config.fetch('source_dir'))
17
17
  @asset_paths = config.fetch('assets').map { |asset_path| File.join(asset_source_dir, "#{asset_path}.#{@type}") }
18
- destination_path = config.fetch('destination_path')
19
- @asset_destination_dir = File.dirname(destination_path)
20
- @asset_destination_filename_prefix = File.basename(destination_path)
18
+ @destination_path = config.fetch('destination_path')
19
+ @asset_destination_dir = File.dirname(@destination_path)
20
+ @asset_destination_filename_prefix = File.basename(@destination_path)
21
21
  @minifier_cmd = config.fetch('minifier_cmd')
22
22
  @stamped_at = nil
23
23
  @is_modified = false
@@ -32,10 +32,13 @@ module Jekyll::Minibundle
32
32
 
33
33
  def destination_path_for_markup
34
34
  # we must rebundle here, if at all, in order to make sure the
35
- # destination path in the markup and the generated file path
36
- # have the same fingerprint
37
- if modified?
38
- @stamped_at = mtime
35
+ # destination path in the markup and the generated file path have
36
+ # the same fingerprint
37
+
38
+ source_mtime = mtime
39
+
40
+ if @stamped_at != source_mtime
41
+ @stamped_at = source_mtime
39
42
  @is_modified = true
40
43
  @_asset_stamp = nil
41
44
  asset_bundle.make_bundle
@@ -60,11 +63,16 @@ module Jekyll::Minibundle
60
63
  @asset_paths.map { |f| File.stat(f).mtime }.max
61
64
  end
62
65
 
66
+ def modified?
67
+ @is_modified
68
+ end
69
+
63
70
  # allows writing destination only after
64
71
  # `destination_path_for_markup` has been called
65
72
  def write(site_destination_dir)
66
- if @is_modified
67
- dst_path = write_destination(site_destination_dir)
73
+ if modified?
74
+ dst_path = destination(site_destination_dir)
75
+ Files.copy_p(path, dst_path)
68
76
 
69
77
  # respect user's umask; Ruby's tempfile has mode 0o600
70
78
  File.chmod(0o666 & ~File.umask, dst_path)
@@ -84,10 +92,11 @@ module Jekyll::Minibundle
84
92
 
85
93
  def asset_bundle
86
94
  @_asset_bundle ||= AssetBundle.new(
87
- type: @type,
88
- asset_paths: @asset_paths,
89
- site_dir: @site.source,
90
- minifier_cmd: @minifier_cmd
95
+ type: @type,
96
+ asset_paths: @asset_paths,
97
+ destination_path: @destination_path,
98
+ site_dir: @site.source,
99
+ minifier_cmd: @minifier_cmd
91
100
  )
92
101
  end
93
102
  end
@@ -1,12 +1,14 @@
1
- require 'jekyll/minibundle/asset_file_operations'
1
+ require 'jekyll/minibundle/files'
2
2
  require 'jekyll/minibundle/asset_file_properties'
3
3
 
4
4
  module Jekyll::Minibundle
5
5
  class DevelopmentFile
6
- include AssetFileOperations
7
6
  include AssetFileProperties
8
7
 
9
- attr_reader :asset_source_path, :asset_destination_dir, :asset_destination_filename, :stamped_at
8
+ attr_reader :asset_source_path,
9
+ :asset_destination_dir,
10
+ :asset_destination_filename,
11
+ :stamped_at
10
12
 
11
13
  def initialize(site, asset_source_path, asset_destination_path)
12
14
  @site = site
@@ -16,16 +18,24 @@ module Jekyll::Minibundle
16
18
  @stamped_at = nil
17
19
  end
18
20
 
21
+ def cleanup
22
+ # no-op
23
+ end
24
+
19
25
  alias destination_path_for_markup asset_destination_path
20
26
 
21
27
  def extname
22
28
  File.extname(asset_destination_filename)
23
29
  end
24
30
 
31
+ def modified?
32
+ stamped_at != mtime
33
+ end
34
+
25
35
  def write(site_destination_dir)
26
36
  if modified?
27
37
  @stamped_at = mtime
28
- write_destination(site_destination_dir)
38
+ Files.copy_p(path, destination(site_destination_dir))
29
39
  true
30
40
  else
31
41
  false
@@ -1,18 +1,31 @@
1
+ require 'fileutils'
2
+
1
3
  module Jekyll::Minibundle
2
4
  module Files
3
- def self.read_last(path, max_size)
4
- File.open(path, 'rb') do |file|
5
- return '' if max_size < 1
5
+ class << self
6
+ def copy_p(src_path, dst_path)
7
+ FileUtils.mkdir_p(File.dirname(dst_path))
8
+ FileUtils.cp(src_path, dst_path)
9
+ end
10
+
11
+ def read_last(path, max_size)
12
+ File.open(path, 'rb') do |file|
13
+ return '' if max_size < 1
6
14
 
7
- file_size = file.stat.size
15
+ file_size = file.stat.size
8
16
 
9
- if file_size < max_size
10
- file.read(file_size)
11
- else
12
- file.seek(file_size - max_size, ::IO::SEEK_SET)
13
- file.read(max_size)
17
+ if file_size < max_size
18
+ file.read(file_size)
19
+ else
20
+ file.seek(file_size - max_size, ::IO::SEEK_SET)
21
+ file.read(max_size)
22
+ end
14
23
  end
15
24
  end
25
+
26
+ def strip_dot_slash_from_path_start(path)
27
+ path.sub(%r{\A\./+}, '')
28
+ end
16
29
  end
17
30
  end
18
31
  end
@@ -1,4 +1,5 @@
1
1
  require 'jekyll/minibundle/hashes'
2
+ require 'jekyll/minibundle/files'
2
3
  require 'jekyll/minibundle/environment'
3
4
  require 'jekyll/minibundle/asset_file_registry'
4
5
  require 'jekyll/minibundle/asset_tag_markup'
@@ -18,7 +19,16 @@ module Jekyll::Minibundle
18
19
  attributes = bundle_config.fetch('attributes')
19
20
 
20
21
  register_asset_files(site, bundle_config).map do |file|
21
- AssetTagMarkup.make_markup(@type, baseurl, file.destination_path_for_markup, attributes)
22
+ dst_path = Files.strip_dot_slash_from_path_start(file.destination_path_for_markup)
23
+
24
+ full_path =
25
+ if baseurl.empty?
26
+ dst_path
27
+ else
28
+ File.join(baseurl, dst_path)
29
+ end
30
+
31
+ AssetTagMarkup.make_markup(@type, full_path, attributes)
22
32
  end.join("\n")
23
33
  end
24
34
 
@@ -52,16 +62,10 @@ module Jekyll::Minibundle
52
62
  end
53
63
 
54
64
  def normalize_baseurl_and_destination_path(baseurl, destination_path)
55
- baseurl = '' if baseurl.nil?
56
-
57
- unless destination_path.start_with?('/')
58
- return [baseurl, destination_path]
59
- end
60
-
61
- normalized_baseurl = baseurl.empty? ? '/' : baseurl
62
- normalized_destination_path = destination_path.sub(%r{\A/+}, '')
65
+ baseurl = '' if baseurl.nil? || baseurl == '.'
66
+ baseurl = '/' if destination_path.start_with?('/') && baseurl.empty?
63
67
 
64
- [normalized_baseurl, normalized_destination_path]
68
+ [Files.strip_dot_slash_from_path_start(baseurl), destination_path.sub(%r{\A/+}, '')]
65
69
  end
66
70
 
67
71
  def register_asset_files(site, bundle_config)
@@ -1,3 +1,4 @@
1
+ require 'jekyll/minibundle/files'
1
2
  require 'jekyll/minibundle/asset_file_registry'
2
3
 
3
4
  module Jekyll::Minibundle
@@ -26,7 +27,7 @@ module Jekyll::Minibundle
26
27
  else
27
28
  AssetFileRegistry.register_stamp_file(site, @source_path, @destination_path)
28
29
  end
29
- @baseurl + file.destination_path_for_markup
30
+ @baseurl + Files.strip_dot_slash_from_path_start(file.destination_path_for_markup)
30
31
  end
31
32
 
32
33
  private
@@ -1,13 +1,14 @@
1
- require 'jekyll/minibundle/asset_file_operations'
1
+ require 'jekyll/minibundle/files'
2
2
  require 'jekyll/minibundle/asset_file_properties'
3
3
  require 'jekyll/minibundle/asset_stamp'
4
4
 
5
5
  module Jekyll::Minibundle
6
6
  class StampFile
7
- include AssetFileOperations
8
7
  include AssetFileProperties
9
8
 
10
- attr_reader :asset_source_path, :asset_destination_dir, :stamped_at
9
+ attr_reader :asset_source_path,
10
+ :asset_destination_dir,
11
+ :stamped_at
11
12
 
12
13
  def initialize(site, asset_source_path, asset_destination_path)
13
14
  @site = site
@@ -19,12 +20,19 @@ module Jekyll::Minibundle
19
20
  @is_modified = false
20
21
  end
21
22
 
23
+ def cleanup
24
+ # no-op
25
+ end
26
+
22
27
  def destination_path_for_markup
23
28
  # we must rebundle here, if at all, in order to make sure the
24
- # destination path in the markup and the generated file path
25
- # have the same fingerprint
26
- if modified?
27
- @stamped_at = mtime
29
+ # destination path in the markup and the generated file path have
30
+ # the same fingerprint
31
+
32
+ source_mtime = mtime
33
+
34
+ if @stamped_at != source_mtime
35
+ @stamped_at = source_mtime
28
36
  @is_modified = true
29
37
  @_asset_stamp = nil
30
38
  end
@@ -40,11 +48,15 @@ module Jekyll::Minibundle
40
48
  @asset_destination_extension
41
49
  end
42
50
 
51
+ def modified?
52
+ @is_modified
53
+ end
54
+
43
55
  # allows writing destination only after
44
56
  # `destination_path_for_markup` has been called
45
57
  def write(site_destination_dir)
46
- if @is_modified
47
- write_destination(site_destination_dir)
58
+ if modified?
59
+ Files.copy_p(path, destination(site_destination_dir))
48
60
  @is_modified = false
49
61
  true
50
62
  else