jekyll-assets 0.7.6 → 0.7.7
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/.rubocop.yml +48 -0
- data/Gemfile +4 -4
- data/Rakefile +5 -3
- data/lib/jekyll-assets/bootstrap.rb +6 -7
- data/lib/jekyll-assets/bourbon.rb +0 -1
- data/lib/jekyll-assets/compass.rb +2 -4
- data/lib/jekyll-assets/neat.rb +0 -1
- data/lib/jekyll/assets_plugin/asset_path.rb +1 -9
- data/lib/jekyll/assets_plugin/configuration.rb +18 -24
- data/lib/jekyll/assets_plugin/environment.rb +4 -12
- data/lib/jekyll/assets_plugin/filters.rb +1 -5
- data/lib/jekyll/assets_plugin/patches/asset_patch.rb +6 -23
- data/lib/jekyll/assets_plugin/patches/bundled_asset_patch.rb +1 -5
- data/lib/jekyll/assets_plugin/patches/context_patch.rb +2 -7
- data/lib/jekyll/assets_plugin/patches/index_patch.rb +2 -7
- data/lib/jekyll/assets_plugin/patches/processed_asset_patch.rb +19 -18
- data/lib/jekyll/assets_plugin/patches/site_patch.rb +11 -22
- data/lib/jekyll/assets_plugin/renderer.rb +7 -16
- data/lib/jekyll/assets_plugin/tag.rb +1 -6
- data/lib/jekyll/assets_plugin/version.rb +1 -1
- data/spec/lib/jekyll-assets/bootstrap_spec.rb +10 -10
- data/spec/lib/jekyll-assets/bourbon_spec.rb +0 -1
- data/spec/lib/jekyll-assets/compass_spec.rb +0 -1
- data/spec/lib/jekyll-assets/neat_spec.rb +0 -1
- data/spec/lib/jekyll/assets_plugin/configuration_spec.rb +30 -18
- data/spec/lib/jekyll/assets_plugin/environment_spec.rb +2 -3
- data/spec/lib/jekyll/assets_plugin/filters_spec.rb +8 -6
- data/spec/lib/jekyll/assets_plugin/patches/site_patch_spec.rb +13 -22
- data/spec/lib/jekyll/assets_plugin/renderer_spec.rb +8 -13
- data/spec/lib/jekyll/assets_plugin/tag_spec.rb +8 -6
- data/spec/spec_helper.rb +3 -7
- data/spec/support/fixtures_path.rb +2 -3
- metadata +4 -3
@@ -1,20 +1,16 @@
|
|
1
1
|
# 3rd-party
|
2
2
|
require "sprockets"
|
3
3
|
|
4
|
-
|
5
4
|
module Jekyll
|
6
5
|
module AssetsPlugin
|
7
6
|
module Patches
|
8
7
|
module BundledAssetPatch
|
9
|
-
|
10
8
|
def jekyll_assets
|
11
9
|
@processed_asset.jekyll_assets
|
12
10
|
end
|
13
11
|
|
12
|
+
::Sprockets::BundledAsset.send :include, self
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
18
|
-
|
19
|
-
|
20
|
-
Sprockets::BundledAsset.send :include, Jekyll::AssetsPlugin::Patches::BundledAssetPatch
|
@@ -1,31 +1,26 @@
|
|
1
1
|
# stdlib
|
2
2
|
require "set"
|
3
3
|
|
4
|
-
|
5
4
|
module Jekyll
|
6
5
|
module AssetsPlugin
|
7
6
|
module Patches
|
8
7
|
module ContextPatch
|
9
|
-
|
10
8
|
def site
|
11
9
|
self.class.instance_variable_get :@site
|
12
10
|
end
|
13
11
|
|
14
|
-
|
15
12
|
def jekyll_assets
|
16
13
|
@jekyll_assets ||= Set.new
|
17
14
|
end
|
18
15
|
|
19
|
-
|
20
|
-
def asset_path pathname, *args
|
16
|
+
def asset_path(pathname, *args)
|
21
17
|
return "" if pathname.to_s.strip.empty?
|
22
18
|
asset = resolve(pathname.to_s[/^[^#?]+/]).to_s
|
23
19
|
jekyll_assets << asset
|
24
|
-
(site.asset_path asset, *args) + (pathname.to_s[/[#?].+/] ||
|
20
|
+
(site.asset_path asset, *args) + (pathname.to_s[/[#?].+/] || "")
|
25
21
|
rescue Sprockets::FileNotFound
|
26
22
|
raise Environment::AssetNotFound, pathname
|
27
23
|
end
|
28
|
-
|
29
24
|
end
|
30
25
|
end
|
31
26
|
end
|
@@ -1,30 +1,25 @@
|
|
1
1
|
# 3rd-party
|
2
2
|
require "sprockets"
|
3
3
|
|
4
|
-
|
5
4
|
module Jekyll
|
6
5
|
module AssetsPlugin
|
7
6
|
module Patches
|
8
7
|
module IndexPatch
|
9
|
-
|
10
|
-
def self.included base
|
8
|
+
def self.included(base)
|
11
9
|
base.class_eval do
|
12
10
|
alias_method :__orig_find_asset, :find_asset
|
13
11
|
alias_method :find_asset, :__wrap_find_asset
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
17
|
-
|
18
|
-
def __wrap_find_asset path, options = {}
|
15
|
+
def __wrap_find_asset(path, options = {})
|
19
16
|
__orig_find_asset(path, options).tap do |asset|
|
20
17
|
asset.instance_variable_set :@site, @environment.site if asset
|
21
18
|
end
|
22
19
|
end
|
23
|
-
|
24
20
|
end
|
25
21
|
end
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
29
|
-
|
30
25
|
Sprockets::Index.send :include, Jekyll::AssetsPlugin::Patches::IndexPatch
|
@@ -1,22 +1,22 @@
|
|
1
1
|
# stdlib
|
2
2
|
require "set"
|
3
3
|
|
4
|
-
|
5
4
|
# 3rd-party
|
6
5
|
require "sprockets"
|
7
6
|
|
8
|
-
|
9
7
|
module Jekyll
|
10
8
|
module AssetsPlugin
|
11
9
|
module Patches
|
12
10
|
module ProcessedAssetPatch
|
13
|
-
|
14
|
-
def self.included base
|
11
|
+
def self.included(base)
|
15
12
|
base.class_eval do
|
16
13
|
attr_reader :jekyll_assets
|
17
14
|
|
18
|
-
alias_method :__orig_build_dependency_paths,
|
19
|
-
|
15
|
+
alias_method :__orig_build_dependency_paths,
|
16
|
+
:build_dependency_paths
|
17
|
+
|
18
|
+
alias_method :build_dependency_paths,
|
19
|
+
:__wrap_build_dependency_paths
|
20
20
|
|
21
21
|
alias_method :__orig_init_with, :init_with
|
22
22
|
alias_method :init_with, :__wrap_init_with
|
@@ -26,34 +26,35 @@ module Jekyll
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
def __wrap_build_dependency_paths environment, context
|
29
|
+
def __wrap_build_dependency_paths(environment, context)
|
31
30
|
@jekyll_assets = Set.new
|
32
31
|
|
33
32
|
context.jekyll_assets.each do |path|
|
34
33
|
@jekyll_assets << path
|
35
|
-
environment.find_asset(path)
|
34
|
+
environment.find_asset(path)
|
35
|
+
.jekyll_assets.each { |p| @jekyll_assets << p }
|
36
36
|
end
|
37
37
|
|
38
38
|
__orig_build_dependency_paths environment, context
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
def __wrap_init_with environment, coder
|
41
|
+
def __wrap_init_with(environment, coder)
|
43
42
|
__orig_init_with environment, coder
|
44
|
-
@jekyll_assets = Set.new coder["jekyll_assets"].map{ |p| expand_root_path(p) }
|
45
|
-
end
|
46
43
|
|
44
|
+
@jekyll_assets = Set.new coder["jekyll_assets"]
|
45
|
+
.map { |p| expand_root_path(p) }
|
46
|
+
end
|
47
47
|
|
48
|
-
def __wrap_encode_with
|
48
|
+
def __wrap_encode_with(coder)
|
49
49
|
__orig_encode_with coder
|
50
|
-
|
50
|
+
|
51
|
+
coder["jekyll_assets"] = jekyll_assets.map do |path|
|
52
|
+
relativize_root_path path
|
53
|
+
end
|
51
54
|
end
|
52
55
|
|
56
|
+
::Sprockets::ProcessedAsset.send :include, self
|
53
57
|
end
|
54
58
|
end
|
55
59
|
end
|
56
60
|
end
|
57
|
-
|
58
|
-
|
59
|
-
Sprockets::ProcessedAsset.send :include, Jekyll::AssetsPlugin::Patches::ProcessedAssetPatch
|
@@ -1,64 +1,55 @@
|
|
1
1
|
# stdlib
|
2
2
|
require "digest/md5"
|
3
3
|
|
4
|
-
|
5
4
|
# 3rd-party
|
6
5
|
require "jekyll"
|
7
6
|
|
8
|
-
|
9
7
|
# internal
|
10
8
|
require "jekyll/assets_plugin/configuration"
|
11
9
|
require "jekyll/assets_plugin/environment"
|
12
10
|
require "jekyll/assets_plugin/asset_path"
|
13
11
|
|
14
|
-
|
15
12
|
module Jekyll
|
16
13
|
module AssetsPlugin
|
17
14
|
module Patches
|
18
15
|
module SitePatch
|
19
|
-
|
20
|
-
def self.included base
|
16
|
+
def self.included(base)
|
21
17
|
base.class_eval do
|
22
18
|
alias_method :__orig_write, :write
|
23
19
|
alias_method :write, :__wrap_write
|
24
20
|
end
|
25
21
|
end
|
26
22
|
|
27
|
-
|
28
23
|
def assets_config
|
29
|
-
@assets_config ||= Configuration.new(
|
24
|
+
@assets_config ||= Configuration.new(config["assets"] || {})
|
30
25
|
end
|
31
26
|
|
32
|
-
|
33
27
|
def assets
|
34
28
|
@assets ||= Environment.new self
|
35
29
|
end
|
36
30
|
|
37
|
-
|
38
31
|
def asset_files
|
39
32
|
@asset_files ||= []
|
40
33
|
end
|
41
34
|
|
42
|
-
|
43
|
-
def asset_path pathname, *args
|
35
|
+
def asset_path(pathname, *args)
|
44
36
|
pathname, _, anchor = pathname.rpartition "#" if pathname["#"]
|
45
37
|
pathname, _, query = pathname.rpartition "?" if pathname["?"]
|
46
38
|
|
47
|
-
AssetPath.new
|
48
|
-
|
49
|
-
|
50
|
-
}.to_s
|
51
|
-
end
|
39
|
+
asset_path = AssetPath.new assets[pathname, *args]
|
40
|
+
asset_path.anchor = anchor
|
41
|
+
asset_path.query = query
|
52
42
|
|
43
|
+
asset_path.to_s
|
44
|
+
end
|
53
45
|
|
54
|
-
def bundle_asset!
|
55
|
-
|
46
|
+
def bundle_asset!(asset)
|
47
|
+
unless asset_files.include? asset
|
56
48
|
asset_files << asset
|
57
|
-
asset.jekyll_assets.each{ |path| bundle_asset! assets[path] }
|
49
|
+
asset.jekyll_assets.each { |path| bundle_asset! assets[path] }
|
58
50
|
end
|
59
51
|
end
|
60
52
|
|
61
|
-
|
62
53
|
def __wrap_write
|
63
54
|
static_files.push(*asset_files).uniq! do |asset|
|
64
55
|
case hash = asset.hash
|
@@ -69,11 +60,9 @@ module Jekyll
|
|
69
60
|
|
70
61
|
__orig_write
|
71
62
|
end
|
72
|
-
|
73
63
|
end
|
74
64
|
end
|
75
65
|
end
|
76
66
|
end
|
77
67
|
|
78
|
-
|
79
68
|
Jekyll::Site.send :include, Jekyll::AssetsPlugin::Patches::SitePatch
|
@@ -1,56 +1,47 @@
|
|
1
1
|
module Jekyll
|
2
2
|
module AssetsPlugin
|
3
3
|
class Renderer
|
4
|
-
|
5
4
|
STYLESHEET = '<link rel="stylesheet" href="%s">'
|
6
5
|
JAVASCRIPT = '<script src="%s"></script>'
|
7
6
|
IMAGE = '<img src="%s">'
|
8
7
|
|
9
|
-
|
10
|
-
def initialize context, logical_path
|
8
|
+
def initialize(context, logical_path)
|
11
9
|
@site = context.registers[:site]
|
12
10
|
@path = logical_path.strip
|
13
11
|
end
|
14
12
|
|
15
|
-
|
16
13
|
def render_asset
|
17
14
|
@site.assets[@path].to_s
|
18
15
|
end
|
19
16
|
|
20
|
-
|
21
17
|
def render_asset_path
|
22
18
|
@site.asset_path @path
|
23
19
|
end
|
24
20
|
|
25
|
-
|
26
21
|
def render_javascript
|
27
22
|
@path << ".js" if File.extname(@path).empty?
|
28
23
|
render_tag JAVASCRIPT
|
29
24
|
end
|
30
25
|
|
31
|
-
|
32
26
|
def render_stylesheet
|
33
27
|
@path << ".css" if File.extname(@path).empty?
|
34
28
|
render_tag STYLESHEET
|
35
29
|
end
|
36
30
|
|
37
|
-
|
38
31
|
def render_image
|
39
32
|
render_tag IMAGE
|
40
33
|
end
|
41
34
|
|
42
|
-
|
43
35
|
protected
|
44
36
|
|
45
|
-
|
46
|
-
def render_tag template
|
37
|
+
def render_tag(template)
|
47
38
|
asset = @site.assets[@path]
|
48
|
-
(@site.assets_config.debug ? asset.to_a : [asset]).map
|
49
|
-
template
|
50
|
-
|
51
|
-
end
|
39
|
+
tags = (@site.assets_config.debug ? asset.to_a : [asset]).map do |a|
|
40
|
+
sprintf template, AssetPath.new(a).to_s
|
41
|
+
end
|
52
42
|
|
43
|
+
tags.join "\n"
|
44
|
+
end
|
53
45
|
end
|
54
46
|
end
|
55
47
|
end
|
56
|
-
|
@@ -1,24 +1,19 @@
|
|
1
1
|
# 3rd-party
|
2
2
|
require "liquid"
|
3
3
|
|
4
|
-
|
5
4
|
# internal
|
6
5
|
require "jekyll/assets_plugin/renderer"
|
7
6
|
|
8
|
-
|
9
7
|
module Jekyll
|
10
8
|
module AssetsPlugin
|
11
9
|
class Tag < Liquid::Tag
|
12
|
-
|
13
|
-
def render context
|
10
|
+
def render(context)
|
14
11
|
Renderer.new(context, @markup).send :"render_#{@tag_name}"
|
15
12
|
end
|
16
|
-
|
17
13
|
end
|
18
14
|
end
|
19
15
|
end
|
20
16
|
|
21
|
-
|
22
17
|
%w{ asset asset_path image javascript stylesheet }.each do |tag|
|
23
18
|
Liquid::Template.register_tag tag, Jekyll::AssetsPlugin::Tag
|
24
19
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "jekyll-assets/bootstrap"
|
3
|
-
|
4
|
-
module Jekyll::AssetsPlugin
|
5
|
-
describe "Bootstrap integration" do
|
6
|
-
it "should globally append bootstrap paths into Sprockets environment" do
|
7
|
-
@site.assets["bootstrap.css"].to_s.should =~ /bootstrap\//
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
require "jekyll-assets/bootstrap"
|
3
|
+
|
4
|
+
module Jekyll::AssetsPlugin
|
5
|
+
describe "Bootstrap integration" do
|
6
|
+
it "should globally append bootstrap paths into Sprockets environment" do
|
7
|
+
@site.assets["bootstrap.css"].to_s.should =~ /bootstrap\//
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
3
|
module Jekyll::AssetsPlugin
|
5
4
|
describe Configuration do
|
6
5
|
context "with defaults" do
|
7
|
-
let(:config){ Configuration.new }
|
6
|
+
let(:config) { Configuration.new }
|
8
7
|
|
9
8
|
context "output assets dirname" do
|
10
9
|
subject { config.dirname }
|
@@ -64,10 +63,10 @@ module Jekyll::AssetsPlugin
|
|
64
63
|
:css_compressor => "sass"
|
65
64
|
})
|
66
65
|
|
67
|
-
config.dirname.
|
68
|
-
config.sources.
|
69
|
-
config.js_compressor.
|
70
|
-
config.css_compressor.
|
66
|
+
expect(config.dirname).to eq "assets"
|
67
|
+
expect(config.sources).to eq %w{abc}
|
68
|
+
expect(config.js_compressor).to be_nil
|
69
|
+
expect(config.css_compressor).to be :sass
|
71
70
|
end
|
72
71
|
|
73
72
|
context "#cache" do
|
@@ -96,13 +95,13 @@ module Jekyll::AssetsPlugin
|
|
96
95
|
|
97
96
|
context "#js_compressor" do
|
98
97
|
context "when js compressor is given as `uglify`" do
|
99
|
-
let(:config){ Configuration.new(:js_compressor => "uglify") }
|
98
|
+
let(:config) { Configuration.new(:js_compressor => "uglify") }
|
100
99
|
subject { config.js_compressor }
|
101
100
|
it { should be :uglify }
|
102
101
|
end
|
103
102
|
|
104
103
|
context "otherwise" do
|
105
|
-
let(:config){ Configuration.new }
|
104
|
+
let(:config) { Configuration.new }
|
106
105
|
subject { config.js_compressor }
|
107
106
|
it { should be_false }
|
108
107
|
end
|
@@ -110,13 +109,13 @@ module Jekyll::AssetsPlugin
|
|
110
109
|
|
111
110
|
context "#css_compressor" do
|
112
111
|
context "when css compressor is given as `sass`" do
|
113
|
-
let(:config){ Configuration.new(:css_compressor => "sass") }
|
112
|
+
let(:config) { Configuration.new(:css_compressor => "sass") }
|
114
113
|
subject { config.css_compressor }
|
115
114
|
it { should be :sass }
|
116
115
|
end
|
117
116
|
|
118
117
|
context "otherwise" do
|
119
|
-
let(:config){ Configuration.new }
|
118
|
+
let(:config) { Configuration.new }
|
120
119
|
subject { config.css_compressor }
|
121
120
|
it { should be_false }
|
122
121
|
end
|
@@ -124,26 +123,39 @@ module Jekyll::AssetsPlugin
|
|
124
123
|
|
125
124
|
context "#gzip" do
|
126
125
|
context "when gzip is disabled" do
|
127
|
-
let(:config){ Configuration.new(:gzip => false) }
|
126
|
+
let(:config) { Configuration.new(:gzip => false) }
|
128
127
|
subject { config.gzip }
|
129
128
|
it { should == [] }
|
130
129
|
end
|
131
130
|
end
|
132
131
|
|
132
|
+
context "#version" do
|
133
|
+
subject { Configuration.new(:version => version).version }
|
134
|
+
|
135
|
+
context "when given as 123" do
|
136
|
+
let(:version) { 123 }
|
137
|
+
it { should eq 123 }
|
138
|
+
it { should be_a Integer }
|
139
|
+
end
|
140
|
+
|
141
|
+
context "when given as 'abc'" do
|
142
|
+
let(:version) { "abc" }
|
143
|
+
it { should eq "abc" }
|
144
|
+
it { should be_a String }
|
145
|
+
end
|
146
|
+
end
|
133
147
|
|
134
148
|
context "Deprecated options" do
|
135
149
|
context "compress" do
|
136
|
-
let(:options){ { :compress => {:js => "uglify", :css => "sass"} } }
|
150
|
+
let(:options) { { :compress => { :js => "uglify", :css => "sass" } } }
|
151
|
+
subject { Configuration.new options }
|
137
152
|
|
138
|
-
|
139
|
-
|
140
|
-
config.js_compressor.should == :uglify
|
141
|
-
config.css_compressor.should == :sass
|
142
|
-
end
|
153
|
+
its(:js_compressor) { should be :uglify }
|
154
|
+
its(:css_compressor) { should be :sass }
|
143
155
|
end
|
144
156
|
|
145
157
|
context "cache_assets" do
|
146
|
-
let(:options){ { :cache_assets => true } }
|
158
|
+
let(:options) { { :cache_assets => true } }
|
147
159
|
|
148
160
|
it "should set `cache` value" do
|
149
161
|
config = Configuration.new options
|