tgfa-jekyll-assets 0.7.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +78 -0
  5. data/.travis.yml +9 -0
  6. data/.yardopts +1 -0
  7. data/Gemfile +15 -0
  8. data/Gemfile.jekyll-1.0 +2 -0
  9. data/Guardfile +8 -0
  10. data/HISTORY.md +202 -0
  11. data/LICENSE +22 -0
  12. data/README.md +569 -0
  13. data/Rakefile +9 -0
  14. data/lib/jekyll/assets_plugin/asset_path.rb +39 -0
  15. data/lib/jekyll/assets_plugin/configuration.rb +87 -0
  16. data/lib/jekyll/assets_plugin/environment.rb +62 -0
  17. data/lib/jekyll/assets_plugin/filters.rb +19 -0
  18. data/lib/jekyll/assets_plugin/patches/asset_patch.rb +68 -0
  19. data/lib/jekyll/assets_plugin/patches/bundled_asset_patch.rb +16 -0
  20. data/lib/jekyll/assets_plugin/patches/context_patch.rb +27 -0
  21. data/lib/jekyll/assets_plugin/patches/index_patch.rb +25 -0
  22. data/lib/jekyll/assets_plugin/patches/processed_asset_patch.rb +60 -0
  23. data/lib/jekyll/assets_plugin/patches/site_patch.rb +68 -0
  24. data/lib/jekyll/assets_plugin/patches.rb +1 -0
  25. data/lib/jekyll/assets_plugin/renderer.rb +47 -0
  26. data/lib/jekyll/assets_plugin/tag.rb +19 -0
  27. data/lib/jekyll/assets_plugin/version.rb +5 -0
  28. data/lib/jekyll/assets_plugin.rb +4 -0
  29. data/lib/jekyll-assets/bootstrap.rb +6 -0
  30. data/lib/jekyll-assets/bourbon.rb +4 -0
  31. data/lib/jekyll-assets/compass.rb +7 -0
  32. data/lib/jekyll-assets/font-awesome.rb +6 -0
  33. data/lib/jekyll-assets/neat.rb +4 -0
  34. data/lib/jekyll-assets.rb +2 -0
  35. data/spec/fixtures/.gitignore +2 -0
  36. data/spec/fixtures/_assets/app.css.erb +5 -0
  37. data/spec/fixtures/_assets/app.js +1 -0
  38. data/spec/fixtures/_assets/fonts/vapor.eot +0 -0
  39. data/spec/fixtures/_assets/fonts/vapor.svg +0 -0
  40. data/spec/fixtures/_assets/fonts/vapor.ttf +0 -0
  41. data/spec/fixtures/_assets/fonts/vapor.woff +0 -0
  42. data/spec/fixtures/_assets/lib/relative.css.scss +12 -0
  43. data/spec/fixtures/_assets/noise.png +0 -0
  44. data/spec/fixtures/_assets/should_be_blank.css.erb +1 -0
  45. data/spec/fixtures/_assets/should_fail.css.erb +1 -0
  46. data/spec/fixtures/_assets/vapor.css.scss +13 -0
  47. data/spec/fixtures/_assets/vapor.js +2 -0
  48. data/spec/fixtures/_assets/vendor/bourbon.css.sass +4 -0
  49. data/spec/fixtures/_assets/vendor/compass.css.sass +4 -0
  50. data/spec/fixtures/_assets/vendor/neat.css.sass +5 -0
  51. data/spec/fixtures/_assets/wowscript.js +0 -0
  52. data/spec/fixtures/_assets/wowstyle.css +0 -0
  53. data/spec/fixtures/_config.yml +2 -0
  54. data/spec/fixtures/_layouts/default.html +9 -0
  55. data/spec/fixtures/_posts/2012-10-19-hello-world.md +6 -0
  56. data/spec/fixtures/index.html +0 -0
  57. data/spec/lib/jekyll/assets_plugin/configuration_spec.rb +167 -0
  58. data/spec/lib/jekyll/assets_plugin/environment_spec.rb +22 -0
  59. data/spec/lib/jekyll/assets_plugin/filters_spec.rb +103 -0
  60. data/spec/lib/jekyll/assets_plugin/patches/site_patch_spec.rb +168 -0
  61. data/spec/lib/jekyll/assets_plugin/renderer_spec.rb +48 -0
  62. data/spec/lib/jekyll/assets_plugin/tag_spec.rb +103 -0
  63. data/spec/lib/jekyll-assets/bootstrap_spec.rb +8 -0
  64. data/spec/lib/jekyll-assets/bourbon_spec.rb +8 -0
  65. data/spec/lib/jekyll-assets/compass_spec.rb +8 -0
  66. data/spec/lib/jekyll-assets/font-awesome_spec.rb +8 -0
  67. data/spec/lib/jekyll-assets/neat_spec.rb +8 -0
  68. data/spec/spec_helper.rb +45 -0
  69. data/spec/support/fixtures_helpers.rb +7 -0
  70. data/tgfa-jekyll-assets.gemspec +41 -0
  71. metadata +322 -0
