jekyll_asset_pipeline 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +19 -0
- data/LICENSE +21 -0
- data/README.md +377 -0
- data/lib/jekyll_asset_pipeline.rb +57 -0
- data/lib/jekyll_asset_pipeline/asset.rb +12 -0
- data/lib/jekyll_asset_pipeline/compressor.rb +30 -0
- data/lib/jekyll_asset_pipeline/converter.rb +40 -0
- data/lib/jekyll_asset_pipeline/extensions/jekyll/site.rb +7 -0
- data/lib/jekyll_asset_pipeline/extensions/jekyll/site_extensions.rb +38 -0
- data/lib/jekyll_asset_pipeline/extensions/liquid/asset_tag.rb +9 -0
- data/lib/jekyll_asset_pipeline/extensions/liquid/asset_tags/css_asset_tag.rb +21 -0
- data/lib/jekyll_asset_pipeline/extensions/liquid/asset_tags/javascript_asset_tag.rb +21 -0
- data/lib/jekyll_asset_pipeline/extensions/liquid/liquid_block_extensions.rb +52 -0
- data/lib/jekyll_asset_pipeline/extensions/ruby/subclass_tracking.rb +15 -0
- data/lib/jekyll_asset_pipeline/pipeline.rb +250 -0
- data/lib/jekyll_asset_pipeline/template.rb +42 -0
- data/lib/jekyll_asset_pipeline/templates/css_tag_template.rb +17 -0
- data/lib/jekyll_asset_pipeline/templates/javascript_tag_template.rb +17 -0
- data/lib/jekyll_asset_pipeline/templates/template_helper.rb +15 -0
- data/lib/jekyll_asset_pipeline/version.rb +3 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6ecbca180339905b9bc06cf3490d19de5af2f5cc
|
4
|
+
data.tar.gz: 8e6fa3d8f9b9290228907c706a46946b05cf076d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 002b87529c6ba6c5409eba9c9e82696234aec6c009b0de5cf5cc69a38396f1b4222711d5e8646b79e68ec8675b8386b9b154c8d9586a462d9ada83b25b97d37a
|
7
|
+
data.tar.gz: 5f6bdaf8987879ec58ea81740d211df8520493a03372b4d5b1fa9b983f2b84bae0044099a79933bc558dc3b28400c2924b99db93109a4c89340e9510a8a093e7
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.4.1 (2017-12-08)
|
4
|
+
|
5
|
+
* [#6] __Test coverage increased to 100%__
|
6
|
+
* [#35] __Updated rake dependency to 12.0__
|
7
|
+
* [#34] __Fixed or mitigated all Rubocop offenses__
|
8
|
+
* [#31] __Documented modules and classes__
|
9
|
+
* [#29] Various README updates
|
10
|
+
* [#28] Gemspec file updates (version dependencies and typos)
|
11
|
+
* [#31] Fix random coverage jumps
|
12
|
+
* [#33] Rescue StandardError instead of Exception
|
13
|
+
* Removed CodeClimate integration
|
14
|
+
|
15
|
+
## 0.4 (2017-12-03)
|
16
|
+
|
17
|
+
* [#20] Support Jekyll 3.5, Liquid 4.0
|
18
|
+
* [#25] Permit root level output of asset files
|
19
|
+
* Fix and refactor to eliminate Rubocop offenses
|
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,377 @@
|
|
1
|
+
# Jekyll Asset Pipeline
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/jekyll-asset-pipeline.png)](http://badge.fury.io/rb/jekyll-asset-pipeline)
|
4
|
+
[![Build Status](https://travis-ci.org/matthodan/jekyll-asset-pipeline.svg?branch=master)](https://travis-ci.org/matthodan/jekyll-asset-pipeline)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/matthodan/jekyll-asset-pipeline/badge.png?branch=master)](https://coveralls.io/r/matthodan/jekyll-asset-pipeline?branch=master)
|
6
|
+
[![Dependency Status](https://gemnasium.com/matthodan/jekyll-asset-pipeline.png)](https://gemnasium.com/matthodan/jekyll-asset-pipeline)
|
7
|
+
|
8
|
+
[Jekyll Asset Pipeline](http://www.matthodan.com/2012/11/22/jekyll-asset-pipeline.html) is a powerful asset pipeline that automatically collects, converts and compresses / minifies your site's JavaScript and CSS assets when you compile your [Jekyll](http://jekyllrb.com/) site.
|
9
|
+
|
10
|
+
## Table of Contents
|
11
|
+
|
12
|
+
- [Features](#features)
|
13
|
+
- [How It Works](#how-it-works)
|
14
|
+
- [Getting Started](#getting-started)
|
15
|
+
- [Asset Preprocessing](#asset-preprocessing)
|
16
|
+
- [CoffeeScript](#coffeescript)
|
17
|
+
- [SASS / SCSS](#sass--scss)
|
18
|
+
- [LESS](#less)
|
19
|
+
- [Successive Preprocessing](#successive-preprocessing)
|
20
|
+
- [Asset Compression](#asset-compression)
|
21
|
+
- [Yahoo's YUI Compressor](#yahoos-yui-compressor)
|
22
|
+
- [Google's Closure Compiler](#googles-closure-compiler)
|
23
|
+
- [Templates](#templates)
|
24
|
+
- [Configuration](#configuration)
|
25
|
+
- [Octopress](#octopress)
|
26
|
+
- [Contribute](#contribute)
|
27
|
+
- [Community](#community)
|
28
|
+
- [Credits](#credits)
|
29
|
+
- [License](#license)
|
30
|
+
|
31
|
+
## Features
|
32
|
+
|
33
|
+
- Declarative dependency management via asset manifests
|
34
|
+
- Asset preprocessing/conversion (supports [CoffeeScript](http://coffeescript.org/), [Sass / Scss](http://sass-lang.com/), [Less](http://lesscss.org/), [Erb](http://ruby-doc.org/stdlib-2.2.0/libdoc/erb/rdoc/ERB.html), etc.)
|
35
|
+
- Asset compression (supports [YUI Compressor](http://yui.github.io/yuicompressor/), [Closure Compiler](https://developers.google.com/closure/compiler/), etc.)
|
36
|
+
- Fingerprints bundled asset filenames with MD5 hashes for better browser caching
|
37
|
+
- Automatic generation of HTML `link` and `script` tags that point to bundled assets
|
38
|
+
- Integrates seamlessly into Jekyll's workflow, including auto site regeneration
|
39
|
+
|
40
|
+
## How It Works
|
41
|
+
|
42
|
+
Jekyll Asset Pipeline's workflow can be summarized as follows:
|
43
|
+
|
44
|
+
1. Reviews site markup for instances of the `css_asset_tag` and `javascript_asset_tag` Liquid tags. Each occurrence of either of these tags identifies when a new bundle needs to be created and outlines (via a manifest) which assets to include in the bundle.
|
45
|
+
2. Collects raw assets based on the manifest and runs them through converters / preprocessors (if necessary) to convert them into valid CSS or JavaScript.
|
46
|
+
3. Combines the processed assets into a single bundle, compresses the bundled assets (if desired) and saves the compressed bundle to the `_site` output folder.
|
47
|
+
4. Replaces `css_asset_tag` and `javascript_asset_tag` Liquid tags with HTML `link` and `script` tags, respectively, that link to the finished bundles.
|
48
|
+
|
49
|
+
## Getting Started
|
50
|
+
|
51
|
+
Jekyll Asset Pipeline is extremely easy to add to your Jekyll project and has no incremental dependencies beyond those required by Jekyll. Once you have a basic Jekyll site up and running, follow the steps below to install and configure Jekyll Asset Pipeline.
|
52
|
+
|
53
|
+
1. Install the `jekyll-asset-pipeline` gem via [Rubygems](http://rubygems.org/).
|
54
|
+
|
55
|
+
``` bash
|
56
|
+
$ gem install jekyll-asset-pipeline
|
57
|
+
```
|
58
|
+
|
59
|
+
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`.
|
60
|
+
|
61
|
+
2. 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 require statement as its contents.
|
62
|
+
|
63
|
+
``` ruby
|
64
|
+
require 'jekyll_asset_pipeline'
|
65
|
+
```
|
66
|
+
|
67
|
+
3. Move your assets into a Jekyll ignored folder (i.e. a folder that begins with an underscore `_`) so that Jekyll won't include these raw assets in the site output. It is recommended to use an `_assets` folder to hold your site's assets.
|
68
|
+
|
69
|
+
4. Add the following [Liquid](http://liquidmarkup.org/) blocks to your site's HTML `head` section. These blocks will be converted into HTML `link` and `script` tags that point to bundled assets. Within each block is a manifest of assets to include in the bundle. Assets are included in the same order that they are listed in the manifest. Replace the `foo` and `bar` assets with your site's assets. At this point we are just using plain old javascript and css files (hence the `.js` and `.css` extensions). See the [Asset Preprocessing](#asset-preprocessing) section to learn how to include files that must be preprocessed (e.g. CoffeeScript, Sass, Less, Erb, etc.). Name the bundle by including a string after the opening tag. We've named our bundles "global" in the below example.
|
70
|
+
|
71
|
+
``` html
|
72
|
+
{% css_asset_tag global %}
|
73
|
+
- /_assets/foo.css
|
74
|
+
- /_assets/bar.css
|
75
|
+
{% endcss_asset_tag %}
|
76
|
+
|
77
|
+
{% javascript_asset_tag global %}
|
78
|
+
- /_assets/foo.js
|
79
|
+
- /_assets/bar.js
|
80
|
+
{% endjavascript_asset_tag %}
|
81
|
+
```
|
82
|
+
Asset manifests must be formatted as YAML arrays and include full paths to each asset from the root of the project. YAML [does not allow tabbed markup](http://www.yaml.org/faq.html), so you must use spaces when indenting your YAML manifest or you will get an error when you compile your site. If you are using assets that must be preprocessed, you should append the appropriate extension (e.g. '.js.coffee', '.css.less') as discussed in the [Asset Preprocessing](#asset-preprocessing) section.
|
83
|
+
|
84
|
+
5. Run the `jekyll build` command to compile your site. You should see an output that includes the following Jekyll Asset Pipeline status messages.
|
85
|
+
|
86
|
+
``` bash
|
87
|
+
$ jekyll build
|
88
|
+
Generating...
|
89
|
+
Asset Pipeline: Processing 'css_asset_tag' manifest 'global'
|
90
|
+
Asset Pipeline: Saved 'global-md5hash.css' to 'yoursitepath/assets'
|
91
|
+
Asset Pipeline: Processing 'javascript_asset_tag' manifest 'global'
|
92
|
+
Asset Pipeline: Saved 'global-md5hash.js' to 'yoursitepath/assets'
|
93
|
+
```
|
94
|
+
|
95
|
+
If you do not see these messages, check that you have __not__ set Jekyll's `safe` option to `true` in your site's `_config.yml`. If the `safe` option is set to `true`, Jekyll will not run plugins.
|
96
|
+
|
97
|
+
That is it! You should now have bundled assets. Look in the `_site` folder of your project for an `assets` folder that contains the bundled assets. HTML tags that point to these assets have been placed in the HTML output where you included the Liquid blocks. *You may notice that your assets have not been converted or compressed-- we will add that functionality next.*
|
98
|
+
|
99
|
+
## Asset Preprocessing
|
100
|
+
|
101
|
+
Asset preprocessing (i.e. conversion) allows us to write our assets in languages such as [CoffeeScript](http://coffeescript.org/), [Sass](http://sass-lang.com/), [Less](http://lesscss.org/), [Erb](http://ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html) or any other language. One of Jekyll Asset Pipeline's key strengths is that it works with __any__ preprocessing library that has a ruby wrapper. Adding a preprocessor is straightforward, but requires a small amount of additional code.
|
102
|
+
|
103
|
+
In the following example, we will add a preprocessor that converts CoffeeScript into JavaScript.
|
104
|
+
|
105
|
+
### CoffeeScript
|
106
|
+
|
107
|
+
1. In the `jekyll_asset_pipeline.rb` file that we created in the [Getting Started](#getting-started) section, add the following code to the end of the file (i.e. after the `require` statement).
|
108
|
+
|
109
|
+
``` ruby
|
110
|
+
module JekyllAssetPipeline
|
111
|
+
class CoffeeScriptConverter < JekyllAssetPipeline::Converter
|
112
|
+
require 'coffee-script'
|
113
|
+
|
114
|
+
def self.filetype
|
115
|
+
'.coffee'
|
116
|
+
end
|
117
|
+
|
118
|
+
def convert
|
119
|
+
return CoffeeScript.compile(@content)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
The above code adds a CoffeeScript converter. You can name a converter anything as long as it inherits from `JekyllAssetPipeline::Converter`. 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. 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.
|
126
|
+
|
127
|
+
2. 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.
|
128
|
+
|
129
|
+
``` bash
|
130
|
+
$ gem install coffee-script
|
131
|
+
```
|
132
|
+
|
133
|
+
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`.
|
134
|
+
|
135
|
+
3. Append a `.coffee` extension to the filename of any asset that should be converted with the `CoffeeScriptConverter`. For example, `foo.js` would become `foo.js.coffee`.
|
136
|
+
|
137
|
+
4. Run the `jekyll build` command to compile your site.
|
138
|
+
|
139
|
+
That is it! Your asset pipeline has converted any CoffeeScript assets into JavaScript before adding them to a bundle.
|
140
|
+
|
141
|
+
### SASS / SCSS
|
142
|
+
|
143
|
+
You probably get the gist of how converters work, but here's an example of a SASS converter for quick reference.
|
144
|
+
|
145
|
+
``` ruby
|
146
|
+
module JekyllAssetPipeline
|
147
|
+
class SassConverter < JekyllAssetPipeline::Converter
|
148
|
+
require 'sass'
|
149
|
+
|
150
|
+
def self.filetype
|
151
|
+
'.scss'
|
152
|
+
end
|
153
|
+
|
154
|
+
def convert
|
155
|
+
return Sass::Engine.new(@content, syntax: :scss).render
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
```
|
160
|
+
|
161
|
+
Don't forget to install the `sass` gem or add it to your Gemfile and run `bundle install` before you run the `jekyll build` command since the above SASS converter requires the `sass` library as a dependency.
|
162
|
+
|
163
|
+
If you're using `@import` statements in your SASS files, you'll probably need to specify a base load path to the SASS engine in your `convert` method.
|
164
|
+
You can use the `@dirname` instance variable for this, which contains the path to the current asset's directory:
|
165
|
+
|
166
|
+
``` ruby
|
167
|
+
...
|
168
|
+
def convert
|
169
|
+
return Sass::Engine.new(@content, syntax: :scss, load_paths: [@dirname]).render
|
170
|
+
end
|
171
|
+
...
|
172
|
+
```
|
173
|
+
|
174
|
+
### LESS
|
175
|
+
|
176
|
+
``` ruby
|
177
|
+
module JekyllAssetPipeline
|
178
|
+
class LessConverter < JekyllAssetPipeline::Converter
|
179
|
+
require 'less'
|
180
|
+
|
181
|
+
def self.filetype
|
182
|
+
'.less'
|
183
|
+
end
|
184
|
+
|
185
|
+
def convert
|
186
|
+
return Less::Parser.new.parse(@content).to_css
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
```
|
191
|
+
|
192
|
+
Don't forget to install the `less` gem or add it to your Gemfile and run `bundle install` before you run the `jekyll build` command since the above LESS converter requires the `less` library as a dependency.
|
193
|
+
|
194
|
+
As with the SASS convertor, you'll probably need to specify a base load path and pass that to the LESS Parser:
|
195
|
+
|
196
|
+
``` ruby
|
197
|
+
...
|
198
|
+
def convert
|
199
|
+
return Less::Parser.new(paths: [@dirname]).parse(@content).to_css
|
200
|
+
end
|
201
|
+
...
|
202
|
+
```
|
203
|
+
|
204
|
+
### Successive Preprocessing
|
205
|
+
|
206
|
+
If you would like to run an asset through multiple preprocessors successively, you can do so by naming your assets with nested file extensions. Nest the extensions in the order (right to left) that the asset should be processed. For example, `.css.scss.erb` would first be processed by an `erb` preprocessor then by a `scss` preprocessor before being rendered. This convention is very similar to the convention used by the [Ruby on Rails asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html#preprocessing).
|
207
|
+
|
208
|
+
Don't forget to define preprocessors for the extensions you use in your filenames, otherwise Jekyll Asset Pipeline will not process your asset.
|
209
|
+
|
210
|
+
## Asset Compression
|
211
|
+
|
212
|
+
Asset compression allows us to decrease the size of our assets and increase the speed of our site. One of Jekyll Asset Pipeline's key strengths is that it works with __any__ compression library that has a ruby wrapper. Adding asset compression is straightforward, but requires a small amount of additional code.
|
213
|
+
|
214
|
+
In the following example, we will add a compressor that uses Yahoo's YUI Compressor to compress our CSS and JavaScript assets.
|
215
|
+
|
216
|
+
### Yahoo's YUI Compressor
|
217
|
+
|
218
|
+
1. In the `jekyll_asset_pipeline.rb` file that we created in the [Getting Started](#getting-started) section, add the following code to the end of the file (i.e. after the `require` statement).
|
219
|
+
|
220
|
+
``` ruby
|
221
|
+
module JekyllAssetPipeline
|
222
|
+
class CssCompressor < JekyllAssetPipeline::Compressor
|
223
|
+
require 'yui/compressor'
|
224
|
+
|
225
|
+
def self.filetype
|
226
|
+
'.css'
|
227
|
+
end
|
228
|
+
|
229
|
+
def compress
|
230
|
+
return YUI::CssCompressor.new.compress(@content)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
class JavaScriptCompressor < JekyllAssetPipeline::Compressor
|
235
|
+
require 'yui/compressor'
|
236
|
+
|
237
|
+
def self.filetype
|
238
|
+
'.js'
|
239
|
+
end
|
240
|
+
|
241
|
+
def compress
|
242
|
+
return YUI::JavaScriptCompressor.new(munge: true).compress(@content)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
```
|
247
|
+
|
248
|
+
The above code adds a CSS and a JavaScript compressor. You can name a compressor anything as long as it inherits from `JekyllAssetPipeline::Compressor`. 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.
|
249
|
+
|
250
|
+
2. 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.
|
251
|
+
|
252
|
+
``` bash
|
253
|
+
$ gem install yui-compressor
|
254
|
+
```
|
255
|
+
|
256
|
+
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`.
|
257
|
+
|
258
|
+
3. Run the `jekyll build` command to compile your site.
|
259
|
+
|
260
|
+
That is it! Your asset pipeline has 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.
|
261
|
+
|
262
|
+
### Google's Closure Compiler
|
263
|
+
|
264
|
+
You probably get the gist of how compressors work, but here's an example of a Google Closure Compiler compressor for quick reference.
|
265
|
+
|
266
|
+
``` ruby
|
267
|
+
class JavaScriptCompressor < JekyllAssetPipeline::Compressor
|
268
|
+
require 'closure-compiler'
|
269
|
+
|
270
|
+
def self.filetype
|
271
|
+
'.js'
|
272
|
+
end
|
273
|
+
|
274
|
+
def compress
|
275
|
+
return Closure::Compiler.new.compile(@content)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
```
|
279
|
+
|
280
|
+
Don't forget to install the `closure-compiler` gem before you run the `jekyll build` command since the above compressor requires the `closure-compiler` library as a dependency.
|
281
|
+
|
282
|
+
## Templates
|
283
|
+
|
284
|
+
When Jekyll Asset Pipeline creates a bundle, it returns an HTML tag that points to the bundle. 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 add a CSS media attribute).
|
285
|
+
|
286
|
+
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.
|
287
|
+
|
288
|
+
1. In the `jekyll_asset_pipeline.rb` file that we created in the [Getting Started](#getting-started) section, add the following code.
|
289
|
+
|
290
|
+
``` ruby
|
291
|
+
module JekyllAssetPipeline
|
292
|
+
class CssTagTemplate < JekyllAssetPipeline::Template
|
293
|
+
def self.filetype
|
294
|
+
'.css'
|
295
|
+
end
|
296
|
+
|
297
|
+
def html
|
298
|
+
"<link href='#{output_path}/#{@filename}' rel='stylesheet' " \
|
299
|
+
"type='text/css' media='screen' />\n"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
```
|
304
|
+
|
305
|
+
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 Jekyll Asset Pipeline module.
|
306
|
+
|
307
|
+
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. `output_path` is a helper method and `@filename` is an instance variable which 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.
|
308
|
+
|
309
|
+
2. Run the `jekyll` command to compile your site.
|
310
|
+
|
311
|
+
That is it! Your asset pipeline used your template to generate an HTML `link` tag that includes a media attribute with the value `screen`. You can verify that this is the case by viewing the generated source within your project's `_site` folder.
|
312
|
+
|
313
|
+
## Configuration
|
314
|
+
|
315
|
+
Jekyll Asset Pipeline provides the following configuration options that can be controlled by adding them to your project's `_config.yml` file. 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.
|
316
|
+
|
317
|
+
``` yaml
|
318
|
+
asset_pipeline:
|
319
|
+
bundle: true
|
320
|
+
compress: true
|
321
|
+
output_path: assets
|
322
|
+
display_path: nil
|
323
|
+
gzip: false
|
324
|
+
```
|
325
|
+
|
326
|
+
Setting | Default | Description
|
327
|
+
---------------|----------|-----------------------------------------------------
|
328
|
+
`bundle` | `true` | controls whether Jekyll Asset Pipeline bundles the assets defined in each manifest. If set to `false`, each asset will be saved individually and individual html tags pointing to each unbundled asset will be produced when you compile your site. It is useful to set this to `false` while you are debugging your site.
|
329
|
+
`compress` | `true` | 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.
|
330
|
+
`output_path` | `assets` | defines where generated bundles should be saved within the `_site` folder of your project.
|
331
|
+
`display_path` | `nil` | overrides the path to assets in generated html tags. This is useful if you are hosting your site at a path other than the root of your domain (e.g. `http://example.com/blog/`).
|
332
|
+
`gzip` | `false` | controls whether Jekyll Asset Pipeline saves gzipped versions of your assets alongside un-gzipped versions.
|
333
|
+
|
334
|
+
|
335
|
+
## Octopress
|
336
|
+
|
337
|
+
[Octopress](http://octopress.org/) is a popular framework for Jekyll that can help you get a blog up and running quickly. Jekyll Asset Pipeline can be added to an Octopress site using the [Getting Started](#getting-started) steps above with the following modifications:
|
338
|
+
|
339
|
+
1. Octopress uses Bundler to manage your site's dependencies. You should add `gem jekyll-asset-pipeline` to your Gemfile and then run `bundle install` to install.
|
340
|
+
|
341
|
+
2. Instead of adding a `_plugins` folder, you should put `jekyll_asset_pipeline.rb` in the `plugins` folder included by default in the root of your Octopress site.
|
342
|
+
|
343
|
+
3. You should still store your assets in an Jekyll ignored folder (i.e. a folder that begins with an underscore `_`), but note that this folder should be located within the `source` folder of your Octopress site (e.g. `source/_assets`).
|
344
|
+
|
345
|
+
4. No change to this step.
|
346
|
+
|
347
|
+
5. Instead of running the `jekyll` command to compile your site, you should use Octopress' rake commands (e.g. `rake generate`) as outlined [here](http://octopress.org/docs/blogging/).
|
348
|
+
|
349
|
+
If you have any difficulties using Jekyll Asset Pipeline with Octopress, please [open an issue](http://github.com/matthodan/jekyll-asset-pipeline/issues).
|
350
|
+
|
351
|
+
## Contribute
|
352
|
+
|
353
|
+
You can contribute to the Jekyll Asset Pipeline by submitting a pull request [via GitHub](https://github.com/matthodan/jekyll-asset-pipeline). There are a few areas that need improvement:
|
354
|
+
|
355
|
+
- __Tests, tests, tests.__ **This project is now fully tested.**
|
356
|
+
- __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. **As of v0.1.0, Jekyll Asset Pipeline now supports successive preprocessing.**
|
357
|
+
- __Handle remote assets.__ Right now, Jekyll Asset Pipeline 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 is pretty interesting. That said, it is generally better to keep remote assets separate so that they load asynchronously.
|
358
|
+
|
359
|
+
If you have any ideas or you would like to see anything else improved please use the [issues section](https://github.com/matthodan/jekyll-asset-pipeline/issues).
|
360
|
+
|
361
|
+
## Changelog
|
362
|
+
|
363
|
+
See [the changelog](CHANGELOG.md).
|
364
|
+
|
365
|
+
## Community
|
366
|
+
|
367
|
+
- Here is [GitHub's list of projects that use the gem](https://github.com/matthodan/jekyll-asset-pipeline/network/dependents).
|
368
|
+
- Here is a currated list of [sites that use Jekyll Asset Pipeline](http://github.com/matthodan/jekyll-asset-pipeline/wiki/Sites-that-use-Jekyll-Asset-Pipeline). Feel free to add your site to the list if you want.
|
369
|
+
|
370
|
+
## Credits
|
371
|
+
|
372
|
+
* [Moshen](https://github.com/moshen/) for creating the [Jekyll Asset Bundler](https://github.com/moshen/jekyll-asset_bundler).
|
373
|
+
* [Mojombo](https://github.com/mojombo) for creating [Jekyll](https://github.com/mojombo/jekyll) in the first place.
|
374
|
+
|
375
|
+
## License
|
376
|
+
|
377
|
+
Jekyll Asset Pipeline is released under the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Stdlib dependencies
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'time'
|
5
|
+
require 'yaml'
|
6
|
+
require 'zlib'
|
7
|
+
|
8
|
+
# Third-party dependencies
|
9
|
+
require 'jekyll'
|
10
|
+
require 'liquid'
|
11
|
+
|
12
|
+
# Jekyll extensions
|
13
|
+
require 'jekyll_asset_pipeline/extensions/jekyll/site_extensions'
|
14
|
+
require 'jekyll_asset_pipeline/extensions/jekyll/site'
|
15
|
+
|
16
|
+
# Liquid extensions
|
17
|
+
require 'jekyll_asset_pipeline/extensions/liquid/liquid_block_extensions'
|
18
|
+
require 'jekyll_asset_pipeline/extensions/liquid/asset_tag'
|
19
|
+
require 'jekyll_asset_pipeline/extensions/liquid/asset_tags/css_asset_tag'
|
20
|
+
# rubocop:disable LineLength
|
21
|
+
require 'jekyll_asset_pipeline/extensions/liquid/asset_tags/javascript_asset_tag'
|
22
|
+
# rubocop:enable LineLength
|
23
|
+
|
24
|
+
# Ruby extensions
|
25
|
+
require 'jekyll_asset_pipeline/extensions/ruby/subclass_tracking'
|
26
|
+
|
27
|
+
# Jekyll Asset Pipeline
|
28
|
+
require 'jekyll_asset_pipeline/version'
|
29
|
+
require 'jekyll_asset_pipeline/asset'
|
30
|
+
require 'jekyll_asset_pipeline/converter'
|
31
|
+
require 'jekyll_asset_pipeline/compressor'
|
32
|
+
require 'jekyll_asset_pipeline/templates/template_helper'
|
33
|
+
require 'jekyll_asset_pipeline/template'
|
34
|
+
require 'jekyll_asset_pipeline/templates/javascript_tag_template'
|
35
|
+
require 'jekyll_asset_pipeline/templates/css_tag_template'
|
36
|
+
require 'jekyll_asset_pipeline/pipeline'
|
37
|
+
|
38
|
+
module JekyllAssetPipeline
|
39
|
+
# Default configuration settings for Jekyll Asset Pipeline
|
40
|
+
# Strings used for keys to play nice when merging with _config.yml
|
41
|
+
#
|
42
|
+
# 'output_path' Destination for bundle file (within the '_site' directory)
|
43
|
+
# 'display_path' Optional. Override path to assets for output HTML refs
|
44
|
+
# 'staging_path' Destination for staged assets (within project root directory)
|
45
|
+
# 'bundle' true = Bundle assets, false = Leave assets unbundled
|
46
|
+
# 'compress' true = Minify assets, false = Leave assets unminified
|
47
|
+
# 'gzip' true = Create gzip versions,
|
48
|
+
# false = Do not create gzip versions
|
49
|
+
DEFAULTS = {
|
50
|
+
'output_path' => 'assets',
|
51
|
+
'display_path' => nil,
|
52
|
+
'staging_path' => '.asset_pipeline',
|
53
|
+
'bundle' => true,
|
54
|
+
'compress' => true,
|
55
|
+
'gzip' => false
|
56
|
+
}.freeze
|
57
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
# Holds an asset (file)
|
3
|
+
class Asset
|
4
|
+
def initialize(content, filename, dirname = '.')
|
5
|
+
@content = content
|
6
|
+
@filename = filename
|
7
|
+
@dirname = dirname
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :content, :filename, :dirname, :output_path
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
# Base class for asset compressors
|
3
|
+
# See https://github.com/matthodan/jekyll-asset-pipeline#asset-compression
|
4
|
+
class Compressor
|
5
|
+
extend JekyllAssetPipeline::SubclassTracking
|
6
|
+
|
7
|
+
def initialize(content)
|
8
|
+
@content = content
|
9
|
+
@compressed = compress
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns compressed content
|
13
|
+
attr_reader :compressed
|
14
|
+
|
15
|
+
# Filetype to process (e.g. '.js')
|
16
|
+
def self.filetype
|
17
|
+
''
|
18
|
+
end
|
19
|
+
|
20
|
+
# Logic to compress assets
|
21
|
+
#
|
22
|
+
# Available instance variables:
|
23
|
+
# @content Content to be compressed
|
24
|
+
#
|
25
|
+
# Returns compressed string
|
26
|
+
def compress
|
27
|
+
@content
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
# Base class for asset converters
|
3
|
+
# See https://github.com/matthodan/jekyll-asset-pipeline#asset-preprocessing
|
4
|
+
class Converter
|
5
|
+
extend JekyllAssetPipeline::SubclassTracking
|
6
|
+
|
7
|
+
def initialize(asset)
|
8
|
+
@content = asset.content
|
9
|
+
@type = File.extname(asset.filename).downcase
|
10
|
+
@dirname = asset.dirname
|
11
|
+
@converted = convert
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :converted
|
15
|
+
|
16
|
+
# Filetype to process (e.g. '.coffee')
|
17
|
+
def self.filetype
|
18
|
+
''
|
19
|
+
end
|
20
|
+
|
21
|
+
# Finds a converter class based on a filename
|
22
|
+
def self.klass(filename)
|
23
|
+
JekyllAssetPipeline::Converter.subclasses.select do |c|
|
24
|
+
c.filetype == File.extname(filename).downcase
|
25
|
+
end.last
|
26
|
+
end
|
27
|
+
|
28
|
+
# Logic to convert assets
|
29
|
+
#
|
30
|
+
# Available instance variables:
|
31
|
+
# @file File to be converted
|
32
|
+
# @content Contents of @file as a string
|
33
|
+
# @type Filetype of file (e.g. '.coffee')
|
34
|
+
#
|
35
|
+
# Returns converted string
|
36
|
+
def convert
|
37
|
+
@content
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
# Contains overrides for the needed Jekyll:Site methods
|
3
|
+
# Included in Jekyll::Site
|
4
|
+
module JekyllSiteExtensions
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
# Store the original Jekyll::Site#cleanup method
|
8
|
+
old_cleanup_method = instance_method(:cleanup)
|
9
|
+
|
10
|
+
# Override Jekyll::Site#cleanup
|
11
|
+
define_method(:cleanup) do
|
12
|
+
# Run the Jekyll::Site#cleanup method
|
13
|
+
original_return_val = old_cleanup_method.bind(self).call
|
14
|
+
|
15
|
+
# Clear Jekyll Asset Pipeline cache
|
16
|
+
Pipeline.clear_cache
|
17
|
+
|
18
|
+
original_return_val
|
19
|
+
end
|
20
|
+
|
21
|
+
# Store the original Jekyll::Site#write method
|
22
|
+
old_write_method = instance_method(:write)
|
23
|
+
|
24
|
+
# Override Jekyll::Site#write
|
25
|
+
define_method(:write) do
|
26
|
+
# Run the Jekyll::Site#write method
|
27
|
+
original_return_value = old_write_method.bind(self).call
|
28
|
+
|
29
|
+
# Clear Jekyll Asset Pipeline staged assets
|
30
|
+
config = self.config['asset_pipeline'] || {}
|
31
|
+
Pipeline.remove_staged_assets(source, config)
|
32
|
+
|
33
|
+
original_return_value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
# This is a Liquid tag block extension
|
3
|
+
# See documentation here:
|
4
|
+
# https://github.com/Shopify/liquid/wiki/liquid-for-programmers#create-your-own-tag-blocks
|
5
|
+
class AssetTag < ::Liquid::Block
|
6
|
+
extend JekyllAssetPipeline::LiquidBlockExtensions::ClassMethods
|
7
|
+
include JekyllAssetPipeline::LiquidBlockExtensions
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This comment is needed, otherwise Rubocop complains because of the
|
2
|
+
# register_tag below and a verbose comment is better than a :nodoc: :)
|
3
|
+
module JekyllAssetPipeline
|
4
|
+
# css_asset_tag Liquid block
|
5
|
+
# See JekyllAssetPipeline::AssetTag and
|
6
|
+
# JekyllAssetPipeline::LiquidBlockExtensions
|
7
|
+
class CssAssetTag < JekyllAssetPipeline::AssetTag
|
8
|
+
def self.tag_name
|
9
|
+
'css_asset_tag'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.output_type
|
13
|
+
'.css'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Register CssAssetTag tag with Liquid
|
18
|
+
::Liquid::Template
|
19
|
+
.register_tag(JekyllAssetPipeline::CssAssetTag.tag_name,
|
20
|
+
JekyllAssetPipeline::CssAssetTag)
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This comment is needed, otherwise Rubocop complains because of the
|
2
|
+
# register_tag below and a verbose comment is better than a :nodoc: :)
|
3
|
+
module JekyllAssetPipeline
|
4
|
+
# javascript_asset_tag Liquid block
|
5
|
+
# See JekyllAssetPipeline::AssetTag and
|
6
|
+
# JekyllAssetPipeline::LiquidBlockExtensions
|
7
|
+
class JavaScriptAssetTag < JekyllAssetPipeline::AssetTag
|
8
|
+
def self.tag_name
|
9
|
+
'javascript_asset_tag'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.output_type
|
13
|
+
'.js'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Register JavaScriptAssetTag tag with Liquid
|
18
|
+
::Liquid::Template
|
19
|
+
.register_tag(JekyllAssetPipeline::JavaScriptAssetTag.tag_name,
|
20
|
+
JekyllAssetPipeline::JavaScriptAssetTag)
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
# Helper module used by JekyllAssetPipeline::AssetTag as well as
|
3
|
+
# classed derived from it (Liquid tag block extensions)
|
4
|
+
# See documentation here:
|
5
|
+
# https://github.com/Shopify/liquid/wiki/liquid-for-programmers#create-your-own-tag-blocks
|
6
|
+
module LiquidBlockExtensions
|
7
|
+
# Unsurprisingly, class methods
|
8
|
+
module ClassMethods
|
9
|
+
def output_type
|
10
|
+
''
|
11
|
+
end
|
12
|
+
|
13
|
+
def tag_name
|
14
|
+
''
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def render(context)
|
19
|
+
site = context.registers[:site]
|
20
|
+
config = site.config.fetch('asset_pipeline', {})
|
21
|
+
|
22
|
+
# Run Jekyll Asset Pipeline
|
23
|
+
pipeline, cached = run_pipeline(site, config)
|
24
|
+
|
25
|
+
return nil unless pipeline.is_a?(Pipeline)
|
26
|
+
|
27
|
+
# Prevent Jekyll from cleaning up saved assets if new pipeline
|
28
|
+
preserve_assets(site, config, pipeline) unless cached
|
29
|
+
|
30
|
+
# Return HTML tag pointing to asset
|
31
|
+
pipeline.html
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def run_pipeline(site, config)
|
37
|
+
Pipeline.run(nodelist.first, @markup.strip, site.source, site.dest,
|
38
|
+
self.class.tag_name, self.class.output_type, config)
|
39
|
+
end
|
40
|
+
|
41
|
+
def preserve_assets(site, config, pipeline)
|
42
|
+
pipeline.assets.each do |asset|
|
43
|
+
config = JekyllAssetPipeline::DEFAULTS.merge(config)
|
44
|
+
staging_path = File.expand_path(File.join(site.source,
|
45
|
+
config['staging_path']))
|
46
|
+
site.static_files << Jekyll::StaticFile.new(site, staging_path,
|
47
|
+
asset.output_path,
|
48
|
+
asset.filename)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
# Allows classes that extend this to return an array of their subclasses
|
3
|
+
module SubclassTracking
|
4
|
+
# Record subclasses of this class (this method is automatically called by
|
5
|
+
# ruby)
|
6
|
+
def inherited(base)
|
7
|
+
subclasses << base
|
8
|
+
end
|
9
|
+
|
10
|
+
# Return an array of classes that are subclasses of this object
|
11
|
+
def subclasses
|
12
|
+
@subclasses ||= []
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,250 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
# The pipeline itself, the run method is where it all happens
|
3
|
+
# rubocop:disable ClassLength
|
4
|
+
class Pipeline
|
5
|
+
# rubocop:enable ClassLength
|
6
|
+
class << self
|
7
|
+
# Generate hash based on manifest
|
8
|
+
def hash(source, manifest, options = {})
|
9
|
+
options = DEFAULTS.merge(options)
|
10
|
+
begin
|
11
|
+
Digest::MD5.hexdigest(YAML.safe_load(manifest).map! do |path|
|
12
|
+
"#{path}#{File.mtime(File.join(source, path)).to_i}"
|
13
|
+
end.join.concat(options.to_s))
|
14
|
+
rescue StandardError => se
|
15
|
+
puts "Failed to generate hash from provided manifest: #{se.message}"
|
16
|
+
raise se
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Run the pipeline
|
21
|
+
# This is called from JekyllAssetPipeline::LiquidBlockExtensions.render
|
22
|
+
# or, to be more precise, from JekyllAssetPipeline::CssAssetTag.render and
|
23
|
+
# JekyllAssetPipeline::JavaScriptAssetTag.render
|
24
|
+
# rubocop:disable ParameterLists
|
25
|
+
def run(manifest, prefix, source, destination, tag, type, config)
|
26
|
+
# rubocop:enable ParameterLists
|
27
|
+
# Get hash for pipeline
|
28
|
+
hash = hash(source, manifest, config)
|
29
|
+
|
30
|
+
# Check if pipeline has been cached
|
31
|
+
return cache[hash], true if cache.key?(hash)
|
32
|
+
|
33
|
+
begin
|
34
|
+
puts "Processing '#{tag}' manifest '#{prefix}'"
|
35
|
+
pipeline = new(manifest, prefix, source, destination, type, config)
|
36
|
+
process_pipeline(hash, pipeline)
|
37
|
+
rescue StandardError => se
|
38
|
+
# Add exception to cache
|
39
|
+
cache[hash] = se
|
40
|
+
|
41
|
+
# Re-raise the exception
|
42
|
+
raise se
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Cache processed pipelines
|
47
|
+
def cache
|
48
|
+
@cache ||= {}
|
49
|
+
end
|
50
|
+
|
51
|
+
# Empty cache
|
52
|
+
def clear_cache
|
53
|
+
@cache = {}
|
54
|
+
end
|
55
|
+
|
56
|
+
# Remove staged assets
|
57
|
+
def remove_staged_assets(source, config)
|
58
|
+
config = DEFAULTS.merge(config)
|
59
|
+
staging_path = File.join(source, config['staging_path'])
|
60
|
+
FileUtils.rm_rf(staging_path)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Add prefix to output
|
64
|
+
def puts(message)
|
65
|
+
$stdout.puts("Asset Pipeline: #{message}")
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def process_pipeline(hash, pipeline)
|
71
|
+
pipeline.assets.each do |asset|
|
72
|
+
puts "Saved '#{asset.filename}' to " \
|
73
|
+
"'#{pipeline.destination}/#{asset.output_path}'"
|
74
|
+
end
|
75
|
+
|
76
|
+
# Add processed pipeline to cache
|
77
|
+
cache[hash] = pipeline
|
78
|
+
|
79
|
+
# Return newly processed pipeline and cached status
|
80
|
+
[pipeline, false]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Initialize new pipeline
|
85
|
+
# rubocop:disable ParameterLists
|
86
|
+
def initialize(manifest, prefix, source, destination, type, options = {})
|
87
|
+
# rubocop:enable ParameterLists
|
88
|
+
@manifest = manifest
|
89
|
+
@prefix = prefix
|
90
|
+
@source = source
|
91
|
+
@destination = destination
|
92
|
+
@type = type
|
93
|
+
@options = JekyllAssetPipeline::DEFAULTS.merge(options)
|
94
|
+
|
95
|
+
process
|
96
|
+
end
|
97
|
+
|
98
|
+
attr_reader :assets, :html, :destination
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
# Process the pipeline
|
103
|
+
def process
|
104
|
+
collect
|
105
|
+
convert
|
106
|
+
bundle if @options['bundle']
|
107
|
+
compress if @options['compress']
|
108
|
+
gzip if @options['gzip']
|
109
|
+
save
|
110
|
+
markup
|
111
|
+
end
|
112
|
+
|
113
|
+
# Collect assets based on manifest
|
114
|
+
def collect
|
115
|
+
@assets = YAML.safe_load(@manifest).map! do |path|
|
116
|
+
full_path = File.join(@source, path)
|
117
|
+
File.open(File.join(@source, path)) do |file|
|
118
|
+
JekyllAssetPipeline::Asset.new(file.read, File.basename(path),
|
119
|
+
File.dirname(full_path))
|
120
|
+
end
|
121
|
+
end
|
122
|
+
rescue StandardError => se
|
123
|
+
puts 'Asset Pipeline: Failed to load assets from provided ' \
|
124
|
+
"manifest: #{se.message}"
|
125
|
+
raise se
|
126
|
+
end
|
127
|
+
|
128
|
+
# Convert assets based on the file extension if converter is defined
|
129
|
+
def convert
|
130
|
+
@assets.each do |asset|
|
131
|
+
# Convert asset multiple times if more than one converter is found
|
132
|
+
finished = false
|
133
|
+
while finished == false
|
134
|
+
# Find a converter to use
|
135
|
+
klass = JekyllAssetPipeline::Converter.klass(asset.filename)
|
136
|
+
|
137
|
+
# Convert asset if converter is found
|
138
|
+
if klass.nil?
|
139
|
+
finished = true
|
140
|
+
else
|
141
|
+
convert_asset(klass, asset)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Convert an asset with a given converter class
|
148
|
+
def convert_asset(klass, asset)
|
149
|
+
# Convert asset content
|
150
|
+
converter = klass.new(asset)
|
151
|
+
|
152
|
+
# Replace asset content and filename
|
153
|
+
asset.content = converter.converted
|
154
|
+
asset.filename = File.basename(asset.filename, '.*')
|
155
|
+
|
156
|
+
# Add back the output extension if no extension left
|
157
|
+
if File.extname(asset.filename) == ''
|
158
|
+
asset.filename = "#{asset.filename}#{@type}"
|
159
|
+
end
|
160
|
+
rescue StandardError => se
|
161
|
+
puts "Asset Pipeline: Failed to convert '#{asset.filename}' " \
|
162
|
+
"with '#{klass}': #{se.message}"
|
163
|
+
raise se
|
164
|
+
end
|
165
|
+
|
166
|
+
# Bundle multiple assets into a single asset
|
167
|
+
def bundle
|
168
|
+
content = @assets.map(&:content).join("\n")
|
169
|
+
|
170
|
+
hash = JekyllAssetPipeline::Pipeline.hash(@source, @manifest, @options)
|
171
|
+
@assets = [
|
172
|
+
JekyllAssetPipeline::Asset.new(content, "#{@prefix}-#{hash}#{@type}")
|
173
|
+
]
|
174
|
+
end
|
175
|
+
|
176
|
+
# Compress assets if compressor is defined
|
177
|
+
def compress
|
178
|
+
@assets.each do |asset|
|
179
|
+
# Find a compressor to use
|
180
|
+
klass = JekyllAssetPipeline::Compressor.subclasses.select do |c|
|
181
|
+
c.filetype == @type
|
182
|
+
end.last
|
183
|
+
|
184
|
+
break unless klass
|
185
|
+
|
186
|
+
begin
|
187
|
+
asset.content = klass.new(asset.content).compressed
|
188
|
+
rescue StandardError => se
|
189
|
+
puts "Asset Pipeline: Failed to compress '#{asset.filename}' " \
|
190
|
+
"with '#{klass}': #{se.message}"
|
191
|
+
raise se
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Create Gzip versions of assets
|
197
|
+
def gzip
|
198
|
+
@assets.map! do |asset|
|
199
|
+
gzip_content = Zlib::Deflate.deflate(asset.content)
|
200
|
+
[
|
201
|
+
asset,
|
202
|
+
JekyllAssetPipeline::Asset
|
203
|
+
.new(gzip_content, "#{asset.filename}.gz", asset.dirname)
|
204
|
+
]
|
205
|
+
end.flatten!
|
206
|
+
end
|
207
|
+
|
208
|
+
# Save assets to file
|
209
|
+
def save
|
210
|
+
output_path = @options['output_path']
|
211
|
+
staging_path = @options['staging_path']
|
212
|
+
|
213
|
+
@assets.each do |asset|
|
214
|
+
directory = File.join(@source, staging_path, output_path)
|
215
|
+
write_asset_file(directory, asset)
|
216
|
+
|
217
|
+
# Store output path of saved file
|
218
|
+
asset.output_path = output_path
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# Write asset file to disk
|
223
|
+
def write_asset_file(directory, asset)
|
224
|
+
FileUtils.mkpath(directory) unless File.directory?(directory)
|
225
|
+
begin
|
226
|
+
# Save file to disk
|
227
|
+
File.open(File.join(directory, asset.filename), 'w') do |file|
|
228
|
+
file.write(asset.content)
|
229
|
+
end
|
230
|
+
rescue StandardError => se
|
231
|
+
puts "Asset Pipeline: Failed to save '#{asset.filename}' to " \
|
232
|
+
"disk: #{se.message}"
|
233
|
+
raise se
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
# Generate html markup pointing to assets
|
238
|
+
def markup
|
239
|
+
# Use display_path if defined, otherwise use output_path in url
|
240
|
+
display_path = @options['display_path'] || @options['output_path']
|
241
|
+
|
242
|
+
@html = @assets.map do |asset|
|
243
|
+
klass = JekyllAssetPipeline::Template.klass(asset.filename)
|
244
|
+
html = klass.new(display_path, asset.filename).html unless klass.nil?
|
245
|
+
|
246
|
+
html
|
247
|
+
end.join
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
# Base class for the tag templates
|
3
|
+
# See https://github.com/matthodan/jekyll-asset-pipeline#templates
|
4
|
+
class Template
|
5
|
+
include JekyllAssetPipeline::TemplateHelper
|
6
|
+
extend JekyllAssetPipeline::SubclassTracking
|
7
|
+
|
8
|
+
def initialize(path, filename)
|
9
|
+
@path = path
|
10
|
+
@filename = filename
|
11
|
+
end
|
12
|
+
|
13
|
+
# Filetype to process (e.g. '.js')
|
14
|
+
def self.filetype
|
15
|
+
''
|
16
|
+
end
|
17
|
+
|
18
|
+
# Priority of template (to override default templates)
|
19
|
+
def self.priority
|
20
|
+
0
|
21
|
+
end
|
22
|
+
|
23
|
+
# Finds a template class based on a filename
|
24
|
+
def self.klass(filename)
|
25
|
+
klasses = JekyllAssetPipeline::Template.subclasses.select do |t|
|
26
|
+
t.filetype == File.extname(filename).downcase
|
27
|
+
end
|
28
|
+
klasses.sort! { |x, y| x.priority <=> y.priority }.last
|
29
|
+
end
|
30
|
+
|
31
|
+
# HTML output to return
|
32
|
+
#
|
33
|
+
# Available instance variables:
|
34
|
+
# @filename Name of bundle file
|
35
|
+
# @path Path to bundle file
|
36
|
+
#
|
37
|
+
# Returns string
|
38
|
+
def html
|
39
|
+
"#{@path}/#{@filename}\n"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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 self.priority
|
9
|
+
-1
|
10
|
+
end
|
11
|
+
|
12
|
+
def html
|
13
|
+
"<link href='#{output_path}/#{@filename}' " \
|
14
|
+
"rel='stylesheet' type='text/css' />"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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 self.priority
|
9
|
+
-1
|
10
|
+
end
|
11
|
+
|
12
|
+
def html
|
13
|
+
"<script src='#{output_path}/#{@filename}' " \
|
14
|
+
"type='text/javascript'></script>"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module JekyllAssetPipeline
|
2
|
+
# Contains helper methods used by the tag template classes
|
3
|
+
module TemplateHelper
|
4
|
+
def output_path
|
5
|
+
root_path? ? '' : "/#{@path}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def root_path?
|
9
|
+
stripped_path = @path.to_s.strip
|
10
|
+
stripped_path.nil? ||
|
11
|
+
stripped_path.empty? ||
|
12
|
+
stripped_path == '/'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll_asset_pipeline
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Hodan
|
8
|
+
- Janos Rusiczki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-12-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jekyll
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.5'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '3.5'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: liquid
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '4.0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '4.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '5.2'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '5.2'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '12.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '12.0'
|
70
|
+
description: |2
|
71
|
+
Jekyll Asset Pipeline adds asset preprocessing (CoffeeScript, Sass,
|
72
|
+
Less, ERB, etc.) and asset compression / minification / gzip (Yahoo YUI
|
73
|
+
Compressor, Google Closure Compiler, etc.) to Jekyll.
|
74
|
+
email:
|
75
|
+
- matthew.c.hodan@gmail.com
|
76
|
+
- janos.rusiczki@gmail.com
|
77
|
+
executables: []
|
78
|
+
extensions: []
|
79
|
+
extra_rdoc_files: []
|
80
|
+
files:
|
81
|
+
- CHANGELOG.md
|
82
|
+
- LICENSE
|
83
|
+
- README.md
|
84
|
+
- lib/jekyll_asset_pipeline.rb
|
85
|
+
- lib/jekyll_asset_pipeline/asset.rb
|
86
|
+
- lib/jekyll_asset_pipeline/compressor.rb
|
87
|
+
- lib/jekyll_asset_pipeline/converter.rb
|
88
|
+
- lib/jekyll_asset_pipeline/extensions/jekyll/site.rb
|
89
|
+
- lib/jekyll_asset_pipeline/extensions/jekyll/site_extensions.rb
|
90
|
+
- lib/jekyll_asset_pipeline/extensions/liquid/asset_tag.rb
|
91
|
+
- lib/jekyll_asset_pipeline/extensions/liquid/asset_tags/css_asset_tag.rb
|
92
|
+
- lib/jekyll_asset_pipeline/extensions/liquid/asset_tags/javascript_asset_tag.rb
|
93
|
+
- lib/jekyll_asset_pipeline/extensions/liquid/liquid_block_extensions.rb
|
94
|
+
- lib/jekyll_asset_pipeline/extensions/ruby/subclass_tracking.rb
|
95
|
+
- lib/jekyll_asset_pipeline/pipeline.rb
|
96
|
+
- lib/jekyll_asset_pipeline/template.rb
|
97
|
+
- lib/jekyll_asset_pipeline/templates/css_tag_template.rb
|
98
|
+
- lib/jekyll_asset_pipeline/templates/javascript_tag_template.rb
|
99
|
+
- lib/jekyll_asset_pipeline/templates/template_helper.rb
|
100
|
+
- lib/jekyll_asset_pipeline/version.rb
|
101
|
+
homepage: https://github.com/matthodan/jekyll-asset-pipeline
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 2.1.0
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.6.14
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: A powerful asset pipeline for Jekyll that bundles, converts, and minifies
|
125
|
+
CSS and JavaScript assets.
|
126
|
+
test_files: []
|