jekyll-asset-pipeline 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README.md +239 -0
- data/lib/jekyll_asset_pipeline/asset_file.rb +8 -0
- data/lib/jekyll_asset_pipeline/bundler.rb +150 -0
- data/lib/jekyll_asset_pipeline/compressor.rb +32 -0
- data/lib/jekyll_asset_pipeline/converter.rb +36 -0
- data/lib/jekyll_asset_pipeline/css_asset_tag.rb +19 -0
- data/lib/jekyll_asset_pipeline/extendable.rb +13 -0
- data/lib/jekyll_asset_pipeline/javascript_asset_tag.rb +19 -0
- data/lib/jekyll_asset_pipeline/template.rb +29 -0
- data/lib/jekyll_asset_pipeline/templates/css_tag_template.rb +16 -0
- data/lib/jekyll_asset_pipeline/templates/javascript_tag_template.rb +16 -0
- data/lib/jekyll_asset_pipeline.rb +34 -0
- metadata +89 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2012 Matt Hodan (http://www.matthodan.com)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,239 @@
|
|
1
|
+
# Jekyll Asset Pipeline
|
2
|
+
|
3
|
+
Jekyll Asset Pipeline collects, converts and minifies your project’s JavaScript and CSS assets.
|
4
|
+
|
5
|
+
|
6
|
+
## Table of Contents
|
7
|
+
|
8
|
+
- [Getting Started](#getting-started)
|
9
|
+
- [Asset Compression](#asset-compression)
|
10
|
+
- [Asset Preprocessing](#asset-preprocessing)
|
11
|
+
- [Templates](#templates)
|
12
|
+
- [Configuration](#configuration)
|
13
|
+
|
14
|
+
## Getting Started
|
15
|
+
|
16
|
+
Jekyll Asset Pipeline is extremely easy to add to your Jekyll project and has no incremental dependacies beyond those already required by Jekyll. Once you have a basic Jekyll site up and running, simply follow the following steps to install and configure Jekyll Asset Pipeline.
|
17
|
+
|
18
|
+
Install the "jekyll-asset-pipeline" gem via [Rubygems](http://rubygems.org/).
|
19
|
+
|
20
|
+
``` bash
|
21
|
+
gem install jekyll-asset-pipeline
|
22
|
+
```
|
23
|
+
|
24
|
+
> *If you are using [Bundler](http://gembundler.com/) to manage your project's gems, you can just add "jekyll-asset-pipeline" to your Gemfile and run `bundle install`.*
|
25
|
+
|
26
|
+
Add a "_plugins" folder to your project (if you do not already have one). Within the "_plugins" folder, add a file named "jekyll_asset_pipeline.rb" with the following code.
|
27
|
+
|
28
|
+
``` ruby
|
29
|
+
require 'jekyll_asset_pipeline'
|
30
|
+
```
|
31
|
+
|
32
|
+
Add a "_assets" folder to your project and copy your JavaScript and CSS assets into the folder. We want Jekyll to ignore these files since we will be including these files via a bundle that is generated by Jekyll Asset Pipeline.
|
33
|
+
|
34
|
+
In the HTML "head" section of your default layout (or other HTML page) of your Jekyll site, add one or both of the following [Liquid](http://liquidmarkup.org/) blocks and replace "foo" and "bar" with your asset files. These blocks will be converted into HTML "link" and "script" tags that point to the bundled asset files. The manifest must be a properly formatted YAML array and must include paths to your raw assets from the root folder of your project.
|
35
|
+
|
36
|
+
``` html
|
37
|
+
{% raw %}{% css_asset_tag global %}
|
38
|
+
- /_assets/foo.css
|
39
|
+
- /_assets/bar.css
|
40
|
+
{% endcss_asset_tag %}{% endraw %}
|
41
|
+
|
42
|
+
{% raw %}{% javascript_asset_tag global %}
|
43
|
+
- /_assets/foo.js
|
44
|
+
- /_assets/bar.js
|
45
|
+
{% endjavascript_asset_tag %}{% endraw %}
|
46
|
+
```
|
47
|
+
|
48
|
+
> *The above example will create two bundles, a CSS bundle named "global-md5hash.css" and a JavaScript bundle named "global-md5hash.js" that include their respective assets per the manifest.*
|
49
|
+
|
50
|
+
Run the `jekyll` command so that Jekyll compiles your site. You should see an output that includes the following Jekyll Asset Pipeline status messages.
|
51
|
+
|
52
|
+
``` bash
|
53
|
+
Asset Pipeline: Compiling bundle... compiled 'global-md5hash.css'.
|
54
|
+
Asset Pipeline: Compiling bundle... compiled 'global-md5hash.js'.
|
55
|
+
```
|
56
|
+
|
57
|
+
> *If you do not see these messages, check that you have __not__ set Jekyll's "safe" option to "true" via a "_config.yml" file. If the "safe" option is set to "true", Jekyll will not run third-party plugins.*
|
58
|
+
|
59
|
+
That's it! You now have an asset pipeline. Look in the "_site" folder of your project and you should see an "assets" folder that contains the bundled assets. You should also see tags that point to these assets in your HTML markup where you included the Liquid blocks.
|
60
|
+
|
61
|
+
## Asset Compression
|
62
|
+
|
63
|
+
Adding compression with your favorite minification library is trivial with Jekyll Asset Pipeline. In the following example, we will add a custom compressor extension that uses Yahoo's YUI Compressor to compress our CSS and JavaScript assets.
|
64
|
+
|
65
|
+
In the "jekyll_asset_pipeline.rb" file that we created in the "Getting Started" section of this post, add the following code to the end of the file (i.e. after the "require" statement we added previously).
|
66
|
+
|
67
|
+
``` ruby
|
68
|
+
module JekyllAssetPipeline
|
69
|
+
class CssCompressor < JekyllAssetPipeline::Compressor
|
70
|
+
require 'yui/compressor'
|
71
|
+
|
72
|
+
def self.filetype
|
73
|
+
'.css'
|
74
|
+
end
|
75
|
+
|
76
|
+
def compress
|
77
|
+
return YUI::CssCompressor.new.compress(@content)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class JavaScriptCompressor < JekyllAssetPipeline::Compressor
|
82
|
+
require 'yui/compressor'
|
83
|
+
|
84
|
+
def self.filetype
|
85
|
+
'.js'
|
86
|
+
end
|
87
|
+
|
88
|
+
def compress
|
89
|
+
return YUI::JavaScriptCompressor.new(munge: true).compress(@content)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
The above code adds a CSS and a JavaScript compressor. You can name the class of a compressor anything as long as it inherits from "JekyllAssetPipeline::Compressor".
|
96
|
+
|
97
|
+
The "self.filetype" method defines the type of asset a compressor will process (either '.js' or '.css'). The "compress" method is where the magic happens. A "@content" instance variable that contains the raw content of our bundle is made available within the compressor. The compressor should process this content and return the processed content (as a string) via a "compress" method.
|
98
|
+
|
99
|
+
If you haven't already, you should now install any dependencies that are required by your compressor. In our case, we need to install the "yui-compressor" gem.
|
100
|
+
|
101
|
+
``` ruby
|
102
|
+
gem install yui-compressor
|
103
|
+
```
|
104
|
+
|
105
|
+
> *If you are using [Bundler](http://gembundler.com/) to manage your project's gems, you can just add "yui-compressor" to your Gemfile and run `bundle install`.*
|
106
|
+
|
107
|
+
Run the `jekyll` command so that Jekyll compiles your site.
|
108
|
+
|
109
|
+
That's it! Your asset pipeline should have compressed your CSS and JavaScript assets. You can verify that this is the case by looking at the contents of the bundles generated in the "_site/assets" folder of your project.
|
110
|
+
|
111
|
+
## Asset Preprocessing
|
112
|
+
|
113
|
+
Asset preprocessing (i.e. conversion) allows us to write our assets in languages such as [CoffeeScript](http://coffeescript.org/), [Sass](http://sass-lang.com/), or any other language we like. Adding asset preprocessing is trivial with Jekyll Asset Pipeline. In the following example, we will add a custom converter extension that converts CoffeeScript into JavaScript.
|
114
|
+
|
115
|
+
### CoffeeScript
|
116
|
+
|
117
|
+
In the "jekyll_asset_pipeline.rb" file that we created in the "Getting Started" section of this post, add the following code to the end of the file (i.e. after the "require" statement we added previously).
|
118
|
+
|
119
|
+
``` ruby
|
120
|
+
module JekyllAssetPipeline
|
121
|
+
class CoffeeScriptConverter < JekyllAssetPipeline::Converter
|
122
|
+
require 'coffee-script'
|
123
|
+
|
124
|
+
def self.filetype
|
125
|
+
'.coffee'
|
126
|
+
end
|
127
|
+
|
128
|
+
def convert
|
129
|
+
return CoffeeScript.compile(@content)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
```
|
134
|
+
|
135
|
+
> *If you already added a compressor, you can include your converter class alongside your compressor within the same JekyllAssetPipeline module.*
|
136
|
+
|
137
|
+
The above code adds a CoffeeScript converter. You can name the class of a converter anything as long as it inherits from "JekyllAssetPipeline::Converter".
|
138
|
+
|
139
|
+
The "self.filetype" method defines the type of asset a converter will process (e.g. ".coffee" for CoffeeScript) based on the extension of the raw asset file. The "convert" method is where the magic happens. A "@content" instance variable that contains the raw content of our asset is made available within the converter. The converter should process this content and return the processed content (as a string) via a "convert" method.
|
140
|
+
|
141
|
+
If you haven't already, you should now install any dependancies that are required by your converter. In our case, we need to install the "coffee-script" gem.
|
142
|
+
|
143
|
+
``` bash
|
144
|
+
gem install coffee-script
|
145
|
+
```
|
146
|
+
|
147
|
+
> *If you are using [Bundler](http://gembundler.com/) to manage your project's gems, you can just add "coffee-script" to your Gemfile and run `bundle install`.*
|
148
|
+
|
149
|
+
Run the `jekyll` command so that Jekyll compiles your site.
|
150
|
+
|
151
|
+
That's it! Your asset pipeline should have converted any CoffeeScript assets into JavaScript and included them in their respective bundle. You may need to disable compression (if you added a compressor) to be able to clearly view the result.
|
152
|
+
|
153
|
+
### SASS
|
154
|
+
|
155
|
+
You probably get the gist of how compressors work, but I thought I'd add an example showing how to add a SASS converter as well.
|
156
|
+
|
157
|
+
``` ruby
|
158
|
+
module JekyllAssetPipeline
|
159
|
+
class SassConverter < JekyllAssetPipeline::Converter
|
160
|
+
require 'sass'
|
161
|
+
|
162
|
+
def self.filetype
|
163
|
+
'.scss'
|
164
|
+
end
|
165
|
+
|
166
|
+
def convert
|
167
|
+
return Sass::Engine.new(@content, syntax: :scss).render
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
```
|
172
|
+
|
173
|
+
> *Don't forget to install the "sass" gem before you run the `jekyll` command since our SASS converter requires this library as a dependency.*
|
174
|
+
|
175
|
+
## Templates
|
176
|
+
|
177
|
+
When Jekyll Asset Pipeline creates a bundle, it returns an HTML tag that points to the bundled file. This tag is either a "link" tag for CSS or a "script" tag for JavaScript. Under most circumstances the default tags will suffice, but you may want to customize this output for special cases (e.g. if you want to use CSS media types).
|
178
|
+
|
179
|
+
In the following example, we will override the default CSS link tag by adding a custom template that produces a link tag with a "media" attribute.
|
180
|
+
|
181
|
+
In the "jekyll_asset_pipeline.rb" file that we created in the "Getting Started" section of this post, add the following code to the end of the file (i.e. after the "require" statement we added previously).
|
182
|
+
|
183
|
+
``` ruby
|
184
|
+
module JekyllAssetPipeline
|
185
|
+
class CssTagTemplate < JekyllAssetPipeline::Template
|
186
|
+
def self.filetype
|
187
|
+
'.css'
|
188
|
+
end
|
189
|
+
|
190
|
+
def html
|
191
|
+
"<link href='/#{@path}/#{@filename}' rel='stylesheet' type='text/css' media='screen' />\n"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
```
|
196
|
+
|
197
|
+
> *If you already added a compressor and/or a converter, you can include your template class alongside your compressor and/or converter within the same JekyllAssetPipeline module.*
|
198
|
+
|
199
|
+
The “self.filetype” method defines the type of bundle a template will target (either ".js" or ".css"). The “html” method is where the magic happens. “@path” and "@filename" instance variables are available within the class and contain the path and filename of the generated bundle, respectively. The template should return a string that contains an HTML tag pointing to the generated bundle via an "html" method.
|
200
|
+
|
201
|
+
Run the `jekyll` command so that Jekyll compiles your site.
|
202
|
+
|
203
|
+
That’s it! Your asset pipeline should now use your template to generate a HTML "link" tag that includes a media attribute with the value "screen". You can verify this is the case by viewing the generated source within your project's "_site" folder.
|
204
|
+
|
205
|
+
## Configuration
|
206
|
+
|
207
|
+
Jekyll Asset Pipeline provides the following two configuration options that can be controled by adding the following to the end of your project's "_config.yml" file.
|
208
|
+
|
209
|
+
``` yaml
|
210
|
+
asset_pipeline:
|
211
|
+
compress: true # Default = true
|
212
|
+
output_path: assets # Default = assets
|
213
|
+
```
|
214
|
+
|
215
|
+
> *If you don't have a "_config.yml" file, consider reading the [configuration section](https://github.com/mojombo/jekyll/wiki/Configuration) of the Jekyll documentation.*
|
216
|
+
|
217
|
+
The "compress" setting tells Jekyll Asset Pipeline whether or not to compress the bundled assets. It is useful to set this setting to "false" while you are debugging your site's JavaScript. The "output_path" setting defines where generated bundles should be saved within the "_site" folder of your project.
|
218
|
+
|
219
|
+
## Contribute
|
220
|
+
|
221
|
+
You can contribute to the Jekyll Asset Pipeline by submitting a pull request [via GitHub](https://github.com/matthodan/jekyll-asset-pipeline).
|
222
|
+
|
223
|
+
Key areas that I have identified for future improvement include:
|
224
|
+
|
225
|
+
- __Tests, tests, tests.__ I'm embarassed to say that I didn't write a single test while building Jekyll Asset Pipeline. This started as a hack for my blog and quickly grew into a library as I tweaked it to support my own needs.
|
226
|
+
- __Handle remote assets.__ Right now, Jekyll Asset Bundler does not provide any way to include remote assets in bundles unless you save them locally before generating your site. Moshen's [Jekyll Asset Bundler](https://github.com/moshen/jekyll-asset_bundler) allows you to include remote assets, which I thought was pretty interesting. That said, I think it is generally better to keep remote assets separate so that they load asynchronously.
|
227
|
+
- __Documentation.__ I wrote this readme to introduce people to Jekyll Asset Pipeline, but there should be a set of docs located on Github that can be better maintained.
|
228
|
+
- __Successive preprocessing.__ Currently you can only preprocess a file once. It would be better if you could run an asset through multiple preprocessors before it gets compressed and bundled.
|
229
|
+
|
230
|
+
Feel free to [message me on GitHub](http://github.com/matthodan) if you want to run an idea by me.
|
231
|
+
|
232
|
+
## Credits
|
233
|
+
|
234
|
+
As I was building Jekyll Asset Pipeline, I came across a number of tools that I was able to draw inspiration and best practices from, but one stood out in particular... I have to give credit to [Moshen](https://github.com/moshen/) for creating the [Jekyll Asset Bundler](https://github.com/moshen/jekyll-asset_bundler).
|
235
|
+
|
236
|
+
Jekyll Asset Bundler *almost* covered all of my needs when I set out to find an asset pipeline solution for my blog. The big missing features in my opinion were support for CoffeeScript and Sass. It also lacked a way to easily add new preprocessors that would have let me easily add support for these converters.
|
237
|
+
|
238
|
+
I also have to give credit to [Mojombo](https://github.com/mojombo) for creating [Jekyll](https://github.com/mojombo/jekyll) in the first place.
|
239
|
+
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
class Bundler
|
3
|
+
def initialize(site, prefix, manifest, type)
|
4
|
+
@site = site
|
5
|
+
@prefix = prefix
|
6
|
+
@manifest = manifest
|
7
|
+
@type = type
|
8
|
+
|
9
|
+
# Initialize configuration hash
|
10
|
+
overrides = @site.config['asset_pipeline']
|
11
|
+
if overrides.is_a? Hash
|
12
|
+
@config = JekyllAssetPipeline::DEFAULTS.merge(overrides)
|
13
|
+
else
|
14
|
+
@config = JekyllAssetPipeline::DEFAULTS
|
15
|
+
end
|
16
|
+
|
17
|
+
self.process
|
18
|
+
end
|
19
|
+
|
20
|
+
# Bundle assets into new file or fetch previously bundled file from cache
|
21
|
+
def process
|
22
|
+
@@cache ||= {}
|
23
|
+
|
24
|
+
self.extract
|
25
|
+
self.collect
|
26
|
+
self.hashify
|
27
|
+
|
28
|
+
if @@cache.has_key?(@hash)
|
29
|
+
print "Asset Pipeline: Using cached bundle..."
|
30
|
+
@file = @@cache[@hash]
|
31
|
+
|
32
|
+
# Prevent Jekyll from cleaning up bundle file
|
33
|
+
@site.static_files << JekyllAssetPipeline::AssetFile.new(@site, @site.dest, @config['output_path'], filename)
|
34
|
+
puts " used '#{@prefix}-#{@hash[0, 6]}#{@type}'."
|
35
|
+
else
|
36
|
+
print "Asset Pipeline: Compiling bundle..."
|
37
|
+
|
38
|
+
# Create directories if necessary
|
39
|
+
path = "#{@site.dest}/#{@config['output_path']}"
|
40
|
+
FileUtils::mkpath(path) unless File.directory?(path)
|
41
|
+
|
42
|
+
# Create bundle file
|
43
|
+
self.convert
|
44
|
+
self.bundle
|
45
|
+
self.compress if @config['compress']
|
46
|
+
|
47
|
+
@file = File.new(File.join(@site.dest, @config['output_path'], filename), "w")
|
48
|
+
@file.write(@bundled)
|
49
|
+
@file.close
|
50
|
+
|
51
|
+
# Prevent Jekyll from cleaning up bundle file
|
52
|
+
@site.static_files << JekyllAssetPipeline::AssetFile.new(@site, @site.dest, @config['output_path'], filename)
|
53
|
+
|
54
|
+
# Save generated file to cache
|
55
|
+
@@cache[@hash] = @file
|
56
|
+
|
57
|
+
puts " compiled '#{@prefix}-#{@hash[0, 6]}#{@type}'."
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Extract asset paths from YAML manifest
|
62
|
+
def extract
|
63
|
+
begin
|
64
|
+
@assets = YAML::load(@manifest)
|
65
|
+
rescue Exception => e
|
66
|
+
puts "Asset Pipeline: Failed to read YAML manifest."
|
67
|
+
raise e
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Collect assets from various sources
|
72
|
+
def collect
|
73
|
+
@assets.map! do |path|
|
74
|
+
begin
|
75
|
+
file = File.open(File.join(@site.source, path))
|
76
|
+
rescue Exception => e
|
77
|
+
puts "Asset Pipeline: Failed to open asset file."
|
78
|
+
raise e
|
79
|
+
end
|
80
|
+
file
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Generate a hash id based on asset file paths and last modified dates
|
85
|
+
def hashify
|
86
|
+
payload = @assets.map do |file|
|
87
|
+
"#{file.path}-#{@config['compress'].to_s}-#{file.mtime.to_i.to_s}"
|
88
|
+
end
|
89
|
+
@hash = Digest::MD5.hexdigest(payload.join)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Search for a Converter to use to convert a file based on the file extension
|
93
|
+
def convert
|
94
|
+
@assets.map! do |file|
|
95
|
+
converter_klass = JekyllAssetPipeline::Converter.subclasses.select do |c|
|
96
|
+
c.filetype == File.extname(file).downcase
|
97
|
+
end.last
|
98
|
+
|
99
|
+
converted = nil
|
100
|
+
unless converter_klass.nil?
|
101
|
+
converter = converter_klass.new(file)
|
102
|
+
converted = converter.converted
|
103
|
+
else
|
104
|
+
converted = file.read
|
105
|
+
end
|
106
|
+
converted
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Bundle all of the separate asset files into one big file
|
111
|
+
def bundle
|
112
|
+
@bundled = @assets.join("\n")
|
113
|
+
end
|
114
|
+
|
115
|
+
# Search for a Compressor to use to compress a file based on the output type
|
116
|
+
def compress
|
117
|
+
compressor_klass = JekyllAssetPipeline::Compressor.subclasses.select do |c|
|
118
|
+
c.filetype == @type
|
119
|
+
end.last
|
120
|
+
|
121
|
+
unless compressor_klass.nil?
|
122
|
+
compressor = compressor_klass.new(@bundled)
|
123
|
+
@bundled = compressor.compressed
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Return filename of bundle
|
128
|
+
def filename
|
129
|
+
"#{@prefix}-#{@hash}#{@type}"
|
130
|
+
end
|
131
|
+
|
132
|
+
# Return an HTML tag that points to the bundle file
|
133
|
+
def html_tag
|
134
|
+
path = @config['output_path']
|
135
|
+
|
136
|
+
template_klass = JekyllAssetPipeline::Template.subclasses.select do |t|
|
137
|
+
t.filetype == @type
|
138
|
+
end.sort! { |a, b| b.priority <=> a.priority }.last
|
139
|
+
|
140
|
+
template = nil
|
141
|
+
unless template_klass.nil?
|
142
|
+
template = template_klass.new(path, filename)
|
143
|
+
@html_tag = template.html
|
144
|
+
else
|
145
|
+
# Return link to file if no template exists
|
146
|
+
return "<a href='/#{path}/#{filename}'>AssetPipeline: No template available for '#{filename}'</a>"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
class Compressor < JekyllAssetPipeline::Extendable
|
3
|
+
def initialize(content)
|
4
|
+
@content = content
|
5
|
+
begin
|
6
|
+
@compressed = self.compress
|
7
|
+
rescue Exception => e
|
8
|
+
puts "Failed to compress asset with '#{self.class.to_s}'."
|
9
|
+
raise e
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def compressed
|
14
|
+
@compressed
|
15
|
+
end
|
16
|
+
|
17
|
+
# Filetype to process (e.g. '.js')
|
18
|
+
def self.filetype
|
19
|
+
''
|
20
|
+
end
|
21
|
+
|
22
|
+
# Logic to compress assets
|
23
|
+
#
|
24
|
+
# Available instance variables:
|
25
|
+
# @content Content to be compressed
|
26
|
+
#
|
27
|
+
# Returns compressed string
|
28
|
+
def compress
|
29
|
+
@content
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
class Converter < JekyllAssetPipeline::Extendable
|
3
|
+
def initialize(file)
|
4
|
+
@file = file
|
5
|
+
@content = file.read
|
6
|
+
@type = File.extname(@file).downcase
|
7
|
+
begin
|
8
|
+
@converted = self.convert
|
9
|
+
rescue Exception => e
|
10
|
+
puts "Failed to convert asset '#{@file.path}'."
|
11
|
+
raise e
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def converted
|
16
|
+
@converted
|
17
|
+
end
|
18
|
+
|
19
|
+
# Filetype to process (e.g. '.coffee')
|
20
|
+
def self.filetype
|
21
|
+
''
|
22
|
+
end
|
23
|
+
|
24
|
+
# Logic to convert assets
|
25
|
+
#
|
26
|
+
# Available instance variables:
|
27
|
+
# @file File to be converted
|
28
|
+
# @content Contents of @file as a string
|
29
|
+
# @type Filetype of file (e.g. '.coffee')
|
30
|
+
#
|
31
|
+
# Returns converted string
|
32
|
+
def convert
|
33
|
+
@content
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
class CssAssetTag < Liquid::Block
|
3
|
+
def render(context)
|
4
|
+
# Get YAML manifest from Liquid block
|
5
|
+
manifest = @nodelist.first
|
6
|
+
prefix = @markup.lstrip.rstrip
|
7
|
+
|
8
|
+
# Compile bundle based on manifest
|
9
|
+
site = context.registers[:site]
|
10
|
+
bundle = JekyllAssetPipeline::Bundler.new(site, prefix, manifest, '.css')
|
11
|
+
|
12
|
+
# Return HTML tag linked to bundle
|
13
|
+
return bundle.html_tag
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Register CssAssetTag tag with Liquid
|
18
|
+
Liquid::Template.register_tag('css_asset_tag', JekyllAssetPipeline::CssAssetTag)
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
class Extendable
|
3
|
+
# Record subclasses of this class (this method is automatically called by ruby)
|
4
|
+
def self.inherited(base)
|
5
|
+
subclasses << base
|
6
|
+
end
|
7
|
+
|
8
|
+
# Return an array of classes that are subclasses of this object
|
9
|
+
def self.subclasses
|
10
|
+
@subclasses ||= []
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
class JavaScriptAssetTag < Liquid::Block
|
3
|
+
def render(context)
|
4
|
+
# Get YAML manifest from Liquid block
|
5
|
+
manifest = @nodelist.first
|
6
|
+
prefix = @markup.lstrip.rstrip
|
7
|
+
|
8
|
+
# Compile bundle based on manifest
|
9
|
+
site = context.registers[:site]
|
10
|
+
bundle = JekyllAssetPipeline::Bundler.new(site, prefix, manifest, '.js')
|
11
|
+
|
12
|
+
# Return HTML tag linked to bundle
|
13
|
+
return bundle.html_tag
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Register JavaScriptAssetTag tag with Liquid
|
18
|
+
Liquid::Template.register_tag('javascript_asset_tag', JekyllAssetPipeline::JavaScriptAssetTag)
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
class Template < JekyllAssetPipeline::Extendable
|
3
|
+
def initialize(path, filename)
|
4
|
+
@path = path
|
5
|
+
@filename = filename
|
6
|
+
end
|
7
|
+
|
8
|
+
# Filetype to process (e.g. '.js')
|
9
|
+
def self.filetype
|
10
|
+
''
|
11
|
+
end
|
12
|
+
|
13
|
+
# Priority of template (to override default templates)
|
14
|
+
def self.priority
|
15
|
+
0
|
16
|
+
end
|
17
|
+
|
18
|
+
# HTML output to return
|
19
|
+
#
|
20
|
+
# Available instance variables:
|
21
|
+
# @path Path to bundle file
|
22
|
+
# @filename Name of bundle file
|
23
|
+
#
|
24
|
+
# Returns string
|
25
|
+
def html
|
26
|
+
"#{@path/@filename}\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
# Default output for CSS assets
|
3
|
+
class CssTagTemplate < JekyllAssetPipeline::Template
|
4
|
+
def self.filetype
|
5
|
+
'.css'
|
6
|
+
end
|
7
|
+
|
8
|
+
def html
|
9
|
+
"<link href='/#{@path}/#{@filename}' rel='stylesheet' type='text/css' />\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def priority
|
13
|
+
-1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
# Default output for JavaScript assets
|
3
|
+
class JavaScriptTagTemplate < JekyllAssetPipeline::Template
|
4
|
+
def self.filetype
|
5
|
+
'.js'
|
6
|
+
end
|
7
|
+
|
8
|
+
def html
|
9
|
+
"<script src='/#{@path}/#{@filename}' type='text/javascript'></script>\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def priority
|
13
|
+
-1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Stdlib dependencies
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'time'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
# Third-party dependencies
|
8
|
+
require 'jekyll'
|
9
|
+
require 'liquid'
|
10
|
+
|
11
|
+
# Jekyll extensions
|
12
|
+
require 'jekyll_asset_pipeline/extendable'
|
13
|
+
require 'jekyll_asset_pipeline/asset_file'
|
14
|
+
require 'jekyll_asset_pipeline/bundler'
|
15
|
+
require 'jekyll_asset_pipeline/compressor'
|
16
|
+
require 'jekyll_asset_pipeline/converter'
|
17
|
+
require 'jekyll_asset_pipeline/template'
|
18
|
+
require 'jekyll_asset_pipeline/templates/javascript_tag_template'
|
19
|
+
require 'jekyll_asset_pipeline/templates/css_tag_template'
|
20
|
+
|
21
|
+
# Liquid extensions
|
22
|
+
require 'jekyll_asset_pipeline/css_asset_tag'
|
23
|
+
require 'jekyll_asset_pipeline/javascript_asset_tag'
|
24
|
+
|
25
|
+
module JekyllAssetPipeline
|
26
|
+
VERSION = '0.0.1'
|
27
|
+
|
28
|
+
# Default configuration settings for Jekyll Asset Bundler
|
29
|
+
# Strings used for keys to play nice when merging with _config.yml
|
30
|
+
DEFAULTS = {
|
31
|
+
'output_path' => 'assets', # Destination for bundle file (within the '_site' directory)
|
32
|
+
'compress' => true # true = Compress assets, false = Leave assets uncompressed
|
33
|
+
}
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-asset-pipeline
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt Hodan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jekyll
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: liquid
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.9.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.9.0
|
46
|
+
description: Bundle, convert and minify JavaScript and CSS assets.
|
47
|
+
email: matthew.c.hodan@gmail.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- lib/jekyll_asset_pipeline/asset_file.rb
|
53
|
+
- lib/jekyll_asset_pipeline/bundler.rb
|
54
|
+
- lib/jekyll_asset_pipeline/compressor.rb
|
55
|
+
- lib/jekyll_asset_pipeline/converter.rb
|
56
|
+
- lib/jekyll_asset_pipeline/css_asset_tag.rb
|
57
|
+
- lib/jekyll_asset_pipeline/extendable.rb
|
58
|
+
- lib/jekyll_asset_pipeline/javascript_asset_tag.rb
|
59
|
+
- lib/jekyll_asset_pipeline/template.rb
|
60
|
+
- lib/jekyll_asset_pipeline/templates/css_tag_template.rb
|
61
|
+
- lib/jekyll_asset_pipeline/templates/javascript_tag_template.rb
|
62
|
+
- lib/jekyll_asset_pipeline.rb
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
homepage: http://github.com/matthodan/jekyll-asset-pipeline
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.24
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Asset packaging system for Jekyll-powered sites.
|
89
|
+
test_files: []
|