data/README.md ADDED
@@ -0,0 +1,569 @@
1
+ # Jekyll::AssetsPlugin
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/jekyll-assets.png)](http://badge.fury.io/rb/jekyll-assets)
4
+ [![Build Status](https://secure.travis-ci.org/ixti/jekyll-assets.png)](http://travis-ci.org/ixti/jekyll-assets)
5
+ [![Dependency Status](https://gemnasium.com/ixti/jekyll-assets.png)](https://gemnasium.com/ixti/jekyll-assets)
6
+ [![Code Climate](https://codeclimate.com/github/ixti/jekyll-assets.png)](https://codeclimate.com/github/ixti/jekyll-assets)
7
+ [![Coverage Status](https://coveralls.io/repos/ixti/jekyll-assets/badge.png)](https://coveralls.io/r/ixti/jekyll-assets)
8
+
9
+ Jekyll plugin, that adds Rails-alike assets pipeline, that means that:
10
+
11
+ - It allows you to write javascript/css assets in other languages such as
12
+ CoffeeScript, Sass, Less and ERB.
13
+ - It allows you to specify dependencies between your assets and automatically
14
+ concatenates them.
15
+ - It allows you to minify/compress your JavaScript and CSS assets using
16
+ compressor you like: YUI, SASS, Uglifier or no compression at all.
17
+ - It supports JavaScript templates for client-side rendering of strings or
18
+ markup. JavaScript templates have the special format extension `.jst` and are
19
+ compiled to JavaScript functions.
20
+ - Adds MD5 fingerprint suffix for _cache busting_. That means your `app.css`
21
+ will become `app-908e25f4bf641868d8683022a5b62f54.css`. See `cachebust`
22
+ configuration option for other variants.
23
+ - Produce gzipped versions of assets. See `gzip` configuration option for
24
+ details.
25
+ - [Compass][compass], [Bourbon][bourbon] and [Neat][neat] built-in support.
26
+ See "Custom Vendors" below.
27
+
28
+ [compass]: http://compass-style.org/
29
+ [bourbon]: http://bourbon.io/
30
+ [neat]: http://neat.bourbon.io/
31
+
32
+ Jekyll-Assets uses fabulous [Sprockets][sprockets] under the hood, so you may
33
+ refer to Rails guide about [Asset Pipeline][rails-guide] for detailed
34
+ information about amazing features it gives you.
35
+
36
+ *Note:* You must have an [ExecJS][extjs] supported runtime in order to use
37
+ CoffeeScript.
38
+
39
+
40
+ [rails-guide]: http://guides.rubyonrails.org/asset_pipeline.html
41
+ [sprockets]: https://github.com/sstephenson/sprockets#readme
42
+ [extjs]: https://github.com/sstephenson/execjs#readme
43
+
44
+ For a quick start check out [jekyll-assets introduction][jekyll-assets-intro]
45
+ that shows how to use it step by step. Also you might want to take a look on
46
+ [my blog sources][ixti-blog-src] as a real-world example as well.
47
+
48
+ [jekyll-assets-intro]: http://ixti.net/software/2012/12/30/unleash-mr-hyde-introduction-of-jekyll-assets.html
49
+ [ixti-blog-src]: https://github.com/ixti/ixti.github.com
50
+
51
+
52
+ ## Installation
53
+
54
+ Add this line to your application's Gemfile:
55
+
56
+ gem 'tgfa-jekyll-assets'
57
+
58
+ And then execute:
59
+
60
+ $ bundle
61
+
62
+ Or install it yourself as:
63
+
64
+ $ gem install tgfa-jekyll-assets
65
+
66
+
67
+ ## How to Use Jekyll-Assets
68
+
69
+ First of all make sure to require it. Common practice is to add following line
70
+ into `_plugins/ext.rb` file:
71
+
72
+ ``` ruby
73
+ require "jekyll-assets"
74
+ ```
75
+
76
+ Once plugin installed, you'll have following Liquid tags available:
77
+
78
+ - `{% javascript app %}`: Generates `<script>` tag for `app.js`
79
+ - `{% stylesheet app %}`: Generates `<link>` tag for `app.css`
80
+ - `{% image logo.png %}`: Generates `<img>` tag for `logo.png`
81
+ - `{% asset_path logo.png %}`: Returns _resulting_ URL for `logo.png`
82
+ - `{% asset app.css %}`: Returns _compiled_ body of `app.css`
83
+
84
+ Also you'll have complimentary Liquid filters as well:
85
+
86
+ - `{{ 'app' | javascript }}`: Generates `<script>` tag for `app.js`
87
+ - `{{ 'app' | stylesheet }}`: Generates `<link>` tag for `app.css`
88
+ - `{{ 'logo.png' | image }}`: Generates `<img>` tag for `logo.png`
89
+ - `{{ 'logo.png' | asset_path }}`: Returns _resulting_ URL for `logo.png`
90
+ - `{{ 'app.css' | asset }}`: Returns _compiled_ body of `app.css`
91
+
92
+ Filters are used mostly to render tag (or asset source) using variable that
93
+ holds value of asset logical path rather than specifiyng it directly. Here's
94
+ an example that speaks for itself:
95
+
96
+ ```
97
+ {% if page.custom_css %}{{ page.custom_css | stylesheet }}{% endif %}
98
+ ```
99
+
100
+ All compiled assets will be stored under `assets/` dir of generated site.
101
+
102
+ Pipeline assets should be under your sources directory of Jekyll site. When a
103
+ file is referenced with liquid tag or with helper from another asset, Sprockets
104
+ searches the three default asset locations for it: `_assets/images`,
105
+ `_assets/javascripts` and `_assets/stylesheets`.
106
+
107
+ For example these files:
108
+
109
+ ```
110
+ _assets/stylesheets/app.css
111
+ _assets/javascripts/app.js
112
+ _assets/javascripts/vendor/jquery.js
113
+ ```
114
+
115
+ would be referenced like this:
116
+
117
+ ``` html
118
+ {% stylesheet app %}
119
+ {% javascript app %}
120
+ {% javascript vendor/jquery %}
121
+ ```
122
+
123
+ You might want to require `vendor/jquery.js` into your `app.js`. To do so, just
124
+ put following line in the beginning of your `app.js` to get it concatenated:
125
+
126
+ ``` javascript
127
+ //= require vendor/jquery
128
+
129
+ $(function () {
130
+ alert('I love BIG BOOKS!');
131
+ });
132
+ ```
133
+
134
+ If you want to use CoffeScript, just add `.coffee` suffix to the file you want
135
+ and you're good to go. For example, here's how your `app.js.coffe` might look
136
+ like:
137
+
138
+ ``` coffeescript
139
+ #= require vendor/jquery
140
+
141
+ $ ->
142
+ alert 'I love BIG BOOKS! And small ones too!'
143
+ ```
144
+
145
+ Notice, that `vendor/jquery` is not required to be coffee script. You can easily
146
+ mix CoffeeScript and vanilla JavaScript, CSS and SCSS and SASS and LESS. The
147
+ difference is only in comments styles used with _directives_.
148
+
149
+ See detailed information about these _directives_ below.
150
+
151
+ You might also want your stylesheets and javascripts to be minified. In this
152
+ case just install the `uglifier` gem and any other gems you will be using, e.g.
153
+ `sass`, `coffee-script`. Then add following lines into your `config.yml`:
154
+
155
+ ``` yaml
156
+ assets:
157
+ js_compressor: uglifier
158
+ css_compressor: sass
159
+ ```
160
+
161
+ If you want to use YUI compressor for minification, install `yui-compressor`
162
+ gem and put `yui` in place of `uglifier` and/or `sass` in the config file.
163
+ You can also define and use your own compressor, see "Custom Compressors".
164
+
165
+ Let's go crazy now! Assume you want your blog's `body` background color to be
166
+ white all the time, but red if you compiled your web-site in December. Just add
167
+ `.erb` suffix extension and you can use ruby in your asset like this:
168
+
169
+ ```
170
+ // file: _assets/stylesheets/app.css.sass.erb
171
+
172
+ body
173
+ background-color: <%= (12 == Date.today.month) ? "red" : "white" %>
174
+ ```
175
+
176
+ Want more? Sure, here you are. You can use JavaScript templating with EJS or ECO
177
+ for example. Create a file `_assets/javascripts/hello.jst.ejs` with following
178
+ contents:
179
+
180
+ ``` html
181
+ <p>Hello, <span><%= name %></span>!</p>
182
+ <p><%= info %></p>
183
+ ```
184
+
185
+ Then use it in your `app.js` file like this:
186
+
187
+ ``` coffeescript
188
+ #= require vendor/jquery
189
+ #= require hello
190
+
191
+ $ ->
192
+ $("body").html JST["hello"]
193
+ name: "ixti"
194
+ info: "I love BIG BOOKS! And small ones too!"
195
+ ```
196
+
197
+ Finally, you might want to store your assets on [Amazon S3][amazon-s3] or any
198
+ CDN service you like. As said previously, all compiled/processed assets got
199
+ special MD5 checksum appended to their original filenames. So, for example,
200
+ your `app.js.coffee` will become something like:
201
+
202
+ app-4f41243847da693a4f356c0486114bc6.js
203
+
204
+ By default, generated URLs will have `/assets/` prefixes, but you will want to
205
+ change this if you are going to host assets somewhere else. This can be easily
206
+ changed via configuration:
207
+
208
+ ``` yaml
209
+ assets:
210
+ baseurl: //my.super-cool-cdn.com/
211
+ ```
212
+
213
+ [amazon-s3]: http://aws.amazon.com/s3
214
+
215
+
216
+ ### Custom Compressors
217
+
218
+ Sprockets comes with good set of preconfigured compressors, but imagine you are
219
+ not satisfied with default settings. For example you want to strip all comments
220
+ but copyrights info. In this case you can define and use your own compressor.
221
+
222
+ To do so, first let's define new compressor in `_plugins/ext.rb`:
223
+
224
+ ``` ruby
225
+ require "jekyll-assets"
226
+ require "sprockets"
227
+
228
+ Sprockets.register_compressor 'application/javascript',
229
+ :my_uglifier, Uglifier.new(:comments => :copyright)
230
+ ```
231
+
232
+ Once it's done, just tell assets to use `my_uglifier` as js compressor:
233
+
234
+ ``` yaml
235
+ assets:
236
+ js_compressor: my_uglifier
237
+ ```
238
+
239
+
240
+ ### Compilation Cache
241
+
242
+ To improve build time, you can enabled compiled assets cache:
243
+
244
+ ``` yaml
245
+ assets:
246
+ cache: true
247
+ ```
248
+
249
+ This will keep cache of compiled assets in `.jekyll-assets-cache` under source
250
+ of your jekyl site. If you want to use different location specify it instead of
251
+ `true`, in this case it should be an absolute path or path relative to source
252
+ path of your jekyl site.
253
+
254
+
255
+ ## Custom Vendors
256
+
257
+ Sometimes you would like to have some 3rd-party vendors. For this purposes,
258
+ normally all you have to do is to override default assets sources in config:
259
+
260
+ ``` yaml
261
+ assets:
262
+ sources:
263
+ - _assets/images
264
+ - _assets/javascripts
265
+ - _assets/stylesheets
266
+ - _vendors/bootstrap/stylesheets
267
+ - _vendors/bootstrap/javascripts
268
+ ```
269
+
270
+ But sometimes this is not enough. For example, with compass. As jekyll-assets
271
+ uses Sprockets internally, you can simply append "global" paths into it. Just
272
+ add following line into your `_plugins/ext.rb` file:
273
+
274
+ ``` ruby
275
+ require "sprockets"
276
+
277
+ Sprockets.append_path "/my/vendor"
278
+ ```
279
+
280
+ That's it, now jekyll-assets will try to look for assets inside `/my/vendor`
281
+ path first.
282
+
283
+
284
+ ### Built-in Vendors Support
285
+
286
+ For your comfort jekyll-assets has built-in support for some popular libraries.
287
+
288
+
289
+ #### Compass Support
290
+
291
+ Require `jekyll-assets/compass` to enable, e.g.:
292
+
293
+ ``` ruby
294
+ require "jekyll-assets"
295
+ require "jekyll-assets/compass"
296
+ ```
297
+
298
+ Now you can add `@import "compass"` in your SASS assets to get Compass goodies.
299
+
300
+ *Note* that if you want to use other than default Compass plugins/frameworks,
301
+ you must require them BEFORE `jekyll-assets/compass`.
302
+
303
+
304
+ #### Bootstrap Support
305
+
306
+ Require `jekyll-assets/bootstrap` to enable, e.g.:
307
+
308
+ ``` ruby
309
+ require "jekyll-assets"
310
+ require "jekyll-assets/bootstrap"
311
+ ```
312
+
313
+ Now you can add `@import "bootstrap"` in your SASS assets to get Bootstrap goodies.
314
+
315
+
316
+ #### Bourbon Support
317
+
318
+ Require `jekyll-assets/bourbon` to enable, e.g.:
319
+
320
+ ``` ruby
321
+ require "jekyll-assets"
322
+ require "jekyll-assets/bourbon"
323
+ ```
324
+
325
+ Now you can add `@import "bourbon"` in your SASS assets to get Bourbon goodies.
326
+
327
+
328
+ #### Font Awesome
329
+
330
+ Require `jekyll-assets/font-awesome` to enable, e.g.:
331
+
332
+ ``` ruby
333
+ require "jekyll-assets"
334
+ require "jekyll-assets/font-awesome"
335
+ ```
336
+
337
+ Now you can add `@import "font-awesome"` in your SASS assets to get Font Awesome goodies.
338
+
339
+
340
+ #### Neat Support
341
+
342
+ Require `jekyll-assets/neat` to enable, e.g.:
343
+
344
+ ``` ruby
345
+ require "jekyll-assets"
346
+ require "jekyll-assets/neat"
347
+ ```
348
+
349
+ Now you can add `@import "neat"` in your SASS assets to get Neat goodies.
350
+
351
+
352
+ ## The Directive Processor
353
+
354
+ *Note:* This section extracted from [Sprockets][sprockets] README.
355
+
356
+ Sprockets runs the *directive processor* on each CSS and JavaScript
357
+ source file. The directive processor scans for comment lines beginning
358
+ with `=` in comment blocks at the top of the file.
359
+
360
+ //= require jquery
361
+ //= require jquery-ui
362
+ //= require backbone
363
+ //= require_tree .
364
+
365
+ The first word immediately following `=` specifies the directive
366
+ name. Any words following the directive name are treated as
367
+ arguments. Arguments may be placed in single or double quotes if they
368
+ contain spaces, similar to commands in the Unix shell.
369
+
370
+ **Note**: Non-directive comment lines will be preserved in the final
371
+ asset, but directive comments are stripped after
372
+ processing. Sprockets will not look for directives in comment blocks
373
+ that occur after the first line of code.
374
+
375
+
376
+ ### Supported Comment Types
377
+
378
+ The directive processor understands comment blocks in three formats:
379
+
380
+ /* Multi-line comment blocks (CSS, SCSS, JavaScript)
381
+ *= require foo
382
+ */
383
+
384
+ // Single-line comment blocks (SCSS, JavaScript)
385
+ //= require foo
386
+
387
+ # Single-line comment blocks (CoffeeScript)
388
+ #= require foo
389
+
390
+
391
+ ### Sprockets Directives
392
+
393
+ You can use the following directives to declare dependencies in asset
394
+ source files.
395
+
396
+ For directives that take a *path* argument, you may specify either a
397
+ logical path or a relative path. Relative paths begin with `./` and
398
+ reference files relative to the location of the current file.
399
+
400
+ #### The `require` Directive
401
+
402
+ `require` *path* inserts the contents of the asset source file
403
+ specified by *path*. If the file is required multiple times, it will
404
+ appear in the bundle only once.
405
+
406
+ #### The `include` Directive
407
+
408
+ `include` *path* works like `require`, but inserts the contents of the
409
+ specified source file even if it has already been included or
410
+ required.
411
+
412
+ #### The `require_directory` Directive
413
+
414
+ `require_directory` *path* requires all source files of the same
415
+ format in the directory specified by *path*. Files are required in
416
+ alphabetical order.
417
+
418
+ #### The `require_tree` Directive
419
+
420
+ `require_tree` *path* works like `require_directory`, but operates
421
+ recursively to require all files in all subdirectories of the
422
+ directory specified by *path*.
423
+
424
+ #### The `require_self` Directive
425
+
426
+ `require_self` tells Sprockets to insert the body of the current
427
+ source file before any subsequent `require` or `include` directives.
428
+
429
+ #### The `depend_on` Directive
430
+
431
+ `depend_on` *path* declares a dependency on the given *path* without
432
+ including it in the bundle. This is useful when you need to expire an
433
+ asset's cache in response to a change in another file.
434
+
435
+ #### The `stub` Directive
436
+
437
+ `stub` *path* allows dependency to be excluded from the asset bundle.
438
+ The *path* must be a valid asset and may or may not already be part
439
+ of the bundle. Once stubbed, it is blacklisted and can't be brought
440
+ back by any other `require`.
441
+
442
+
443
+ ## Configuration
444
+
445
+ You can fine-tune configuration by editing your `_config.yml`:
446
+
447
+ ``` yaml
448
+ #
449
+ # Plugin: jekyll-assets
450
+ #
451
+ assets:
452
+ #
453
+ # Pathname of the destination of generated (bundled) assets relative
454
+ # to the destination of the root.
455
+ #
456
+ dirname: assets
457
+ #
458
+ # Base URL of assets paths.
459
+ #
460
+ baseurl: /assets/
461
+ #
462
+ # Pathnames where to find assets relative to the root of the site.
463
+ #
464
+ sources:
465
+ - _assets/javascripts
466
+ - _assets/stylesheets
467
+ - _assets/images
468
+ #
469
+ # Sets JS compressor. No compression by default.
470
+ # Possible variants: 'yui', 'uglifier', nil
471
+ #
472
+ js_compressor: ~
473
+ #
474
+ # Sets CSS compressor. No compression by default.
475
+ # Possible variants: 'yui', 'sass', nil
476
+ #
477
+ css_compressor: ~
478
+ #
479
+ # Sets cachebusting policy for generated assets.
480
+ #
481
+ # Possible variants:
482
+ #
483
+ # none - disables cachebusting
484
+ #
485
+ # source file: _assets/javascripts/app.css
486
+ # output file: _site/assets/javascriptis/app.css
487
+ # output URL: /assets/javascripts/app.css
488
+ #
489
+ # soft - leave filenames as-is, but `?cb=<md5>` suffix for URLs generated
490
+ # with `asset_path`, `javascript` and `stylesheet`:
491
+ #
492
+ # source file: _assets/javascripts/app.css
493
+ # output file: _site/assets/javascriptis/app.css
494
+ # output URL: /assets/javascripts/app.css?cb=4f41243847da693a4f356c0486114bc6
495
+ #
496
+ # hard - (default) injects cachebusting checksum into processed filename:
497
+ #
498
+ # source file: _assets/javascripts/app.css
499
+ # output file: _site/assets/javascriptis/app-4f41243847da693a4f356c0486114bc6.css
500
+ # output URL: /assets/javascripts/app-4f41243847da693a4f356c0486114bc6.css
501
+ #
502
+ cachebust: hard
503
+ #
504
+ # Whenever or not cache compiled assets (disabled by default).
505
+ # See `Compilation Cache` section of README for details.
506
+ #
507
+ cache: false
508
+ #
509
+ # Specifies list of MIME types that needs to have gzipped versions.
510
+ # You can set it to `false` to disable gzipping. Only javascripts and
511
+ # stylesheets are gzipped by default.
512
+ #
513
+ gzip: [ text/css, application/javascript ]
514
+ #
515
+ # Does not concatenates files requested by `javascript` and `stylesheet`
516
+ # helpers. Instead outputs multiple files in order they are required.
517
+ # Default: false
518
+ #
519
+ debug: false
520
+ #
521
+ # Configuration version. Used to force cache invalidation.
522
+ # Default: 1
523
+ #
524
+ version: 1
525
+ ```
526
+
527
+
528
+ ## "Th-th-th-that's all folks!"
529
+
530
+ Feel free to follow me on [twitter][twitter], chat via [jabber][jabber] or
531
+ write an [e-mail][e-mail]. :D
532
+
533
+ [twitter]: https://twitter.com/zapparov
534
+ [jabber]: xmpp://zapparov@jabber.ru
535
+ [e-mail]: mailto://ixti@member.fsf.org
536
+
537
+
538
+ ## Contributing
539
+
540
+ 1. Fork it
541
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
542
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
543
+ 4. Push to the branch (`git push origin my-new-feature`)
544
+ 5. Create new Pull Request
545
+
546
+
547
+ ## License
548
+
549
+ Copyright (C) 2012-2013 Aleksey V Zapparov (http://ixti.net/)
550
+
551
+ The MIT License
552
+
553
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
554
+ this software and associated documentation files (the “Software”), to deal in
555
+ the Software without restriction, including without limitation the rights to
556
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
557
+ of the Software, and to permit persons to whom the Software is furnished to do
558
+ so, subject to the following conditions:
559
+
560
+ The above copyright notice and this permission notice shall be included in all
561
+ copies or substantial portions of the Software.
562
+
563
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
564
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
565
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
566
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
567
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
568
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
569
+ SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new
5
+
6
+ require "rubocop/rake_task"
7
+ Rubocop::RakeTask.new
8
+
9
+ task :default => [:spec, :rubocop]
@@ -0,0 +1,39 @@
1
+ module Jekyll
2
+ module AssetsPlugin
3
+ class AssetPath
4
+ attr_writer :anchor, :query
5
+
6
+ def initialize(asset)
7
+ asset.bundle!
8
+ @asset = asset
9
+ end
10
+
11
+ def cachebust
12
+ @cachebust ||= @asset.site.assets_config.cachebust
13
+ end
14
+
15
+ def path
16
+ :hard == cachebust && @asset.digest_path || @asset.logical_path
17
+ end
18
+
19
+ def query
20
+ query = []
21
+
22
+ query << "cb=#{@asset.digest}" if :soft == cachebust
23
+ query << @query if @query
24
+
25
+ return if query.empty?
26
+
27
+ "?" << query.join("&")
28
+ end
29
+
30
+ def anchor
31
+ "##{@anchor}" if @anchor
32
+ end
33
+
34
+ def to_s
35
+ "#{@asset.site.assets_config.baseurl}/#{path}#{query}#{anchor}"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,87 @@
1
+ # stdlib
2
+ require "ostruct"
3
+
4
+ module Jekyll
5
+ module AssetsPlugin
6
+ class Configuration
7
+ DEFAULTS = {
8
+ :dirname => "assets",
9
+ :sources => %w[_assets/javascripts
10
+ _assets/stylesheets
11
+ _assets/images],
12
+ :js_compressor => nil,
13
+ :css_compressor => nil,
14
+ :cachebust => :hard,
15
+ :cache => false,
16
+ :gzip => %w[text/css application/javascript],
17
+ :debug => false,
18
+ :version => 1
19
+ }.freeze
20
+
21
+ def initialize(config = {})
22
+ @data = OpenStruct.new DEFAULTS.merge(config)
23
+
24
+ @data.sources = [@data.sources] if @data.sources.is_a? String
25
+ @data.dirname = @data.dirname.gsub(%r{^/+|/+$}, "")
26
+
27
+ compress = OpenStruct.new @data.compress
28
+
29
+ @data.js_compressor ||= compress.js
30
+ @data.css_compressor ||= compress.css
31
+ @data.cache ||= @data.cache_assets
32
+
33
+ # if baseurl not given - autoguess base on dirname
34
+ @data.baseurl ||= "/#{@data.dirname}/".squeeze "/"
35
+ end
36
+
37
+ def baseurl
38
+ @data.baseurl.chomp "/"
39
+ end
40
+
41
+ def js_compressor
42
+ compressor @data.js_compressor
43
+ end
44
+
45
+ def css_compressor
46
+ compressor @data.css_compressor
47
+ end
48
+
49
+ def cachebust
50
+ return :none if none?(@data.cachebust)
51
+ return @data.cachebust.to_sym if @data.cachebust.to_s[/^(soft|hard)$/]
52
+ fail "Unknown cachebust strategy: #{@data.cachebust}"
53
+ end
54
+
55
+ def cache_assets?
56
+ @data.cache ? true : false
57
+ end
58
+
59
+ def cache_path
60
+ @data.cache.is_a?(String) ? @data.cache : ".jekyll-assets-cache"
61
+ end
62
+
63
+ def gzip
64
+ return @data.gzip if @data.gzip.is_a? Array
65
+ @data.gzip ? DEFAULTS[:gzip] : []
66
+ end
67
+
68
+ def version
69
+ @data.version
70
+ end
71
+
72
+ def method_missing(name, *args, &block)
73
+ @data.send name, *args, &block
74
+ end
75
+
76
+ private
77
+
78
+ def none?(val)
79
+ val.to_s.empty? || "none" == val.to_s.downcase
80
+ end
81
+
82
+ def compressor(val)
83
+ none?(val) ? nil : val.to_sym
84
+ end
85
+ end
86
+ end
87
+ end