jekyll-assets 0.5.4 → 0.6.0

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.
data/HISTORY.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 0.6.0 (2013-07-14)
2
+
3
+ * Remove `type` attributes from tags genereated by `javascript` and
4
+ `stylesheet` helpers. See #37.
5
+ * Fix issue with nested assets not being regenerated when cache enabled.
6
+ See #35.
7
+
8
+
1
9
  ### 0.5.4 (2103-07-07)
2
10
 
3
11
  * Rename configuration options `compress.js` and `compress.css` into
data/README.md CHANGED
@@ -151,13 +151,13 @@ case just install `uglifier` gem and add following lines into your `config.yml`:
151
151
 
152
152
  ``` yaml
153
153
  assets:
154
- compress:
155
- js: uglifier
156
- css: sass
154
+ js_compressor: uglifier
155
+ css_compressor: sass
157
156
  ```
158
157
 
159
158
  If you want to use YUI compressor for minification, install `yui-compressor`
160
159
  gem and put `yui` in place of `uglifier` and/or `sass` in the config file.
160
+ You can also define and use your own compressor, see "Custom Compressors".
161
161
 
162
162
  Let's go crazy now! Assume you want your blog's `body` background color to be
163
163
  white all the time, but red if you compiled your web-site in December. Just add
@@ -210,6 +210,30 @@ assets:
210
210
  [amazon-s3]: http://aws.amazon.com/s3
211
211
 
212
212
 
213
+ ### Custom Compressors
214
+
215
+ Sprockets comes with good set of preconfigured compressors, but imagine you are
216
+ not satisfied with default settings. For example you want to strip all comments
217
+ but copyrights info. In this csae you can define and use your own compressor.
218
+
219
+ To do so, first let's define new compressor in `_plugins/ext.rb`:
220
+
221
+ ``` ruby
222
+ require "jekyll-assets"
223
+ require "sprockets"
224
+
225
+ Sprockets.register_compressor 'application/javascript',
226
+ :my_uglifier, Uglifier.new(:comments => :copyright)
227
+ ```
228
+
229
+ Once it's done, just tell assets to use `my_uglifier` as js compressor:
230
+
231
+ ``` yaml
232
+ assets:
233
+ js_compressor: my_uglifier
234
+ ```
235
+
236
+
213
237
  ### Compilation Cache
214
238
 
215
239
  To improve build time, you can enabled compiled assets cache:
@@ -0,0 +1,20 @@
1
+ # 3rd-party
2
+ require "sprockets"
3
+
4
+
5
+ module Jekyll
6
+ module AssetsPlugin
7
+ module Patches
8
+ module AssetPatch
9
+
10
+ def jekyll_assets
11
+ []
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+
20
+ Sprockets::Asset.send :include, Jekyll::AssetsPlugin::Patches::AssetPatch
@@ -0,0 +1,20 @@
1
+ # 3rd-party
2
+ require "sprockets"
3
+
4
+
5
+ module Jekyll
6
+ module AssetsPlugin
7
+ module Patches
8
+ module BundledAssetPatch
9
+
10
+ def jekyll_assets
11
+ @processed_asset.jekyll_assets
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+
20
+ Sprockets::BundledAsset.send :include, Jekyll::AssetsPlugin::Patches::BundledAssetPatch
@@ -1,3 +1,7 @@
1
+ # stdlib
2
+ require "set"
3
+
4
+
1
5
  module Jekyll
2
6
  module AssetsPlugin
3
7
  module Patches
@@ -8,8 +12,16 @@ module Jekyll
8
12
  end
9
13
 
10
14
 
11
- def asset_path *args
12
- site.asset_path(*args)
15
+ def _jekyll_assets
16
+ @_jekyll_assets ||= Set.new
17
+ end
18
+
19
+
20
+ def asset_path path, *args
21
+ _jekyll_assets << resolve(path).to_s
22
+ site.asset_path path, *args
23
+ rescue Sprockets::FileNotFound
24
+ raise Environment::AssetNotFound, path
13
25
  end
14
26
 
15
27
  end
@@ -9,16 +9,16 @@ module Jekyll
9
9
 
10
10
  def self.included base
11
11
  base.class_eval do
12
- alias_method :find_asset_without_jekyll, :find_asset
13
- alias_method :find_asset, :find_asset_with_jekyll
12
+ alias_method :__orig_find_asset, :find_asset
13
+ alias_method :find_asset, :__wrap_find_asset
14
14
  end
15
15
  end
16
16
 
17
17
 
18
- def find_asset_with_jekyll path, options = {}
19
- asset = find_asset_without_jekyll path, options
20
- @environment.site.bundle_asset! asset if asset and options[:bundle]
21
- asset
18
+ def __wrap_find_asset path, options = {}
19
+ __orig_find_asset(path, options).tap do |asset|
20
+ @environment.site.bundle_asset! asset if asset and options[:bundle]
21
+ end
22
22
  end
23
23
 
24
24
  end
