jekyll-assets 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b48bcbe756753d18e5daab5826fd0d2e5e1c129
4
- data.tar.gz: 3291bf13013e12384be82f76ac4f6ff4c37562f5
3
+ metadata.gz: c1beb6828d5534b96a31042623acb912c13b3e38
4
+ data.tar.gz: 688fabb88be88681c40954736b663d216f7ad93d
5
5
  SHA512:
6
- metadata.gz: 2881e933bea8ac977bca0cb95e51f7b09d028c681f1333ef5a8e055594dc35e860887cc70c9c5e10038c5c6bcd21787685b72ad554f8d5577c41ec0e999a9ba4
7
- data.tar.gz: bee841e2c8a1be65d76b05bf56949cc57b559bcd3f4c4d1ce75b420ebd66c94c40ea3c54b32d3668a42d45cb74005bf9798c11def68c55428ae39cce6590608a
6
+ metadata.gz: c085055cc33ff864f394b22d0f98530f8d3d71a871baf01f7dd00d8cc59151c9907e9ce1f65b46d828fb93086fd70d80df1dd80b2115cd6961aebf05e8565f29
7
+ data.tar.gz: 5b0f8f7cc6bb1010c23be8a2ffb15f744283c2ada9b56ed9010dd5fa7c9407ded47742117e2d8017fd6d415f8e9bd28d6e6937643563cd4ed2c388a7f9947d81
data/README.md CHANGED
@@ -36,16 +36,26 @@ assets:
36
36
  compress:
37
37
  css: false | true | default - development: false, production: true
38
38
  js: false | true | default - development: false, production: true
39
+
40
+ #
41
+
42
+ autowrite: true
39
43
  cache: false | directory | default: .asset-cache
44
+ cache_type: memory | filesystem | default: filesystem
40
45
  cdn: https://cdn.example.com
41
46
  skip_baseurl_with_cdn: false
42
47
  skip_prefix_with_cdn: false
43
48
  prefix: "/assets"
44
- autowrite: true
49
+ digest: true
50
+
51
+ #
52
+
45
53
  assets:
46
54
  - "*.png"
47
55
  - "bundle.css"
48
- digest: true
56
+
57
+ #
58
+
49
59
  sources:
50
60
  - _assets/css
51
61
  - _assets/images
@@ -54,6 +64,9 @@ assets:
54
64
  - _assets/fonts
55
65
  - _assets/img
56
66
  - _assets/js
67
+
68
+ #
69
+
57
70
  features:
58
71
  liquid: true | false | default: false
59
72
  automatic_img_size: true | false | n(fixnum): 2,4,6,8 | default: true
@@ -1,17 +1,16 @@
1
- # ----------------------------------------------------------------------------
2
1
  # Frozen-string-literal: true
3
2
  # Copyright: 2012 - 2016 - MIT License
4
3
  # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
4
 
7
5
  module Jekyll
8
6
  module Assets
9
7
  class Cached < Sprockets::CachedEnvironment
10
- attr_reader :jekyll
11
- attr_reader :parent
12
-
13
- # ----------------------------------------------------------------------
8
+ attr_reader :jekyll, :parent
14
9
 
10
+ # --
11
+ # @param [Env] env the environment
12
+ # Initialize a new instance
13
+ # --
15
14
  def initialize(env)
16
15
  @parent = env
17
16
  @jekyll = env.jekyll
@@ -19,6 +18,10 @@ module Jekyll
19
18
  super env
20
19
  end
21
20
 
21
+
22
+ # --
23
+ # Resolve an asset.
24
+ # --
22
25
  def resolve(*args)
23
26
  @resolve_cache[args] ||= super
24
27
  end
@@ -1,8 +1,6 @@
1
- # ----------------------------------------------------------------------------
2
1
  # Frozen-string-literal: true
3
2
  # Copyright: 2012 - 2016 - MIT License
4
3
  # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
4
 
7
5
  module Jekyll
8
6
  module Assets
@@ -13,9 +11,10 @@ module Jekyll
13
11
  _assets/javascripts _assets/js
