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
@@ -1,166 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- require "forwardable"
8
-
9
- module Jekyll
10
- module Assets
11
- module Liquid
12
- class Tag
13
- class ProxiedAsset
14
- attr_reader :args, :asset, :env
15
- extend Forwardable
16
-
17
- # ------------------------------------------------------------------
18
-
19
- attr_reader :content_type
20
-
21
- def_delegator :@asset, :liquid_tags
22
- def_delegator :@asset, :source_filename
23
- def_delegator :@asset, :mtime
24
-
25
- # ------------------------------------------------------------------
26
-
27
- def initialize(asset, args, env, tag)
28
- @env = env
29
- @asset = asset.dup
30
- @args = args
31
- @tag = tag
32
- @path = Pathutil.new(asset.logical_path)
33
- @content_type = asset.content_type
34
-
35
- cache_file
36
- proxy_file
37
- end
38
-
39
- # ------------------------------------------------------------------
40
-
41
- def integrity
42
- Sprockets::DigestUtils.integrity_uri(
43
- digest
44
- )
45
- end
46
-
47
- # ------------------------------------------------------------------
48
-
49
- def cached?
50
- @_cached
51
- end
52
-
53
- # ------------------------------------------------------------------
54
-
55
- def write_to(name)
56
- FileUtils.mkdir_p File.dirname(name)
57
- Sprockets::PathUtils.atomic_write(name) do |f|
58
- f.write source
59
- end
60
- end
61
-
62
- # ------------------------------------------------------------------
63
-
64
- def source
65
- filename.binread
66
- end
67
-
68
- # ------------------------------------------------------------------
69
-
70
- def filename
71
- Pathutil.new(
72
- env.in_cache_dir(digest_path)
73
- )
74
- end
75
-
76
- # ------------------------------------------------------------------
77
-
78
- def digest
79
- Digest::SHA2.hexdigest(
80
- args.proxies.to_s
81
- )
82
- end
83
-
84
- # ------------------------------------------------------------------
85
-
86
- def content_type=(type)
87
- return if @content_type == type
88
-
89
- @path = @path.sub_ext(_ext_for(type))
90
- @content_type = type
91
- end
92
-
93
- # ------------------------------------------------------------------
94
- # We always digest a proxied asset so it's uniq based on what
95
- # proxies you give us, it would be ignorant to treat it otherwise,
96
- # we also make sure they are URL safe by digesting the args.
97
- # ------------------------------------------------------------------
98
-
99
- def logical_path
100
- digest_path
101
- end
102
-
103
- # ------------------------------------------------------------------
104
-
105
- def digest_path
106
- "#{@path.sub_ext ""}-#{digest}#{@path.extname}"
107
- end
108
-
109
- # --------------------------------------------------------------------
110
-
111
- private
112
- def _mime_for(ext)
113
- Sprockets.mime_exts[
114
- ext
115
- ]
116
- end
117
-
118
- # --------------------------------------------------------------------
119
-
120
- private
121
- def _ext_for(type)
122
- Sprockets.mime_types[type][:extensions].first
123
- end
124
-
125
- # ------------------------------------------------------------------
126
-
127
- private
128
- def proxy_file
129
- unless cached?
130
- args.proxies.each do |key, val|
131
- old_type = content_type
132
- old_filename = filename
133
- Proxies.get(key).first[:class].new(self, val, @args).process
134
- old_filename.rm if old_type != content_type
135
- end
136
- end
137
- end
138
-
139
- # ------------------------------------------------------------------
140
-
141
- private
142
- def find_cached
143
- glob = filename.dirname.glob(filename.basename.sub_ext('.*'))
144
- @_cached = filename.dirname.directory? && !glob.first.nil?
145
- if @_cached
146
- self.content_type = _mime_for(File.extname(glob.first))
147
- end
148
-
149
- @_cached
150
- end
151
-
152
- # ------------------------------------------------------------------
153
-
154
- private
155
- def cache_file
156
- return true if @_cached || find_cached
157
-
158
- filename.dirname.mkdir_p
159
- Pathutil.new(asset.filename).cp filename
160
- true
161
- end
162
- end
163
- end
164
- end
165
- end
166
- end
@@ -1,130 +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
- class Tag
11
- module Proxies
12
- def self.add_by_class(class_, name, tag, *args)
13
- proc_ = proc { |v| [v.to_s, v, v.to_sym] }
14
- all << {
15
- :name => proc_.call(name).uniq,
16
- :args => [args].flatten.map(&proc_).flatten.uniq,
17
- :tags => [ tag].flatten.map(&proc_).flatten.uniq,
18
- :class => class_
19
- }
20
-
21
- all
22
- end
23
-
24
- # ------------------------------------------------------------------
25
-
26
- def self.add(name, tag, *args, &block)
27
- if tag.is_a?(Array)
28
- return tag.each do |v|
29
- klass = generate_class(name, v, &block)
30
- add_by_class(*klass,
31
- *args
32
- )
33
- end
34
- end
35
-
36
- klass = generate_class(name, tag, &block)
37
- add_by_class(*klass,
38
- *args
39
- )
40
- end
41
-
42
- # ------------------------------------------------------------------
43
-
44
- def self.keys
45
- all.select { |val| !val[:class].is_a?(Symbol) }.map do |val|
46
- val[:name]
47
- end.flatten
48
- end
49
-
50
- # ------------------------------------------------------------------
51
-
52
- def self.base_keys
53
- all.select { |val| val[:class].is_a?(Symbol) }.map do |val|
54
- val[:name]
55
- end.flatten
56
- end
57
-
58
- # ------------------------------------------------------------------
59
-
60
- def self.has?(name, tag = nil, arg = nil)
61
- get(name, tag, arg).any?
62
- end
63
-
64
- # ------------------------------------------------------------------
65
-
66
- def self.get(name, tag = nil, arg = nil)
67
- if name && tag && arg then get_by_name_and_tag_and_arg(name, tag, arg)
68
- elsif name && tag
69
- get_by_name_and_tag(name, tag)
70
-
71
- else
72
- all.select do |val|
73
- val[:name].include?(name)
74
- end
75
- end
76
- end
77
-
78
- # ------------------------------------------------------------------
79
-
80
- def self.get_by_name_and_tag_and_arg(name, tag, arg)
81
- all.select do |val|
82
- val[:name].include?(name) && (val[:tags].include?(:all) || val[:tags] \
83
- .include?(tag)) && val[:args].include?(arg)
84
- end
85
- end
86
-
87
- # ------------------------------------------------------------------
88
-
89
- def self.get_by_name_and_tag(name, tag)
90
- all.select do |val|
91
- val[:name].include?(name) && (val[:tags].include?(:all) || val[:tags] \
92
- .include?(tag))
93
- end
94
- end
95
-
96
- # ------------------------------------------------------------------
97
-
98
- def self.all
99
- @_all ||= Set.new
100
- end
101
-
102
- # ------------------------------------------------------------------
103
-
104
- private_class_method
105
- def self.generate_class(name, tag, &block)
106
- class_ = const_set(random_name, Class.new)
107
- class_.class_eval(&block)
108
- return class_, name, tag
109
- end
110
-
111
- # ------------------------------------------------------------------
112
-
113
- private_class_method
114
- def self.random_name
115
- (0...12).map { ("a".."z").to_a.values_at(rand(26)) }.join.capitalize
116
- end
117
-
118
- # ------------------------------------------------------------------
119
- # TODO: Put in a better place.
120
- # ------------------------------------------------------------------
121
-
122
- add_by_class :internal, :data, :all, ["@uri"]
123
- add_by_class :internal, :sprockets, :all, %W(
124
- accept write_to
125
- )
126
- end
127
- end
128
- end
129
- end
130
- end
@@ -1,15 +0,0 @@
1
- module JekyllAssetsPatchesJekyllCleaner
2
- def obsolete_files
3
- super.delete_if do |v|
4
- v.start_with?(site.in_dest_dir(
5
- site.sprockets.prefix_path
6
- ))
7
- end
8
- end
9
- end
10
-
11
- module Jekyll
12
- class Cleaner
13
- prepend JekyllAssetsPatchesJekyllCleaner
14
- end
15
- end
@@ -1,5 +0,0 @@
1
- module Jekyll
2
- class Site
3
- attr_accessor :sprockets
4
- end
5
- end
@@ -1,29 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- # Frozen-string-literal: true
3
- # Copyright: 2012 - 2016 - MIT License
4
- # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
-
7
- module Kernel
8
- def try_require(file)
9
- require file
10
- if block_given?
11
- yield
12
- end
13
- rescue LoadError
14
- return nil
15
- end
16
-
17
- # --------------------------------------------------------------------------
18
-
19
- def try_require_if_javascript(file)
20
- ["execjs", file].map(&method(:require))
21
- if block_given?
22
- yield
23
- end
24
- rescue LoadError, ExecJS::RuntimeUnavailable
25
- Jekyll.logger.debug("ExecJS, JS Runtime or `#{file}' not available." \
26
- " Skipping the loading of libraries.")
27
- return
28
- end
29
- end
@@ -1,28 +0,0 @@
1
- # Frozen-string-literal: true
2
- # Copyright: 2012 - 2016 - MIT License
3
- # Encoding: utf-8
4
-
5
- module Sprockets
6
- class Asset
7
-
8
- # --
9
- # List all the liquid tags this asset used.
10
- # --
11
- def liquid_tags
12
- metadata[:liquid_tags] ||= begin
13
- Set.new
14
- end
15
- end
16
-
17
-
18
- # --
19
- # Pull out the data uri.
20
- # @return [String]
21
- # --
22
- def data_uri
23
- "data:#{content_type};base64,#{Rack::Utils.escape(
24
- Base64.encode64(to_s)
25
- )}"
26
- end
27
- end
28
- end
@@ -1,70 +0,0 @@
1
- try_require_if_javascript "less" do
2
- module Jekyll
3
- module Assets
4
- module Processors
5
- class LESS
6
-
7
- # --------------------------------------------------------------------
8
- # Setup and pull out the context and update the data, shipping it.
9
- # --------------------------------------------------------------------
10
-
11
- def self.call(input)
12
- data = input[:data]; paths = [input[:load_path]]
13
- tree = Less.instance_variable_get(:@loader).require("less/tree")
14
- context = input[:environment].context_class.new(input)
15
- patch_tree(tree, context)
16
-
17
- paths |= input[:environment].paths
18
- paths |= Dir.glob(input[:load_path] + '/*').select(&File.method(:directory?))
19
- parser = Less::Parser.new(:paths => paths)
20
-
21
- context.metadata.merge({
22
- :data => Less::Parser.new(:paths => paths) \
23
- .parse(data).to_css
24
- })
25
- end
26
-
27
- # --------------------------------------------------------------------
28
- # Add the sprockets helpers into the Less environment so people can
29
- # use assets from within Less... as they see fit.
30
- # --------------------------------------------------------------------
31
- # We also make sure to disable their quotes so that we can quote
32
- # ourselves if we need to, otherwise we simply just take the values.
33
- # --------------------------------------------------------------------
34
-
35
- def self.patch_tree(tree, context)
36
- Helpers.instance_methods.each do |m|
37
- tree.functions[m.to_s.tr("_", "-")] = tree.functions[m.to_s] = lambda do |*args|
38
- args.last.tap do |o|
39
- o[:quote] = ""
40
- o[:value] = context.send(m, args.last.toCSS().gsub(
41
- /^"|"$/, ""
42
- ))
43
-
44
- if m.to_s.end_with?("_path")
45
- o[:value] = o[:value].inspect
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
55
-
56
- # ----------------------------------------------------------------------------
57
-
58
- if Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new(4.0)
59
- Sprockets.register_mime_type "text/less", :extensions => [".less", ".css.less"]
60
- Sprockets.register_transformer("text/less", "test/css",
61
- Jekyll::Assets::Processors::LESS
62
- )
63
- else
64
- Sprockets.register_engine(
65
- ".less", Jekyll::Assets::Processors::LESS, {
66
- :silence_deprecation => true
67
- }
68
- )
69
- end
70
- end