jekyll-assets 2.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -2
  3. data/LICENSE +2 -2
  4. data/README.md +38 -31
  5. data/Rakefile +1 -40
  6. data/lib/jekyll-assets.rb +3 -1
  7. data/lib/jekyll/assets.rb +18 -16
  8. data/lib/jekyll/assets/addons.rb +3 -9
  9. data/lib/jekyll/assets/addons/autoprefixer.rb +6 -2
  10. data/lib/jekyll/assets/addons/bootstrap.rb +3 -1
  11. data/lib/jekyll/assets/addons/fontawesome.rb +7 -0
  12. data/lib/jekyll/assets/addons/{js_es6.rb → javascript.rb} +3 -1
  13. data/lib/jekyll/assets/addons/less.rb +9 -0
  14. data/lib/jekyll/assets/cached.rb +13 -2
  15. data/lib/jekyll/assets/config.rb +24 -14
  16. data/lib/jekyll/assets/env.rb +92 -40
  17. data/lib/jekyll/assets/hook.rb +14 -4
  18. data/lib/jekyll/assets/hooks.rb +5 -5
  19. data/lib/jekyll/assets/hooks/cache.rb +11 -3
  20. data/lib/jekyll/assets/hooks/compression.rb +12 -2
  21. data/lib/jekyll/assets/hooks/{configuration.rb → config.rb} +3 -1
  22. data/lib/jekyll/assets/hooks/erb.rb +15 -0
  23. data/lib/jekyll/assets/hooks/helpers.rb +4 -3
  24. data/lib/jekyll/assets/hooks/jekyll/drops.rb +3 -1
  25. data/lib/jekyll/assets/hooks/jekyll/setup.rb +6 -8
  26. data/lib/jekyll/assets/hooks/jekyll/write.rb +6 -2
  27. data/lib/jekyll/assets/hooks/logger.rb +6 -2
  28. data/lib/jekyll/assets/hooks/sources.rb +4 -1
  29. data/lib/jekyll/assets/hooks/sprockets.rb +3 -1
  30. data/lib/jekyll/assets/hooks/version.rb +6 -2
  31. data/lib/jekyll/assets/liquid.rb +3 -1
  32. data/lib/jekyll/assets/liquid/drop.rb +20 -2
  33. data/lib/jekyll/assets/liquid/filters.rb +13 -14
  34. data/lib/jekyll/assets/liquid/tag.rb +101 -39
  35. data/lib/jekyll/assets/liquid/tag/defaults.rb +2 -0
  36. data/lib/jekyll/assets/liquid/tag/defaults/image.rb +25 -5
  37. data/lib/jekyll/assets/liquid/tag/parser.rb +27 -19
  38. data/lib/jekyll/assets/liquid/tag/proxied_asset.rb +33 -20
  39. data/lib/jekyll/assets/liquid/tag/proxies.rb +21 -16
  40. data/lib/jekyll/assets/logger.rb +29 -15
  41. data/lib/jekyll/assets/manifest.rb +98 -0
  42. data/lib/jekyll/assets/patches.rb +4 -2
  43. data/lib/jekyll/assets/patches/jekyll/site.rb +0 -4
  44. data/lib/jekyll/assets/patches/kernel.rb +4 -14
  45. data/lib/jekyll/assets/patches/sprockets/asset.rb +10 -4
  46. data/lib/jekyll/assets/patches/sprockets/helpers.rb +31 -0
  47. data/lib/jekyll/assets/processors.rb +1 -0
  48. data/lib/jekyll/assets/processors/less.rb +68 -0
  49. data/lib/jekyll/assets/processors/liquid.rb +46 -0
  50. data/lib/jekyll/assets/proxies.rb +1 -0
  51. data/lib/jekyll/assets/proxies/magick.rb +167 -0
  52. data/lib/jekyll/assets/version.rb +4 -2
  53. metadata +52 -23
  54. data/lib/jekyll/assets/addons/compass.rb +0 -11
  55. data/lib/jekyll/assets/addons/font_awesome.rb +0 -5
  56. data/lib/jekyll/assets/addons/processors/liquid.rb +0 -31
  57. data/lib/jekyll/assets/addons/proxies/magick.rb +0 -126
  58. data/lib/jekyll/assets/hooks/context_patches.rb +0 -17
  59. data/lib/jekyll/assets/hooks/disable_erb.rb +0 -10
  60. data/lib/jekyll/assets/patches/jekyll/cleaner.rb +0 -15
