jekyll-assets 3.0.5 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +2 -1
  3. data/LICENSE +1 -1
  4. data/README.md +136 -149
  5. data/Rakefile +37 -5
  6. data/lib/jekyll-assets.rb +1 -1
  7. data/lib/jekyll/assets.rb +14 -3
  8. data/lib/jekyll/assets/config.rb +1 -1
  9. data/lib/jekyll/assets/context.rb +1 -1
  10. data/lib/jekyll/assets/default.rb +1 -1
  11. data/lib/jekyll/assets/drop.rb +1 -1
  12. data/lib/jekyll/assets/env.rb +52 -19
  13. data/lib/jekyll/assets/extensible.rb +1 -1
  14. data/lib/jekyll/assets/filters.rb +1 -1
  15. data/lib/jekyll/assets/hook.rb +31 -3
  16. data/lib/jekyll/assets/html.rb +1 -1
  17. data/lib/jekyll/assets/logger.rb +52 -10
  18. data/lib/jekyll/assets/manifest.rb +1 -1
  19. data/lib/jekyll/assets/map.rb +2 -2
  20. data/lib/jekyll/assets/map/css.rb +1 -1
  21. data/lib/jekyll/assets/map/javascript.rb +1 -1
  22. data/lib/jekyll/assets/map/writer.rb +2 -2
  23. data/lib/jekyll/assets/patches/asset.rb +1 -1
  24. data/lib/jekyll/assets/patches/cached.rb +4 -4
  25. data/lib/jekyll/assets/patches/find_asset.rb +1 -1
  26. data/lib/jekyll/assets/patches/functions.rb +1 -1
  27. data/lib/jekyll/assets/patches/obsolete.rb +1 -1
  28. data/lib/jekyll/assets/patches/site.rb +1 -1
  29. data/lib/jekyll/assets/plugins.rb +1 -1
  30. data/lib/jekyll/assets/plugins/bootstrap.rb +3 -3
  31. data/lib/jekyll/assets/plugins/closure_comments.rb +32 -0
  32. data/lib/jekyll/assets/plugins/font-awesome.rb +2 -2
  33. data/lib/jekyll/assets/plugins/frontmatter.rb +1 -1
  34. data/lib/jekyll/assets/plugins/html/audio.rb +1 -1
  35. data/lib/jekyll/assets/plugins/html/component.rb +1 -1
  36. data/lib/jekyll/assets/plugins/html/css.rb +1 -1
  37. data/lib/jekyll/assets/plugins/html/defaults/audio.rb +1 -1
  38. data/lib/jekyll/assets/plugins/html/defaults/component.rb +1 -1
  39. data/lib/jekyll/assets/plugins/html/defaults/css.rb +1 -1
  40. data/lib/jekyll/assets/plugins/html/defaults/favicon.rb +1 -1
  41. data/lib/jekyll/assets/plugins/html/defaults/img.rb +2 -2
  42. data/lib/jekyll/assets/plugins/html/defaults/js.rb +1 -1
  43. data/lib/jekyll/assets/plugins/html/defaults/vid.rb +1 -1
  44. data/lib/jekyll/assets/plugins/html/favicon.rb +1 -1
  45. data/lib/jekyll/assets/plugins/html/img.rb +2 -2
  46. data/lib/jekyll/assets/plugins/html/js.rb +1 -1
  47. data/lib/jekyll/assets/plugins/html/pic.rb +1 -1
  48. data/lib/jekyll/assets/plugins/html/svg.rb +1 -1
  49. data/lib/jekyll/assets/plugins/html/vid.rb +1 -1
  50. data/lib/jekyll/assets/plugins/liquid.rb +1 -1
  51. data/lib/jekyll/assets/plugins/magick.rb +2 -2
  52. data/lib/jekyll/assets/plugins/optim.rb +2 -2
  53. data/lib/jekyll/assets/plugins/prefixer.rb +2 -2
  54. data/lib/jekyll/assets/plugins/proxy/magick.rb +1 -1
  55. data/lib/jekyll/assets/plugins/proxy/optim.rb +1 -1
  56. data/lib/jekyll/assets/plugins/searcher.rb +17 -3
  57. data/lib/jekyll/assets/proxy.rb +1 -1
  58. data/lib/jekyll/assets/reader.rb +33 -0
  59. data/lib/jekyll/assets/tag.rb +54 -13
  60. data/lib/jekyll/assets/url.rb +2 -7
  61. data/lib/jekyll/assets/utils.rb +16 -23
  62. data/lib/jekyll/assets/version.rb +2 -2
  63. data/lib/jekyll/assets/writer.rb +46 -0
  64. metadata +6 -3
