jekyll-assets 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.7.0 (2013-08-11)
2
+
3
+ * Adds `debug` mode that outputs multiple scripts/styles instead of bundling
4
+ them. See #40.
5
+
6
+
1
7
  ### 0.6.1 (2013-07-22)
2
8
 
3
9
  * Fix regression with `asset_path`. See #38.
data/README.md CHANGED
@@ -42,7 +42,7 @@ information about amazing features it gives you.
42
42
  [extjs]: https://github.com/sstephenson/execjs#readme
43
43
 
44
44
  For a quick start check out [jekyll-assets introduction][jekyll-assets-intro]
45
- that shows how to use it step by step. Also you might want to take a look on
45
+ that shows how to use it step by step. Also you might want to take a look on
46
46
  [my blog sources][ixti-blog-src] as a real-world example as well.
47
47
 
48
48
  [jekyll-assets-intro]: http://ixti.net/software/2012/12/30/unleash-mr-hyde-introduction-of-jekyll-assets.html
@@ -147,7 +147,8 @@ difference is only in comments styles used with _directives_.
147
147
  See detailes information about these _directives_ below.
148
148
 
149
149
  You might also want your stylesheets and javascripts to be minified. In this
150
- case just install `uglifier` gem and add following lines into your `config.yml`:
150
+ case just install the `uglifier` gem and any other gems you will be using, e.g.
151
+ `sass`, `coffee-script`. Then add following lines into your `config.yml`:
151
152
 
152
153
  ``` yaml
153
154
  assets:
@@ -484,6 +485,12 @@ assets:
484
485
  # stylesheets are gzipped by default.
485
486
  #
486
487
  gzip: [ text/css, application/javascript ]
488
+ #
489
+ # Does not concatenates files requested by `javascript` and `stylesheet`
490
+ # helpers. Instead outputs multiple files in order they are required.
491
+ # Default: false
492
+ #
493
+ debug: false
487
494
  ```
488
495
 
489
496
 
@@ -0,0 +1,50 @@
1
+ module Jekyll
2
+ module AssetsPlugin
3
+ class AssetPath
4
+
5
+ attr_reader :asset
6
+
7
+
8
+ def initialize site, pathname, *args
9
+ pathname, _, @anchor = pathname.rpartition "#" if pathname["#"]
10
+ pathname, _, @query = pathname.rpartition "?" if pathname["?"]
11
+
12
+ @asset = site.assets[pathname, *args]
13
+ @site = site
14
+
15
+ site.bundle_asset! asset
16
+ end
17
+
18
+
19
+ def cachebust
20
+ @cachebust ||= @site.assets_config.cachebust
21
+ end
22
+
23
+
24
+ def path
25
+ :hard == cachebust && asset.digest_path || asset.logical_path
26
+ end
27
+
28
+
29
+ def query
30
+ query = []
31
+
32
+ query << "cb=#{asset.digest}" if :soft == cachebust
33
+ query << @query if @query
34
+
35
+ "?#{query.join '&'}" unless query.empty?
36
+ end
37
+
38
+
39
+ def anchor
40
+ "##{@anchor}" if @anchor
41
+ end
42
+
43
+
44
+ def to_s
45
+ "#{@site.assets_config.baseurl}/#{path}#{query}#{anchor}"
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -12,7 +12,8 @@ module Jekyll
12
12
  :css_compressor => nil,
13
13
  :cachebust => :hard,
14
14
  :cache => false,
15
- :gzip => %w{ text/css application/javascript }
15
+ :gzip => %w{ text/css application/javascript },
16
+ :debug => false
16
17
  }.freeze
17
18
 
18
19
 
@@ -49,7 +50,9 @@ module Jekyll
49
50
 
50
51
 
51
52
  def cachebust
52
- none?(@data.cachebust) ? :none : @data.cachebust.to_sym
53
+ return :none if none?(@data.cachebust)
54
+ return @data.cachebust.to_sym if @data.cachebust.to_s =~ /^(soft|hard)$/
55
+ raise "Unknown cachebust strategy: #{@data.cachebust}"
53
56
  end