@@ -1,6 +1,8 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
+ # Copyright: 2012 - 2016 - MIT License
3
4
  # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
4
6
 
5
7
  module Jekyll
6
8
  module Assets
@@ -11,38 +13,50 @@ module Jekyll
11
13
  @_log ||= Jekyll.logger
12
14
  end
13
15
 
16
+ # ----------------------------------------------------------------------
14
17
  # Log Level: 1
18
+ # ----------------------------------------------------------------------
15
19
 
16
- def warn(msg = nil, &block)
17
- msg = (block_given?? block.call : msg)
18
- log.warn(PREFIX, msg)
20
+ def warn(msg = nil)
21
+ log.warn(PREFIX,
22
+ block_given?? yield : msg
23
+ )
19
24
  end
20
25
 
26
+ # ----------------------------------------------------------------------
21
27
  # Log Level: 1
28
+ # ----------------------------------------------------------------------
22
29
 
23
- def error(msg = nil, &block)
24
- msg = (block_given?? block.call : msg)
25
- log.error(PREFIX, msg)
30
+ def error(msg = nil)
31
+ log.error(PREFIX,
32
+ block_given?? yield : msg
33
+ )
26
34
  end
27
35
 
36
+ # ----------------------------------------------------------------------
28
37
  # Log Level: 2
38
+ # ----------------------------------------------------------------------
29
39
 
30
- def info(msg = nil, &block)
31
- msg = (block_given?? block.call : msg)
32
- log.info(PREFIX, msg)
40
+ def info(msg = nil)
41
+ log.info(PREFIX,
42
+ block_given?? yield : msg
43
+ )
33
44
  end
34
45
 
46
+ # ----------------------------------------------------------------------
35
47
  # Log Level: 3
48
+ # ----------------------------------------------------------------------
36
49
 
37
- def debug(msg = nil, &block)
38
- msg = (block_given?? block.call : msg)
39
- log.debug(PREFIX, msg)
50
+ def debug(msg = nil)
51
+ log.debug(PREFIX,
52
+ block_given?? yield : msg
53
+ )
40
54
  end
41
55
 
42
- #
56
+ # ----------------------------------------------------------------------
43
57
 
44
58
  def log_level=(*)
45
- raise RuntimeError, "Please set log levels on Jekyll.logger"
59
+ raise "Please set log levels on Jekyll.logger"
46
60
  end
47
61
  end
48
62
  end
