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.
- checksums.yaml +4 -4
- data/Gemfile +21 -17
- data/LICENSE +1 -1
- data/README.md +365 -297
- data/Rakefile +13 -2
- data/lib/jekyll/assets.rb +15 -11
- data/lib/jekyll/assets/config.rb +91 -55
- data/lib/jekyll/assets/context.rb +32 -0
- data/lib/jekyll/assets/default.rb +98 -0
- data/lib/jekyll/assets/drop.rb +62 -0
- data/lib/jekyll/assets/env.rb +135 -278
- data/lib/jekyll/assets/extensible.rb +86 -0
- data/lib/jekyll/assets/filters.rb +22 -0
- data/lib/jekyll/assets/hook.rb +115 -48
- data/lib/jekyll/assets/html.rb +88 -0
- data/lib/jekyll/assets/logger.rb +17 -59
- data/lib/jekyll/assets/manifest.rb +15 -126
- data/lib/jekyll/assets/map.rb +57 -0
- data/lib/jekyll/assets/map/css.rb +43 -0
- data/lib/jekyll/assets/map/javascript.rb +43 -0
- data/lib/jekyll/assets/map/writer.rb +192 -0
- data/lib/jekyll/assets/patches/cached_env.rb +79 -0
- data/lib/jekyll/assets/patches/functions.rb +31 -0
- data/lib/jekyll/assets/patches/obsolete_files.rb +42 -0
- data/lib/jekyll/assets/patches/sprockets.rb +9 -0
- data/lib/jekyll/assets/patches/sprockets_data_uri.rb +12 -0
- data/lib/jekyll/assets/plugins.rb +9 -0
- data/lib/jekyll/assets/plugins/bootstrap.rb +5 -0
- data/lib/jekyll/assets/plugins/font-awesome.rb +8 -0
- data/lib/jekyll/assets/plugins/frontmatter.rb +28 -0
- data/lib/jekyll/assets/plugins/html/audio.rb +32 -0
- data/lib/jekyll/assets/plugins/html/css.rb +24 -0
- data/lib/jekyll/assets/plugins/html/defaults/audio.rb +69 -0
- data/lib/jekyll/assets/plugins/html/defaults/css.rb +48 -0
- data/lib/jekyll/assets/plugins/html/defaults/img.rb +54 -0
- data/lib/jekyll/assets/plugins/html/defaults/js.rb +48 -0
- data/lib/jekyll/assets/plugins/html/defaults/vid.rb +63 -0
- data/lib/jekyll/assets/plugins/html/img.rb +76 -0
- data/lib/jekyll/assets/plugins/html/js.rb +30 -0
- data/lib/jekyll/assets/plugins/html/pic.rb +125 -0
- data/lib/jekyll/assets/plugins/html/svg.rb +37 -0
- data/lib/jekyll/assets/plugins/html/vid.rb +26 -0
- data/lib/jekyll/assets/plugins/liquid.rb +57 -0
- data/lib/jekyll/assets/plugins/magick.rb +7 -0
- data/lib/jekyll/assets/plugins/optim.rb +7 -0
- data/lib/jekyll/assets/plugins/prefixer.rb +28 -0
- data/lib/jekyll/assets/plugins/proxy/magick.rb +131 -0
- data/lib/jekyll/assets/plugins/proxy/optim.rb +64 -0
- data/lib/jekyll/assets/plugins/searcher.rb +72 -0
- data/lib/jekyll/assets/proxy.rb +109 -0
- data/lib/jekyll/assets/tag.rb +176 -0
- data/lib/jekyll/assets/url.rb +23 -0
- data/lib/jekyll/assets/utils.rb +348 -0
- data/lib/jekyll/assets/version.rb +2 -2
- data/lib/jekyll/assets/writer.rb +36 -0
- metadata +102 -81
- data/lib/jekyll-assets.rb +0 -7
- data/lib/jekyll/assets/addons/autoprefixer.rb +0 -11
- data/lib/jekyll/assets/addons/bootstrap.rb +0 -9
- data/lib/jekyll/assets/addons/fontawesome.rb +0 -9
- data/lib/jekyll/assets/addons/javascript.rb +0 -11
- data/lib/jekyll/assets/cached.rb +0 -30
- data/lib/jekyll/assets/helpers.rb +0 -74
- data/lib/jekyll/assets/hooks/cache.rb +0 -21
- data/lib/jekyll/assets/hooks/compression.rb +0 -25
- data/lib/jekyll/assets/hooks/config.rb +0 -12
- data/lib/jekyll/assets/hooks/erb.rb +0 -15
- data/lib/jekyll/assets/hooks/jekyll/drops.rb +0 -9
- data/lib/jekyll/assets/hooks/jekyll/setup.rb +0 -11
- data/lib/jekyll/assets/hooks/jekyll/write.rb +0 -11
- data/lib/jekyll/assets/hooks/logger.rb +0 -11
- data/lib/jekyll/assets/hooks/sources.rb +0 -13
- data/lib/jekyll/assets/hooks/sprockets.rb +0 -9
- data/lib/jekyll/assets/hooks/version.rb +0 -11
- data/lib/jekyll/assets/liquid/context.rb +0 -19
- data/lib/jekyll/assets/liquid/drop.rb +0 -81
- data/lib/jekyll/assets/liquid/filters.rb +0 -49
- data/lib/jekyll/assets/liquid/tag.rb +0 -244
- data/lib/jekyll/assets/liquid/tag/defaults.rb +0 -27
- data/lib/jekyll/assets/liquid/tag/defaults/image.rb +0 -81
- data/lib/jekyll/assets/liquid/tag/defaults/sha.rb +0 -58
- data/lib/jekyll/assets/liquid/tag/parser.rb +0 -202
- data/lib/jekyll/assets/liquid/tag/proxied_asset.rb +0 -166
- data/lib/jekyll/assets/liquid/tag/proxies.rb +0 -130
- data/lib/jekyll/assets/patches/jekyll/cleaner.rb +0 -15
- data/lib/jekyll/assets/patches/jekyll/site.rb +0 -5
- data/lib/jekyll/assets/patches/kernel.rb +0 -29
- data/lib/jekyll/assets/patches/sprockets/asset.rb +0 -28
- data/lib/jekyll/assets/processors/less.rb +0 -70
- data/lib/jekyll/assets/processors/liquid.rb +0 -46
- data/lib/jekyll/assets/proxies/image_optim.rb +0 -80
- data/lib/jekyll/assets/proxies/magick.rb +0 -194
data/Rakefile
CHANGED
@@ -1,4 +1,15 @@
|
|
1
|
-
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012 - 2017 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
$stderr = StringIO.new
|
6
|
+
require "bundler/setup"
|
2
7
|
require "rspec/core/rake_task"
|
8
|
+
require "rubocop/rake_task"
|
9
|
+
$stderr = STDERR
|
10
|
+
|
11
|
+
# --
|
3
12
|
RSpec::Core::RakeTask.new(:spec)
|
4
|
-
|
13
|
+
RuboCop::RakeTask.new(:rubocop) { |t| t.options = %w(--format=e --parallel) }
|
14
|
+
Rake::Task[:spec].enhance { Rake::Task[:rubocop].invoke }
|
15
|
+
task default: %i(spec rubocop)
|
data/lib/jekyll/assets.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2012 -
|
2
|
+
# Copyright: 2012 - 2017 - MIT License
|
3
3
|
# Encoding: utf-8
|
4
4
|
|
5
|
-
require "sprockets"
|
6
|
-
require "extras/all"
|
7
5
|
require "pathutil"
|
8
6
|
require "jekyll"
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
# --
|
9
|
+
# rubocop:disable Layout/BlockEndNewline
|
10
|
+
# rubocop:disable Layout/MultilineBlockLayout
|
11
|
+
# rubocop:disable Style/BlockDelimiters
|
12
|
+
# --
|
13
|
+
def require_all(*globs)
|
14
|
+
path = Pathutil.new("assets").expand_path(__dir__)
|
15
|
+
globs.each { |v| path.glob(v).reject(&:directory?).each do |vv|
|
16
|
+
require vv
|
17
|
+
end }
|
18
|
+
end
|
13
19
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
:require
|
18
|
-
))
|
20
|
+
require_relative "assets/env"
|
21
|
+
Jekyll::Hooks.register :site, :post_read do |o|
|
22
|
+
Jekyll::Assets::Env.new(o)
|
19
23
|
end
|
data/lib/jekyll/assets/config.rb
CHANGED
@@ -1,80 +1,116 @@
|
|
1
1
|
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2012 -
|
2
|
+
# Copyright: 2012 - 2017 - MIT License
|
3
3
|
# Encoding: utf-8
|
4
4
|
|
5
|
+
require "jekyll"
|
6
|
+
require "active_support/hash_with_indifferent_access"
|
7
|
+
require "active_support/core_ext/hash/indifferent_access"
|
8
|
+
require "active_support/core_ext/hash/deep_merge"
|
9
|
+
require_relative "hook"
|
10
|
+
|
5
11
|
module Jekyll
|
6
12
|
module Assets
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
class Config < HashWithIndifferentAccess
|
14
|
+
DEVELOPMENT = {
|
15
|
+
digest: false,
|
16
|
+
precompile: [],
|
17
|
+
source_maps: true,
|
18
|
+
destination: "/assets",
|
19
|
+
compression: false,
|
20
|
+
raw_precompile: [],
|
21
|
+
defaults: {},
|
22
|
+
gzip: false,
|
13
23
|
|
14
|
-
|
24
|
+
compressors: {
|
25
|
+
uglifier: {
|
26
|
+
comments: false,
|
27
|
+
harmony: true,
|
28
|
+
},
|
29
|
+
},
|
15
30
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
"digest" => false,
|
22
|
-
"assets" => [],
|
23
|
-
"autowrite" => true,
|
31
|
+
caching: {
|
32
|
+
path: ".jekyll-cache/assets",
|
33
|
+
enabled: true,
|
34
|
+
type: "file",
|
35
|
+
},
|
24
36
|
|
25
|
-
|
26
|
-
|
27
|
-
|
37
|
+
cdn: {
|
38
|
+
baseurl: false,
|
39
|
+
destination: false,
|
40
|
+
url: nil,
|
28
41
|
},
|
29
42
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
43
|
+
sources: %w(
|
44
|
+
assets/css
|
45
|
+
assets/fonts
|
46
|
+
assets/images
|
47
|
+
assets/videos
|
48
|
+
assets/audios
|
49
|
+
assets/javascript
|
50
|
+
assets/video
|
51
|
+
assets/audio
|
52
|
+
assets/image
|
53
|
+
assets/img
|
54
|
+
assets/js
|
37
55
|
|
38
|
-
|
56
|
+
_assets/css
|
57
|
+
_assets/fonts
|
58
|
+
_assets/images
|
59
|
+
_assets/videos
|
60
|
+
_assets/audios
|
61
|
+
_assets/javascript
|
62
|
+
_assets/video
|
63
|
+
_assets/audio
|
64
|
+
_assets/image
|
65
|
+
_assets/img
|
66
|
+
_assets/js
|
67
|
+
|
68
|
+
css
|
69
|
+
fonts
|
70
|
+
images
|
71
|
+
videos
|
72
|
+
audios
|
73
|
+
javascript
|
74
|
+
audio
|
75
|
+
video
|
76
|
+
image
|
77
|
+
img
|
78
|
+
js
|
79
|
+
),
|
80
|
+
}.freeze
|
39
81
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
"css" => true,
|
44
|
-
"js" => true
|
45
|
-
}
|
82
|
+
PRODUCTION = DEVELOPMENT.deep_merge({
|
83
|
+
source_maps: false,
|
84
|
+
compression: true,
|
46
85
|
}).freeze
|
47
86
|
|
48
87
|
# --
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
return
|
55
|
-
|
56
|
-
else
|
57
|
-
sources = DefaultSources + config["sources"].to_a
|
58
|
-
config["sources"] = Set.new(sources.map do |val|
|
59
|
-
jekyll.in_source_dir(val)
|
60
|
-
end)
|
61
|
-
end
|
88
|
+
def initialize(config)
|
89
|
+
super(self.class.defaults)
|
90
|
+
Hook.trigger(:config, :before_merge) { |h| h.call(self) }
|
91
|
+
deep_merge!(config)
|
92
|
+
merge_sources!
|
62
93
|
end
|
63
94
|
|
64
95
|
# --
|
65
|
-
|
96
|
+
# @return [HashWithIndifferentAccess]
|
97
|
+
# @note this is useful if you are in safe mode.
|
98
|
+
# The original defaults we have set.
|
99
|
+
# --
|
66
100
|
def self.defaults
|
67
|
-
|
68
|
-
then Development else Production
|
69
|
-
end
|
101
|
+
Jekyll.dev? ? DEVELOPMENT : PRODUCTION
|
70
102
|
end
|
71
103
|
|
72
104
|
# --
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
105
|
+
# Merge our sources with their sources.
|
106
|
+
# @note we don't really allow users to remove our sources.
|
107
|
+
# @return [nil]
|
108
|
+
# --
|
109
|
+
private
|
110
|
+
def merge_sources!
|
111
|
+
ours = self.class.defaults[:sources]
|
112
|
+
theirs = [self[:sources] || []].flatten.compact
|
113
|
+
self[:sources] = theirs | ours
|
78
114
|
end
|
79
115
|
end
|
80
116
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012 - 2017 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
require_relative "context"
|
6
|
+
require_relative "tag"
|
7
|
+
|
8
|
+
# --
|
9
|
+
module Jekyll
|
10
|
+
module Assets
|
11
|
+
module Context
|
12
|
+
# --
|
13
|
+
# Allows you to get an asset by it's path.
|
14
|
+
# @note this SASS helper fully supports proxy arguments.
|
15
|
+
# @param [Hash] opts this is unused but necessary.
|
16
|
+
# @param [String] path the path.
|
17
|
+
# @return [String] the path.
|
18
|
+
# --
|
19
|
+
def asset_path(path, _ = {})
|
20
|
+
ctx1 = Liquid::ParseContext.new
|
21
|
+
ctx2 = Liquid::Context.new({}, {}, site: environment.jekyll)
|
22
|
+
Jekyll::Assets::Tag.new("img", "#{path} @path", ctx1)
|
23
|
+
.render(ctx2)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# --
|
30
|
+
Jekyll::Assets::Hook.register(:env, :after_init) do
|
31
|
+
context_class.send(:include, Jekyll::Assets::Context)
|
32
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012 - 2017 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
require_relative "extensible"
|
6
|
+
require "active_support/hash_with_indifferent_access"
|
7
|
+
require "active_support/core_ext/hash/indifferent_access"
|
8
|
+
require "active_support/core_ext/hash/deep_merge"
|
9
|
+
|
10
|
+
module Jekyll
|
11
|
+
module Assets
|
12
|
+
class Default < Extensible
|
13
|
+
# --
|
14
|
+
# @param [String] type the content type.
|
15
|
+
# @param [Hash] args the args from the liquid tag.
|
16
|
+
# Get all of the static defaults.
|
17
|
+
# @return [Hash]
|
18
|
+
# --
|
19
|
+
def self.get(type:, args:)
|
20
|
+
rtn = Default.inherited.select do |o|
|
21
|
+
o.for?({
|
22
|
+
type: type,
|
23
|
+
args: args,
|
24
|
+
})
|
25
|
+
end
|
26
|
+
|
27
|
+
ida = HashWithIndifferentAccess.new
|
28
|
+
rtn.each_with_object(ida) do |v, h|
|
29
|
+
h.deep_merge!(v.static)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# --
|
34
|
+
# Set non-static defaults around the asset.
|
35
|
+
# @param [Hash] args the arguments to work on.
|
36
|
+
# @param [String] type the content type to work with.
|
37
|
+
# @param [Sprockets::Asset] asset the asset.
|
38
|
+
# @param [Env] env the environment.
|
39
|
+
# @return nil
|
40
|
+
# --
|
41
|
+
def self.set(args, asset:, ctx:)
|
42
|
+
set_static(args, asset: asset)
|
43
|
+
rtn = Default.inherited.select do |o|
|
44
|
+
o.for?(type: asset.content_type, args: args)
|
45
|
+
end
|
46
|
+
|
47
|
+
rtn.each do |o|
|
48
|
+
o.new({
|
49
|
+
args: args,
|
50
|
+
asset: asset,
|
51
|
+
ctx: ctx,
|
52
|
+
}).run
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# --
|
57
|
+
def self.set_static(args, asset:)
|
58
|
+
get(type: asset.content_type, args: args).each do |k, v|
|
59
|
+
k = k.to_sym
|
60
|
+
|
61
|
+
unless args.key?(k)
|
62
|
+
args[k] = args[k].is_a?(Hash) ?
|
63
|
+
args[k].deep_merge(v) : v
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# --
|
69
|
+
# @param [Hash] hash the defaults.
|
70
|
+
# @note this is used from your inherited class.
|
71
|
+
# Allows you to set static defaults for your defaults.
|
72
|
+
# @return nil
|
73
|
+
# --
|
74
|
+
def self.static(hash = nil)
|
75
|
+
return @static ||= {}.with_indifferent_access if hash.nil?
|
76
|
+
static.deep_merge!(hash)
|
77
|
+
end
|
78
|
+
|
79
|
+
# --
|
80
|
+
# Search for set_* methods and run those setters.
|
81
|
+
# @note this shouldn't be used directly by end-users.
|
82
|
+
# @return nile
|
83
|
+
# --
|
84
|
+
def run
|
85
|
+
methods = self.class.instance_methods - Object.instance_methods
|
86
|
+
methods.grep(%r!^set_!).each do |v|
|
87
|
+
send(v)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# --
|
92
|
+
def config
|
93
|
+
@config ||= @env.asset_config[:defaults][self.class
|
94
|
+
.name.split("::").last.downcase]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Frozen-string-literal: true
|
2
|
+
# Copyright: 2012 - 2017 - MIT License
|
3
|
+
# Encoding: utf-8
|
4
|
+
|
5
|
+
require "liquid/drop"
|
6
|
+
require "forwardable/extended"
|
7
|
+
require "fastimage"
|
8
|
+
|
9
|
+
module Jekyll
|
10
|
+
module Assets
|
11
|
+
class Drop < Liquid::Drop
|
12
|
+
extend Forwardable::Extended
|
13
|
+
def initialize(path, jekyll:)
|
14
|
+
@path = path
|
15
|
+
@sprockets = jekyll.sprockets
|
16
|
+
@jekyll = jekyll
|
17
|
+
@asset = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
rb_delegate :width, to: :dimensions, type: :hash
|
21
|
+
rb_delegate :height, to: :dimensions, type: :hash
|
22
|
+
rb_delegate :basename, to: :File, args: :@path
|
23
|
+
rb_delegate :content_type, to: :asset
|
24
|
+
rb_delegate :integrity, to: :asset
|
25
|
+
rb_delegate :filename, to: :asset
|
26
|
+
|
27
|
+
# --
|
28
|
+
# @todo this needs to move to `_url`
|
29
|
+
# @return [String] the prefixed and digested path.
|
30
|
+
# The digest path.
|
31
|
+
# --
|
32
|
+
def digest_path
|
33
|
+
@sprockets.prefix_url(asset.digest_path)
|
34
|
+
end
|
35
|
+
|
36
|
+
# --
|
37
|
+
# Image dimensions if the asest is an image.
|
38
|
+
# @return [Hash<Integer,Integer>] the dimensions.
|
39
|
+
# @note this can break easily.
|
40
|
+
# --
|
41
|
+
def dimensions
|
42
|
+
@dimensions ||= begin
|
43
|
+
img = FastImage.size(asset.filename.to_s)
|
44
|
+
|
45
|
+
{
|
46
|
+
width: img.first,
|
47
|
+
height: img.last,
|
48
|
+
}
|
49
|
+
end
|
50
|
+
rescue => e
|
51
|
+
Logger.error e
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def asset
|
56
|
+
@asset ||= begin
|
57
|
+
@sprockets.find_asset!(@path)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/jekyll/assets/env.rb
CHANGED
@@ -1,340 +1,197 @@
|
|
1
1
|
# Frozen-string-literal: true
|
2
|
-
# Copyright: 2012 -
|
2
|
+
# Copyright: 2012 - 2017 - MIT License
|
3
3
|
# Encoding: utf-8
|
4
4
|
|
5
|
+
require "pathutil"
|
6
|
+
require "forwardable/extended"
|
7
|
+
require "jekyll/sanity"
|
8
|
+
require "sprockets"
|
9
|
+
require "jekyll"
|
10
|
+
|
11
|
+
require_all "patches/*"
|
12
|
+
require_relative "utils"
|
13
|
+
require_relative "drop"
|
14
|
+
require_relative "version"
|
15
|
+
require_relative "filters"
|
16
|
+
require_relative "manifest"
|
17
|
+
require_relative "config"
|
18
|
+
require_relative "logger"
|
19
|
+
require_relative "hook"
|
20
|
+
require_relative "tag"
|
21
|
+
require_relative "url"
|
22
|
+
|
5
23
|
module Jekyll
|
6
24
|
module Assets
|
7
25
|
class Env < Sprockets::Environment
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
class << self
|
12
|
-
|
13
|
-
# --
|
14
|
-
# A list of instances for Jekyll and their paths.
|
15
|
-
# This works around Jekyll watch and build booting twice.
|
16
|
-
# @return [Hash]
|
17
|
-
# --
|
18
|
-
def instances
|
19
|
-
return @instances ||= {
|
20
|
-
#
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
# --
|
25
|
-
# A list of Liquid Proxies.
|
26
|
-
# @return [Set]
|
27
|
-
# --
|
28
|
-
def liquid_proxies
|
29
|
-
Liquid::Tag::Proxies
|
30
|
-
end
|
26
|
+
extend Forwardable::Extended
|
27
|
+
include Utils
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
# --
|
37
|
-
def init(jekyll, key = jekyll.in_source_dir)
|
38
|
-
Jekyll.logger.debug "Creating a new instance of: ", self
|
39
|
-
Jekyll.logger.debug "The old value of Sprockets: ",
|
40
|
-
jekyll.sprockets
|
41
|
-
|
42
|
-
instances[key] = new(
|
43
|
-
jekyll
|
44
|
-
)
|
29
|
+
# --
|
30
|
+
attr_reader :manifest
|
31
|
+
attr_reader :asset_config
|
32
|
+
attr_reader :jekyll
|
45
33
|
|
46
|
-
|
47
|
-
|
34
|
+
# --
|
35
|
+
def initialize(jekyll = nil)
|
36
|
+
@asset_config = Config.new(jekyll.config["assets"] ||= {})
|
37
|
+
Logger.debug "Callings hooks for env, before_init" do
|
38
|
+
Hook.trigger :env, :before_init do |h|
|
39
|
+
instance_eval(&h)
|
40
|
+
end
|
48
41
|
end
|
49
|
-
end
|
50
42
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
43
|
+
super()
|
44
|
+
@jekyll = jekyll
|
45
|
+
@manifest = Manifest.new(self, in_dest_dir)
|
46
|
+
@jekyll.sprockets = self
|
47
|
+
@logger = Logger
|
48
|
+
@cache = nil
|
49
|
+
|
50
|
+
setup_sources!
|
51
|
+
enable_compression!
|
52
|
+
setup_drops!
|
53
|
+
precompile!
|
54
|
+
copy_raw!
|
55
|
+
|
56
|
+
Logger.debug "Calling hooks for env, after_init" do
|
57
|
+
Hook.trigger :env, :after_init do |h|
|
58
|
+
instance_eval(&h)
|
59
|
+
end
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
62
|
-
# --
|
63
|
-
# Disables GZIP. You should be using your server to do this and even
|
64
|
-
# if you don't, there are far better and more efficient algorithms out
|
65
|
-
# right now that are in beta. Try Googling Googles new compression.
|
66
63
|
# --
|
67
64
|
def skip_gzip?
|
68
|
-
|
65
|
+
!asset_config[:gzip]
|
69
66
|
end
|
70
67
|
|
71
68
|
# --
|
72
|
-
#
|
73
|
-
#
|
69
|
+
# @note this is configurable with :caching -> :type
|
70
|
+
# Create a cache, or a null cache (if no caching) for caching.
|
71
|
+
# @note this is configurable with :caching -> :enabled
|
72
|
+
# @return [Sprockets::Cache]
|
74
73
|
# --
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
74
|
+
def cache
|
75
|
+
@cache ||= begin
|
76
|
+
type = asset_config[:caching][:type]
|
77
|
+
enbl = asset_config[:caching][:enabled]
|
78
|
+
path = in_cache_dir
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
@unparsed_assets ||= logical_paths.select do |(_, val)|
|
86
|
-
val.start_with?(jekyll.in_source_dir)
|
80
|
+
out = Sprockets::Cache::MemoryStore.new if enbl && type == "memory"
|
81
|
+
out = Sprockets::Cache::FileStore.new(path) if enbl && type == "file"
|
82
|
+
out = Sprockets::Cache::NullStore.new unless enbl
|
83
|
+
Sprockets::Cache.new(out, Logger)
|
87
84
|
end
|
88
85
|
end
|
89
86
|
|
90
87
|
# --
|
91
|
-
#
|
88
|
+
# @note this does not find the asset.
|
89
|
+
# Takes all user assets and turns them into a drop.
|
92
90
|
# @return [Hash]
|
93
91
|
# --
|
94
92
|
def to_liquid_payload
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
# Initialize a new instance of this class.
|
104
|
-
# @param [<Anything>] path This is passed upstream, we don't care.
|
105
|
-
# @param [Jekyll::Site] jekyll the Jekyll instances.
|
106
|
-
# XXX: Merge with .init in 3.0
|
107
|
-
# --
|
108
|
-
def initialize(path, jekyll = nil)
|
109
|
-
(jekyll = path; path = nil) if path.is_a?(Jekyll::Site)
|
110
|
-
|
111
|
-
@used = Set.new
|
112
|
-
path ? super(path) : super()
|
113
|
-
@jekyll = jekyll
|
114
|
-
|
115
|
-
# TODO: In Jekyll-Assets 3 this should be fixed up to be a method.
|
116
|
-
@cache_path = asset_config.fetch("cache", ".asset-cache") || ".asset-cache"
|
117
|
-
if File.exist?(cache_path_in_source_dir = jekyll.in_source_dir(@cache_path))
|
118
|
-
@cache_path = cache_path_in_source_dir
|
119
|
-
end
|
120
|
-
|
121
|
-
# XXX: In 3.0, we need to drop anything to do with instance eval,
|
122
|
-
# and imply pass the instance, this will make our code cleaner.
|
123
|
-
|
124
|
-
Hook.trigger :env, :init do |hook|
|
125
|
-
hook.arity > 0 || 0 > hook.arity ? hook.call(self) : instance_eval(
|
126
|
-
&hook
|
127
|
-
)
|
128
|
-
end
|
93
|
+
each_file.each_with_object({}) do |k, h|
|
94
|
+
skip, path = false, Pathutil.new(strip_paths(k))
|
95
|
+
path.descend do |p|
|
96
|
+
skip = p.start_with?("_")
|
97
|
+
if skip
|
98
|
+
break
|
99
|
+
end
|
100
|
+
end
|
129
101
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
102
|
+
next if skip
|
103
|
+
h.update({
|
104
|
+
path.to_s => Drop.new(path, {
|
105
|
+
jekyll: jekyll,
|
106
|
+
}),
|
107
|
+
})
|
135
108
|
end
|
136
109
|
end
|
137
110
|
|
138
111
|
# --
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
def liquid_proxies
|
143
|
-
self.class.liquid_proxies
|
144
|
-
end
|
145
|
-
|
146
|
-
# --
|
147
|
-
# Make a path land inside of our cache directory.
|
148
|
-
# @param [<Anything>] *paths the paths you wish to land.
|
149
|
-
# @return [Pathname/Pathutil]
|
150
|
-
# --
|
151
|
-
def in_cache_dir(*paths)
|
152
|
-
paths.reduce(cache_path) do |base, path|
|
153
|
-
Jekyll.sanitized_path(base, path)
|
112
|
+
def self.old_sprockets?
|
113
|
+
@old_sprockets ||= begin
|
114
|
+
Gem::Version.new(Sprockets::VERSION) < Gem::Version.new("4.0.beta")
|
154
115
|
end
|
155
116
|
end
|
156
117
|
|
157
118
|
# --
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end
|
119
|
+
private
|
120
|
+
def enable_compression!
|
121
|
+
return unless asset_config[:compression]
|
122
|
+
config = asset_config[:compressors][:uglifier].symbolize_keys
|
123
|
+
self. js_compressor = Sprockets::UglifierCompressor.new(config)
|
124
|
+
self.css_compressor = :scss
|
165
125
|
end
|
166
126
|
|
167
127
|
# --
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
each_logical_path(*assets).map do |v|
|
174
|
-
manifest.find(v).first
|
128
|
+
def copy_raw!
|
129
|
+
raw_precompiles.each do |v|
|
130
|
+
v[:dst].mkdir_p if v[:dst].extname.empty?
|
131
|
+
v[:dst].parent.mkdir_p unless v[:dst].extname.empty?
|
132
|
+
v[:src].cp(v[:dst])
|
175
133
|
end
|
176
134
|
end
|
177
135
|
|
178
136
|
# --
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
# The BaseURL mixed with Jekyll's own BaseURL.
|
188
|
-
# rubocop:disable Style/ExtraSpacing
|
189
|
-
# --
|
190
|
-
def baseurl
|
191
|
-
ary = []
|
192
|
-
|
193
|
-
ary << jekyll.config["baseurl"] unless cdn? && asset_config["skip_baseurl_with_cdn"]
|
194
|
-
ary << asset_config[ "prefix"] unless cdn? && asset_config[ "skip_prefix_with_cdn"]
|
195
|
-
|
196
|
-
File.join(*ary.delete_if do |val|
|
197
|
-
val.nil? || val.empty?
|
198
|
-
end)
|
199
|
-
end
|
200
|
-
|
201
|
-
# --
|
202
|
-
# Whether or not we are in development mode.
|
203
|
-
# rubocop:enable Style/ExtraSpacing
|
204
|
-
# --
|
205
|
-
def dev?
|
206
|
-
%W(development test).include?(Jekyll.env)
|
207
|
-
end
|
208
|
-
|
209
|
-
# --
|
210
|
-
# Whether or not we should compress assets.
|
211
|
-
# --
|
212
|
-
def compress?(what)
|
213
|
-
!!asset_config["compress"].fetch(
|
214
|
-
what, false
|
215
|
-
)
|
216
|
-
end
|
217
|
-
|
218
|
-
# --
|
219
|
-
# The asset configuration.
|
220
|
-
# --
|
221
|
-
def asset_config
|
222
|
-
jekyll.config["assets"] ||= {}
|
223
|
-
end
|
224
|
-
|
225
|
-
# --
|
226
|
-
# Whether or not we are digesting.
|
227
|
-
# @return [true,false]
|
228
|
-
# --
|
229
|
-
def digest?
|
230
|
-
!!asset_config[
|
231
|
-
"digest"
|
232
|
-
]
|
233
|
-
end
|
234
|
-
|
235
|
-
# --
|
236
|
-
# Prefix path prefixes the path with the baseurl and the cdn if it
|
237
|
-
# exists and is in the right mode to use it. Otherwise it will only use
|
238
|
-
# the baseurl and asset prefix. All of these can be adjusted...
|
239
|
-
# @param [String,Pathname,Pathutil] path the path to prefix.
|
240
|
-
# @return [Pathname,Pathutil,String]
|
241
|
-
# --
|
242
|
-
def prefix_path(path = nil)
|
243
|
-
cdn = asset_config["cdn"]
|
244
|
-
base_url = baseurl
|
245
|
-
|
246
|
-
path_ = []
|
247
|
-
path_ << base_url unless base_url.empty?
|
248
|
-
path_ << path unless path.nil?
|
249
|
-
|
250
|
-
url = cdn && cdn?? File.join(cdn, *path_) : File.join(*path_)
|
251
|
-
url.chomp("/")
|
252
|
-
end
|
253
|
-
|
254
|
-
|
255
|
-
# --
|
256
|
-
# Sprockets cached instance.
|
257
|
-
# @return [Cached]
|
258
|
-
# --
|
259
|
-
def cached
|
260
|
-
return @cached ||= Cached.new(
|
261
|
-
self
|
262
|
-
)
|
263
|
-
end
|
137
|
+
private
|
138
|
+
def precompile!
|
139
|
+
assets = asset_config[:precompile]
|
140
|
+
assets.map do |v|
|
141
|
+
v !~ %r!\*! ? manifest.compile(v) : glob_paths(v).each do |sv|
|
142
|
+
manifest.compile(sv)
|
143
|
+
end
|
144
|
+
end
|
264
145
|
|
265
|
-
|
266
|
-
# The manifest we use to pull assets.
|
267
|
-
# @return [Manifest]
|
268
|
-
# --
|
269
|
-
def manifest
|
270
|
-
return @manifest ||= Manifest.new(self, jekyll.in_dest_dir(
|
271
|
-
asset_config["prefix"]
|
272
|
-
))
|
146
|
+
nil
|
273
147
|
end
|
274
148
|
|
275
149
|
# --
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
Jekyll.logger.error "", "Asset inconsistency, expected " +
|
285
|
-
"#{manifest.all.size}, can only write #{
|
286
|
-
assets.size
|
287
|
-
}"
|
288
|
-
rescue
|
289
|
-
# When a serious error happens in the upstream manifest.
|
290
|
-
Jekyll.logger.error "", "Asset inconsistency, unable to " \
|
291
|
-
"determine the problem, please clear your cache."
|
150
|
+
private
|
151
|
+
def setup_sources!
|
152
|
+
source_dir, cwd = Pathutil.new(jekyll.in_source_dir), Pathutil.cwd
|
153
|
+
asset_config["sources"].each do |v|
|
154
|
+
path = source_dir.join(v).expand_path
|
155
|
+
next unless path.in_path?(cwd)
|
156
|
+
unless paths.include?(path)
|
157
|
+
append_path path
|
292
158
|
end
|
293
159
|
end
|
294
160
|
|
295
|
-
|
296
|
-
|
297
|
-
Liquid::Tag::ProxiedAsset
|
298
|
-
)
|
299
|
-
end
|
300
|
-
|
301
|
-
# These are assets that aren't proxied, they returned fals when
|
302
|
-
# they were asked if they belonged to a proxy.
|
161
|
+
paths
|
162
|
+
end
|
303
163
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
164
|
+
# --
|
165
|
+
private
|
166
|
+
def setup_drops!
|
167
|
+
Jekyll::Hooks.register :site, :pre_render do |_, h|
|
168
|
+
h["assets"] = to_liquid_payload
|
308
169
|
end
|
170
|
+
end
|
309
171
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
if assets.key?(true)
|
316
|
-
unless assets[true].empty?
|
317
|
-
Pathutil.new(in_cache_dir)
|
318
|
-
.mkdir_p
|
319
|
-
end
|
172
|
+
require_all "plugins/*"
|
173
|
+
require_all "plugins/html/defaults/*"
|
174
|
+
require_all "plugins/html/*"
|
175
|
+
require_relative "context"
|
176
|
+
require_relative "writer"
|
320
177
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
end
|
178
|
+
require_relative "map" unless old_sprockets?
|
179
|
+
Hook.register :env, :after_init, priority: 3 do
|
180
|
+
unless self.class.old_sprockets?
|
181
|
+
Map.register_on(self)
|
326
182
|
end
|
327
183
|
end
|
328
184
|
|
329
185
|
# --
|
330
|
-
#
|
186
|
+
# @see https://github.com/rails/sprockets/pull/523
|
187
|
+
# Registers a few MimeTypes since I don't think
|
188
|
+
# Sprockets will update before we release, so we
|
189
|
+
# need them to be available.
|
331
190
|
# --
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
)
|
337
|
-
end
|
191
|
+
Sprockets.register_mime_type "audio/mp4", extensions: %w(.m4a)
|
192
|
+
Sprockets.register_mime_type "audio/ogg", extensions: %w(.ogg .oga)
|
193
|
+
Sprockets.register_mime_type "audio/flac", extensions: %w(.flac)
|
194
|
+
Sprockets.register_mime_type "audio/aac", extensions: %w(.aac)
|
338
195
|
end
|
339
196
|
end
|
340
197
|
end
|