[![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/coverage/github/envygeeks/jekyll-assets.svg?style=for-the-badge)](https://codeclimate.com/github/envygeeks/jekyll-assets/test_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://envygeeks.io#donate)
![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)
# 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, and even the proxy of said assets in a way that does not interfere with either [Sprockets](https://github.com/rails/sprockets), or [Jekyll](3), and 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/CoffeeScript processors, with you only having to add it to your Gemfile, and updating your ``, and ``.
## Using Jekyll Assets with Jekyll
```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
```
### Requirments
* Ruby ***2.3+***
* Jekyll ***3.5+***
* Sprockets ***3.3+***
***If you would like SourceMap support, or faster Sprockets, you should prefer to use Sprockets "~> 4.0.beta", we support SourceMaps in this version of Sprockets because it supports them. It's manifest an other features are also much better inside of this version of Sprockets.***
```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 "assets" inside of that file. Any environment variable noted as "val on `JEKYLL_ENV`" is only overridden when not explicitly set. All values listed below are default, you need not copy these into your configuration file unless you plan to change a value.
```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
### Usage
#### Liquid
```liquid
{% asset src @magick:2x alt='This is my alt' %}
{% asset src @magick:2x alt='This is my alt' %}
```
#### HTML
```html
```
### 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.
#### Usage
```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.
#### Builtins
| 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` | ✔ | ✗ |
| `:config` | `:before_merge` | ✗ | `Config{}` |
| `asset` | `:before_compile` | ✗ | `Asset`, `Manifest` |
### Usage
```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.
##### Usage
```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
### Font Awesome
#### Installation
```ruby
gem "font-awesome-sass"
```
#### Usage
```scss
@import "font-awesome-sprockets"
@import "font-awesome"
```
### CSS Auto-Prefixing
#### Installation
```ruby
gem "autoprefixer-rails"
```
#### Config
```yml
assets:
autoprefixer:
browsers:
- "last 2 versions"
- "IE > 9"
```
### Bootstrap
#### Installation
***4.x***
```ruby
gem "bootstrap"
```
***3.x***
```ruby
gem "boostrap-sass"
```
#### Usage
```scss
@import 'bootstrap'
```
### ImageMagick
#### Installation
```ruby
gem "mini_magick"
```
#### Tag 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: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
#### Installation
```ruby
gem "image_optim"
```
#### Config
Check the [ImageOptim](https://github.com/toy/image_optim#configuration) to get idea about configuration options.
```yml
assets:
plugins:
img:
optim:
default:
verbose: true
zero_png:
advpng:
level: 0
optipng:
level: 0
pngout:
strategy: 4
```
#### Tag Args
| Name | Accepts Value |
|---|---|
| `@image_optim:preset`* | ✗ |
\****Where `preset` is the name of the preset.***
### Building Your Own Plugins
#### Global Instance Vars
| Name | Class |
|---|---|
| `@env` | `Jekyll::Assets::Env` |
| `@args` | `Liquid::Tag::Parser{}` |
| `@jekyll` | `Jekyll::Site` |
| `@asset` | `Sprockets::Asset` |
##### HTML Instance Vars
| Name | Class | Type |
|---|---|---|
| `@doc` | `Nokogiri:: XML::Document` | `image/svg+xml` |
| `@doc` | `Nokogiri::HTML::Document` | `image/*` |