jekyll-assets 2.4.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +21 -17
  3. data/LICENSE +1 -1
  4. data/README.md +365 -297
  5. data/Rakefile +13 -2
  6. data/lib/jekyll/assets.rb +15 -11
  7. data/lib/jekyll/assets/config.rb +91 -55
  8. data/lib/jekyll/assets/context.rb +32 -0
  9. data/lib/jekyll/assets/default.rb +98 -0
  10. data/lib/jekyll/assets/drop.rb +62 -0
  11. data/lib/jekyll/assets/env.rb +135 -278
  12. data/lib/jekyll/assets/extensible.rb +86 -0
  13. data/lib/jekyll/assets/filters.rb +22 -0
  14. data/lib/jekyll/assets/hook.rb +115 -48
  15. data/lib/jekyll/assets/html.rb +88 -0
  16. data/lib/jekyll/assets/logger.rb +17 -59
  17. data/lib/jekyll/assets/manifest.rb +15 -126
  18. data/lib/jekyll/assets/map.rb +57 -0
  19. data/lib/jekyll/assets/map/css.rb +43 -0
  20. data/lib/jekyll/assets/map/javascript.rb +43 -0
  21. data/lib/jekyll/assets/map/writer.rb +192 -0
  22. data/lib/jekyll/assets/patches/cached_env.rb +79 -0
  23. data/lib/jekyll/assets/patches/functions.rb +31 -0
  24. data/lib/jekyll/assets/patches/obsolete_files.rb +42 -0
  25. data/lib/jekyll/assets/patches/sprockets.rb +9 -0
  26. data/lib/jekyll/assets/patches/sprockets_data_uri.rb +12 -0
  27. data/lib/jekyll/assets/plugins.rb +9 -0
  28. data/lib/jekyll/assets/plugins/bootstrap.rb +5 -0
  29. data/lib/jekyll/assets/plugins/font-awesome.rb +8 -0
  30. data/lib/jekyll/assets/plugins/frontmatter.rb +28 -0
  31. data/lib/jekyll/assets/plugins/html/audio.rb +32 -0
  32. data/lib/jekyll/assets/plugins/html/css.rb +24 -0
  33. data/lib/jekyll/assets/plugins/html/defaults/audio.rb +69 -0
  34. data/lib/jekyll/assets/plugins/html/defaults/css.rb +48 -0
  35. data/lib/jekyll/assets/plugins/html/defaults/img.rb +54 -0
  36. data/lib/jekyll/assets/plugins/html/defaults/js.rb +48 -0
  37. data/lib/jekyll/assets/plugins/html/defaults/vid.rb +63 -0
  38. data/lib/jekyll/assets/plugins/html/img.rb +76 -0
  39. data/lib/jekyll/assets/plugins/html/js.rb +30 -0
  40. data/lib/jekyll/assets/plugins/html/pic.rb +125 -0
  41. data/lib/jekyll/assets/plugins/html/svg.rb +37 -0
  42. data/lib/jekyll/assets/plugins/html/vid.rb +26 -0
  43. data/lib/jekyll/assets/plugins/liquid.rb +57 -0
  44. data/lib/jekyll/assets/plugins/magick.rb +7 -0
  45. data/lib/jekyll/assets/plugins/optim.rb +7 -0
  46. data/lib/jekyll/assets/plugins/prefixer.rb +28 -0
  47. data/lib/jekyll/assets/plugins/proxy/magick.rb +131 -0
  48. data/lib/jekyll/assets/plugins/proxy/optim.rb +64 -0
  49. data/lib/jekyll/assets/plugins/searcher.rb +72 -0
  50. data/lib/jekyll/assets/proxy.rb +109 -0
  51. data/lib/jekyll/assets/tag.rb +176 -0
  52. data/lib/jekyll/assets/url.rb +23 -0
  53. data/lib/jekyll/assets/utils.rb +348 -0
  54. data/lib/jekyll/assets/version.rb +2 -2
  55. data/lib/jekyll/assets/writer.rb +36 -0
  56. metadata +102 -81
  57. data/lib/jekyll-assets.rb +0 -7
  58. data/lib/jekyll/assets/addons/autoprefixer.rb +0 -11
  59. data/lib/jekyll/assets/addons/bootstrap.rb +0 -9
  60. data/lib/jekyll/assets/addons/fontawesome.rb +0 -9
  61. data/lib/jekyll/assets/addons/javascript.rb +0 -11
  62. data/lib/jekyll/assets/cached.rb +0 -30
  63. data/lib/jekyll/assets/helpers.rb +0 -74
  64. data/lib/jekyll/assets/hooks/cache.rb +0 -21
  65. data/lib/jekyll/assets/hooks/compression.rb +0 -25
  66. data/lib/jekyll/assets/hooks/config.rb +0 -12
  67. data/lib/jekyll/assets/hooks/erb.rb +0 -15
  68. data/lib/jekyll/assets/hooks/jekyll/drops.rb +0 -9
  69. data/lib/jekyll/assets/hooks/jekyll/setup.rb +0 -11
  70. data/lib/jekyll/assets/hooks/jekyll/write.rb +0 -11
  71. data/lib/jekyll/assets/hooks/logger.rb +0 -11
  72. data/lib/jekyll/assets/hooks/sources.rb +0 -13
  73. data/lib/jekyll/assets/hooks/sprockets.rb +0 -9
  74. data/lib/jekyll/assets/hooks/version.rb +0 -11
  75. data/lib/jekyll/assets/liquid/context.rb +0 -19
  76. data/lib/jekyll/assets/liquid/drop.rb +0 -81
  77. data/lib/jekyll/assets/liquid/filters.rb +0 -49
  78. data/lib/jekyll/assets/liquid/tag.rb +0 -244
  79. data/lib/jekyll/assets/liquid/tag/defaults.rb +0 -27
  80. data/lib/jekyll/assets/liquid/tag/defaults/image.rb +0 -81
  81. data/lib/jekyll/assets/liquid/tag/defaults/sha.rb +0 -58
  82. data/lib/jekyll/assets/liquid/tag/parser.rb +0 -202
  83. data/lib/jekyll/assets/liquid/tag/proxied_asset.rb +0 -166
  84. data/lib/jekyll/assets/liquid/tag/proxies.rb +0 -130
  85. data/lib/jekyll/assets/patches/jekyll/cleaner.rb +0 -15
  86. data/lib/jekyll/assets/patches/jekyll/site.rb +0 -5
  87. data/lib/jekyll/assets/patches/kernel.rb +0 -29
  88. data/lib/jekyll/assets/patches/sprockets/asset.rb +0 -28
  89. data/lib/jekyll/assets/processors/less.rb +0 -70
  90. data/lib/jekyll/assets/processors/liquid.rb +0 -46
  91. data/lib/jekyll/assets/proxies/image_optim.rb +0 -80
  92. data/lib/jekyll/assets/proxies/magick.rb +0 -194