data/Rakefile CHANGED
@@ -1,8 +1,40 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2017 - 2018 - MIT License
3
+ # Author: Jordon Bedwell
3
4
  # Encoding: utf-8
4
5
 
5
- task(:spec) { exec "script/test" }
6
- task(:test) { exec "script/test" }
7
- task(:rubocop) { exec "script/lint" }
8
- task(:lint) { exec "script/lint" }
6
+ # --
7
+ # 🔖
8
+ # RSpec, MiniTest, Whatever.
9
+ # --
10
+ task :spec do
11
+ exec "script/test"
12
+ end
13
+ # --
14
+ # 🔖
15
+ # RSpec, MiniTest, Whatever.
16
+ # --
17
+ task :test do
18
+ exec "script/test"
19
+ end
20
+ # --
21
+ # 🔖
22
+ # @see .rubocop.yml
23
+ # Rubocop.
24
+ # --
25
+ task :rubocop do
26
+ exec "script/lint"
27
+ end
28
+ # --
29
+ # 🔖
30
+ # @see .rubocop.yml
31
+ # Rubocop.
32
+ # --
33
+ task :lint do
34
+ exec "script/lint"
35
+ end
36
+
37
+ # --
38
+ Dir.glob("script/rake.d/*.rake").each do |v|
39
+ load v
40
+ end
@@ -1,5 +1,5 @@
1
1
  # rubocop:disable Naming/FileName
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Frozen-string-literal: true
4
4
  # Encoding: utf-8
5
5
 
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  require "pathutil"
@@ -18,7 +18,18 @@ def require_all(*globs)
18
18
  end
19
19
 
20
20
  require_relative "assets/env"
21
- Jekyll::Hooks.register(:site, :post_read) { |o| Jekyll::Assets::Env.new(o) }
22
- Jekyll::Hooks.register :site, :post_write do |o|
21
+ Jekyll::Hooks.register :site, :post_read, priority: 99 do |o|
22
+ unless o.sprockets
23
+ Jekyll::Assets::Env.new(o)
24
+ end
25
+ end
26
+
27
+ # --
28
+ # Post render hook.
29
+ # We need to run really early because we want to have our
30
+ # stuff block and be done just incase something else relies
31
+ # on our stuff to do their stuff. Such as reloaders.
32
+ # --
33
+ Jekyll::Hooks.register :site, :post_render, priority: 99 do |o|
23
34
  o&.sprockets&.write_all
24
35
  end
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  require "jekyll"
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  require_relative "context"
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  require_relative "extensible"
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  require "liquid/drop"
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  require "pathutil"
@@ -14,6 +14,8 @@ require_relative "drop"
14
14
  require_relative "version"
15
15
  require_relative "filters"
16
16
  require_relative "manifest"
17
+ require_relative "writer"
18
+ require_relative "reader"
17
19
  require_relative "config"
18
20
  require_relative "logger"
19
21
  require_relative "hook"
@@ -32,13 +34,17 @@ module Jekyll
32
34
  attr_reader :asset_config
33
35
  attr_reader :jekyll
34
36
 
37
+ # --
38
+ rb_delegate :old?, to: :"self.class"
39
+ rb_delegate :old_sprockets?, {
40
+ to: :"self.class",
41
+ }
42
+
35
43
  # --
36
44
  def initialize(jekyll = nil)
37
45
  @asset_config = Config.new(jekyll.config["assets"] ||= {})
38
- Logger.debug "Callings hooks for env, before_init" do
39
- Hook.trigger :env, :before_init do |h|
40
- instance_eval(&h)
41
- end
46
+ Hook.trigger :env, :before_init do |h|
47
+ instance_eval(&h)
42
48
  end
43
49
 
44
50
  super()
@@ -46,6 +52,7 @@ module Jekyll
46
52
  @assets_to_write = []