@@ -0,0 +1,59 @@
1
+ # stdlib
2
+ require "set"
3
+
4
+
5
+ # 3rd-party
6
+ require "sprockets"
7
+
8
+
9
+ module Jekyll
10
+ module AssetsPlugin
11
+ module Patches
12
+ module ProcessedAssetPatch
13
+
14
+ def self.included base
15
+ base.class_eval do
16
+ attr_reader :jekyll_assets
17
+
18
+ alias_method :__orig_build_dependency_paths, :build_dependency_paths
19
+ alias_method :build_dependency_paths, :__wrap_build_dependency_paths
20
+
21
+ alias_method :__orig_init_with, :init_with
22
+ alias_method :init_with, :__wrap_init_with
23
+
24
+ alias_method :__orig_encode_with, :encode_with
25
+ alias_method :encode_with, :__wrap_encode_with
26
+ end
27
+ end
28
+
29
+
30
+ def __wrap_build_dependency_paths environment, context
31
+ @jekyll_assets = Set.new
32
+
33
+ context._jekyll_assets.each do |path|
34
+ @jekyll_assets << path
35
+ environment.find_asset(path).jekyll_assets.each{ |p| @jekyll_assets << p }
36
+ end
37
+
38
+ __orig_build_dependency_paths environment, context
39
+ end
40
+
41
+
42
+ def __wrap_init_with environment, coder
43
+ __orig_init_with environment, coder
44
+ @jekyll_assets = Set.new coder["jekyll_assets"].map{ |p| expand_root_path(p) }
45
+ end
46
+
47
+
48
+ def __wrap_encode_with coder
49
+ __orig_encode_with coder
50
+ coder["jekyll_assets"] = jekyll_assets.map{ |p| relativize_root_path p }
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+
59
+ Sprockets::ProcessedAsset.send :include, Jekyll::AssetsPlugin::Patches::ProcessedAssetPatch
@@ -15,8 +15,8 @@ module Jekyll
15
15
 
16
16
  def self.included base
17
17
  base.class_eval do
18
- alias_method :write_without_assets, :write
19
- alias_method :write, :write_with_assets
18
+ alias_method :__orig_write, :write
19
+ alias_method :write, :__wrap_write
20
20
  end
21
21
  end
22
22
 
@@ -61,15 +61,17 @@ module Jekyll
61
61
  if not asset_files.include? asset
62
62
  file = AssetFile.new self, asset
63
63
 
64
+ asset.jekyll_assets.each{ |path| bundle_asset! assets[path] }
65
+
64
66
  asset_files << file
65
67
  static_files << file
66
68
  end
67
69
  end
68
70
 
69
71
 
70
- def write_with_assets
72
+ def __wrap_write
71
73
  static_files.push(*asset_files).uniq!
72
- write_without_assets
74
+ __orig_write
73
75
  end
74
76
 
75
77
  end
@@ -2,8 +2,8 @@ module Jekyll
2
2
  module AssetsPlugin
3
3
  class Renderer
4
4
 
5
- STYLESHEET = '<link rel="stylesheet" type="text/css" href="%s">'
6
- JAVASCRIPT = '<script type="text/javascript" src="%s"></script>'
5
+ STYLESHEET = '<link rel="stylesheet" href="%s">'
6
+ JAVASCRIPT = '<script src="%s"></script>'
7
7
 
8
8
 
9
9
  def initialize context, logical_path
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module AssetsPlugin
3
- VERSION = "0.5.4"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -131,11 +131,31 @@ module Jekyll::AssetsPlugin
131
131
 
132
132
  it "should regenerate assets upon multiple #process" do
133
133
  @site.assets_config.cachebust = :none
134
- 2.times { @site.process }
135
-
134
+ 2.times{ @site.process }
136
135
  @dest.join("assets", "app.css").exist?.should be_true
137
136
  end
138
137
 
138
+
139
+ context "with cache" do
140
+ def site
141
+ Jekyll::Site.new(Jekyll.configuration({
142
+ "source" => fixtures_path.to_s,
143
+ "assets" => { "cache" => true, "cachebust" => :none },
144
+ "destination" => @dest.to_s
145
+ }))
146
+ end
147
+
148
+ after do
149
+ site.assets.cache_path.rmtree if site.assets.cache_path.exist?
150
+ end
151
+
152
+ it "should regenerate static assets upon multiple #process" do
153
+ 2.times{ site.process }
154
+ @dest.join("assets", "noise.png").exist?.should be_true
155
+ end
156
+ end
157
+
158
+
139
159
  context "#gzip" do
140
160
  subject { site.assets_config }
141
161
 
data/spec/spec_helper.rb CHANGED
@@ -26,6 +26,8 @@ RSpec.configure do |config|
26
26
  config.include Jekyll::AssetsPlugin::RSpecHelpers
27
27
 
28
28
  config.before(:all) do
29
+ Jekyll.logger.log_level = Jekyll::Stevenson::WARN
30
+
29
31
  @dest = fixtures_path.join("_site")
30
32
  @site = Jekyll::Site.new(Jekyll.configuration({
31
33
  "source" => fixtures_path.to_s,
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: 0.5.4
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-07 00:00:00.000000000 Z
12
+ date: 2013-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
@@ -185,8 +185,11 @@ files:
185
185
  - lib/jekyll/assets_plugin/environment.rb
186
186
  - lib/jekyll/assets_plugin/filters.rb
187
187
  - lib/jekyll/assets_plugin/patches.rb
188
+ - lib/jekyll/assets_plugin/patches/asset_patch.rb
189
+ - lib/jekyll/assets_plugin/patches/bundled_asset_patch.rb
188
190
  - lib/jekyll/assets_plugin/patches/context_patch.rb
189
191
  - lib/jekyll/assets_plugin/patches/index_patch.rb
192
+ - lib/jekyll/assets_plugin/patches/processed_asset_patch.rb
190
193
  - lib/jekyll/assets_plugin/patches/site_patch.rb
191
194
  - lib/jekyll/assets_plugin/renderer.rb
192
195
  - lib/jekyll/assets_plugin/tag.rb
@@ -242,7 +245,7 @@ rubyforge_project:
242
245
  rubygems_version: 1.8.23
243
246
  signing_key:
244
247
  specification_version: 3
245
- summary: jekyll-assets-0.5.4
248
+ summary: jekyll-assets-0.6.0
246
249
  test_files:
247
250
  - spec/fixtures/.gitignore
248
251
  - spec/fixtures/_assets/app.css.erb