54
57
 
55
58
 
@@ -7,8 +7,67 @@ module Jekyll
7
7
  module Patches
8
8
  module AssetPatch
9
9
 
10
- def jekyll_assets
11
- []
10
+ def self.included base
11
+ base.send :extend, ClassMethods
12
+ base.send :include, InstanceMethods
13
+ end
14
+
15
+
16
+ module ClassMethods
17
+
18
+ def mtimes
19
+ @mtimes ||= Hash.new
20
+ end
21
+
22
+ end
23
+
24
+
25
+ module InstanceMethods
26
+
27
+ attr_reader :site
28
+
29
+
30
+ def jekyll_assets
31
+ []
32
+ end
33
+
34
+
35
+ def destination dest
36
+ File.join dest, site.assets_config.dirname, filename
37
+ end
38
+
39
+
40
+ def filename
41
+ case cachebust = site.assets_config.cachebust
42
+ when :none, :soft then logical_path
43
+ when :hard then digest_path
44
+ else raise "Unknown cachebust strategy: #{cachebust.inspect}"
45
+ end
46
+ end
47
+
48
+
49
+ def modified?
50
+ self.class.mtimes[pathname.to_s] != mtime.to_i
51
+ end
52
+
53
+
54
+ def write dest
55
+ dest_path = destination dest
56
+
57
+ return false if File.exist?(dest_path) and !modified?
58
+ self.class.mtimes[pathname.to_s] = mtime.to_i
59
+
60
+ write_to dest_path
61
+ write_to "#{dest_path}.gz" if gzip?
62
+
63
+ true
64
+ end
65
+
66
+
67
+ def gzip?
68
+ site.assets_config.gzip.include? content_type
69
+ end
70
+
12
71
  end
13
72
 
14
73
  end
@@ -17,11 +17,11 @@ module Jekyll
17
17
  end
18
18
 
19
19
 
