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
data/lib/jekyll-assets.rb DELETED
@@ -1,7 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- require "jekyll/assets"
@@ -1,11 +0,0 @@
1
- # Frozen-string-literal: true
2
- # Copyright: 2012 - 2016 - MIT License
3
- # Encoding: utf-8
4
-
5
- try_require_if_javascript "autoprefixer-rails" do
6
- Jekyll::Assets::Hook.register :env, :init do |env|
7
- AutoprefixerRails.install(env, env.asset_config[
8
- "autoprefixer"
9
- ])
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- try_require "bootstrap-sass" do
8
- Bootstrap.load!
9
- end
@@ -1,9 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- try_require "font-awesome-sass" do
8
- FontAwesome::Sass.load!
9
- end
@@ -1,11 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- try_require_if_javascript "sprockets/es6" do
8
- if ExecJS.runtime.is_a?(ExecJS::RubyRhinoRuntime)
9
- Jekyll.logger.warn "ES6 transpiler has trouble with RubyRhino, use Node"
10
- end
11
- end
@@ -1,30 +0,0 @@
1
- # Frozen-string-literal: true
2
- # Copyright: 2012 - 2016 - MIT License
3
- # Encoding: utf-8
4
-
5
- module Jekyll
6
- module Assets
7
- class Cached < Sprockets::CachedEnvironment
8
- attr_reader :jekyll, :parent
9
-
10
- # --
11
- # @param [Env] env the environment
12
- # Initialize a new instance
13
- # --
14
- def initialize(env)
15
- @parent = env
16
- @jekyll = env.jekyll
17
- @resolve_cache = {}
18
- super env
19
- end
20
-
21
-
22
- # --
23
- # Resolve an asset.
24
- # --
25
- def resolve(*args)
26
- @resolve_cache[args] ||= super
27
- end
28
- end
29
- end
30
- end
@@ -1,74 +0,0 @@
1
- module Jekyll
2
- module Assets
3
- module Helpers
4
- extend Forwardable::Extended
5
- rb_delegate :manifest, {
6
- :to => :parent
7
- }
8
-
9
- # --
10
- # @param [String] path the path you wish to resolve.
11
- # Find the path to the asset.
12
- # --
13
- def asset_path(path, opts = {})
14
- return path if Pathname.new(path).absolute?
15
- asset = manifest.find(path).first
16
-
17
- if asset
18
- manifest.add(asset)
19
- parent.prefix_path(
20
- parent.digest?? asset.digest_path : asset.logical_path
21
- )
22
- else
23
- path
24
- end
25
- end
26
-
27
- # --
28
- # @param [String] path the path you wish to resolve.
29
- # Pull the asset path and wrap it in url().
30
- # --
31
- def asset_url(path, opts = {})
32
- "url(#{asset_path(
33
- path, opts
34
- )})"
35
- end
36
-
37
- # --
38
- # Get access to the actual asset environment.
39
- # @return [Jekyll::Assets::Env]
40
- # --
41
- def parent
42
- environment.is_a?(Cached) ? environment.parent : environment
43
- end
44
-
45
- # --
46
- # Creates font_url, font_path, image_path, image_url,
47
- # img_path, and img_url for your pleasure.
48
- # --
49
- %W(font image img).each do |key|
50
- define_method "#{key}_path" do |*args|
51
- asset_path(
52
- *args
53
- )
54
- end
55
-
56
- #
57
-
58
- define_method "#{key}_url" do |*args|
59
- asset_url(
60
- *args
61
- )
62
- end
63
- end
64
- end
65
- end
66
- end
67
-
68
- #
69
-
70
- module Sprockets
71
- class Context
72
- prepend Jekyll::Assets::Helpers
73
- end
74
- end
@@ -1,21 +0,0 @@
1
- # Frozen-string-literal: true
2
- # Copyright: 2012 - 2016 - MIT License
3
- # Encoding: utf-8
4
-
5
- Jekyll::Assets::Hook.register :env, :init do
6
- cache = asset_config.fetch("cache", ".asset-cache")
7
- type = asset_config.fetch("cache_type",
8
- "filesystem"
9
- )
10
-
11
- if cache != false && type != "memory"
12
- self.cache = Sprockets::Cache::FileStore.new(cache_path)
13
-
14
- elsif cache && type == "memory"
15
- self.cache = Sprockets::Cache::MemoryStore.new
16
-
17
- else
18
- Jekyll.logger.info "", "Asset caching is disabled by configuration. " \
19
- "However, if you're using proxies, a cache might still be created."
20
- end
21
- end
@@ -1,25 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- Jekyll::Assets::Hook.register :env, :init do
8
- if compress?("css")
9
- self.css_compressor = :sass
10
- end
11
-
12
- if compress?("js")
13
- try_require "uglifier" do
14
- if !jekyll.safe && (opts = self.asset_config.fetch("external", {}).fetch("uglifier", nil))
15
- self.js_compressor = Uglifier.new(
16
- opts.symbolize_keys
17
- )
18
-
19
- else
20
- self.js_compressor = \
21
- :uglify
22
- end
23
- end
24
- end
25
- end
@@ -1,12 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- Jekyll::Assets::Hook.register :env, :init, :early do
8
- jekyll.config["assets"] = Jekyll::Assets::Config.merge(asset_config)
9
- Jekyll::Assets::Config.merge_sources(
10
- jekyll, asset_config
11
- )
12
- end
@@ -1,15 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- Jekyll::Assets::Hook.register :env, :init, :early do
8
- self.config = hash_reassoc(config, :engines) do |hash|
9
- hash.delete(
10
- ".erb"
11
- )
12
-
13
- hash
14
- end
15
- end
@@ -1,9 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- Jekyll::Hooks.register :site, :pre_render do |jekyll, payload|
8
- payload["assets"] = jekyll.sprockets.to_liquid_payload
9
- end
@@ -1,11 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- Jekyll::Hooks.register :site, :after_reset do |jekyll|
8
- Jekyll::Assets::Env.init(
9
- jekyll
10
- )
11
- end
@@ -1,11 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- Jekyll::Hooks.register :site, :post_write do |jekyll|
8
- if jekyll.sprockets.asset_config["autowrite"]
9
- then jekyll.sprockets.write_all
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- Jekyll::Assets::Hook.register :env, :init do
8
- if jekyll.config["verbose"]
9
- self.logger = Jekyll::Assets::Logger.new
10
- end
11
- end
@@ -1,13 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- Jekyll::Assets::Hook.register :env, :init do
8
- asset_config["sources"] ||= []
9
-
10
- asset_config["sources"].each do |path|
11
- append_path jekyll.in_source_dir(path)
12
- end
13
- end
@@ -1,9 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- Jekyll::Assets::Hook.register :env, :init do
8
- jekyll.sprockets = self
9
- end
@@ -1,11 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- Jekyll::Assets::Hook.register :env, :init do
8
- self.version = Digest::MD5.hexdigest(
9
- asset_config.inspect
10
- )
11
- end
@@ -1,19 +0,0 @@
1
- # Frozen-string-literal: true
2
- # Copyright: 2012 - 2017 - MIT License
3
- # Encoding: utf-8
4
-
5
- module Jekyll
6
- module Assets
7
- module Liquid
8
- if defined?(::Liquid::ParseContext)
9
- class ParseContext < ::Liquid::ParseContext
10
- #
11
- end
12
- else
13
- class ParseContext < Array
14
- #
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,81 +0,0 @@
1
- # Frozen-string-literal: true
2
- # Copyright: 2012 - 2016 - MIT License
3
- # Encoding: utf-8
4
-
5
- require "fastimage"
6
-
7
- module Jekyll
8
- module Assets
9
- module Liquid
10
- class Drop < ::Liquid::Drop
11
- extend Forwardable
12
- def initialize(path, jekyll)
13
- @path = path
14
- @jekyll = jekyll
15
- @asset = nil
16
- end
17
-
18
- # --------------------------------------------------------------------
19
-
20
- def_delegator :asset, :digest_path
21
- def_delegator :asset, :logical_path
22
- def_delegator :asset, :content_type, :type
23
- def_delegator :asset, :content_type
24
- def_delegator :asset, :filename
25
-
26
- # --------------------------------------------------------------------
27
-
28
- def basename
29
- File.basename(@path)
30
- end
31
-
32
- # --------------------------------------------------------------------
33
-
34
- def integrity
35
- return asset.integrity
36
- end
37
-
38
- # --------------------------------------------------------------------
39
-
40
- def width
41
- if image?
42
- dimensions.first
43
- end
44
- end
45
-
46
- # --------------------------------------------------------------------
47
-
48
- def height
49
- if image?
50
- dimensions.last
51
- end
52
- end
53
-
54
- # --------------------------------------------------------------------
55
-
56
- def dimensions
57
- if image?
58
- @dimensions ||= FastImage.size(asset.filename.to_s)
59
- end
60
- end
61
-
62
- # --------------------------------------------------------------------
63
-
64
- private
65
- def image?
66
- %W(image/png image/jpeg image/gif).include?(
67
- asset.content_type
68
- )
69
- end
70
-
71
- # --------------------------------------------------------------------
72
-
73
- private
74
- def asset
75
- @asset ||= @jekyll.sprockets.manifest.find(@path) \
76
- .first
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,49 +0,0 @@
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
- module Liquid
10
- module Filters
11
- ACCEPTABLE_FILTERS = [:css, :img, :asset_path, :stylesheet,
12
- :javascript, :style, :image, :js]
13
-
14
- # --
15
- # The base filters.
16
- # --
17
- ACCEPTABLE_FILTERS.each do |val|
18
- define_method val do |path, args = ""|
19
- Tag.send(:new, val, "#{path} #{args}", ParseContext.new).render(
20
- @context
21
- )
22
- end
23
- end
24
-
25
- # --
26
- # Include multiple assets.
27
- # @return [Strings]
28
- # --
29
- def jekyll_asset_multi(assets)
30
- return Shellwords.shellsplit(assets).map { |s| s.split(":", 2) }.map do |tag, arguments|
31
- Tag.send(:new, tag, arguments, ParseContext.new).render(
32
- @context
33
- )
34
- end \
35
-
36
- .join(
37
- "\n"
38
- )
39
- end
40
- end
41
-
42
- #
43
-
44
- ::Liquid::Template.register_filter(
45
- Filters
46
- )
47
- end
48
- end
49
- end