@@ -0,0 +1,98 @@
1
+ # ----------------------------------------------------------------------------
2
+ # Frozen-string-literal: true
3
+ # Copyright: 2012 - 2016 - MIT License
4
+ # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
6
+
7
+ module Jekyll
8
+ module Assets
9
+
10
+ # ------------------------------------------------------------------------
11
+ # This is a wholesale rip of Sprockets::Manifest, we only adjust it to
12
+ # care about whether or not we want to digest, we don't always digest.
13
+ # ------------------------------------------------------------------------
14
+
15
+ class Manifest < Sprockets::Manifest
16
+ def compile(*args)
17
+ unless environment
18
+ raise(
19
+ Error, "manifest requires environment for compilation"
20
+ )
21
+ end
22
+
23
+ filenames = []
24
+ concurrent_compressors = []
25
+ concurrent_writers = []
26
+
27
+ find(*args) do |asset|
28
+ files[asset.digest_path] = {
29
+ "mtime" => asset.mtime.iso8601,
30
+ "logical_path" => asset.logical_path,
31
+ "integrity" => Sprockets::DigestUtils.hexdigest_integrity_uri(asset.hexdigest),
32
+ "digest" => asset.hexdigest,
33
+ "size" => asset.bytesize
34
+ }
35
+
36
+ assets[asset.logical_path] = asset.digest_path
37
+ alias_logical_path = self.class.compute_alias_logical_path(
38
+ asset.logical_path
39
+ )
40
+
41
+ if alias_logical_path
42
+ assets[alias_logical_path] = asset.digest_path
43
+ end
44
+
45
+ target = \
46
+ if environment.digest?
47
+ File.join(dir,
48
+ asset.digest_path
49
+ )
50
+ else
51
+ File.join(dir,
52
+ asset.logical_path
53
+ )
54
+ end
55
+
56
+ if File.exist?(target)
57
+ logger.debug(
58
+ "Skipping #{target}, already exists"
59
+ )
60
+ else
61
+ logger.info "Writing #{target}"
62
+ write_file = Concurrent::Future.execute { asset.write_to target }
63
+ concurrent_writers << write_file
64
+ end
65
+
66
+ filenames << asset.filename
67
+ next if environment.skip_gzip?
68
+ gzip = Utils::Gzip.new(asset)
69
+ next if gzip.cannot_compress?(
70
+ environment.mime_types
71
+ )
72
+
73
+ if File.exist?("#{target}.gz")
74
+ logger.debug(
75
+ "Skipping #{target}.gz, already exists"
76
+ )
77
+ else
78
+ logger.info "Writing #{target}.gz"
79
+ concurrent_compressors << Concurrent::Future.execute do
80
+ write_file.wait! if write_file
81
+ gzip.compress(
82
+ target
83
+ )
84
+ end
85
+ end
86
+ end
87
+
88
+ concurrent_writers.each(&:wait!)
89
+ concurrent_compressors.each(
90
+ &:wait!
91
+ )
92
+
93
+ save
94
+ filenames
95
+ end
96
+ end
97
+ end
98
+ end
@@ -1,8 +1,10 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
+ # Copyright: 2012 - 2016 - MIT License
3
4
  # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
4
6
 
5
- require_relative "patches/jekyll/cleaner"
6
7
  require_relative "patches/sprockets/asset"
8
+ require_relative "patches/sprockets/helpers"
7
9
  require_relative "patches/jekyll/site"
8
10
  require_relative "patches/kernel"
@@ -1,7 +1,3 @@
1
- # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
- # Encoding: utf-8
4
-
5
1
  module Jekyll
6
2
  class Site
7
3
  attr_accessor :sprockets
@@ -1,20 +1,10 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
+ # Copyright: 2012 - 2016 - MIT License
3
4
  # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
4
6
 
5
7
  module Kernel
6
- def javascript?
7
- require "execjs"
8
- if block_given?
9
- yield
10
- end
11
- rescue LoadError, ExecJS::RuntimeUnavailable
12
- Jekyll.logger.debug("ExecJS or JS Runtime not available." \
13
- " Skipping loading of library.")
14
- end
15
-
16
- #
17
-
18
8
  def try_require(file)
19
9
  require file
20
10
  if block_given?
@@ -24,7 +14,7 @@ module Kernel
24
14
  return nil
25
15
  end
26
16
 
27
- #
17
+ # --------------------------------------------------------------------------
28
18
 
29
19
  def try_require_if_javascript(file)
30
20
  ["execjs", file].map(&method(:require))
@@ -1,17 +1,23 @@
1
+ # ----------------------------------------------------------------------------
1
2
  # Frozen-string-literal: true
2
- # Copyright: 2012-2015 - MIT License
3
+ # Copyright: 2012 - 2016 - MIT License
3
4
  # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
4
6
 
5
7
  module Sprockets
6
8
  class Asset
7
9
  def liquid_tags
8
- metadata[:liquid_tags] ||= Set.new
10
+ metadata[:liquid_tags] ||= begin
11
+ Set.new
12
+ end
9
13
  end
10
14
 
11
- #
15
+ # ------------------------------------------------------------------------
12
16
 
