japr 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # JAPR (Jekyll Asset Pipeline Reborn)
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/japr.png)](http://badge.fury.io/rb/japr) [![Build Status](https://secure.travis-ci.org/kitsched/japr.png)](https://travis-ci.org/kitsched/japr) [![Coverage Status](https://coveralls.io/repos/kitsched/japr/badge.png?branch=master)](https://coveralls.io/r/kitsched/japr?branch=master) [![Dependency Status](https://gemnasium.com/kitsched/japr.png)](https://gemnasium.com/kitsched/japr) [![Code Climate](https://codeclimate.com/github/kitsched/japr.png)](https://codeclimate.com/github/kitsched/japr)
3
+ [![Gem Version](https://badge.fury.io/rb/japr.png)](http://badge.fury.io/rb/japr)
4
+ [![Build Status](https://secure.travis-ci.org/kitsched/japr.png)](https://travis-ci.org/kitsched/japr)
5
+ [![Coverage Status](https://coveralls.io/repos/kitsched/japr/badge.png?branch=master)](https://coveralls.io/r/kitsched/japr?branch=master)
6
+ [![Dependency Status](https://gemnasium.com/kitsched/japr.png)](https://gemnasium.com/kitsched/japr)
7
+ [![Code Climate](https://codeclimate.com/github/kitsched/japr.png)](https://codeclimate.com/github/kitsched/japr)
4
8
 
5
9
  JAPR 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.
6
10
 
@@ -12,7 +16,13 @@ This project is a fork of [Jekyll Asset Pipeline](https://github.com/matthodan/j
12
16
  - [How It Works](#how-it-works)
13
17
  - [Getting Started](#getting-started)
14
18
  - [Asset Preprocessing](#asset-preprocessing)
19
+ - [CoffeeScript](#coffeescript)
20
+ - [SASS / SCSS](#sass--scss)
21
+ - [LESS](#less)
22
+ - [Successive Preprocessing](#successive-preprocessing)
15
23
  - [Asset Compression](#asset-compression)
24
+ - [Yahoo's YUI Compressor](#yahoos-yui-compressor)
25
+ - [Google's Closure Compiler](#googles-closure-compiler)
16
26
  - [Templates](#templates)
17
27
  - [Configuration](#configuration)
18
28
  - [Octopress](#octopress)
@@ -27,39 +37,39 @@ This project is a fork of [Jekyll Asset Pipeline](https://github.com/matthodan/j
27
37
  - Asset preprocessing/conversion (supports [CoffeeScript](http://coffeescript.org/), [Sass / Scss](http://sass-lang.com/), [Less](http://lesscss.org/), [Erb](http://ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html), etc.)
28
38
  - Asset compression (supports [YUI Compressor](http://developer.yahoo.com/yui/compressor/), [Closure Compiler](https://developers.google.com/closure/compiler/), etc.)
29
39
  - Fingerprints bundled asset filenames with MD5 hashes for better browser caching
30
- - Automatic generation of HTML "link" and "script" tags that point to bundled assets
40
+ - Automatic generation of HTML `link` and `script` tags that point to bundled assets
31
41
  - Integrates seamlessly into Jekyll's workflow, including auto site regeneration
32
42
 
33
43
  ## How It Works
34
44
 
35
45
  JAPR's workflow can be summarized as follows:
36
46
 
37
- 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.
47
+ 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.
38
48
  2. Collects raw assets based on the manifest and runs them through converters / preprocessors (if necessary) to convert them into valid CSS or JavaScript.
39
- 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.
40
- 4. Replaces `css_asset_tag` and `javascript_asset_tag` Liquid tags with HTML "link" and "script" tags, respectively, that link to the finished bundles.
49
+ 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.
50
+ 4. Replaces `css_asset_tag` and `javascript_asset_tag` Liquid tags with HTML `link` and `script` tags, respectively, that link to the finished bundles.
41
51
 
42
52
  ## Getting Started
43
53
 
44
54
  JAPR 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 JAPR.
45
55
 
46
- 1. Install the "japr" gem via [Rubygems](http://rubygems.org/).
56
+ 1. Install the `japr` gem via [Rubygems](http://rubygems.org/).
47
57
 
48
58
  ``` bash
49
59
  $ gem install japr
50
60
  ```
51
61
 
52
- > *If you are using [Bundler](http://gembundler.com/) to manage your project's gems, you can just add "japr" to your Gemfile and run `bundle install`.*
62
+ If you are using [Bundler](http://gembundler.com/) to manage your project's gems, you can just add `japr` to your Gemfile and run `bundle install`.
53
63
 
54
- 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.
64
+ 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.
55
65
 
56
66
  ``` ruby
57
67
  require 'japr'
58
68
  ```
59
69
 
60
- 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.
70
+ 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.
61
71
 
62
- 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.
72
+ 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.
63
73
 
64
74
  ``` html
65
75
  {% css_asset_tag global %}
@@ -72,9 +82,9 @@ JAPR is extremely easy to add to your Jekyll project and has no incremental depe
72
82
  - /_assets/bar.js
73
83
  {% endjavascript_asset_tag %}
74
84
  ```
75
- > *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.*
85
+ 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.
76
86
 
77
- 5. Run the `jekyll build` command to compile your site. You should see an output that includes the following JAPR status messages.
87
+ 5. Run the `jekyll build` command to compile your site. You should see an output that includes the following JAPR status messages.
78
88
 
79
89
  ``` bash
80
90
  $ jekyll build
@@ -85,19 +95,19 @@ JAPR is extremely easy to add to your Jekyll project and has no incremental depe
85
95
  Asset Pipeline: Saved 'global-md5hash.js' to 'yoursitepath/assets'
86
96
  ```
87
97
 
88
- > *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.*
98
+ 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.
89
99
 
90
- 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.*
100
+ 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.*
91
101
 
92
102
  ## Asset Preprocessing
93
103
 
94
- 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 JAPR'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.
104
+ 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 JAPR'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.
95
105
 
96
106
  In the following example, we will add a preprocessor that converts CoffeeScript into JavaScript.
97
107
 
98
108
  ### CoffeeScript
99
109
 
100
- 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).
110
+ 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).
101
111
 
102
112
  ``` ruby
103
113
  module JAPR
@@ -115,81 +125,100 @@ In the following example, we will add a preprocessor that converts CoffeeScript
115
125
  end
116
126
  ```
117
127
 
118
- > The above code adds a CoffeeScript converter. You can name a converter anything as long as it inherits from "JAPR::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.
128
+ The above code adds a CoffeeScript converter. You can name a converter anything as long as it inherits from `JAPR::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.
119
129
 
120
- 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.
130
+ 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.
121
131
 
122
132
  ``` bash
123
133
  $ gem install coffee-script
124
134
  ```
125
135
 
126
- > *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`.*
136
+ 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`.
127
137
 
128
- 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".
138
+ 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`.
129
139
 
130
140
  4. Run the `jekyll build` command to compile your site.
131
141
 
132
- That is it! Your asset pipeline has converted any CoffeeScript assets into JavaScript before adding them to a bundle.
142
+ That is it! Your asset pipeline has converted any CoffeeScript assets into JavaScript before adding them to a bundle.
133
143
 
134
144
  ### SASS / SCSS
135
145
 
136
146
  You probably get the gist of how converters work, but here's an example of a SASS converter for quick reference.
137
147
 
138
- ``` ruby
139
- module JAPR
140
- class SassConverter < JAPR::Converter
141
- require 'sass'
148
+ ``` ruby
149
+ module JAPR
150
+ class SassConverter < JAPR::Converter
151
+ require 'sass'
142
152
 
143
- def self.filetype
144
- '.scss'
145
- end
153
+ def self.filetype
154
+ '.scss'
155
+ end
146
156
 
147
- def convert
148
- return Sass::Engine.new(@content, syntax: :scss).render
149
- end
157
+ def convert
158
+ return Sass::Engine.new(@content, syntax: :scss).render
150
159
  end
151
160
  end
152
- ```
161
+ end
162
+ ```
153
163
 
154
- > *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.*
164
+ 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.
165
+
166
+ 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.
167
+ You can use the `@dirname` instance variable for this, which contains the path to the current asset's directory:
168
+
169
+ ``` ruby
170
+ ...
171
+ def convert
172
+ return Sass::Engine.new(@content, syntax: :scss, load_paths: [@dirname]).render
173
+ end
174
+ ...
175
+ ```
155
176
 
156
177
  ### LESS
157
178
 
158
- ``` ruby
159
- module JAPR
160
- class LessConverter < JAPR::Converter
161
- require 'less'
179
+ ``` ruby
180
+ module JAPR
181
+ class LessConverter < JAPR::Converter
182
+ require 'less'
162
183
 
163
- def self.filetype
164
- '.less'
165
- end
184
+ def self.filetype
185
+ '.less'
186
+ end
166
187
 
167
- def convert
168
- return Less::Parser.new.parse(@content).to_css
169
- end
188
+ def convert
189
+ return Less::Parser.new.parse(@content).to_css
170
190
  end
171
191
  end
172
- ```
192
+ end
193
+ ```
194
+
195
+ 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.
196
+
197
+ As with the SASS convertor, you'll probably need to specify a base load path and pass that to the LESS Parser:
173
198
 
174
- > *Don't forget to install the "less" gem or add it to your Gemfile and run
175
- `bundle install` before you run the `jekyll build` command since the above
176
- LESS converter requires the "less" library as a dependency.*
199
+ ``` ruby
200
+ ...
201
+ def convert
202
+ return Less::Parser.new(paths: [@dirname]).parse(@content).to_css
203
+ end
204
+ ...
205
+ ```
177
206
 
178
207
  ### Successive Preprocessing
179
208
 
180
- 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).
209
+ 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).
181
210
 
182
- > *Don't forget to define preprocessors for the extensions you use in your filenames, otherwise JAPR will not process your asset.*
211
+ Don't forget to define preprocessors for the extensions you use in your filenames, otherwise JAPR will not process your asset.
183
212
 
184
213
  ## Asset Compression
185
214
 
186
- Asset compression allows us to decrease the size of our assets and increase the speed of our site. One of JAPR'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.
215
+ Asset compression allows us to decrease the size of our assets and increase the speed of our site. One of JAPR'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.
187
216
 
188
217
  In the following example, we will add a compressor that uses Yahoo's YUI Compressor to compress our CSS and JavaScript assets.
189
218
 
190
219
  ### Yahoo's YUI Compressor
191
220
 
192
- 1. In the "jekyll\_asset\_pipeline.rb" file that we created in the "Getting Started" section, add the following code to the end of the file (i.e. after the "require" statement).
221
+ 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).
193
222
 
194
223
  ``` ruby
195
224
  module JAPR
@@ -219,99 +248,102 @@ In the following example, we will add a compressor that uses Yahoo's YUI Compres
219
248
  end
220
249
  ```
221
250
 
222
- > The above code adds a CSS and a JavaScript compressor. You can name a compressor anything as long as it inherits from "JAPR::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.
251
+ The above code adds a CSS and a JavaScript compressor. You can name a compressor anything as long as it inherits from `JAPR::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.
223
252
 
224
- 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.
253
+ 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.
225
254
 
226
- ``` ruby
255
+ ``` bash
227
256
  $ gem install yui-compressor
228
257
  ```
229
258
 
230
- > *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`.*
259
+ 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`.
231
260
 
232
261
  3. Run the `jekyll build` command to compile your site.
233
262
 
234
- 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.
263
+ 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.
235
264
 
236
265
  ### Google's Closure Compiler
237
266
 
238
267
  You probably get the gist of how compressors work, but here's an example of a Google Closure Compiler compressor for quick reference.
239
268
 
240
- ``` ruby
241
- class JavaScriptCompressor < JAPR::Compressor
242
- require 'closure-compiler'
269
+ ``` ruby
270
+ class JavaScriptCompressor < JAPR::Compressor
271
+ require 'closure-compiler'
243
272
 
244
- def self.filetype
245
- '.js'
246
- end
273
+ def self.filetype
274
+ '.js'
275
+ end
247
276
 
248
- def compress
249
- return Closure::Compiler.new.compile(@content)
250
- end
277
+ def compress
278
+ return Closure::Compiler.new.compile(@content)
251
279
  end
252
- ```
253
- > *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.*
280
+ end
281
+ ```
282
+
283
+ 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.
254
284
 
255
285
  ## Templates
256
286
 
257
- When JAPR 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).
287
+ When JAPR 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).
258
288
 
259
- 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.
289
+ 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.
260
290
 
261
- 1. In the "jekyll\_asset\_pipeline.rb" file that we created in the "Getting Started" section, add the following code.
291
+ 1. In the `jekyll_asset_pipeline.rb` file that we created in the [Getting Started](#getting-started) section, add the following code.
262
292
 
263
- ``` ruby
264
- module JAPR
265
- class CssTagTemplate < JAPR::Template
266
- def self.filetype
267
- '.css'
268
- end
293
+ ``` ruby
294
+ module JAPR
295
+ class CssTagTemplate < JAPR::Template
296
+ def self.filetype
297
+ '.css'
298
+ end
269
299
 
270
- def html
271
- "<link href='/#{@path}/#{@filename}' rel='stylesheet' type='text/css' media='screen' />\n"
272
- end
300
+ def html
301
+ "<link href='/#{@path}/#{@filename}' rel='stylesheet'" \
302
+ "type='text/css' media='screen' />\n"
273
303
  end
274
304
  end
275
- ```
305
+ end
306
+ ```
276
307
 
277
- > *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 JAPR module.*
308
+ 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 JAPR module.
278
309
 
279
- > 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.
310
+ 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.
280
311
 
281
312
  2. Run the `jekyll` command to compile your site.
282
313
 
283
- 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.
314
+ 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.
284
315
 
285
316
  ## Configuration
286
317
 
287
- JAPR provides the following configuration options that can be controlled by adding the following to the end of your project's "\_config.yml" file.
318
+ JAPR 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.
288
319
 
289
320
  ``` yaml
290
321
  asset_pipeline:
291
- bundle: true # Default = true
292
- compress: true # Default = true
293
- output_path: assets # Default = assets
294
- display_path: nil # Default = nil
295
- gzip: false # Default = false
322
+ bundle: true
323
+ compress: true
324
+ output_path: assets
325
+ display_path: nil
326
+ gzip: false
296
327
  ```
297
328
 
298
- > *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.*
299
- >
300
- > - The "bundle" setting controls whether JAPR bundles the assets defined in each manifest. If "bundle" is 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.
301
- > - The "compress" setting tells JAPR whether or not to compress the bundled assets. It is useful to set this setting to "false" while you are debugging your site.
302
- > - The "output\_path" setting defines where generated bundles should be saved within the "\_site" folder of your project.
303
- > - The "display\_path" setting 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/").
304
- > - The "gzip" setting controls whether JAPR saves gzipped versions of your assets alongside un-gzipped versions.
329
+ Setting | Default | Description
330
+ ---------------|----------|-----------------------------------------------------
331
+ `bundle` | `true` | controls whether JAPR 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.
332
+ `compress` | `true` | tells JAPR whether or not to compress the bundled assets. It is useful to set this setting to `false` while you are debugging your site.
333
+ `output_path` | `assets` | defines where generated bundles should be saved within the `_site` folder of your project.
334
+ `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/`).
335
+ `gzip` | `false` | controls whether JAPR saves gzipped versions of your assets alongside un-gzipped versions.
336
+
305
337
 
306
338
  ## Octopress
307
339
 
308
- [Octopress](http://octopress.org/) is a popular framework for Jekyll that can help you get a blog up and running quickly. JAPR can be added to an Octopress site using the [Getting Started](#getting-started) steps above with the following modifications:
340
+ [Octopress](http://octopress.org/) is a popular framework for Jekyll that can help you get a blog up and running quickly. JAPR can be added to an Octopress site using the [Getting Started](#getting-started) steps above with the following modifications:
309
341
 
310
- 1. Octopress uses Bundler to manage your site's dependencies. You should add `gem "japr"` to your Gemfile and then run `bundle install` to install.
342
+ 1. Octopress uses Bundler to manage your site's dependencies. You should add `gem japr` to your Gemfile and then run `bundle install` to install.
311
343
 
312
- 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.
344
+ 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.
313
345
 
314
- 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").
346
+ 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`).
315
347
 
316
348
  4. No change to this step.
317
349
 
@@ -323,16 +355,15 @@ If you have any difficulties using JAPR with Octopress, please [open an issue](h
323
355
 
324
356
  You can contribute to the JAPR by submitting a pull request [via GitHub](https://github.com/kitsched/japr). There are a few areas that need improvement:
325
357
 
326
- - __Tests, tests, tests.__ **This project is now almost fully tested.**
327
- - __Handle remote assets.__ Right now, JAPR 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.
328
- - __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, JAPR now supports successive preprocessing.**
358
+ - __Tests, tests, tests.__ **This project is now almost fully tested.**
359
+ - __Handle remote assets.__ Right now, JAPR 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.
360
+ - __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, JAPR now supports successive preprocessing.**
329
361
 
330
362
  If you have any ideas or you would like to see anything else improved please use the [issues section](https://github.com/kitsched/japr/issues).
331
363
 
332
364
  ## Community
333
365
 
334
- - Here is a list of [sites that use JAPR](http://github.com/kitsched/japr/wiki/Sites-that-use-JAPR). Feel free to add your site to the list if you want.
335
-
366
+ - Here is a list of [sites that use JAPR](http://github.com/kitsched/japr/wiki/Sites-that-use-JAPR). Feel free to add your site to the list if you want.
336
367
 
337
368
  ## Credits
338
369
 
@@ -5,8 +5,8 @@ module JAPR
5
5
  def initialize(asset)
6
6
  @content = asset.content
7
7
  @type = File.extname(asset.filename).downcase
8
- @converted = convert
9
8
  @dirname = asset.dirname
9
+ @converted = convert
10
10
  end
11
11
 
12
12
  def converted
@@ -158,9 +158,7 @@ module JAPR
158
158
 
159
159
  # Bundle multiple assets into a single asset
160
160
  def bundle
161
- content = @assets.map do |a|
162
- a.content
163
- end.join("\n")
161
+ content = @assets.map(&:content).join("\n")
164
162
 
165
163
  hash = JAPR::Pipeline.hash(@source, @manifest, @options)
166
164
  @assets = [JAPR::Asset.new(content, "#{@prefix}-#{hash}#{@type}")]
@@ -1,3 +1,3 @@
1
1
  module JAPR
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: japr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-27 00:00:00.000000000 Z
12
+ date: 2015-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll