middleman-async-loader 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f7f4a3797344054640db69e496a09016770bc886
4
+ data.tar.gz: 89651f7c92e19038b11ed383b4577cc4e04c30c5
5
+ SHA512:
6
+ metadata.gz: 6efe5783a67e5fdfc82d91d39fca4dc6f9ebf44385ec04f9a2eccb2ca567e2ab23bbb7b676ad3d3340918a669d3f769a638ac9c92813407d2e7a63228c98191e
7
+ data.tar.gz: b875e5268897d16e09f3b582b58c1f41a93f67afae62422a53e3eb82d492882b7cbcb3c8945415f83606347ed185509b150f09ee0438a75ac1ae3548dd0a137c
@@ -0,0 +1,41 @@
1
+ require 'middleman-core'
2
+
3
+ class AsyncLoader < Middleman::Extension
4
+ helpers do
5
+ def load_css(*sources)
6
+ bundle_sources(sources, :css)
7
+ end
8
+
9
+ def load_font(*sources)
10
+ bundle_sources(sources, :css, true)
11
+ end
12
+
13
+ def load_js(*sources)
14
+ bundle_sources(sources, :js, true)
15
+ end
16
+
17
+ alias :async_js :load_js
18
+ alias :async_font :load_font
19
+ alias :async_css :load_css
20
+
21
+ private
22
+
23
+ def async_wrap string
24
+ "(function(){#{string}}());"
25
+ end
26
+
27
+ def bundle_sources(sources, type, isFont = false)
28
+ bootstrap() + async_wrap(sources.map { |source|
29
+ "___asl('#{type.to_s}','#{asset_path(type, source)}'#{',true' if isFont});"
30
+ }.reduce(:+))
31
+ end
32
+
33
+ def bootstrap
34
+ return "" if @has_loaded == true
35
+ @has_loaded = true
36
+ "window.___asl=function(t,f,wf){var d=document,e=d.createElement(t=='css'?'link':'script');e[t=='css'?'href':'src']=f;e[t=='css'?'rel':'type']=t=='css'?'stylesheet':'text/javascript';if(wf){e.rel='subresource'};d.body.appendChild(e)};"
37
+ end
38
+ end
39
+ end
40
+
41
+ AsyncLoader.register(:async_loader)
@@ -0,0 +1 @@
1
+ require 'middleman-async-loader'
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-async-loader
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Julian Krispel-Samsel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Inline JS and CSS in just one line.
14
+ email: julian@rainforestapp.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/middleman-async-loader.rb
20
+ - lib/middleman_extension.rb
21
+ homepage: https://github.com/rainforestapp/middleman-async-loader
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.5.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Inline JS and CSS in just one line.
45
+ test_files: []