47
53
  @manifest = Manifest.new(self, in_dest_dir)
48
54
  @jekyll.sprockets = self
55
+ @total_time = 0.000000
49
56
  @logger = Logger
50
57
  @cache = nil
51
58
 
@@ -56,10 +63,8 @@ module Jekyll
56
63
  precompile!
57
64
  copy_raw!
58
65
 
59
- Logger.debug "Calling hooks for env, after_init" do
60
- Hook.trigger :env, :after_init do |h|
61
- instance_eval(&h)
62
- end
66
+ Hook.trigger :env, :after_init do |h|
67
+ instance_eval(&h)
63
68
  end
64
69
  end
65
70
 
@@ -68,6 +73,30 @@ module Jekyll
68
73
  !asset_config[:gzip]
69
74
  end
70
75
 
76
+ # --
77
+ def find_asset(v, *a)
78
+ msg = "Searched for, and rendered #{v} in %<time>s"
79
+ out = Logger.with_timed_logging msg do
80
+ super(v, *a)
81
+ end
82
+
83
+ # We keep track.
84
+ @total_time += out[:time]
85
+ out[:result]
86
+ end
87
+
88
+ # --
89
+ def find_asset!(v, *a)
90
+ msg = "Searched for, and rendered #{v} in %<time>s"
91
+ out = Logger.with_timed_logging msg do
92
+ super(v, *a)
93
+ end
94
+
95
+ # We keep track.
96
+ @total_time += out[:time]
97
+ out[:result]
98
+ end
99
+
71
100
  # --
72
101
  # @note this is configurable with :caching -> :type
73
102
  # Create a cache, or a null cache (if no caching) for caching.
@@ -118,17 +147,18 @@ module Jekyll
118
147
  end
119
148
  end
120
149
 
150
+ # --
151
+ class << self
152
+ alias old? old_sprockets?
153
+ end
154
+
121
155
  # --
122
156
  def write_all
123
157
  remove_old_assets unless asset_config[:digest]
124
158
  manifest.compile(*assets_to_write); @asset_to_write = []
125
- Logger.debug "Calling hooks for env, after_write" do
126
- Hook.trigger :env, :after_write do |h|
127
- instance_eval(&h)
128
- end
129
- end
130
-
131
- true
159
+ Hook.trigger(:env, :after_write) { |h| instance_eval(&h) }
160
+ Logger.debug "took #{format(@total_time.round(2).to_s,
161
+ '%.2f')}s"
132
162
  end
133
163
 
134
164
  # ---
@@ -149,10 +179,13 @@ module Jekyll
149
179
  # --
150
180
  private
151
181
  def enable_compression!
182
+ self.js_compressor, self.css_compressor = nil, nil
183
+
152
184
  return unless asset_config[:compression]
153
185
  config = asset_config[:compressors][:uglifier].symbolize_keys
154
186
  self. js_compressor = Sprockets::UglifierCompressor.new(config)
155
- self.css_compressor = :scss
187
+ Utils.activate("sassc") { self.css_compressor = :scssc } unless old?
188
+ self.css_compressor ||= :scss
156
189
  end
157
190
 
158
191
  # --
@@ -169,7 +202,7 @@ module Jekyll
169
202
  def precompile!
170
203
  assets = asset_config[:precompile]
171
204
  assets.map do |v|
172
- v !~ %r!\*! ? @assets_to_write |= [sv] : glob_paths(v).each do |sv|
205
+ v !~ %r!\*! ? @assets_to_write |= [v] : glob_paths(v).each do |sv|
173
206
  @assets_to_write |= [sv]
174
207
  end
175
208
  end
@@ -207,7 +240,7 @@ module Jekyll
207
240
 
208
241
  require_relative "map" unless old_sprockets?
209
242
  Hook.register :env, :after_init, priority: 3 do
210
- unless self.class.old_sprockets?
243
+ unless old?
211
244
  Map.register_on(self)
212
245
  end
213
246
  end
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  module Jekyll
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  require_relative "context"
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  module Jekyll
@@ -52,10 +52,34 @@ module Jekyll
52
52
  2 => [],
53
53
  3 => [],
54
54
  },
