octopress-ink 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/assets/js/loadCSS.js +52 -0
- data/lib/octopress-ink.rb +1 -1
- data/lib/octopress-ink/assets/coffeescript.rb +3 -2
- data/lib/octopress-ink/assets/javascript.rb +5 -1
- data/lib/octopress-ink/assets/stylesheet.rb +5 -1
- data/lib/octopress-ink/configuration.rb +2 -0
- data/lib/octopress-ink/plugin_asset_pipeline.rb +51 -8
- data/lib/octopress-ink/plugins.rb +3 -3
- data/lib/octopress-ink/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e180ab69ca97fb343d48d3a0665e16ad6c5e6963
|
4
|
+
data.tar.gz: 5e700849429a751dd528724d2be1f504ff500871
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31e72d34e77edd8bee81c158b22e89f93cd9acd81d5e8c59a8f3bc5d47579cbd3f9825ed3170b1b38a5ce77317819acb4ec5798df999e8d5b0c0db717c709542
|
7
|
+
data.tar.gz: 4deec11c178c1331b3276ce878713128aac70a4afd9003ec91e67f2a1063388e38e70e58ebed2a0b75e8019fbf11f85f2fb4ca4c6cdfb44654ffdee981d5ea5b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### 1.1.0 (2015-05-03)
|
4
|
+
- New: Added support for asynchronous stylesheet loading. [#56](https://github.com/octopress/ink/pull/56)
|
5
|
+
- New: Now loading combined javascripts asynchronously by default.
|
6
|
+
|
3
7
|
## 1.0.0 - 2015-05-02
|
4
8
|
- Minor: Improved styling for Octopress Ink list command output.
|
5
9
|
- Minor: Fixed issue where changelog couldn't be processed by Octopress Docs.
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/*!
|
2
|
+
loadCSS: load a CSS file asynchronously.
|
3
|
+
[c]2014 @scottjehl, Filament Group, Inc.
|
4
|
+
Licensed MIT
|
5
|
+
*/
|
6
|
+
|
7
|
+
/* exported loadCSS */
|
8
|
+
function loadCSS( href, before, media, callback ){
|
9
|
+
"use strict";
|
10
|
+
// Arguments explained:
|
11
|
+
// `href` is the URL for your CSS file.
|
12
|
+
// `before` optionally defines the element we'll use as a reference for injecting our <link>
|
13
|
+
// By default, `before` uses the first <script> element in the page.
|
14
|
+
// However, since the order in which stylesheets are referenced matters, you might need a more specific location in your document.
|
15
|
+
// If so, pass a different reference element to the `before` argument and it'll insert before that instead
|
16
|
+
// note: `insertBefore` is used instead of `appendChild`, for safety re: http://www.paulirish.com/2011/surefire-dom-element-insertion/
|
17
|
+
var ss = window.document.createElement( "link" );
|
18
|
+
var ref = before || window.document.getElementsByTagName( "script" )[ 0 ];
|
19
|
+
var sheets = window.document.styleSheets;
|
20
|
+
ss.rel = "stylesheet";
|
21
|
+
ss.href = href;
|
22
|
+
// temporarily, set media to something non-matching to ensure it'll fetch without blocking render
|
23
|
+
ss.media = "only x";
|
24
|
+
// DEPRECATED
|
25
|
+
if( callback ) {
|
26
|
+
ss.onload = callback;
|
27
|
+
}
|
28
|
+
|
29
|
+
// inject link
|
30
|
+
ref.parentNode.insertBefore( ss, ref );
|
31
|
+
// This function sets the link's media back to `all` so that the stylesheet applies once it loads
|
32
|
+
// It is designed to poll until document.styleSheets includes the new sheet.
|
33
|
+
ss.onloadcssdefined = function( cb ){
|
34
|
+
var defined;
|
35
|
+
for( var i = 0; i < sheets.length; i++ ){
|
36
|
+
if( sheets[ i ].href && sheets[ i ].href.indexOf( href ) > -1 ){
|
37
|
+
defined = true;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
if( defined ){
|
41
|
+
cb();
|
42
|
+
} else {
|
43
|
+
setTimeout(function() {
|
44
|
+
ss.onloadcssdefined( cb );
|
45
|
+
});
|
46
|
+
}
|
47
|
+
};
|
48
|
+
ss.onloadcssdefined(function() {
|
49
|
+
ss.media = media || "all";
|
50
|
+
});
|
51
|
+
return ss;
|
52
|
+
}
|
data/lib/octopress-ink.rb
CHANGED
@@ -2,8 +2,9 @@ module Octopress
|
|
2
2
|
module Ink
|
3
3
|
module Assets
|
4
4
|
class Coffeescript < Javascript
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
def tag_path
|
7
|
+
Filters.expand_url(File.join(dir, File.basename(file, '.*') << '.js'))
|
7
8
|
end
|
8
9
|
|
9
10
|
def add
|
@@ -3,7 +3,11 @@ module Octopress
|
|
3
3
|
module Assets
|
4
4
|
class Javascript < Asset
|
5
5
|
def tag
|
6
|
-
%Q{<script src="#{
|
6
|
+
%Q{<script src="#{tag_path}"></script>}
|
7
|
+
end
|
8
|
+
|
9
|
+
def tag_path
|
10
|
+
Filters.expand_url(File.join(dir, file))
|
7
11
|
end
|
8
12
|
|
9
13
|
def add
|
@@ -27,7 +27,11 @@ module Octopress
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def tag
|
30
|
-
%Q{<link href="#{
|
30
|
+
%Q{<link href="#{tag_path}" media="#{media}" rel="stylesheet" type="text/css">}
|
31
|
+
end
|
32
|
+
|
33
|
+
def tag_path
|
34
|
+
Filters.expand_url(File.join(dir, output_file_name))
|
31
35
|
end
|
32
36
|
|
33
37
|
def add
|
@@ -10,9 +10,9 @@ module Octopress
|
|
10
10
|
@javascripts = nil
|
11
11
|
@uglify_settings = nil
|
12
12
|
@combined_js = ''
|
13
|
-
@combined_stylesheets = nil
|
14
13
|
@stylesheet_fingerprint = {}
|
15
14
|
@javascript_fingerprint = nil
|
15
|
+
@uglify_settings ||= Jekyll::Utils.symbolize_hash_keys(Ink.configuration['asset_pipeline']['uglifier'])
|
16
16
|
end
|
17
17
|
|
18
18
|
# Compile CSS to take advantage of Sass's compression settings
|
@@ -55,20 +55,60 @@ module Octopress
|
|
55
55
|
|
56
56
|
# Return a link tag, for all plugins' stylesheets
|
57
57
|
#
|
58
|
+
def stylesheet_tag
|
59
|
+
if Ink.configuration['asset_pipeline']['async_css']
|
60
|
+
async_stylesheet_tag
|
61
|
+
else
|
62
|
+
combined_stylesheet_tag
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
58
66
|
def combined_stylesheet_tag
|
59
67
|
tags = ''
|
60
|
-
|
61
|
-
tags.concat "<link href='#{
|
68
|
+
combined_stylesheet_urls.each do |media, url|
|
69
|
+
tags.concat "<link href='#{url}' media='#{media}' rel='stylesheet' type='text/css'>"
|
62
70
|
end
|
63
71
|
tags
|
64
72
|
end
|
65
73
|
|
66
|
-
def
|
74
|
+
def async_stylesheet_tag
|
75
|
+
js = uglify(File.read(Ink.gem_dir('assets','js','loadCSS.js')))
|
76
|
+
%Q{<script>#{js}\n#{load_css}\n</script>\n<noscript>#{combined_stylesheet_tag}</noscript>}
|
77
|
+
end
|
78
|
+
|
79
|
+
def load_css
|
80
|
+
script = ''
|
81
|
+
combined_stylesheet_urls.each do |media, url|
|
82
|
+
script << %Q{loadCSS("#{url}", null, "#{media}")\n}
|
83
|
+
end
|
84
|
+
script
|
85
|
+
end
|
86
|
+
|
87
|
+
def combined_stylesheet_urls
|
88
|
+
urls = {}
|
89
|
+
combine_stylesheets.keys.each do |media|
|
90
|
+
urls[media] = combined_stylesheet_url(media)
|
91
|
+
end
|
92
|
+
urls
|
93
|
+
end
|
94
|
+
|
95
|
+
def combined_stylesheet_url(media)
|
96
|
+
Filters.expand_url(combined_stylesheet_path(media))
|
97
|
+
end
|
98
|
+
|
99
|
+
def javascript_tag
|
67
100
|
unless @combined_js == ''
|
68
|
-
|
101
|
+
if Ink.configuration['asset_pipeline']['async_js']
|
102
|
+
"<script async src='#{combined_javascript_url}'></script>"
|
103
|
+
else
|
104
|
+
"<script src='#{combined_javascript_url}'></script>"
|
105
|
+
end
|
69
106
|
end
|
70
107
|
end
|
71
108
|
|
109
|
+
def combined_javascript_url
|
110
|
+
Filters.expand_url(combined_javascript_path)
|
111
|
+
end
|
72
112
|
|
73
113
|
# Combine stylesheets from each plugin
|
74
114
|
#
|
@@ -80,6 +120,7 @@ module Octopress
|
|
80
120
|
@combined_stylesheets ||= begin
|
81
121
|
combined = {}
|
82
122
|
|
123
|
+
|
83
124
|
stylesheets.clone.each do |media,files|
|
84
125
|
files.each do |file|
|
85
126
|
header = "/* #{file.plugin.type.capitalize}: #{file.plugin.name} */"
|
@@ -148,12 +189,10 @@ module Octopress
|
|
148
189
|
javascripts.each do |file|
|
149
190
|
|
150
191
|
js = if compress_js?(file)
|
151
|
-
@uglify_settings ||= Jekyll::Utils.symbolize_hash_keys(Ink.configuration['asset_pipeline']['uglifier'])
|
152
|
-
|
153
192
|
if cached = Cache.read_cache(file, @uglify_settings)
|
154
193
|
cached
|
155
194
|
else
|
156
|
-
js =
|
195
|
+
js = uglify(file.content)
|
157
196
|
Cache.write_to_cache(file, js, @uglify_settings)
|
158
197
|
end
|
159
198
|
else
|
@@ -172,6 +211,10 @@ module Octopress
|
|
172
211
|
end
|
173
212
|
end
|
174
213
|
|
214
|
+
def uglify(js)
|
215
|
+
Uglifier.new(@uglify_settings).compile(js)
|
216
|
+
end
|
217
|
+
|
175
218
|
def compress_js?(file)
|
176
219
|
Ink.configuration['asset_pipeline']['compress_js'] && !file.path.end_with?('.min.js')
|
177
220
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Octopress
|
2
2
|
module Ink
|
3
3
|
module Plugins
|
4
|
-
attr_reader :registered
|
4
|
+
attr_reader :registered, :css_asset_paths, :js_asset_paths
|
5
5
|
extend self
|
6
6
|
|
7
7
|
@registered = false
|
@@ -150,7 +150,7 @@ module Octopress
|
|
150
150
|
|
151
151
|
def css_tags
|
152
152
|
if Ink.configuration['asset_pipeline']['combine_css']
|
153
|
-
PluginAssetPipeline.
|
153
|
+
PluginAssetPipeline.stylesheet_tag
|
154
154
|
else
|
155
155
|
@css_tags.join('')
|
156
156
|
end
|
@@ -158,7 +158,7 @@ module Octopress
|
|
158
158
|
|
159
159
|
def js_tags
|
160
160
|
if Ink.configuration['asset_pipeline']['combine_js']
|
161
|
-
PluginAssetPipeline.
|
161
|
+
PluginAssetPipeline.javascript_tag
|
162
162
|
else
|
163
163
|
@js_tags.join('')
|
164
164
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octopress-ink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -222,6 +222,7 @@ files:
|
|
222
222
|
- assets/docs/index.markdown
|
223
223
|
- assets/docs/plugin-reference.markdown
|
224
224
|
- assets/docs/working-with-plugins.markdown
|
225
|
+
- assets/js/loadCSS.js
|
225
226
|
- lib/octopress-ink.rb
|
226
227
|
- lib/octopress-ink/assets.rb
|
227
228
|
- lib/octopress-ink/assets/asset.rb
|