@@ -0,0 +1,48 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2012 - 2017 - MIT License
3
+ # Encoding: utf-8
4
+
5
+ require "jekyll/assets"
6
+
7
+ module Jekyll
8
+ module Assets
9
+ class Default
10
+ class JS < Default
11
+ content_types "text/javascript"
12
+ content_types "application/javascript"
13
+ static type: "text/javascript"
14
+
15
+ def set_src
16
+ return @args[:src] = @asset.url if @asset.is_a?(Url)
17
+ @args[:src] = @env.prefix_url(@asset
18
+ .digest_path)
19
+ end
20
+
21
+ def set_integrity
22
+ return unless integrity?
23
+ @args[:integrity] = @asset.integrity
24
+ unless @args.key?(:crossorigin)
25
+ @args[:crossorigin] = "anonymous"
26
+ end
27
+ end
28
+
29
+ # --
30
+ def integrity?
31
+ config[:integrity] && !@asset.is_a?(Url) &&
32
+ !@args.key?(:integrity)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ # --
40
+ Jekyll::Assets::Hook.register :config, :before_merge do |c|
41
+ c.deep_merge!({
42
+ defaults: {
43
+ js: {
44
+ integrity: Jekyll.production?,
45
+ },
46
+ },
47
+ })
48
+ end
@@ -0,0 +1,63 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2012 - 2017 - MIT License
3
+ # Encoding: utf-8
4
+
5
+ require "jekyll/assets"
6
+
7
+ module Jekyll
8
+ module Assets
9
+ class Default
10
+ class Video < Default
11
+ content_types "video/avi"
12
+ content_types "video/webm"
13
+ content_types "video/mp4"
14
+
15
+ # --
16
+ def set_src
17
+ dpath = asset.digest_path
18
+ return args[:src] = asset.url if asset.is_a?(Url)
19
+ return args[:src] = env.prefix_url(dpath) unless args[:inline]
20
+ # This is insanity, but who am I to judge you, and what you do.
21
+ args[:src] = asset.data_uri
22
+ end
23
+
24
+ # --
25
+ def set_controls
26
+ return if args.key?(:controls)
27
+
28
+ args[:controls] = true
29
+ unless args.key?(:controlsList) || args.key?(:controlslist)
30
+ args[:controlList] = "nodownload"
31
+ end
32
+ end
33
+
34
+ # --
35
+ def set_integrity
36
+ return unless integrity?
37
+
38
+ args[:integrity] = asset.integrity
39
+ unless args.key?(:crossorigin)
40
+ args[:crossorigin] = "anonymous"
41
+ end
42
+ end
43
+
44
+ # --
45
+ def integrity?
46
+ config[:integrity] && !asset.is_a?(Url) &&
47
+ !args.key?(:integrity)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ # --
55
+ Jekyll::Assets::Hook.register :config, :before_merge do |c|
56
+ c.deep_merge!({
57
+ defaults: {
58
+ video: {
59
+ integrity: Jekyll.production?,
60
+ },
61
+ },
62
+ })
63
+ end
@@ -0,0 +1,76 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2012 - 2017 - MIT License
3
+ # Encoding: utf-8
4
+
5
+ require "jekyll/assets"
6
+ require "nokogiri"
7
+
8
+ module Jekyll
9
+ module Assets
10
+ class HTML
11
+ class IMG < HTML
12
+ content_types "image/bmp"
13
+ content_types "image/webp"
14
+ content_types "image/svg+xml"
15
+ content_types "image/jpeg"
16
+ content_types "image/tiff"
17
+ content_types "image/gif"
18
+ content_types "image/png"
19
+ content_types "image/jpg"
20
+
21
+ # --
22
+ def run
23
+ Nokogiri::HTML::Builder.with(doc) do |d|
24
+ if srcset?
25
+ complex(d)
26
+ else
27
+ d.img(args.to_h({
28
+ html: true, skip: HTML.skips
29
+ }))
30
+ end
31
+ end
32
+ end
33
+
34
+ # --
35
+ def complex(doc)
36
+ img = doc.img @args.to_h(html: true, skip: HTML.skips)
37
+ Array(args[:srcset][:width]).each do |w|
38
+ w, d = w.to_s.split(%r!\s+!, 2)
39
+ Integer(w)
40
+
41
+ img["srcset"] ||= ""
42
+ img["srcset"] += ", #{path(width: w)} #{d || "#{w}w"}"
43
+ img["srcset"] = img["srcset"].gsub(
44
+ %r!^,\s*!, "")
45
+ end
46
+ end
47
+
48
+ # --
49
+ def path(width:)
50
+ args_ = "#{args[:argv1]} magick:resize=#{width} @path"
51
+ Tag.new("asset", args_, Liquid::ParseContext.new)
52
+ .render(ctx)
53
+ end
54
+
55
+ # --
56
+ def srcset?
57
+ args.key?(:srcset) && args[:srcset]
58
+ .key?(:width)
59
+ end
60
+
61
+ # --
62
+ # @example {% asset src srcset="" %}
63
+ # @example {% asset src %}
64
+ # --
65
+ def self.for?(type:, args:)
66
+ return false unless super
67
+ return false if args.key?(:pic)
68
+ return false if args.key?(:inline) &&
69
+ type == "image/svg+xml"
70
+
71
+ true
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,30 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2012 - 2017 - MIT License
3
+ # Encoding: utf-8
4
+
5
+ require "jekyll/assets"
6
+ require "nokogiri"
7
+
8
+ module Jekyll
9
+ module Assets
10
+ class HTML
11
+ class JS < HTML
12
+ content_types "application/javascript",
13
+ "text/javascript"
14
+
15
+ def run
16
+ if @asset.is_a?(Url) && @args[:inline]
17
+ raise Tag::MixedArg, "@external", "@inline"
18
+
19
+ else
20
+ Nokogiri::HTML::Builder.with(@doc) do |d|
21
+ attr = @args.to_h(html: true, skip: HTML.skips)
22
+ d.script(@asset.to_s, attr) if @args[:inline]
23
+ d.script(attr) unless @args[:inline]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,125 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2012 - 2017 - MIT License
3
+ # Encoding: utf-8
4
+
5
+ require "jekyll/assets"
6
+ require "nokogiri"
7
+
8
+ module Jekyll
9
+ module Assets
10
+ class HTML
11
+ class Pic < HTML
12
+ content_types "image/webp"
13
+ content_types "image/jpeg"
14
+ content_types "image/tiff"
15
+ content_types "image/svg+xml"
16
+ content_types "image/bmp"
17
+ content_types "image/gif"
18
+ content_types "image/png"
19
+ content_types "image/jpg"
20
+
21
+ # --
22
+ # @todo this should be reworked so we don't need to use
23
+ # tag to loop back in on ourselves.
24
+ # --
25
+ def run
26
+ args[:picture] ||= {}
27
+ Nokogiri::HTML::Builder.with(doc) do |d|
28
+ if proper_pic?
29
+ complex(d)
30
+ else
31
+ d.picture args[:picture] do
32
+ d.img args.to_h({
33
+ html: true, skip: HTML.skips + %i(
34
+ picture
35
+ )
36
+ })
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ # --
43
+ def complex(doc)
44
+ @args[:img] ||= {}
45
+ args = @args.to_h(html: true, skip: HTML.skips)
46
+ @args[:img][:src] = asset.digest_path
47
+ _, sources = kv
48
+
49
+ doc.picture @args[:picture] do
50
+ Array(sources).each do |w|
51
+ w, d = w.to_s.split(%r!\s+!, 2)
52
+ Integer(w)
53
+
54
+ source({
55
+ width: w,
56
+ args: args.dup,
57
+ src: path(width: w),
58
+ density: d,
59
+ doc: doc,
60
+ })
61
+ end
62
+
63
+ doc.img(@args[:img])
64
+ end
65
+ end
66
+
67
+ # --
68
+ def path(width:)
69
+ args_ = "#{args[:argv1]} magick:resize=#{width} @path"
70
+ Tag.new("asset", args_, Liquid::ParseContext.new)
71
+ .render(ctx)
72
+ end
73
+
74
+ # --
75
+ def source(doc:, args:, src:, width:, density:)
76
+ args.delete(:src)
77
+ k, = kv
78
+
79
+ args[:srcset] = "#{src} #{density || "#{width}w"}"
80
+ args[:media] = "(#{k}: #{width}px)" unless k == :width \
81
+ || args[:media]
82
+
83
+ doc.source args
84
+ end
85
+
86
+ # --
87
+ def kv
88
+ @kv ||= begin
89
+ src = args[:srcset]
90
+
91
+ out = [:"max-width", src[:"max-width"]] if src[:"max-width"]
92
+ out = [:"min-width", src[:"min-width"]] if src[:"min-width"] && !out
93
+ out = [:width, src[:width]] if src[:width] && !out
94
+
95
+ out
96
+ end
97
+ end
98
+
99
+ # --
100
+ def proper_pic?
101
+ args.key?(:srcset) && (
102
+ args[:srcset].key?(:"max-width") ||
103
+ args[:srcset].key?(:"min-width") ||
104
+ args[:srcset].key?(:width))
105
+ end
106
+
107
+ # --
108
+ def self.cleanup(s)
109
+ s.gsub(%r!<(picture)>(.+)<\/\1>!) do |v|
110
+ v.gsub(%r!</source>!, "")
111
+ end
112
+ end
113
+
114
+ # --
115
+ # {% img src src="" @pic %}
116
+ # --
117
+ def self.for?(args:, type:)
118
+ return false unless super
119
+ return false unless args.key?(:pic)
120
+ true
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,37 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2012 - 2017 - MIT License
3
+ # Encoding: utf-8
4
+
5
+ require "jekyll/assets"
6
+
7
+ module Jekyll
8
+ module Assets
9
+ class HTML
10
+ class SVG < HTML
11
+ content_types "image/svg+xml"
12
+
13
+ # --
14
+ def run
15
+ arg = @args.to_h(html: true)
16
+ arg.each do |k, v|
17
+ @doc.set_attribute(k, v)
18
+ end
19
+ end
20
+
21
+ # --
22
+ def self.wants_xml?
23
+ true
24
+ end
25
+
26
+ # --
27
+ def self.for?(type:, args:)
28
+ return false unless super
29
+ return false unless args.key?(:inline) &&
30
+ !args.key?(:srcset)
31
+
32
+ true
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2012 - 2017 - MIT License
3
+ # Encoding: utf-8
4
+
5
+ require "jekyll/assets"
6
+ require "nokogiri"
7
+
8
+ module Jekyll
9
+ module Assets
10
+ class HTML
11
+ class Video < HTML
12
+ content_types "video/avi"
13
+ content_types "video/webm"
14
+ content_types "video/mp4"
15
+
16
+ def run
17
+ Nokogiri::HTML::Builder.with(doc) do |d|
18
+ d.video("No support for video.", args.to_h({
19
+ html: true, skip: HTML.skips
20
+ }))
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,57 @@
1
+ # Frozen-string-literal: true
2
+ # Copyright: 2012 - 2017 - MIT License
3
+ # Encoding: utf-8
4
+
5
+ require "pathutil"
6
+ require_relative "../utils"
7
+ require "jekyll/assets"
8
+ require "jekyll"
9
+
10
+ module Jekyll
11
+ module Assets
12
+ module Plugins
13
+ class Liquid
14
+ TYPES = {
15
+ "text/liquid+sass" => %w(.sass.liquid .liquid.sass),
16
+ "application/liquid+javascript" => %w(.liquid.js .js.liquid),
17
+ "application/liquid+ecmascript-6" => %w(.liquid.es6 .es6.liquid),
18
+ "text/liquid+coffeescript" => %w(.liquid.coffee .coffee.liquid),
19
+ "text/liquid+scss" => %w(.liquid.scss .scss.liquid),
20
+ "text/liquid+css" => %w(.liquid.css .css.liquid),
21
+ }.freeze
22
+
23
+ def self.call(ctx)
24
+ env = ctx[:environment]
25
+ registers = { site: env.jekyll }
26
+ environment = env.jekyll.to_liquid.merge(jekyll: {
27
+ "version" => Jekyll::VERSION, "environment" => Jekyll.env
28
+ })
29
+
30
+ bctx = ::Liquid::Context.new(environment, {}, registers)
31
+ ctx[:data] = env.parse_liquid(ctx[:data], {
32
+ ctx: bctx,
33
+ })
34
+ end
35
+ end
36
+
37
+ # --
38
+ # Registers it inside of Sprockets.
39
+ # Because we need to keep some support for 3.x we register it
40
+ # two different ways depending on the type of Sprockets.
41
+ # --
42
+ if !Env.old_sprockets?
43
+ Liquid::TYPES.each do |k, v|
44
+ to = Utils.strip_secondary_content_type(k)
45
+ charset = Sprockets.mime_types[to][:charset]
46
+ Sprockets.register_mime_type(k, extensions: v, charset: charset)
47
+ Sprockets.register_transformer(k, to, Liquid)
48
+ end
49
+ else
50
+ # Still the easiest way tbqf. Never change.
51
+ Sprockets.register_engine ".liquid", Liquid, {
52
+ silence_deprecation: true,
53
+ }
54
+ end
55
+ end
56
+ end
57
+ end