14
12
  ).freeze
15
13
 
16
- # ----------------------------------------------------------------------
14
+ # --
17
15
 
18
16
  Development = {
17
+ "cache_type" => "filesystem",
19
18
  "skip_baseurl_with_cdn" => false,
20
19
  "skip_prefix_with_cdn" => false,
21
20
  "prefix" => "/assets",
@@ -35,7 +34,7 @@ module Jekyll
35
34
  }
36
35
  }.freeze
37
36
 
38
- # ----------------------------------------------------------------------
37
+ # --
39
38
 
40
39
  Production = Development.merge({
41
40
  "digest" => true,
@@ -45,8 +44,10 @@ module Jekyll
45
44
  }
46
45
  }).freeze
47
46
 
48
- # ----------------------------------------------------------------------
49
-
47
+ # --
48
+ # @param [Jekyll::Site] jekyll The jekyll instance.
49
+ # Merge our sources with Jekyll's sources.
50
+ # --
50
51
  def self.merge_sources(jekyll, config) config["sources"] ||= []
51
52
  if !config["sources"].grep(/\A\s*_assets\/?\s*\Z/).empty?
52
53
  return
@@ -59,7 +60,7 @@ module Jekyll
59
60
  end
60
61
  end
61
62
 
62
- # ----------------------------------------------------------------------
63
+ # --
63
64
 
64
65
  def self.defaults
65
66
  if %W(development test).include?(Jekyll.env)
@@ -67,7 +68,7 @@ module Jekyll
67
68
  end
68
69
  end
69
70
 
70
- # ----------------------------------------------------------------------
71
+ # --
71
72
 
72
73
  def self.merge(new_hash, old_hash = defaults)
73
74
  old_hash.merge(new_hash) do |_, old_val, new_val|
@@ -1,58 +1,96 @@
1
- # ----------------------------------------------------------------------------
2
1
  # Frozen-string-literal: true
3
2
  # Copyright: 2012 - 2016 - MIT License
4
3
  # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
4
 
7
5
  module Jekyll
8
6
  module Assets
9
7
  class Env < Sprockets::Environment
10
- attr_reader :jekyll, :used
8
+ attr_accessor :jekyll
11
9
 
12
10
  class << self
13
- attr_accessor :past
11
+
12
+ # --
13
+ # A list of instances for Jekyll and their paths.
14
+ # This works around Jekyll watch and build booting twice.
15
+ # @return [Hash]
16
+ # --
17
+ def instances
18
+ return @instances ||= {
19
+ #
20
+ }
21
+ end
22
+
23
+ # --
24
+ # A list of Liquid Proxies.
25
+ # @return [Set]
26
+ # --
14
27
  def liquid_proxies
15
28
  Liquid::Tag::Proxies
16
29
  end
17
30
 
18
- # --------------------------------------------------------------------
31
+ # --
32
+ # XXX: Remove this in 3.0, it's unecessary.
33
+ # Initialize a new instance of ourselves onto Jekyll if not exist.
34
+ # @param [Jekyll::Site] jekyll the site instance.
35
+ # --
36
+ def init(jekyll, key = jekyll.in_source_dir)
37
+ Jekyll.logger.debug "Creating a new instance of: ", self
38
+ Jekyll.logger.debug "The old value of Sprockets: ",
39
+ jekyll.sprockets
40
+
41
+ instances[key] = new(
42
+ jekyll
43
+ )
19
44
 
20
- def init(jekyll)
21
- new(jekyll)
22
45
  jekyll.sprockets.excludes.map(&jekyll.config["exclude"].method(:<<))