55
+
56
+ before_read: {
57
+ 1 => [],
58
+ 2 => [],
59
+ 3 => [],
60
+ },
61
+
62
+ after_read: {
63
+ 1 => [],
64
+ 2 => [],
65
+ 3 => [],
66
+ },
67
+
68
+ before_write: {
69
+ 1 => [],
70
+ 2 => [],
71
+ 3 => [],
72
+ },
73
+
74
+ after_write: {
75
+ 1 => [],
76
+ 2 => [],
77
+ 3 => [],
78
+ },
55
79
  },
56
80
 
57
81
  liquid: {
58
- pre_render: {
82
+ before_render: {
59
83
  1 => [],
60
84
  2 => [],
61
85
  3 => [],
@@ -110,7 +134,11 @@ module Jekyll
110
134
  # @return [nil]
111
135
  # --
112
136
  def self.trigger(*point, &block)
113
- get_point(*point).map do |v|
137
+ hooks = get_point(*point)
138
+ Logger.debug "messaging hooks on #{point.last} " \
139
+ "through #{point.first}"
140
+
141
+ hooks.map do |v|
114
142
  block.call(v)
115
143
  end
116
144
  end
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  require_relative "extensible"
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  require "jekyll"
@@ -8,26 +8,68 @@ module Jekyll
8
8
  module Assets
9
9
  class Logger
10
10
  PREFIX = "Assets: "
11
+ COLORS = {
12
+ error: :red,
13
+ debug: :yellow,
14
+ info: :cyan,
15
+ }.freeze
16
+
17
+ # --
11
18
  def self.logger
12
19
  self
13
20
  end
14
21
 
15
22
  # --
16
- # @note this is to be removed after 3.6.
17
- # Creates self methods so that we can accept blocks.
18
- # @param [String,Proc] message the message that to log.
23
+ def self.with_timed_logging(msg, type: :debug)
24
+ s, t, out = Time.now, nil, yield; Logger.send(type) do
25
+ format("\n#{msg}", {
26
+ time: "#{t = Time.now - s}s",
27
+ })
28
+ end
29
+
30
+ {
31
+ result: out, time: t
32
+ }
33
+ end
34
+
35
+ # --
36
+ def self.err_file(file)
37
+ Jekyll.logger.error("Asset File", file)
38
+ end
39
+
40
+ # --
41
+ def self.colorize?
42
+ @color ||= begin
43
+ Jekyll.env == "development" && system("test -t 2")
44
+ end
45
+ end
46
+
47
+ # --
48
+ # Makes a logging method
49
+ # @param type [Symbol] the type of logger.
19
50
  # @return nil
20
51
  # --
21
- %i(warn error info debug).each do |v|
22
- define_singleton_method v do |message = nil, &block|
23
- message = block.call if block
24
- Jekyll.logger.send(v, PREFIX, message)
52
+ def self.make_logger(type:)
53
+ define_singleton_method type do |m = nil, &b|
54
+ m = (b ? b.call : m).gsub(Pathutil.pwd + "/", "")
55
+ r = m =~ %r!writing\s+!i ? :debug : type
56
+ Jekyll.logger.send(r, PREFIX, m)
25
57
  end
26
58
  end
27
59
 
28
60
  # --
29
- def self.efile(file)
30
- Jekyll.logger.error("Asset File", file)
61
+ private_class_method :make_logger
62
+
63
+ # --
64
+ # @note this is to be removed after 3.6.
65
+ # Creates self methods so that we can accept blocks.
66
+ # @param [String,Proc] message the message that to log.
67
+ # @return nil
68
+ # --
69
+ %i(warn error info debug).each do |v|
70
+ make_logger({
71
+ type: v,
72
+ })
31
73
  end
32
74
  end
33
75
  end
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  require "sprockets/manifest"
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  require_relative "map/css"
@@ -10,7 +10,7 @@ require "pathutil"
10
10
  module Jekyll
11
11
  module Assets
12
12
  module Map
13
- NAME = "%s.map"
13
+ NAME = "%<name>s.map"
14
14
  DIR_NAME = "source-maps"
15
15
  DIR = Pathutil.new(DIR_NAME)
16
16
  EXT = ".map"
@@ -1,5 +1,5 @@
1
1
  # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
2
+ # Copyright: 2012 - 2018 - MIT License
3
3
  # Encoding: utf-8
4
4
 
5
5
  require "sprockets"