20
- def asset_path path, *args
21
- jekyll_assets << resolve(path.to_s[/^[^#?]+/]).to_s
22
- site.asset_path path, *args
20
+ def asset_path pathname, *args
21
+ jekyll_assets << resolve(pathname.to_s[/^[^#?]+/]).to_s
22
+ site.asset_path pathname, *args
23
23
  rescue Sprockets::FileNotFound
24
- raise Environment::AssetNotFound, path
24
+ raise Environment::AssetNotFound, pathname
25
25
  end
26
26
 
27
27
  end
@@ -17,7 +17,7 @@ module Jekyll
17
17
 
18
18
  def __wrap_find_asset path, options = {}
19
19
  __orig_find_asset(path, options).tap do |asset|
20
- @environment.site.bundle_asset! asset if asset and options[:bundle]
20
+ asset.instance_variable_set :@site, @environment.site if asset
21
21
  end
22
22
  end
23
23
 
@@ -5,7 +5,7 @@ require "jekyll"
5
5
  # internal
6
6
  require "jekyll/assets_plugin/configuration"
7
7
  require "jekyll/assets_plugin/environment"
8
- require "jekyll/assets_plugin/asset_file"
8
+ require "jekyll/assets_plugin/asset_path"
9
9
 
10
10
 
11
11
  module Jekyll
@@ -36,35 +36,15 @@ module Jekyll
36
36
  end
37
37
 
38
38
 
39
- def asset_path pathname, *args
40
- pathname, _, anchor = pathname.rpartition "#" if pathname["#"]
41
- pathname, _, query = pathname.rpartition "?" if pathname["?"]
42
-
43
- asset = assets[pathname, *args]
44
- baseurl = "#{assets_config.baseurl}/"
45
-
46
- case cachebust = assets_config.cachebust
47
- when :none then baseurl << asset.logical_path
48
- when :soft then baseurl << asset.logical_path << "?cb=#{asset.digest}"
49
- when :hard then baseurl << asset.digest_path
50
- else raise "Unknown cachebust strategy: #{cachebust.inspect}"
51
- end
52
-
53
- baseurl << (:soft == cachebust ? "&" : "?") << query if query
54
- baseurl << "#" << anchor if anchor
55
-
56
- baseurl
39
+ def asset_path *args
40
+ AssetPath.new(self, *args).to_s
57
41
  end
58
42
 
59
43
 
60
44
  def bundle_asset! asset
61
45
  if not asset_files.include? asset
62
- file = AssetFile.new self, asset
63
-
46
+ asset_files << asset
64
47
  asset.jekyll_assets.each{ |path| bundle_asset! assets[path] }
65
-
66
- asset_files << file
67
- static_files << file
68
48
  end
69
49
  end
70
50
 
@@ -25,6 +25,12 @@ module Jekyll
25
25
  def render_javascript
26
26
  @path << ".js" if File.extname(@path).empty?
27
27
 
28
+ if @site.assets_config.debug
29
+ return @site.assets[@path].to_a.map{ |a|
30
+ JAVASCRIPT % @site.asset_path(a.logical_path, :bundle => false)
31
+ }.join("\n")
32
+ end
33
+
28
34
  JAVASCRIPT % render_asset_path
29
35
  end
30
36
 
@@ -32,6 +38,12 @@ module Jekyll
32
38
  def render_stylesheet
33
39
  @path << ".css" if File.extname(@path).empty?
34
40
 
41
+ if @site.assets_config.debug
42
+ return @site.assets[@path].to_a.map{ |a|
43
+ STYLESHEET % @site.asset_path(a.logical_path, :bundle => false)
44
+ }.join("\n")
45
+ end
46
+
35
47
  STYLESHEET % render_asset_path
36
48
  end
37
49
 
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module AssetsPlugin
3
- VERSION = "0.6.1"
3
+ VERSION = "0.7.0"
4
4
  end
5
5
  end
@@ -1,3 +1,4 @@
1
+ //= require wowstyle
1
2
  /* vapor css framework */
2
3
 
3
4
  @font-face {
@@ -1 +1,2 @@
1
+ //= require wowscript
1
2
  /* vapor js framework */
File without changes
File without changes
@@ -51,6 +51,11 @@ module Jekyll::AssetsPlugin
51
51
  it { should == ".jekyll-assets-cache" }
52
52
  end
53
53
 
54
+ context "debug" do
55
+ subject { config.debug }
56
+ it { should be_false }
57
+ end
58
+
54
59
  end
55
60
 
56
61
  it "should override specified options and leave defaults for missing" do
@@ -39,13 +39,6 @@ module Jekyll::AssetsPlugin
39
39
  noise_img_re = %r{url\(/assets/noise-[a-f0-9]{32}\.png\)}
40
40
  site.assets["app.css"].to_s.should match(noise_img_re)
41
41
  end
42
-
43
- it "should be appended to the static_files list" do
44
- asset = site.assets["app.css"] # make sure main asset was compiled
45
- asset = site.assets["noise.png"]
46
-
47
- site.static_files.include?(asset).should be_true
48
- end
49
42
  end
50
43
  end
51
44
  end
@@ -0,0 +1,56 @@
1
+ # stdlib
2
+ require "ostruct"
3
+
4
+
5
+ require "spec_helper"
6
+
7
+
8
+ module Jekyll::AssetsPlugin
9
+ describe Renderer do
10
+
11
+ let(:site) do
12
+ Jekyll::Site.new Jekyll.configuration({
13
+ "source" => fixtures_path.to_s,
14
+ "destination" => @dest.to_s,
15
+ "assets" => assets_config
16
+ })
17
+ end
18
+
19
+
20
+ let(:renderer) do
21
+ context = OpenStruct.new(:registers => { :site => site })
22
+ Renderer.new context, "app"
23
+ end
24
+
25
+
26
+ describe "#render_javascript" do
27
+ subject { renderer.render_javascript }
28
+
29
+ context "when debug mode enabled" do
30
+ let(:assets_config){ Hash[:debug, true] }
31
+ it { should match %r{^(\s*<script src="[^"]+"></script>\s*){3}$} }
32
+ end
33
+
34
+ context "when debug mode disabled" do
35
+ let(:assets_config){ Hash[:debug, false] }
36
+ it { should match %r{^(\s*<script src="[^"]+"></script>\s*){1}$} }
37
+ end
38
+ end
39
+
40
+
41
+ describe "#render_stylesheet" do
42
+ subject { renderer.render_stylesheet }
43
+
44
+ context "when debug mode enabled" do
45
+ let(:assets_config){ Hash[:debug, true] }
46
+ it { should match %r{^(\s*<link rel="stylesheet" href="[^"]+">\s*){3}$} }
47
+ end
48
+
49
+ context "when debug mode disabled" do
50
+ let(:assets_config){ Hash[:debug, false] }
51
+ it { should match %r{^(\s*<link rel="stylesheet" href="[^"]+">\s*){1}$} }
52
+ end
53
+ end
54
+
55
+ end
56
+ 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: 0.6.1
4
+ version: 0.7.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-21 00:00:00.000000000 Z
12
+ date: 2013-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
@@ -180,7 +180,7 @@ files:
180
180
  - lib/jekyll-assets/compass.rb
181
181
  - lib/jekyll-assets/neat.rb
182
182
  - lib/jekyll/assets_plugin.rb
183
- - lib/jekyll/assets_plugin/asset_file.rb
183
+ - lib/jekyll/assets_plugin/asset_path.rb
184
184
  - lib/jekyll/assets_plugin/configuration.rb
185
185
  - lib/jekyll/assets_plugin/environment.rb
186
186
  - lib/jekyll/assets_plugin/filters.rb
@@ -208,6 +208,8 @@ files:
208
208
  - spec/fixtures/_assets/vendor/bourbon.css.sass
209
209
  - spec/fixtures/_assets/vendor/compass.css.sass
210
210
  - spec/fixtures/_assets/vendor/neat.css.sass
211
+ - spec/fixtures/_assets/wowscript.js
212
+ - spec/fixtures/_assets/wowstyle.css
211
213
  - spec/fixtures/_config.yml
212
214
  - spec/fixtures/_layouts/default.html
213
215
  - spec/fixtures/_posts/2012-10-19-hello-world.md
@@ -215,11 +217,11 @@ files:
215
217
  - spec/lib/jekyll-assets/bourbon_spec.rb
216
218
  - spec/lib/jekyll-assets/compass_spec.rb
217
219
  - spec/lib/jekyll-assets/neat_spec.rb
218
- - spec/lib/jekyll/assets_plugin/asset_file_spec.rb
219
220
  - spec/lib/jekyll/assets_plugin/configuration_spec.rb
220
221
  - spec/lib/jekyll/assets_plugin/environment_spec.rb
221
222
  - spec/lib/jekyll/assets_plugin/filters_spec.rb
222
223
  - spec/lib/jekyll/assets_plugin/patches/site_patch_spec.rb
224
+ - spec/lib/jekyll/assets_plugin/renderer_spec.rb
223
225
  - spec/lib/jekyll/assets_plugin/tag_spec.rb
224
226
  - spec/spec_helper.rb
225
227
  - spec/support/fixtures_path.rb
@@ -247,7 +249,7 @@ rubyforge_project:
247
249
  rubygems_version: 1.8.23
248
250
  signing_key:
249
251
  specification_version: 3
250
- summary: jekyll-assets-0.6.1
252
+ summary: jekyll-assets-0.7.0
251
253
  test_files:
252
254
  - spec/fixtures/.gitignore
253
255
  - spec/fixtures/_assets/app.css.erb
@@ -263,6 +265,8 @@ test_files:
263
265
  - spec/fixtures/_assets/vendor/bourbon.css.sass
264
266
  - spec/fixtures/_assets/vendor/compass.css.sass
265
267
  - spec/fixtures/_assets/vendor/neat.css.sass
268
+ - spec/fixtures/_assets/wowscript.js
269
+ - spec/fixtures/_assets/wowstyle.css
266
270
  - spec/fixtures/_config.yml
267
271
  - spec/fixtures/_layouts/default.html
268
272
  - spec/fixtures/_posts/2012-10-19-hello-world.md
@@ -270,11 +274,11 @@ test_files:
270
274
  - spec/lib/jekyll-assets/bourbon_spec.rb
271
275
  - spec/lib/jekyll-assets/compass_spec.rb
272
276
  - spec/lib/jekyll-assets/neat_spec.rb
273
- - spec/lib/jekyll/assets_plugin/asset_file_spec.rb
274
277
  - spec/lib/jekyll/assets_plugin/configuration_spec.rb
275
278
  - spec/lib/jekyll/assets_plugin/environment_spec.rb
276
279
  - spec/lib/jekyll/assets_plugin/filters_spec.rb
277
280
  - spec/lib/jekyll/assets_plugin/patches/site_patch_spec.rb
281
+ - spec/lib/jekyll/assets_plugin/renderer_spec.rb
278
282
  - spec/lib/jekyll/assets_plugin/tag_spec.rb
279
283
  - spec/spec_helper.rb
280
284
  - spec/support/fixtures_path.rb
@@ -1,86 +0,0 @@
1
- module Jekyll
2
- module AssetsPlugin
3
- class AssetFile
4
-
5
- @@mtimes = Hash.new
6
-
7
-
8
- attr_reader :logical_path
9
-
10
-
11
- def initialize site, asset
12
- @site, @asset, @logical_path = site, asset, asset.logical_path
13
- end
14
-
15
-
16
- def destination dest
17
- File.join dest, @site.assets_config.dirname, filename
18
- end
19
-
20
-
21
- def filename
22
- case cachebust = @site.assets_config.cachebust
23
- when :none, :soft then asset.logical_path
24
- when :hard then asset.digest_path
25
- else raise "Unknown cachebust strategy: #{cachebust.inspect}"
26
- end
27
- end
28
-
29
-
30
- def asset
31
- @asset = @site.assets[logical_path] if @asset.stale? @site.assets
32
- @asset
33
- end
34
-
35
-
36
- def content_type
37
- asset.content_type
38
- end
39
-
40
-
41
- def path
42
- asset.pathname.to_s
43
- end
44
-
45
-
46
- def mtime
47
- asset.mtime.to_i
48
- end
49
-
50
-
51
- def modified?
52
- @@mtimes[path] != mtime
53
- end
54
-
55
-
56
- def write dest
57
- dest_path = destination dest
58
-
59
- return false if File.exist?(dest_path) and !modified?
60
- @@mtimes[path] = mtime
61
-
62
- asset.write_to dest_path
63
- asset.write_to "#{dest_path}.gz" if gzip?
64
-
65
- true
66
- end
67
-
68
-
69
- def == other
70
- return false unless other.respond_to? :logical_path
71
- other.logical_path == logical_path
72
- end
73
-
74
-
75
- def gzip?
76
- @site.assets_config.gzip.include? content_type
77
- end
78
-
79
-
80
- def to_s
81
- "#<Jekyll::AssetsPlugin::AssetFile:#{logical_path}>"
82
- end
83
-
84
- end
85
- end
86
- end
@@ -1,34 +0,0 @@
1
- require "spec_helper"
2
-
3
-
4
- module Jekyll::AssetsPlugin
5
- describe AssetFile do
6
- context "#destination" do
7
- subject do
8
- AssetFile.new(@site, @site.assets["app.css"]).destination @dest.to_s
9
- end
10
-
11
- context "with none cachebust" do
12
- before { @site.assets_config.cachebust = :none }
13
- it { should match(%r{/app\.css$}) }
14
- end
15
-
16
- context "with soft cachebust" do
17
- before { @site.assets_config.cachebust = :soft }
18
- it { should match(%r{/app\.css$}) }
19
- end
20
-
21
- context "with hard cachebust" do
22
- before { @site.assets_config.cachebust = :hard }
23
- it { should match %r{/app-[0-9a-f]{32}\.css$} }
24
- end
25
-
26
- context "with unknown cachebust" do
27
- before { @site.assets_config.cachebust = :wtf }
28
- it "should raise error" do
29
- expect { @site.asset_path "app.css" }.to raise_error
30
- end
31
- end
32
- end
33
- end
34
- end