13
17
  def data_uri
14
- "data:#{content_type};base64,#{Rack::Utils.escape(Base64.encode64(to_s))}"
18
+ "data:#{content_type};base64,#{Rack::Utils.escape(
19
+ Base64.encode64(to_s)
20
+ )}"
15
21
  end
16
22
  end
17
23
  end
@@ -0,0 +1,31 @@
1
+ # ----------------------------------------------------------------------------
2
+ # Frozen-string-literal: true
3
+ # Copyright: 2012 - 2016 - MIT License
4
+ # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
6
+
7
+ require "sprockets/helpers"
8
+ Sprockets::Helpers.instance_methods.reject { |v| v=~ /^(path_to_|assets_environment$)/ }.each do |m|
9
+ Sprockets::Helpers.send(:define_method, m.to_s.gsub(/_path$/, "_url")) do |*args|
10
+ %Q(url("#{send(m, *args)}"))
11
+ end
12
+ end
13
+
14
+ module Sprockets
15
+ module Helpers
16
+ alias_method :_old_ap, :asset_path
17
+
18
+ def rcache
19
+ return @resolver_cache ||= {
20
+ #
21
+ }
22
+ end
23
+
24
+ def asset_path(asset, h = {})
25
+ return unless out = _old_ap(asset)
26
+ path = environment.find_asset(resolve_without_compat(asset))
27
+ environment.parent.used.add(path)
28
+ out
29
+ end
30
+ end
31
+ end
@@ -0,0 +1 @@
1
+ require_relative "processors/liquid"
@@ -0,0 +1,68 @@
1
+ require "less"
2
+
3
+ module Jekyll
4
+ module Assets
5
+ module Processors
6
+ class LESS
7
+
8
+ # --------------------------------------------------------------------
9
+ # Setup and pull out the context and update the data, shipping it.
10
+ # --------------------------------------------------------------------
11
+
12
+ def self.call(input)
13
+ data = input[:data]; paths = [input[:load_path]]
14
+ tree = Less.instance_variable_get(:@loader).require("less/tree")
15
+ context = input[:environment].context_class.new(input)
16
+ patch_tree(tree, context)
17
+
18
+ paths |= input[:environment].paths
19
+ paths |= Dir.glob(input[:load_path] + '/*').select(&File.method(:directory?))
20
+ parser = Less::Parser.new(:paths => paths)
21
+
22
+ context.metadata.merge({
23
+ :data => Less::Parser.new(:paths => paths) \
24
+ .parse(data).to_css
25
+ })
26
+ end
27
+
28
+ # --------------------------------------------------------------------
29
+ # Add the sprockets helpers into the Less environment so people can
30
+ # use assets from within Less... as they see fit.
31
+ # --------------------------------------------------------------------
32
+ # We also make sure to disable their quotes so that we can quote
33
+ # ourselves if we need to, otherwise we simply just take the values.
34
+ # --------------------------------------------------------------------
35
+
36
+ def self.patch_tree(tree, context)
37
+ Sprockets::Helpers.instance_methods.reject { |v| v=~ /^(path_to_|assets_environment$)/ }.each do |m|
38
+ tree.functions[m.to_s.tr("_", "-")] = tree.functions[m.to_s] = lambda do |*args|
39
+ args.last.tap do |o|
40
+ o[:quote] = "" # We handle that ourselves, fuck that.
41
+ o[:value] = context.send(m, args.last.toCSS().gsub(
42
+ /^"|"$/, ""
43
+ ))
44
+
45
+ if m.to_s.end_with?("_path")
46
+ o[:value] = o[:value].inspect
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ # ----------------------------------------------------------------------------
58
+
59
+ if Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new(4.0)
60
+ Sprockets.register_mime_type "text/less", :extensions => [".less", ".css.less"]
61
+ Sprockets.register_transformer("text/less", "test/css",
62
+ Jekyll::Assets::Processors::LESS
63
+ )
64
+ else
65
+ Sprockets.register_engine(
66
+ ".less", Jekyll::Assets::Processors::LESS
67
+ )
68
+ end
@@ -0,0 +1,46 @@
1
+ module Jekyll
2
+ module Assets
3
+ module Processors
4
+ class Liquid
5
+ FOR = %W(
6
+ text/css text/sass text/less application/javascript
7
+ text/scss text/coffeescript text/javascript).freeze
8
+ EXT = %W(.liquid .js.liquid .css.liquid .scss.liquid).freeze
9
+
10
+ # --------------------------------------------------------------------
11
+
12
+ def self.call(context, jekyll = context[:environment].jekyll)
13
+ if context[:environment].parent.asset_config["features"]["liquid"] || \
14
+ File.extname(context[:filename]) == ".liquid"
15
+
16
+ payload_ = jekyll.site_payload
17
+ renderer = jekyll.liquid_renderer.file(context[:filename])
18
+ context[:data] = renderer.parse(context[:data]).render! payload_, \
19
+ :filters => [Jekyll::Filters],
20
+ :registers => {
21
+ :site => jekyll
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ # ----------------------------------------------------------------------------
31
+ # There might be a few missing, if there is please do let me know.
32
+ # ----------------------------------------------------------------------------
33
+
34
+ Jekyll::Assets::Processors::Liquid::EXT.each do |ext|
35
+ Sprockets.register_engine(
36
+ ext, Jekyll::Assets::Processors::Liquid
37
+ )
38
+ end
39
+
40
+ # ----------------------------------------------------------------------------
41
+
42
+ Jekyll::Assets::Processors::Liquid::FOR.each do |val|
43
+ Sprockets.register_preprocessor(
44
+ val, Jekyll::Assets::Processors::Liquid
45
+ )
46
+ end
@@ -0,0 +1 @@
1
+ require_relative "proxies/magick"
@@ -0,0 +1,167 @@
1
+ # ----------------------------------------------------------------------------
2
+ # Frozen-string-literal: true
3
+ # Copyright: 2012 - 2016 - MIT License
4
+ # Encoding: utf-8
5
+ # ----------------------------------------------------------------------------
6
+
7
+ try_require "mini_magick" do
8
+ args = %W(resize quality rotate crop flip gravity)
9
+ presets = %W(@2x @4x @1/2 @1/3 @2/3 @1/4 @2/4 @3/4
10
+ @double @quadruple @half @one-third @two-thirds @one-fourth
11
+ @two-fourths @three-fourths)
12
+
13
+ Jekyll::Assets::Env.liquid_proxies.add :magick, :img, *(args + presets) do
14
+ PRESETS = presets
15
+ ARGS = args
16
+
17
+ class DoubleResizeError < RuntimeError
18
+ def initialize
19
+ "Both resize and @*x provided, this is not supported."
20
+ end
21
+ end
22
+
23
+ # ------------------------------------------------------------------------
24
+ # @see https://github.com/minimagick/minimagick#usage -- All but
25
+ # the boolean @ options are provided by Minimagick.
26
+ # ------------------------------------------------------------------------
27
+
28
+ def initialize(asset, opts, args)
29
+ @path = asset.filename
30
+ @opts = opts
31
+ @asset = asset
32
+ @args = args
33
+ end
34
+
35
+ # ------------------------------------------------------------------------
36
+
37
+ def process
38
+ img = MiniMagick::Image.open(@path)
39
+ methods = private_methods(true).select { |v| v.to_s.start_with?("magick_") }
40
+ if img.respond_to?(:combine_options)
41
+ then img.combine_options do |cmd|
42
+ methods.each do |method|
43
+ send(
44
+ method, img, cmd
45
+ )
46
+ end
47
+ end
48
+
49
+ else
50
+ methods.each do |method|
51
+ send(
52
+ method, img, img
53
+ )
54
+ end
55
+ end
56
+
57
+ img.write(
58
+ @path
59
+ )
60
+ ensure
61
+ img.destroy!
62
+ end
63
+
64
+ # ------------------------------------------------------------------------
65
+
66
+ private
67
+ def any_preset?(*keys)
68
+ @opts.keys.any? do |key|
69
+ keys.include?(key)
70
+ end
71
+ end
72
+
73
+ # ------------------------------------------------------------------------
74
+
75
+ private
76
+ def preset?
77
+ (@opts.keys - ARGS.map(&:to_sym)).any?
78
+ end
79
+
80
+ # ------------------------------------------------------------------------
81
+
82
+ private
83
+ def magick_quality(_, cmd)
84
+ if @opts.key?(:quality)
85
+ then cmd.quality @opts[:quality]
86
+ end
87
+ end
88
+
89
+ # ------------------------------------------------------------------------
90
+
91
+ private
92
+ def magick_resize(_, cmd)
93
+ raise DoubleResizeError if @opts.key?(:resize) && preset?
94
+ if @opts.key?(:resize)
95
+ then cmd.resize @opts[:resize]
96
+ end
97
+ end
98
+
99
+ # ------------------------------------------------------------------------
100
+
101
+ private
102
+ def magick_rotate(_, cmd)
103
+ if @opts.key?(:rotate)
104
+ then cmd.rotate @opts[:rotate]
105
+ end
106
+ end
107
+
108
+ # ------------------------------------------------------------------------
109
+
110
+ private
111
+ def magick_flip(_, cmd)
112
+ if @opts.key?(:flip)
113
+ then cmd.flip @opts[:flip]
114
+ end
115
+ end
116
+
117
+ # ------------------------------------------------------------------------
118
+
119
+ private
120
+ def magick_crop(_, cmd)
121
+ if @opts.key?(:crop)
122
+ then cmd.crop @opts[:crop]
123
+ end
124
+ end
125
+
126
+ # ------------------------------------------------------------------------
127
+
128
+ private
129
+ def magick_gravity(_, cmd)
130
+ if @opts.key?(:gravity)
131
+ then cmd.gravity @opts[:gravity]
132
+ end
133
+ end
134
+
135
+ # ------------------------------------------------------------------------
136
+ # I just want you to know, we don't even care if you do multiple
137
+ # resizes or try to, we don't attempt to even attempt to attempt to care
138
+ # we expect you to be logical and if you aren't we will comply.
139
+ # ------------------------------------------------------------------------
140
+ # rubocop:disable Metrics/PerceivedComplexity
141
+ # rubocop:disable Metrics/CyclomaticComplexity
142
+ # rubocop:disable Style/ParallelAssignment
143
+ # rubocop:disable Metrics/AbcSize
144
+ # ------------------------------------------------------------------------
145
+
146
+ private
147
+ def magick_preset_resize(img, cmd)
148
+ return unless preset?
149
+ width, height = img.width * 4, img.height * 4 if any_preset?(:"4x", :quadruple)
150
+ width, height = img.width * 2, img.height * 2 if any_preset?(:"2x", :double)
151
+ width, height = img.width / 2, img.height / 2 if any_preset?(:"1/2", :half)
152
+ width, height = img.width / 3, img.height / 3 if any_preset?(:"1/3", :"one-third")
153
+ width, height = img.width / 4, img.height / 4 if any_preset?(:"1/4", :"one-fourth")
154
+ width, height = img.width / 3 * 2, img.height / 3 * 2 if any_preset?(:"2/3", :"two-thirds")
155
+ width, height = img.width / 4 * 2, img.height / 4 * 2 if any_preset?(:"2/4", :"two-fourths")
156
+ width, height = img.width / 4 * 3, img.height / 4 * 3 if any_preset?(:"3/4", :"three-fourths")
157
+ cmd.resize "#{width}x#{height}"
158
+ end
159
+
160
+ # ------------------------------------------------------------------------
161
+ # rubocop:enable Metrics/PerceivedComplexity
162
+ # rubocop:enable Metrics/CyclomaticComplexity
163
+ # rubocop:enable Style/ParallelAssignment
164
+ # rubocop:enable Metrics/AbcSize
165
+ # ------------------------------------------------------------------------
166
+ end
167
+ end