jekyll-assets 1.0.0 → 2.0.0.pre.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +10 -10
- data/LICENSE +16 -18
- data/README.md +94 -554
- data/Rakefile +2 -8
- data/lib/jekyll/assets.rb +18 -12
- data/lib/jekyll/assets/cached.rb +12 -0
- data/lib/jekyll/assets/configuration.rb +43 -87
- data/lib/jekyll/assets/context.rb +23 -0
- data/lib/jekyll/assets/env.rb +181 -0
- data/lib/jekyll/assets/extras/es6.rb +5 -0
- data/lib/jekyll/assets/extras/font-awesome.rb +1 -0
- data/lib/jekyll/assets/extras/helpers.rb +6 -0
- data/lib/jekyll/assets/extras/prefix.rb +5 -0
- data/lib/jekyll/assets/filters.rb +9 -11
- data/lib/jekyll/assets/helpers.rb +37 -0
- data/lib/jekyll/assets/hook.rb +45 -0
- data/lib/jekyll/assets/hooks/post_read.rb +3 -0
- data/lib/jekyll/assets/hooks/post_write.rb +3 -0
- data/lib/jekyll/assets/logger.rb +25 -0
- data/lib/jekyll/assets/patches/jekyll/cleaner.rb +11 -0
- data/lib/jekyll/assets/patches/jekyll/site.rb +5 -0
- data/lib/jekyll/assets/patches/sprockets/asset.rb +13 -0
- data/lib/jekyll/assets/tag.rb +136 -9
- data/lib/jekyll/assets/tag/parser.rb +129 -0
- data/lib/jekyll/assets/tag/proxied_asset.rb +84 -0
- data/lib/jekyll/assets/tag/proxies.rb +86 -0
- data/lib/jekyll/assets/tag/proxies/magick.rb +101 -0
- data/lib/jekyll/assets/version.rb +1 -1
- metadata +59 -149
- data/.gitignore +0 -27
- data/.rspec +0 -1
- data/.rubocop.yml +0 -43
- data/.rubocop_todo.yml +0 -10
- data/.travis.yml +0 -16
- data/.yardopts +0 -1
- data/Appraisals +0 -7
- data/Guardfile +0 -7
- data/HISTORY.md +0 -297
- data/gemfiles/jekyll_2.gemfile +0 -17
- data/gemfiles/jekyll_3.gemfile +0 -17
- data/jekyll-assets.gemspec +0 -34
- data/lib/jekyll-assets.rb +0 -2
- data/lib/jekyll/assets/asset_path.rb +0 -39
- data/lib/jekyll/assets/environment.rb +0 -62
- data/lib/jekyll/assets/patches.rb +0 -1
- data/lib/jekyll/assets/patches/asset_patch.rb +0 -102
- data/lib/jekyll/assets/patches/bundled_asset_patch.rb +0 -16
- data/lib/jekyll/assets/patches/context_patch.rb +0 -31
- data/lib/jekyll/assets/patches/index_patch.rb +0 -25
- data/lib/jekyll/assets/patches/processed_asset_patch.rb +0 -59
- data/lib/jekyll/assets/patches/site_patch.rb +0 -62
- data/lib/jekyll/assets/renderer.rb +0 -122
- data/spec/fixtures/.gitignore +0 -2
- data/spec/fixtures/.jekyll-metadata +0 -0
- data/spec/fixtures/_assets/alert.js +0 -1
- data/spec/fixtures/_assets/app.css.erb +0 -5
- data/spec/fixtures/_assets/app.js +0 -1
- data/spec/fixtures/_assets/app.min.css +0 -0
- data/spec/fixtures/_assets/app.min.js +0 -0
- data/spec/fixtures/_assets/fonts/vapor.eot +0 -0
- data/spec/fixtures/_assets/fonts/vapor.svg +0 -0
- data/spec/fixtures/_assets/fonts/vapor.ttf +0 -0
- data/spec/fixtures/_assets/fonts/vapor.woff +0 -0
- data/spec/fixtures/_assets/lib/relative.css.scss +0 -12
- data/spec/fixtures/_assets/noise.png +0 -0
- data/spec/fixtures/_assets/noize.png +0 -0
- data/spec/fixtures/_assets/should_be_blank.css.erb +0 -1
- data/spec/fixtures/_assets/should_fail.css.erb +0 -1
- data/spec/fixtures/_assets/vapor.css.scss +0 -13
- data/spec/fixtures/_assets/vapor.js +0 -2
- data/spec/fixtures/_assets/vendor/with_bootstrap.css.sass +0 -1
- data/spec/fixtures/_assets/vendor/with_bourbon.css.sass +0 -4
- data/spec/fixtures/_assets/vendor/with_compass.css.sass +0 -4
- data/spec/fixtures/_assets/vendor/with_neat.css.sass +0 -5
- data/spec/fixtures/_assets/wowscript.js +0 -0
- data/spec/fixtures/_assets/wowstyle.css +0 -0
- data/spec/fixtures/_config.yml +0 -2
- data/spec/fixtures/_layouts/default.html +0 -9
- data/spec/fixtures/_posts/2012-10-19-hello-world.md +0 -6
- data/spec/fixtures/_posts/2015-02-02-duplicates.md +0 -8
- data/spec/fixtures/index.html +0 -0
- data/spec/lib/jekyll/assets/configuration_spec.rb +0 -172
- data/spec/lib/jekyll/assets/environment_spec.rb +0 -18
- data/spec/lib/jekyll/assets/filters_spec.rb +0 -112
- data/spec/lib/jekyll/assets/patches/site_patch_spec.rb +0 -176
- data/spec/lib/jekyll/assets/renderer_spec.rb +0 -286
- data/spec/lib/jekyll/assets/tag_spec.rb +0 -139
- data/spec/spec_helper.rb +0 -58
- data/spec/support/fixtures_helpers.rb +0 -7
data/Rakefile
CHANGED
data/lib/jekyll/assets.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
|
-
require "
|
2
|
-
require "
|
3
|
-
require "jekyll
|
4
|
-
require "jekyll/assets/version"
|
1
|
+
require "sprockets"
|
2
|
+
require "sprockets/helpers"
|
3
|
+
require "jekyll"
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
require_relative "assets/hook"
|
6
|
+
require_relative "assets/helpers"
|
7
|
+
require_relative "assets/extras/es6"
|
8
|
+
require_relative "assets/extras/font-awesome"
|
9
|
+
require_relative "assets/extras/helpers"
|
10
|
+
require_relative "assets/extras/prefix"
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
require_relative "assets/env"
|
13
|
+
require_relative "assets/patches/jekyll/cleaner"
|
14
|
+
require_relative "assets/patches/sprockets/asset"
|
15
|
+
require_relative "assets/patches/jekyll/site"
|
16
|
+
|
17
|
+
require_relative "assets/hooks/post_read"
|
18
|
+
require_relative "assets/hooks/post_write"
|
19
|
+
require_relative "assets/filters"
|
20
|
+
require_relative "assets/tag"
|
@@ -1,94 +1,50 @@
|
|
1
|
-
# stdlib
|
2
|
-
require "ostruct"
|
3
|
-
|
4
1
|
module Jekyll
|
5
2
|
module Assets
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
3
|
+
module Configuration
|
4
|
+
DEVELOPMENT = {
|
5
|
+
"skip_prefix_with_cdn" => false,
|
6
|
+
"prefix" => "/assets",
|
7
|
+
"digest" => false,
|
8
|
+
"assets" => [],
|
9
|
+
|
10
|
+
"compress" => {
|
11
|
+
"css" => false,
|
12
|
+
"js" => false
|
13
|
+
},
|
14
|
+
|
15
|
+
"sources" => [
|
16
|
+
"_assets/css", "_assets/stylesheets",
|
17
|
+
"_assets/images", "_assets/img", "_assets/fonts",
|
18
|
+
"_assets/javascripts", "_assets/js"
|
19
|
+
]
|
20
|
+
}
|
21
|
+
|
22
|
+
PRODUCTION = DEVELOPMENT.merge({
|
23
|
+
"digest" => true,
|
24
|
+
"compress" => {
|
25
|
+
"css" => true,
|
26
|
+
"js" => true
|
27
|
+
},
|
28
|
+
})
|
29
|
+
|
30
|
+
def self.defaults
|
31
|
+
%W(development test).include?(Jekyll.env) ? \
|
32
|
+
DEVELOPMENT : PRODUCTION
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.merge(merge_into, config = self.defaults)
|
36
|
+
merge_into = merge_into.dup
|
37
|
+
config.each_with_object(merge_into) do |(k, v), h|
|
38
|
+
if !h.has_key?(k) || (v.is_a?(Hash) && !h[k])
|
39
|
+
h[k] = v
|
40
|
+
|
41
|
+
elsif v.is_a?(Hash)
|
42
|
+
h[k] = merge h[k], \
|
43
|
+
v
|
44
|
+
end
|
44
45
|
end
|
45
46
|
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
def js_compressor
|
50
|
-
compressor @data.js_compressor
|
51
|
-
end
|
52
|
-
|
53
|
-
def css_compressor
|
54
|
-
compressor @data.css_compressor
|
55
|
-
end
|
56
|
-
|
57
|
-
def cachebust
|
58
|
-
return :none if none?(@data.cachebust)
|
59
|
-
return @data.cachebust.to_sym if @data.cachebust.to_s[/^(soft|hard)$/]
|
60
|
-
fail "Unknown cachebust strategy: #{@data.cachebust}"
|
61
|
-
end
|
62
|
-
|
63
|
-
def cache_assets?
|
64
|
-
@data.cache ? true : false
|
65
|
-
end
|
66
|
-
|
67
|
-
def cache_path
|
68
|
-
@data.cache.is_a?(String) ? @data.cache : ".jekyll-assets-cache"
|
69
|
-
end
|
70
|
-
|
71
|
-
def gzip
|
72
|
-
return @data.gzip if @data.gzip.is_a? Array
|
73
|
-
@data.gzip ? DEFAULTS[:gzip] : []
|
74
|
-
end
|
75
|
-
|
76
|
-
def version
|
77
|
-
@data.version
|
78
|
-
end
|
79
|
-
|
80
|
-
def method_missing(name, *args, &block)
|
81
|
-
@data.send name, *args, &block
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
|
86
|
-
def none?(val)
|
87
|
-
val.to_s.empty? || "none" == val.to_s.downcase
|
88
|
-
end
|
89
|
-
|
90
|
-
def compressor(val)
|
91
|
-
none?(val) ? nil : val.to_sym
|
47
|
+
merge_into
|
92
48
|
end
|
93
49
|
end
|
94
50
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Assets
|
3
|
+
class Context
|
4
|
+
def initialize(context)
|
5
|
+
patch context
|
6
|
+
end
|
7
|
+
|
8
|
+
def patch(what)
|
9
|
+
what.class_eval do
|
10
|
+
alias_method :_old_asset_path, :asset_path
|
11
|
+
def asset_path(asset, opts = {})
|
12
|
+
out = _old_asset_path asset
|
13
|
+
return unless out
|
14
|
+
|
15
|
+
environment.parent.used.add(environment.find_asset \
|
16
|
+
resolve(asset))
|
17
|
+
out
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require_relative "logger"
|
2
|
+
require_relative "configuration"
|
3
|
+
require_relative "context"
|
4
|
+
require_relative "cached"
|
5
|
+
|
6
|
+
module Jekyll
|
7
|
+
module Assets
|
8
|
+
class Env < Sprockets::Environment
|
9
|
+
attr_reader :jekyll, :used
|
10
|
+
class << self
|
11
|
+
attr_accessor :digest_cache, :assets_cache
|
12
|
+
def digest_cache
|
13
|
+
@_digest_cache ||= \
|
14
|
+
{}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(path, jekyll = nil)
|
19
|
+
jekyll, path = path, nil if path.is_a?(Jekyll::Site)
|
20
|
+
@used, @jekyll = Set.new, jekyll
|
21
|
+
path ? super(path) : super()
|
22
|
+
disable_erb
|
23
|
+
|
24
|
+
jekyll.config["assets"] = Configuration.merge(asset_config)
|
25
|
+
private_methods(false).select { |v| v =~ %r!\Asetup_! }.map { |v| send(v) }
|
26
|
+
Hook.trigger :env, :post_init, self
|
27
|
+
jekyll.sprockets = self
|
28
|
+
end
|
29
|
+
|
30
|
+
def in_cache_dir(*paths)
|
31
|
+
cache_dir = asset_config.fetch("cache", ".asset-cache") || nil
|
32
|
+
jekyll.in_source_dir(
|
33
|
+
cache_dir, *paths
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def cached_write?
|
38
|
+
!@used.any?
|
39
|
+
end
|
40
|
+
|
41
|
+
def all_assets(cached = false)
|
42
|
+
if !cached
|
43
|
+
then Set.new(@used).merge extra_assets
|
44
|
+
else Set.new(self.class.assets_cache).merge extra_assets
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def extra_assets
|
49
|
+
each_logical_path(*asset_config.fetch("assets", [])).map do |v|
|
50
|
+
find_asset v
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def cdn?() !dev? && !!asset_config["cdn"] end
|
55
|
+
def baseurl() jekyll.config["baseurl"] || "" end
|
56
|
+
def dev?() %W(development test).include? Jekyll.env end
|
57
|
+
def compress?(what) !!asset_config["compress"][what] end
|
58
|
+
def asset_config() jekyll.config["assets"] ||= {} end
|
59
|
+
def digest?() !!asset_config["digest"] end
|
60
|
+
def prefix() asset_config["prefix"] end
|
61
|
+
|
62
|
+
def prefix_path(path = "")
|
63
|
+
prefix = cdn? && asset_config["skip_prefix_with_cdn"] ? "" : self.prefix
|
64
|
+
path = [baseurl, prefix, path]
|
65
|
+
if cdn? && (cdn = asset_config["cdn"])
|
66
|
+
File.join(cdn, *path).chomp(
|
67
|
+
"/"
|
68
|
+
)
|
69
|
+
else
|
70
|
+
File.join(*path).chomp(
|
71
|
+
"/"
|
72
|
+
)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def cached
|
77
|
+
Cached.new(self)
|
78
|
+
end
|
79
|
+
|
80
|
+
def write_all
|
81
|
+
if cached_write?
|
82
|
+
then write_cached_assets else write_assets
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def write_assets(assets = self.all_assets)
|
88
|
+
self.class.assets_cache = assets
|
89
|
+
self.class.digest_cache = Hash[assets.map do |a|
|
90
|
+
[a.logical_path, a.digest]
|
91
|
+
end]
|
92
|
+
|
93
|
+
assets.each do |v|
|
94
|
+
v.write_to as_path v
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
def write_cached_assets(assets = all_assets(true))
|
100
|
+
assets.each do |a|
|
101
|
+
if !a.is_a?(Tag::ProxiedAsset)
|
102
|
+
viejo = self.class.digest_cache[a.logical_path]
|
103
|
+
nuevo = find_asset(a.logical_path).digest
|
104
|
+
path = as_path a
|
105
|
+
|
106
|
+
if nuevo == viejo && File.file?(path)
|
107
|
+
next
|
108
|
+
end
|
109
|
+
else
|
110
|
+
if File.file?(a.logical_path)
|
111
|
+
next
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
self.class.digest_cache[a.logical_path] = a.digest
|
116
|
+
a.write_to as_path a
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
def as_path(v)
|
122
|
+
path = digest?? v.digest_path : v.logical_path
|
123
|
+
jekyll.in_dest_dir(File.join(prefix, path))
|
124
|
+
end
|
125
|
+
|
126
|
+
def disable_erb
|
127
|
+
self.config = hash_reassoc(config, :engines) do |h|
|
128
|
+
h.delete(".erb")
|
129
|
+
h
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
def setup_css_compressor
|
135
|
+
if compress?("css")
|
136
|
+
self.css_compressor = :sass
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
def setup_js_compressor
|
142
|
+
if compress?("js")
|
143
|
+
Helpers.try_require "uglifier" do
|
144
|
+
self.js_compressor = :uglify
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
private
|
150
|
+
def setup_context
|
151
|
+
Context.new(context_class)
|
152
|
+
end
|
153
|
+
|
154
|
+
private
|
155
|
+
def setup_version
|
156
|
+
self.version = Digest::MD5.hexdigest \
|
157
|
+
jekyll.config.fetch("assets", {}).to_s
|
158
|
+
end
|
159
|
+
|
160
|
+
private
|
161
|
+
def setup_sources
|
162
|
+
asset_config["sources"].each do |v|
|
163
|
+
append_path jekyll.in_source_dir(v)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
def setup_logger
|
169
|
+
self.logger = Logger.new
|
170
|
+
end
|
171
|
+
|
172
|
+
private
|
173
|
+
def setup_cache
|
174
|
+
if cache_dir = asset_config.fetch("cache", ".asset-cache")
|
175
|
+
self.cache = Sprockets::Cache::FileStore.new \
|
176
|
+
jekyll.in_source_dir(cache_dir)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Jekyll::Assets::Helpers.try_require "font-awesome-sass"
|
@@ -1,19 +1,17 @@
|
|
1
|
-
# internal
|
2
|
-
require "jekyll/assets/renderer"
|
3
|
-
|
4
1
|
module Jekyll
|
5
2
|
module Assets
|
6
3
|
module Filters
|
7
|
-
%
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
RUBY
|
4
|
+
%W(js css img image javascript stylesheet style asset_path).each do |v|
|
5
|
+
define_method v do |path, args = ""|
|
6
|
+
Tag.send(:new, v, "#{path} #{args}", "").render(
|
7
|
+
@context
|
8
|
+
)
|
9
|
+
end
|
14
10
|
end
|
15
11
|
end
|
16
12
|
end
|
17
13
|
end
|
18
14
|
|
19
|
-
Liquid::Template.register_filter
|
15
|
+
Liquid::Template.register_filter(
|
16
|
+
Jekyll::Assets::Filters
|
17
|
+
)
|