23
46
  jekyll.config["keep_files"] |= jekyll.sprockets.asset_config["prefix"].gsub(/\A\//, "").to_a
24
47
  jekyll.config["exclude"].uniq!
25
48
  end
26
49
  end
27
50
 
28
- # ----------------------------------------------------------------------
51
+ # --
52
+ # XXX: Remove in 3.0
53
+ # Used is deprecated, use Manifest#add.
54
+ # @return [Manifest]
55
+ # --
56
+ def used
57
+ Logger.deprecate "Env#used is deprecated use Manifest#add", jekyll do
58
+ manifest
59
+ end
60
+ end
61
+
62
+ # --
29
63
  # Disables GZIP. You should be using your server to do this and even
30
64
  # if you don't, there are far better and more efficient algorithms out
31
65
  # right now that are in beta. Try Googling Googles new compression.
32
- # ----------------------------------------------------------------------
33
-
66
+ # --
34
67
  def skip_gzip?
35
68
  true
36
69
  end
37
70
 
38
- # ----------------------------------------------------------------------
39
-
71
+ # --
72
+ # Builds a list of excludes for Jekyll.
73
+ # @return [Set]
74
+ # --
40
75
  def excludes
41
76
  excludes = Set.new
42
77
  excludes << strip_path(in_cache_dir)
43
78
  excludes
44
79
  end
45
80
 
46
- # ----------------------------------------------------------------------
47
-
81
+ # --
82
+ # Returns all the assets.
83
+ # --
48
84
  def all_unparsed_assets
49
85
  @unparsed_assets ||= logical_paths.select do |(_, val)|
50
86
  val.start_with?(jekyll.in_source_dir)
51
87
  end
52
88
  end
53
89
 
54
- # ----------------------------------------------------------------------
55
-
90
+ # --
91
+ # Converts this class into a set of Drops.
92
+ # @return [Hash]
93
+ # --
56
94
  def to_liquid_payload
57
95
  jekyll.sprockets.all_unparsed_assets.each_with_object({}) do |(key, val), hash|
58
96
  hash[key] = Jekyll::Assets::Liquid::Drop.new(
@@ -61,70 +99,88 @@ module Jekyll
61
99
  end
62
100
  end
63
101
 
64
- # ----------------------------------------------------------------------
65
-
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
+ # --
66
108
  def initialize(path, jekyll = nil)
67
109
  (jekyll = path; path = nil) if path.is_a?(Jekyll::Site)
68
110
 
69
111
  @used = Set.new
70
- @jekyll = jekyll
71
112
  path ? super(path) : super()
113
+ @jekyll = jekyll
114
+
115
+ # XXX: In 3.0, we need to drop anything to do with instance eval,
116
+ # and imply pass the instance, this will make our code cleaner.
117
+
72
118
  Hook.trigger :env, :init do |hook|
73
119
  hook.arity > 0 || 0 > hook.arity ? hook.call(self) : instance_eval(
74
120
  &hook
75
121
  )
76
122
  end
77
- end
78
123
 
79
- # ----------------------------------------------------------------------
124
+ # Make sure that we add extras.
125
+ extra_assets.each do |asset|
126
+ manifest.add(
127
+ asset
128
+ )
129
+ end
130
+ end
80
131
 
132
+ # --
133
+ # A list of Liquid Proxies.
134
+ # @return [Set]
135
+ # --
81
136
  def liquid_proxies
82
137
  self.class.liquid_proxies
83
138
  end
84
139
 
85
- # ----------------------------------------------------------------------
86
- # Make sure a path falls withint our cache dir.
87
- # ----------------------------------------------------------------------
88
-
140
+ # --
141
+ # Make a path land inside of our cache directory.
142
+ # @param [<Anything>] *paths the paths you wish to land.
143
+ # @return [Pathname/Pathutil]
144
+ # --
89
145
  def in_cache_dir(*paths)
90
146
  jekyll.in_source_dir(asset_config["cache"] || ".asset-cache",
91
147
  *paths
92
148
  )
93
149
  end
94
150
 
95
- # ----------------------------------------------------------------------
96
- # Merged form of `#extra_assets`
97
- # ----------------------------------------------------------------------
98
-
151
+ # --
152
+ # Deprecated: Use Manifest#to_compile
153
+ # XXX: Remove in 3.0
154
+ # --
99
155
  def all_assets
100
- Set.new(@used).merge(
101
- extra_assets
102
- )
156
+ Logger.deprecate "Env#all_assets is deprecated, use Manifest#all", jekyll do
157
+ manifest.all
158
+ end
103
159
  end
104
160
 
105
- # ----------------------------------------------------------------------
161
+ # --
106
162
  # Assets you tell us you want to always compile, even if you do not
107
163
  # use them. Just like Rails this is probably normally used.
108
- # ----------------------------------------------------------------------
109
-
164
+ # --
110
165
  def extra_assets
111
166
  assets = asset_config["assets"] ||= []
112
167
  each_logical_path(*assets).map do |v|
113
- find_asset v
168
+ manifest.find(v).first
114
169
  end
115
170
  end
116
171
 
117
- # ----------------------------------------------------------------------
118
-
172
+ # --
173
+ # Whether or not we need a CDN.
174
+ # --
119
175
  def cdn?
120
176
  !dev? && asset_config.key?("cdn") && \
121
177
  asset_config["cdn"]
122
178
  end
123
179
 
124
- # ----------------------------------------------------------------------
180
+ # --
181
+ # The BaseURL mixed with Jekyll's own BaseURL.
125
182
  # rubocop:disable Style/ExtraSpacing
126
- # ----------------------------------------------------------------------
127
-
183
+ # --
128
184
  def baseurl
129
185
  ary = []
130
186
 
@@ -136,42 +192,47 @@ module Jekyll
136
192
  end)
137
193
  end
138
194
 
139
- # ----------------------------------------------------------------------
195
+ # --
196
+ # Whether or not we are in development mode.
140
197
  # rubocop:enable Style/ExtraSpacing
141
- # ----------------------------------------------------------------------
142
-
198
+ # --
143
199
  def dev?
144
200
  %W(development test).include?(Jekyll.env)
145
201
  end
146
202
 
147
- # ----------------------------------------------------------------------
148
-
203
+ # --
204
+ # Whether or not we should compress assets.
205
+ # --
149
206
  def compress?(what)
150
207
  !!asset_config["compress"].fetch(
151
208
  what, false
152
209
  )
153
210
  end
154
211
 
155
- # ----------------------------------------------------------------------
156
-
212
+ # --
213
+ # The asset configuration.
214
+ # --
157
215
  def asset_config
158
216
  jekyll.config["assets"] ||= {}
159
217
  end
160
218
 
161
- # ----------------------------------------------------------------------
162
-
219
+ # --
220
+ # Whether or not we are digesting.
221
+ # @return [true,false]
222
+ # --
163
223
  def digest?
164
224
  !!asset_config[
165
225
  "digest"
166
226
  ]
167
227
  end
168
228
 
169
- # ----------------------------------------------------------------------
229
+ # --
170
230
  # Prefix path prefixes the path with the baseurl and the cdn if it
171
231
  # exists and is in the right mode to use it. Otherwise it will only use
172
- # the baseurl and asset prefix. All of these can be adjusted.
173
- # ----------------------------------------------------------------------
174
-
232
+ # the baseurl and asset prefix. All of these can be adjusted...
233
+ # @param [String,Pathname,Pathutil] path the path to prefix.
234
+ # @return [Pathname,Pathutil,String]
235
+ # --
175
236
  def prefix_path(path = nil)
176
237
  cdn = asset_config["cdn"]
177
238
  base_url = baseurl
@@ -184,32 +245,42 @@ module Jekyll
184
245
  url.chomp("/")
185
246
  end
186
247
 
187
- # ----------------------------------------------------------------------
188
248
 
249
+ # --
250
+ # Sprockets cached instance.
251
+ # @return [Cached]
252
+ # --
189
253
  def cached
190
254
  return @cached ||= Cached.new(
191
255
  self
192
256
  )
193
257
  end
194
258
 
195
- # ----------------------------------------------------------------------
196
-
259
+ # --
260
+ # The manifest we use to pull assets.
261
+ # @return [Manifest]
262
+ # --
197
263
  def manifest
198
264
  return @manifest ||= Manifest.new(self, jekyll.in_dest_dir(
199
265
  asset_config["prefix"]
200
266
  ))
201
267
  end
202
268
 
203
- # ----------------------------------------------------------------------
269
+ # --
204
270
  # Write assets with the manifest if they aren't proxied assets. If
205
271
  # they are then we go on to write them ourselves. We don't necessarily
206
272
  # integrate with the manifest that deeply because it's hard.
207
- # ----------------------------------------------------------------------
208
-
273
+ # --
209
274
  def write_all
210
- assets = all_assets.partition { |v| v.is_a?(Liquid::Tag::ProxiedAsset) }
211
- writeable_assets = assets.last.map(&:dependencies).push(assets.last).reduce(&:|)
212
- manifest.compile(writeable_assets.map(&:logical_path))
275
+ assets = manifest.all.partition { |v| v.is_a?(Liquid::Tag::ProxiedAsset) }
276
+ manifest.compile(assets.last.map(
277
+ &:logical_path
278
+ ))
279
+
280
+ # Proxied assets will not compile the normal way since they are
281
+ # always considered uniq when used, and they supply their own inline
282
+ # caching, so we always write them individually since they will
283
+ # never actually show up inside of the manifest.
213
284
 
214
285
  assets.first.map do |asset|
215
286
  asset.write_to(jekyll.in_dest_dir(File.join(asset_config["prefix"],
@@ -218,8 +289,9 @@ module Jekyll
218
289
  end
219
290
  end
220
291
 
221
- # ----------------------------------------------------------------------
222
-
292
+ # --
293
+ # Undocumented
294
+ # --
223
295
  private
224
296
  def strip_path(path)
225
297
  path.sub(jekyll.in_source_dir("/"), "")
@@ -15,7 +15,7 @@ module Jekyll
15
15
  asset = manifest.find(path).first
16
16
 
17
17
  if asset
18
- parent.used.add(asset)
18
+ manifest.add(asset)
19
19
  parent.prefix_path(
20
20
  parent.digest?? asset.digest_path : asset.logical_path
21
21
  )
@@ -1,17 +1,25 @@
1
- # ----------------------------------------------------------------------------
2
1
  # Frozen-string-literal: true
3
2
  # Copyright: 2012 - 2016 - MIT License
4
3
  # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
4
 
7
5
  Jekyll::Assets::Hook.register :env, :init do
8
- cache_dir = asset_config.fetch("cache",
9
- ".asset-cache"
6
+ cache = asset_config.fetch("cache", ".asset-cache")
7
+ type = asset_config.fetch("cache_type",
8
+ "filesystem"
10
9
  )
11
10
 
12
- if cache_dir
13
- self.cache = Sprockets::Cache::FileStore.new(
14
- jekyll.in_source_dir(cache_dir)
15
- )
11
+ if cache != false && type != "memory"
12
+ self.cache = begin
13
+ Sprockets::Cache::FileStore.new(
14
+ jekyll.in_source_dir(
15
+ cache
16
+ )
17
+ )
18
+ end
19
+
20
+ elsif cache && type == "memory"
21
+ self.cache = begin
22
+ Sprockets::Cache::MemoryStore.new
23
+ end
16
24
  end
17
25
  end
@@ -115,7 +115,7 @@ module Jekyll
115
115
 
116
116
  private
117
117
  def process_tag(args, sprockets, asset)
118
- sprockets.used.add(asset) unless @tag == "asset_source"
118
+ sprockets.manifest.add(asset) unless @tag == "asset_source"
119
119
  Defaults.set_defaults_for!(@tag, args ||= {}, asset, sprockets)
120
120
  build_html(args, sprockets, asset)
121
121
  end
@@ -9,52 +9,65 @@ module Jekyll
9
9
  class Logger
10
10
  PREFIX = "Jekyll Assets:"
11
11
 
12
+ class << self
13
+
14
+ # --
15
+ # @param [String] msg the message you wish to send out.
16
+ # Deprecate a method and warn the user about it.
17
+ # --
18
+ def deprecate(msg, instance)
19
+ filepath = caller[1].split(/\.rb:/).first + ".rb"
20
+ filepath = Pathutil.new(filepath).relative_path_from(instance.in_source_dir)
21
+ Jekyll.logger.error("", format("%s: %s", msg.red, filepath))
22
+ yield if block_given?
23
+ end
24
+ end
25
+
26
+ # --
27
+ # @return [Jekyll:Logger]
28
+ # The logger.
29
+ # --
12
30
  def log
13
- @_log ||= Jekyll.logger
31
+ return @log ||= Jekyll.logger
14
32
  end
15
33
 
16
- # ----------------------------------------------------------------------
34
+ # --
17
35
  # Log Level: 1
18
- # ----------------------------------------------------------------------
19
-
36
+ # --
20
37
  def warn(msg = nil)
21
38
  log.warn(PREFIX,
22
39
  block_given?? yield : msg
23
40
  )
24
41
  end
25
42
 
26
- # ----------------------------------------------------------------------
43
+ # --
27
44
  # Log Level: 1
28
- # ----------------------------------------------------------------------
29
-
45
+ # --
30
46
  def error(msg = nil)
31
47
  log.error(PREFIX,
32
48
  block_given?? yield : msg
33
49
  )
34
50
  end
35
51
 
36
- # ----------------------------------------------------------------------
52
+ # --
37
53
  # Log Level: 2
38
- # ----------------------------------------------------------------------
39
-
54
+ # --
40
55
  def info(msg = nil)
41
56
  log.info(PREFIX,
42
57
  block_given?? yield : msg
43
58
  )
44
59
  end
45
60
 
46
- # ----------------------------------------------------------------------
61
+ # --
47
62
  # Log Level: 3
48
- # ----------------------------------------------------------------------
49
-
63
+ # --
50
64
  def debug(msg = nil)
51
65
  log.debug(PREFIX,
52
66
  block_given?? yield : msg
53
67
  )
54
68
  end
55
69
 
56
- # ----------------------------------------------------------------------
57
-
70
+ # --
58
71
  def log_level=(*)
59
72
  raise "Please set log levels on Jekyll.logger"
60
73
  end
@@ -1,18 +1,40 @@
1
- # ----------------------------------------------------------------------------
2
1
  # Frozen-string-literal: true
3
2
  # Copyright: 2012 - 2016 - MIT License
4
3
  # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
4
 
7
5
  module Jekyll
8
6
  module Assets
7
+ class Manifest < Sprockets::Manifest
8
+ extend Forwardable::Extended
9
+ rb_delegate :add, {
10
+ :to => :used
11
+ }
9
12
 
10
- # ------------------------------------------------------------------------
11
- # This is a wholesale rip of Sprockets::Manifest, we only adjust it to
12
- # care about whether or not we want to digest, we don't always digest.
13
- # ------------------------------------------------------------------------
13
+ # --
14
+ # The assets to be compiled.
15
+ # @return [Set]
16
+ # --
17
+ def used
18
+ @assets ||= Set.new
19
+ end
14
20
 
15
- class Manifest < Sprockets::Manifest
21
+ # --
22
+ # All the assets, plus the used.
23
+ # @return [Set]
24
+ # --
25
+ def all
26
+ @assets | (files.map do |_, v|
27
+ find(v[
28
+ "logical_path"
29
+ ]).first
30
+ end)
31
+ end
32
+
33
+ # --
34
+ # This is a wholesale rip of Sprockets::Manifest#compkle, we only
35
+ # adjust it to care about whether or not we want to digest, we don't
36
+ # always digest in development.
37
+ # --
16
38
  def compile(*args)
17
39
  unless environment
18
40
  raise(
@@ -1,11 +1,9 @@
1
- # ----------------------------------------------------------------------------
2
1
  # Frozen-string-literal: true
3
2
  # Copyright: 2012 - 2016 - MIT License
4
3
  # Encoding: utf-8
5
- # ----------------------------------------------------------------------------
6
4
 
7
5
  module Jekyll
8
6
  module Assets
9
- VERSION="2.2.2"
7
+ VERSION="2.2.3"
10
8
  end
11
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordon Bedwell