jekyll-cdn 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ .rvmrc
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+
4
+ gem 'minitest'
@@ -0,0 +1,55 @@
1
+ ## Purpose
2
+
3
+ Jekyll-cdn makes hosting site assets on a content delivery network smooth
4
+ as butter. It currently provides cache-busting Liquid filters. Expect other
5
+ tools in the future.
6
+
7
+ ## Use
8
+
9
+ ### The Filters
10
+ There are three filters:
11
+
12
+ * `stylesheet_path` - `<asset_path>/stylesheets/<input>?<cache-buster>`
13
+ * `javascript_path` - `<asset_path>/javascripts/<input>?<cache-buster>`
14
+ * `asset_path` - `<asset_path>/<input>?<cache-buster>`
15
+
16
+ Use a filter in your template like so: `{{ 'css_file_name' | stylesheet_path }}`
17
+
18
+ ### Installation and Configuration
19
+
20
+ Run `gem install jekyll-cdn` or add it to your Gemfile. Next add the line
21
+ `require 'jeykll-cdn'` to `_plugins/extensions.rb`.
22
+
23
+ In `_config.yml`, add a base url for your assets:
24
+
25
+ asset_url: http://assets.zeespencer.com/assets
26
+
27
+ You may wish to use different asset urls for local and hosted builds. This is
28
+ accomplished like so:
29
+
30
+ # _config.yml
31
+ asset_url:
32
+ - hosted: http://assets.zeespencer.com/assets
33
+ - local: /assets
34
+
35
+ By default jekyll-cdn assumes you want to build a local version. To build the
36
+ hosted version, use `JEKYLL_ENV=hosted jekyll <other options>`.
37
+
38
+
39
+ ### Contributing
40
+
41
+ * Pull requests will be reviewed within a few days.
42
+ * Pull requests with tests and explaining value to users have top priority.
43
+ * Be kind. I will also be kind.
44
+
45
+
46
+ ### License
47
+
48
+ The MIT License (MIT)
49
+ Copyright (c) 2013 Zee Spencer
50
+
51
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
52
+
53
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift("lib")
2
+ require 'jekyll-cdn/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'jekyll-cdn'
6
+ s.version = Jekyll::CDN::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ['Zee Spencer']
9
+ s.email = ['zee@zeespencer.com']
10
+ s.homepage = 'https://github.com/zspencer/jekyll-cdn'
11
+ s.description = "Jekyll CDN support smooth as butter"
12
+ s.summary = "Jekyll CDN support smooth as butter"
13
+ s.files = `git ls-files`.split("\n")
14
+ s.require_paths = ['lib']
15
+ end
@@ -0,0 +1,35 @@
1
+
2
+ module Jekyll
3
+ module Filters
4
+ def stylesheet_path(stylesheet_name)
5
+ asset_path("stylesheets/#{stylesheet_name}")
6
+ end
7
+
8
+ def javascript_path(javascript_name)
9
+ asset_path("javascripts/#{javascript_name}")
10
+ end
11
+
12
+ def asset_path(asset_sub_path)
13
+ "#{asset_url}/#{asset_sub_path}?#{cache_buster}"
14
+ end
15
+
16
+
17
+ def asset_url
18
+ ENV['JEKYLL_ENV'] ||= "local"
19
+ configured_url = @context.registers[:site].config["asset_url"]
20
+ url = if configured_url.respond_to? :find
21
+ configured_url.find do |h|
22
+ h.keys.include? ENV['JEKYLL_ENV']
23
+ end.fetch(ENV['JEKYLL_ENV'], false)
24
+ else
25
+ configured_url
26
+ end
27
+ url || "/assets"
28
+ end
29
+ private
30
+
31
+ def cache_buster
32
+ Time.now.to_i
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module CDN
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,64 @@
1
+ require 'ostruct'
2
+ require 'yaml'
3
+ require 'minitest/autorun'
4
+
5
+ $LOAD_PATH.unshift("lib")
6
+ require "jekyll-cdn"
7
+
8
+ describe "Jekyll CDN Filters" do
9
+ include Jekyll::Filters
10
+ describe "#stylesheet_path" do
11
+ it "looks like <asset-url>/stylesheets/<file-specified>?<cache-buster>" do
12
+ stub(:asset_url, "/foo") { stub(:cache_buster, "12345") do
13
+ stylesheet_path("bar.css").must_equal("/foo/stylesheets/bar.css?12345")
14
+ end }
15
+ end
16
+ end
17
+
18
+ describe "#javascript_path" do
19
+ it "looks like <asset-url>/javascripts/<file-specified>?<cache-buster>" do
20
+ stub(:asset_url, "/foo") { stub(:cache_buster, "12345") do
21
+ javascript_path("bar.js").must_equal("/foo/javascripts/bar.js?12345")
22
+ end }
23
+ end
24
+ end
25
+
26
+ describe "#asset_path" do
27
+ it "looks like <asset-url>/<file-specified>?<cache-buster>" do
28
+ stub(:asset_url, "/foo") { stub(:cache_buster, "12345") do
29
+ asset_path("bar.mp3").must_equal("/foo/bar.mp3?12345")
30
+ end }
31
+ end
32
+ end
33
+
34
+ describe "#asset_url" do
35
+ def config_with(config)
36
+ site = OpenStruct.new(:config => YAML.load(config))
37
+ @context = OpenStruct.new(:registers => { :site => site })
38
+ end
39
+
40
+ it "sets asset_url to /assets when no asset_url is configured" do
41
+ config_with("no_asset_url: asdf")
42
+ asset_url.must_equal("/assets")
43
+ end
44
+
45
+ it "sets asset_url to the only value when asset_url isn't a list" do
46
+ config_with("asset_url: /asdf")
47
+ asset_url.must_equal("/asdf")
48
+ end
49
+
50
+ it "sets asset_url to the local value when ENV['JEKYLL_ENV'] is undefined" do
51
+ config_with("asset_url:
52
+ - local: /local")
53
+ asset_url.must_equal("/local")
54
+ end
55
+
56
+ it "sets asset_url to the hosted value when ENV['JEKYLL_ENV'] is hosted" do
57
+ ENV['JEKYLL_ENV']='hosted'
58
+ config_with("asset_url:
59
+ - hosted: /hosted")
60
+ asset_url.must_equal("/hosted")
61
+ end
62
+ end
63
+ end
64
+
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-cdn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zee Spencer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Jekyll CDN support smooth as butter
15
+ email:
16
+ - zee@zeespencer.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README.markdown
24
+ - Rakefile
25
+ - jekyll-cdn.gemspec
26
+ - lib/jekyll-cdn.rb
27
+ - lib/jekyll-cdn/version.rb
28
+ - spec/jekyll-cdn_spec.rb
29
+ homepage: https://github.com/zspencer/jekyll-cdn
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.25
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Jekyll CDN support smooth as butter
53
+ test_files: []