[![Code Climate](https://img.shields.io/codeclimate/maintainability/envygeeks/jekyll-assets.svg?style=for-the-badge)](https://codeclimate.com/github/envygeeks/jekyll-assets/maintainability)
[![Code Climate](https://img.shields.io/codeclimate/c/envygeeks/jekyll-assets.svg?style=for-the-badge)](https://codeclimate.com/github/envygeeks/jekyll-assets/coverage)
[![Travis CI](https://img.shields.io/travis/envygeeks/jekyll-assets/master.svg?style=for-the-badge)](https://travis-ci.org/envygeeks/jekyll-assets)
[![Donate](https://img.shields.io/badge/-DONATE-yellow.svg?style=for-the-badge)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LKGZAWXLZ8ZPG)
![Gem Version](https://img.shields.io/gem/v/jekyll-assets.svg?style=for-the-badge)
![Gem DL](https://img.shields.io/gem/dt/jekyll-assets.svg?style=for-the-badge)
***Looking for information on what's changed? See https://envygeeks.io/2017/11/21/jekyll-assets-3-released***
# Jekyll Assets
Jekyll Assets is a drop in [asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html) that uses [Sprockets](https://github.com/rails/sprockets) to build specifically for Jekyll. It utilizes [Sprockets](https://github.com/rails/sprockets), and [Jekyll](https://jekyllrb.com) to try and achieve a clean, and extensible assets platform that supports plugins, caching, converting your assets. It even supports proxying of said assets in a way that does not interfere with either [Sprockets](https://github.com/rails/sprockets), or [Jekyll](https://jekyllrb.com), or your own source. By default you can add Jekyll Assets to your Gemfile, as a plugin, and have it act as a drop-in replacement for Jekyll's basic SASS processors, with you only having to add it to your Gemfile, and updating your ``, and ``.
## Installing
```ruby
gem "jekyll-assets", group: :jekyll_plugins
gem "jekyll-assets", git: "https://github.com/envygeeks/jekyll-assets", group: :jekyll_plugins
gem "jekyll-assets", "~> x.x.alpha", group: :jekyll_plugins
```
---
### System Requirements
* `ruby`: ***2.3+***
* `sprockets`: ***3.3+***
* `jekyll`: ***3.5+***
---
If you'd like SourceMaps, or *faster* Sprockets, opt to use Sprockets `4.0`, you can use it by placing it to your Gemfile.
```ruby
gem "sprockets", "~> 4.0.beta", {
require: false
}
```
## Configuration
The configuration file is the same as Jekyll's, which is `_config.yml`. Except we use the special key called `assets` inside of that file. All values listed below are default, you need not copy these into your configuration file unless you plan to change a value. *Setting a value makes it explicit, and shared across both **production**, and **development**.*
```yaml
source_maps: true # false on JEKYLL_ENV=production
destination: "/assets"
compression: true
gzip: false
defaults:
js: { integrity: false } # true on JEKYLL_ENV=production
css: { integrity: false } # true on JEKYLL_ENV=production
img: { integrity: false } # true on JEKYLL_ENV=production
caching:
path: ".jekyll-cache/assets"
type: file # Possible values: memory, file
enabled: true
# --
# Assets you wish to always have compiled.
# This can also be combined with raw_precompile which
# copies assets without running through the pipeline
# making them ultra fast.
# --
precompile: []
raw_precompile: [
#
]
# --
# baseurl: whether or not to append site.baseurl
# destination: the folder you store them in on the CDN.
# url: the CDN url (fqdn, or w/ identifier).
# --
cdn:
baseurl: false
destination: false
url: null
# --
# These are all default. No need to add them
# Only use this if you have more.
# --
sources:
- assets/css
- assets/fonts
- assets/images
- assets/videos
- assets/javascript
- assets/video
- assets/image
- assets/img
- assets/js
- _assets/css
- _assets/fonts
- _assets/images
- _assets/videos
- _assets/javascript
- _assets/video
- _assets/image
- _assets/img
- _assets/js
- css
- fonts
- images
- videos
- javascript
- video
- image
- img
- js
plugins:
css: { autoprefixer: {}}
img: { optim: {}}
```
## Tag `{% asset %}`, ``
```html
{% asset src @magick:2x alt='This is my alt' %}
{% asset src @magick:2x alt='This is my alt' %}
```
## Defaults
We provide several defaults that get set when you run an asset, depending on content type, this could be anything from type, all the way to integrity. *If there is a default attribute you do not wish to be included, you can disable the attribute with `!attribute`, and it will be skipped over.*
```liquid
{% asset img.png !integrity %}
{% asset bundle.css !type %}
```
### Arguments
Our tags will take any number of arguments, and convert them to HTML, and even attach them to your output if the HTML processor you use accepts that kind of data. ***This applies to anything but hashes, and arrays.*** So adding say, a class, or id, is as easy as doing `id="val"` inside of your tag arguments.
#### Built In
| Arg | Description | Type | Return Type |
|---|---|---|---|
| `@path` | Path | `*/*` | `text`
| `@data` | `data` URI | `*/*` | `text` |
| `@inline` | CSS `
```
## Hooks
| Point | Name | Instance | Args |
| ---| --- | --- | --- |
| `:env` | `:before_init` | ✔ | ✗ |
| `:env` | `:after_init` | ✔ | ✗ |
| `:env` | `:after_write` | ✔ | ✗ |
| `:config` | `:before_merge` | ✗ | `Config{}` |
| `:asset` | `:before_compile` | ✗ | `Asset`, `Manifest` |
| `:asset` | `:after_compression` | ✗ | input{}, output{}, type=*/* |
### Example
```ruby
Jekyll::Assets::Hook.register :env, :before_init do
append_path "myPluginsCustomPath"
end
```
```ruby
Jekyll::Assets::Hook.register :config, :init do |c|
c.deep_merge!({
plugins: {
my_plugin: {
opt: true
}
}
})
end
```
#### Plugin Hooks
Your plugin can also register it's own hooks on our Hook system, so that you can trigger hooks around your stuff as well, this is useful for extensive plugins that want more power.
```ruby
Jekyll::Assets::Hook.add_point(:plugin, :hook)
```
```ruby
Jekyll::Assets::Hook.trigger(:plugin, :hook) { |v| v.call(:arg) }
Jekyll::Assets::Hook.trigger(:plugin, :hook) do |v|
instance_eval(&v)
end
```
## Default Plugins
### Google Closure Alternates
```
gem "crass"
```
Once crass is added, we will detect vendor prefixes, and add `/* @alternate */` to them, with or without compression enabled, and with protections against compression stripping.
### Font Awesome
```ruby
gem "font-awesome-sass"
```
```scss
@import "font-awesome-sprockets";
@import "font-awesome";
html {
// ...
}
```
### CSS Auto-Prefixing
```ruby
gem "autoprefixer-rails"
```
```yml
assets:
autoprefixer:
browsers:
- "last 2 versions"
- "IE > 9"
```
### Bootstrap
```ruby
gem "boostrap-sass" # 3.x
gem "bootstrap" # 4.x
```
```scss
@import 'bootstrap'
html {
// ...
}
```
```scss
//=require _bootstrap.css
//=require bootstrap/_reboot.css
```
### ImageMagick
```ruby
gem "mini_magick"
```
#### Args
See the [MiniMagick docs](https://github.com/minimagick/minimagick#usage)
to get an idea what `` can be.
| Name | Accepts Value |
| --------------------------- | ------------- |
| `magick:compress` | ✔ |
| `magick:resize` | ✔ |
| `magick:format`* | ✔ |
| `magick:quality` | ✔ |
| `magick:rotate` | ✔ |
| `magick:gravity` | ✔ |
| `magick:crop` | ✔ |
| `magick:flip` | ✔ |
| `magick:background` | ✔ |
| `magick:transparency` | ✔ |
| `@magick:double` | ✗ |
| `@magick:half` | ✗ |
\* *`magick:format` requires an ext or a valid MIME content type like `image/jpeg` or `.jpg`. We will `ImageMagick -format` on your behalf with that information by getting the extension.*
### ImageOptim
```ruby
gem "image_optim"
gem "image_optim_bin" # Optional
```
#### Configuration
```yml
assets:
plugins:
img:
optim:
{}
```
Check the [ImageOptim](https://github.com/toy/image_optim#configuration) to get idea about configuration options, and to get a list of stuff you need to install on your system to use it, if you do not wish to use "image_optim_bin",
#### Args
| Name | Accepts Value |
| --------------------------------- | ------------- |
| `optim` | ✔ |
| `@optim` | ✗ |
***By default `@optim` will use the default `jekyll`, otherwise you can provide `optim=preset` and have it used that preset. ImageOptim provides advanced, and default as their default presets, you can define your own preset via Jekyll Assets configuration listed above.***
### Building Your Own Plugins
#### Globals
| Name | Class |
| --------- | ----------------------- |
| `@env` | `Jekyll::Assets::Env` |
| `@args` | `Liquid::Tag::Parser{}` |
| `@jekyll` | `Jekyll::Site` |
| `@asset` | `Sprockets::Asset` |
#### HTML
| Name | Class | Type |
| ------ | -------------------------- | --------------- |
| `@doc` | `Nokogiri:: XML::Document` | `image/svg+xml` |
| `@doc` | `Nokogiri::HTML::Document` | `image/*` |
## Migrating from Earlier Versions
### Configuration
*Before*
```yaml
cdn: https://example.com
```
*After*
```yaml
cdn:
url: https://example.com
```
### Images/CSS/JS
*Before*
```liquid
{% css css.css %}
{% img image.jpg width:60 class:image %}
{% js js.js %}
```
*After*
```liquid
{% asset css.css %}
{% asset image.jpg width=60 class=image %}
{% asset js.js %}
```
### Custom Tags
*Before*
```liquid
```
*After*
```liquid
```