bunto-assets 1.0.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +19 -0
- data/LICENSE +21 -0
- data/README.md +275 -0
- data/Rakefile +3 -0
- data/lib/bunto/assets/addons/autoprefixer.rb +13 -0
- data/lib/bunto/assets/addons/bootstrap.rb +7 -0
- data/lib/bunto/assets/addons/font_awesome.rb +7 -0
- data/lib/bunto/assets/addons/javascript.rb +11 -0
- data/lib/bunto/assets/cached.rb +20 -0
- data/lib/bunto/assets/config.rb +76 -0
- data/lib/bunto/assets/env.rb +207 -0
- data/lib/bunto/assets/hook.rb +78 -0
- data/lib/bunto/assets/hooks/bunto/drops.rb +9 -0
- data/lib/bunto/assets/hooks/bunto/setup.rb +13 -0
- data/lib/bunto/assets/hooks/bunto/write.rb +9 -0
- data/lib/bunto/assets/hooks/cache.rb +15 -0
- data/lib/bunto/assets/hooks/compression.rb +17 -0
- data/lib/bunto/assets/hooks/configuration.rb +12 -0
- data/lib/bunto/assets/hooks/context.rb +11 -0
- data/lib/bunto/assets/hooks/erb.rb +15 -0
- data/lib/bunto/assets/hooks/helpers.rb +14 -0
- data/lib/bunto/assets/hooks/logger.rb +9 -0
- data/lib/bunto/assets/hooks/sources.rb +13 -0
- data/lib/bunto/assets/hooks/sprockets.rb +9 -0
- data/lib/bunto/assets/hooks/version.rb +11 -0
- data/lib/bunto/assets/hooks.rb +20 -0
- data/lib/bunto/assets/liquid/drop.rb +76 -0
- data/lib/bunto/assets/liquid/filters.rb +28 -0
- data/lib/bunto/assets/liquid/tag/defaults/image.rb +69 -0
- data/lib/bunto/assets/liquid/tag/defaults.rb +23 -0
- data/lib/bunto/assets/liquid/tag/parser.rb +200 -0
- data/lib/bunto/assets/liquid/tag/proxied_asset.rb +114 -0
- data/lib/bunto/assets/liquid/tag/proxies.rb +118 -0
- data/lib/bunto/assets/liquid/tag.rb +203 -0
- data/lib/bunto/assets/liquid.rb +15 -0
- data/lib/bunto/assets/logger.rb +59 -0
- data/lib/bunto/assets/patches/bunto/cleaner.rb +16 -0
- data/lib/bunto/assets/patches/bunto/site.rb +11 -0
- data/lib/bunto/assets/patches/kernel.rb +29 -0
- data/lib/bunto/assets/patches/sprockets/asset.rb +21 -0
- data/lib/bunto/assets/patches.rb +10 -0
- data/lib/bunto/assets/processors/liquid.rb +42 -0
- data/lib/bunto/assets/proxies/magick.rb +155 -0
- data/lib/bunto/assets/version.rb +11 -0
- data/lib/bunto/assets.rb +24 -0
- data/lib/bunto-assets.rb +7 -0
- metadata +197 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6b31429ffff3e57efcf0c643a23cdf1b3a02bc8d
|
4
|
+
data.tar.gz: 773fe2c9059efc63d4696517fd2b31a1af3a5aed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c40b39c878020cfae98efff6d70bdf43de74850056316296a54ece7b43c1da5325e318ecee9a7dbdd100fb5c69dcbc108373b5af2939732b633b67da38f03478
|
7
|
+
data.tar.gz: 1bf712167ae3b29691fc45870401d1d540ab17a03c482b9d014a864767e93c0634dec6311d2f659fc1854374125634802dedf03b389c401459db8e1aa33f1877
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
gemspec
|
3
|
+
|
4
|
+
gem "rake"
|
5
|
+
group :development do
|
6
|
+
gem "therubyracer", :platforms => :mri, :require => false
|
7
|
+
gem "pry", :require => false
|
8
|
+
end
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem "codeclimate-test-reporter", :require => false
|
12
|
+
end
|
13
|
+
|
14
|
+
gem "uglifier", :require => false
|
15
|
+
gem "sprockets-es6", "~> 0.6", :require => false
|
16
|
+
gem "autoprefixer-rails", "~> 6.0", :require => false
|
17
|
+
gem "font-awesome-sass", "~> 4.4", :require => false
|
18
|
+
gem "bootstrap-sass", "~> 3.3", :require => false
|
19
|
+
gem "mini_magick", "~> 4.2", :require => false
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2012-2015 Aleksey V Zapparov (http://ixti.net/)
|
2
|
+
Copyright (c) 2015-present Jordon Bedwell (https://envygeeks.io)
|
3
|
+
Copyright (c) 2016-present Suriyaa Kudo (https://j.mp/ItsSuriyaa)
|
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,275 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/bunto/bunto-assets.svg?branch=master)][travis]
|
2
|
+
|
3
|
+
[travis]: https://travis-ci.org/bunto/bunto-assets
|
4
|
+
|
5
|
+
# Bunto Assets
|
6
|
+
|
7
|
+
Bunto assets is an asset pipeline using Sprockets (v3) to build especially
|
8
|
+
for Bunto. It utilizes new features of both Sprockets and Bunto to achieve
|
9
|
+
a clean and extensible assets platform for Bunto.
|
10
|
+
|
11
|
+
## Using Bunto Assets with Bunto
|
12
|
+
|
13
|
+
Add `gem "bunto-assets"` to your `Gemfile` and add `bunto-assets`
|
14
|
+
to your `_config.yml` like the following:
|
15
|
+
|
16
|
+
```yaml
|
17
|
+
gems:
|
18
|
+
- bunto-assets
|
19
|
+
```
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
A lot of our configuration transforms based on the `BUNTO_ENV` variable
|
24
|
+
set in your environment. Such as digesting and whether or not to enable the
|
25
|
+
CDN. Some of them can be explicitly overridden but a few cannot right now.
|
26
|
+
You should set your `BUNTO_ENV=development` on your development
|
27
|
+
machine and `BUNTO_ENV=production` when building to push.
|
28
|
+
|
29
|
+
```yaml
|
30
|
+
assets:
|
31
|
+
compress:
|
32
|
+
css: false | true | default - development: false, production: true
|
33
|
+
js: false | true | default - development: false, production: true
|
34
|
+
cache: false | directory | default: .asset-cache
|
35
|
+
cdn: https://cdn.example.com
|
36
|
+
skip_baseurl_with_cdn: false
|
37
|
+
skip_prefix_with_cdn: false
|
38
|
+
prefix: "/assets"
|
39
|
+
assets:
|
40
|
+
- "*.png"
|
41
|
+
- "bundle.css"
|
42
|
+
digest: true
|
43
|
+
sources:
|
44
|
+
- _assets/css
|
45
|
+
- _assets/images
|
46
|
+
- _assets/javascripts
|
47
|
+
- _assets/stylesheets
|
48
|
+
- _assets/fonts
|
49
|
+
- _assets/img
|
50
|
+
- _assets/js
|
51
|
+
features:
|
52
|
+
liquid: true | false | default: false
|
53
|
+
automatic_img_size: true | false | default: true
|
54
|
+
automatic_img_alt : true | false | default: true
|
55
|
+
```
|
56
|
+
|
57
|
+
### Liquid Processing with your Bunto context
|
58
|
+
|
59
|
+
By default (whether `features.liquid` is true or false) we will process
|
60
|
+
all files with the extension ".liquid", so if you give us ".scss.liquid"
|
61
|
+
we will parse the liquid and then we will parse the SCSS and finally
|
62
|
+
output your ".css" file.
|
63
|
+
|
64
|
+
When `features.liquid` is set to true, we will process ***ALL*** files
|
65
|
+
through Liquid, regardless of whether they have the ".liquid" extension.
|
66
|
+
Use this at your own risk.
|
67
|
+
|
68
|
+
### Cache Folder
|
69
|
+
|
70
|
+
If you plan to change the `cache` folder, please make sure to add that
|
71
|
+
folder to your `exclude` list in Bunto or you will generate over and over
|
72
|
+
and over again, `.` folders are not ignored by default.
|
73
|
+
|
74
|
+
### Sources
|
75
|
+
|
76
|
+
The listed resources in the example are all defaults. It should be noted
|
77
|
+
that we append your sources instead of replace our resources with yours. So
|
78
|
+
if you add `_assets/folder` then we will append that to our sources and
|
79
|
+
both will work.
|
80
|
+
|
81
|
+
***NOTE: if you use our `_assets` base folder container as a base folder for
|
82
|
+
your sprockets, we will not append our sources, we will only use that
|
83
|
+
folder as the sole source (base folder.)***
|
84
|
+
|
85
|
+
### Digesting
|
86
|
+
|
87
|
+
* Disable digesting by default in development.
|
88
|
+
* Digest by default in production.
|
89
|
+
|
90
|
+
***You can force digesting with `digest: true` in your `_config.yml`***
|
91
|
+
|
92
|
+
### Compression
|
93
|
+
|
94
|
+
* Requires sass and uglifier.
|
95
|
+
* Disable compression by default in development.
|
96
|
+
* Enable by default in production.
|
97
|
+
|
98
|
+
### Bower Components
|
99
|
+
|
100
|
+
Modify your `.bowerrc` file and add:
|
101
|
+
|
102
|
+
```json
|
103
|
+
{
|
104
|
+
"directory": "_assets/bower"
|
105
|
+
}
|
106
|
+
```
|
107
|
+
|
108
|
+
And then add `_assets/bower` to your sources list and Sprockets will do the
|
109
|
+
the rest for you... you can even `//= require bower_asset.js`. We will even
|
110
|
+
compress them for you per normal if Sprockets supports it and allows us to.
|
111
|
+
|
112
|
+
***You do not need to modify your `.bowerrc` file, you can optionally just
|
113
|
+
add it to your sources list and it will work that way too! As long as it's in
|
114
|
+
your Bunto folder.***
|
115
|
+
|
116
|
+
## Tags
|
117
|
+
|
118
|
+
* image, img
|
119
|
+
* javascript, js
|
120
|
+
* stylesheet, css, style
|
121
|
+
* asset, asset_source
|
122
|
+
* asset_path
|
123
|
+
|
124
|
+
### Tag Example:
|
125
|
+
|
126
|
+
```liquid
|
127
|
+
{% img src magick:2x alt:'This is my alt' %}
|
128
|
+
{% img src magick:2x alt:'This is my alt' sprockets:accept:image/gif %}
|
129
|
+
```
|
130
|
+
|
131
|
+
### What do the colons mean? Proxies/Tags
|
132
|
+
|
133
|
+
* `argument` is a boolean HTML argument.
|
134
|
+
* `key:value` is an HTML key="value" if no proxy exists.
|
135
|
+
* `proxy:key:value` will set a proxy key with the given value.
|
136
|
+
* `proxy:key` is a boolean argument if the proxy and key exists.
|
137
|
+
* `unknown:key:value` will raise `DoubleColonError`, escape it.
|
138
|
+
* `proxy:unknown:value` will raise a `UnknownProxyError`.
|
139
|
+
|
140
|
+
Lets say we have `sprockets` proxies and sprockets allows you to proxy accept,
|
141
|
+
if you send `{% img src sprockets:accept:image/gif }` then Sprockets find_asset
|
142
|
+
will get `{ :accept => "image/gif" }` but if you try to proxy "unknown" on
|
143
|
+
sprockets we will raise a Proxy error. For more information then look at
|
144
|
+
`parser_spec.rb` in the spec folder because it literally lays out the ground
|
145
|
+
rules for our tags as a specification.
|
146
|
+
|
147
|
+
### Current Proxies:
|
148
|
+
|
149
|
+
* `sprockets:accept:<value>`
|
150
|
+
* `sprockets:write_to:<value>`
|
151
|
+
|
152
|
+
## Liquid Variables
|
153
|
+
|
154
|
+
We support liquid arguments for tag values (but not tag keys), and we also
|
155
|
+
support Liquid pre-processing (with your Bunto context) sass/less/css files
|
156
|
+
you need do nothing special for the preprocessing an entire file, it's
|
157
|
+
always done.
|
158
|
+
|
159
|
+
An example of using Liquid in your tags:
|
160
|
+
|
161
|
+
```liquid
|
162
|
+
{% img '{{ image_path }}' %}
|
163
|
+
{% img '{{ image_path }}' proxy:key:'{{ value }}' %}
|
164
|
+
{% img {{\ image_path\ }} %}
|
165
|
+
```
|
166
|
+
|
167
|
+
An example of using Liquid in your SCSS:
|
168
|
+
|
169
|
+
```scss
|
170
|
+
.bg {
|
171
|
+
background: url(asset_path("{{ site.background_image }}"));
|
172
|
+
}
|
173
|
+
```
|
174
|
+
|
175
|
+
You have full access to your entire Bunto context from any liquid
|
176
|
+
processing we do, so you can do whatever you like and be as dynamic as you
|
177
|
+
like, including full loops and conditional Liquid based CSS since we
|
178
|
+
pre-process your text files.
|
179
|
+
|
180
|
+
## Getting a list of your assets and basic info from Liquid
|
181
|
+
|
182
|
+
We provide all *your* assets as a hash of Liquid Drops so you can get basic
|
183
|
+
info that we wish you to have access to without having to prepare the class.
|
184
|
+
|
185
|
+
```liquid
|
186
|
+
{{ assets["bundle.css"].content_type }} => "text/css"
|
187
|
+
{{ assets["images.jpg"].width }} => 62
|
188
|
+
{{ assets["images.jpg"].height }} => 62
|
189
|
+
```
|
190
|
+
|
191
|
+
The current list of available accessors:
|
192
|
+
|
193
|
+
* `logical_path`
|
194
|
+
* `content_type` -> `type`
|
195
|
+
* `filename`
|
196
|
+
* `basename`
|
197
|
+
* `width`
|
198
|
+
* `height`
|
199
|
+
|
200
|
+
If you would like more, please feel free to add a pull request, at this
|
201
|
+
time we will reject all pull requests that wish to add any digested paths as
|
202
|
+
those are dynamically created when a proxy is ran so we can never predict
|
203
|
+
it reliably unless we proxy and that would be a performance problem.
|
204
|
+
|
205
|
+
## ERB Support
|
206
|
+
|
207
|
+
ERB Support is removed in favor of trying to get this included on Github Pages
|
208
|
+
eventually (if I can.) Having ERB presents a security risk to Github because it
|
209
|
+
would allow you to use Ruby in ways they don't want you to.
|
210
|
+
|
211
|
+
## Filters
|
212
|
+
|
213
|
+
There is a full suite of filters, actually, any tag and any proxy can be a
|
214
|
+
filter by way of filter arguments, take the following example:
|
215
|
+
|
216
|
+
```liquid
|
217
|
+
{{ src | img : "magick:2x magick:quality:92" }}
|
218
|
+
```
|
219
|
+
|
220
|
+
## Hooks
|
221
|
+
|
222
|
+
* `:env => [:init]`
|
223
|
+
|
224
|
+
You can register and trigger hooks like so:
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
Bunto::Assets::Hook.register :env, :init do
|
228
|
+
# Your Work
|
229
|
+
end
|
230
|
+
```
|
231
|
+
|
232
|
+
## Sass Helpers
|
233
|
+
|
234
|
+
***Our currently supported helpers are:***
|
235
|
+
|
236
|
+
* asset_path
|
237
|
+
* image_path
|
238
|
+
* font_path
|
239
|
+
|
240
|
+
## Addons
|
241
|
+
|
242
|
+
* CSS Auto Prefixer - add "autoprefixer-rails" to your Gemfile.
|
243
|
+
* ES6 Transpiler (through Babel) - add "sprockets-es6" to your Gemfile.
|
244
|
+
* Image Magick - add "mini_magick" to your Gemfile, only works with `img`, `image`.
|
245
|
+
* Bootstrap - add "bootstrap-sass" to your Gemfile and "@import 'bootstrap'"
|
246
|
+
* Font Awesome - add "font-awesome-sass" to your Gemfile.
|
247
|
+
|
248
|
+
***Please note that some of these (if not all) have trouble with Rhino --
|
249
|
+
`therubyrhino` so you would probably be best to just use Node.js or io.js at
|
250
|
+
that point rather than trying to fight it.***
|
251
|
+
|
252
|
+
### Image Magick Proxy arguments:
|
253
|
+
|
254
|
+
* `magick:resize:<value>`
|
255
|
+
* `magick:format:<value>`
|
256
|
+
* `magick:quality:<value>`
|
257
|
+
* `magick:rotate:<value>`
|
258
|
+
* `magick:gravity:<value>`
|
259
|
+
* `magick:crop:<value>`
|
260
|
+
* `magick:flip:<value>`
|
261
|
+
* `magick:quadruple`, `magick:4x`
|
262
|
+
* `magick:one-third`, `magick:1/3`
|
263
|
+
* `magick:three-fourths`, `magick:3/4`
|
264
|
+
* `magick:two-fourths`, `magick:2/4`
|
265
|
+
* `magick:two-thirds`, `magick:2/3`
|
266
|
+
* `magick:one-fourth`, `magick:1/4`
|
267
|
+
* `magick:half`, `magick:1/2`
|
268
|
+
|
269
|
+
## Having trouble with our documentation?
|
270
|
+
|
271
|
+
If you do not understand something in our documentation please feel
|
272
|
+
free to file a ticket and it will be explained and the documentation updated,
|
273
|
+
however... if you have already figured out the problem please feel free to
|
274
|
+
submit a pull request with clarification in the documentation and we'll
|
275
|
+
happily work with you on updating it.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
# Frozen-string-literal: true
|
3
|
+
# Copyright: 2016-present - MIT License
|
4
|
+
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
try_require_if_javascript "autoprefixer-rails" do
|
8
|
+
Bunto::Assets::Hook.register :env, :init do |env|
|
9
|
+
AutoprefixerRails.install(env, env.asset_config[
|
10
|
+
"autoprefixer"
|
11
|
+
])
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
# Frozen-string-literal: true
|
3
|
+
# Copyright: 2016-present - MIT License
|
4
|
+
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
try_require "bootstrap-sass"
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
# Frozen-string-literal: true
|
3
|
+
# Copyright: 2016-present - MIT License
|
4
|
+
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
try_require "font-awesome-sass"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
# Frozen-string-literal: true
|
3
|
+
# Copyright: 2016-present - MIT License
|
4
|
+
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
try_require_if_javascript "sprockets/es6" do
|
8
|
+
if ExecJS.runtime.is_a?(ExecJS::RubyRhinoRuntime)
|
9
|
+
Bunto.logger.warn "ES6 transpiler has trouble with RubyRhino, use Node"
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
# Frozen-string-literal: true
|
3
|
+
# Copyright: 2016-present - MIT License
|
4
|
+
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module Bunto
|
8
|
+
module Assets
|
9
|
+
class Cached < Sprockets::CachedEnvironment
|
10
|
+
attr_reader :bunto
|
11
|
+
attr_reader :parent
|
12
|
+
|
13
|
+
def initialize(env)
|
14
|
+
@parent = env
|
15
|
+
@bunto = env.bunto
|
16
|
+
super env
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
# Frozen-string-literal: true
|
3
|
+
# Copyright: 2016-present - MIT License
|
4
|
+
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module Bunto
|
8
|
+
module Assets
|
9
|
+
module Config
|
10
|
+
DefaultSources = %W(
|
11
|
+
_assets/css _assets/stylesheets
|
12
|
+
_assets/images _assets/img _assets/fonts
|
13
|
+
_assets/javascripts _assets/js
|
14
|
+
).freeze
|
15
|
+
|
16
|
+
# ----------------------------------------------------------------------
|
17
|
+
|
18
|
+
Development = {
|
19
|
+
"skip_baseurl_with_cdn" => false,
|
20
|
+
"skip_prefix_with_cdn" => false,
|
21
|
+
"prefix" => "/assets",
|
22
|
+
"digest" => false,
|
23
|
+
"assets" => [],
|
24
|
+
|
25
|
+
"compress" => {
|
26
|
+
"css" => false,
|
27
|
+
"js" => false
|
28
|
+
},
|
29
|
+
|
30
|
+
"features" => {
|
31
|
+
"automatic_img_alt" => true,
|
32
|
+
"automatic_img_size" => true,
|
33
|
+
"liquid" => false
|
34
|
+
}
|
35
|
+
}.freeze
|
36
|
+
|
37
|
+
# ----------------------------------------------------------------------
|
38
|
+
|
39
|
+
Production = Development.merge({
|
40
|
+
"digest" => true,
|
41
|
+
"compress" => {
|
42
|
+
"css" => true,
|
43
|
+
"js" => true
|
44
|
+
}
|
45
|
+
}).freeze
|
46
|
+
|
47
|
+
# ----------------------------------------------------------------------
|
48
|
+
|
49
|
+
def self.merge_sources(bunto, config)
|
50
|
+
config["sources"] ||= []
|
51
|
+
return if config["sources"].grep(/\A\s*_assets\/?\s*\Z/).size > 0
|
52
|
+
sources = DefaultSources + config["sources"].to_a
|
53
|
+
|
54
|
+
config["sources"] = Set.new(sources.map do |val|
|
55
|
+
bunto.in_source_dir(val)
|
56
|
+
end)
|
57
|
+
end
|
58
|
+
|
59
|
+
# ----------------------------------------------------------------------
|
60
|
+
|
61
|
+
def self.defaults
|
62
|
+
if %W(development test).include?(Bunto.env)
|
63
|
+
then Development else Production
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# ----------------------------------------------------------------------
|
68
|
+
|
69
|
+
def self.merge(new_hash, old_hash = defaults)
|
70
|
+
old_hash.merge(new_hash) do |_, old_val, new_val|
|
71
|
+
old_val.is_a?(Hash) && new_val.is_a?(Hash) ? merge(new_val, old_val) : new_val
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
# Frozen-string-literal: true
|
3
|
+
# Copyright: 2016-present - MIT License
|
4
|
+
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module Bunto
|
8
|
+
module Assets
|
9
|
+
class Env < Sprockets::Environment
|
10
|
+
attr_reader :bunto, :used
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :past
|
14
|
+
def liquid_proxies
|
15
|
+
Liquid::Tag::Proxies
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# ----------------------------------------------------------------------
|
20
|
+
|
21
|
+
def excludes
|
22
|
+
excludes = Set.new
|
23
|
+
excludes << strip_path(in_cache_dir)
|
24
|
+
excludes
|
25
|
+
end
|
26
|
+
|
27
|
+
# ----------------------------------------------------------------------
|
28
|
+
|
29
|
+
def all_unparsed_assets
|
30
|
+
@unparsed_assets ||= logical_paths.select do |(_, val)|
|
31
|
+
val.start_with?(bunto.in_source_dir)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# ----------------------------------------------------------------------
|
36
|
+
|
37
|
+
def to_liquid_payload
|
38
|
+
bunto.sprockets.all_unparsed_assets.each_with_object({}) do |(key, val), hash|
|
39
|
+
hash[key] = Bunto::Assets::Liquid::Drop.new(
|
40
|
+
val, bunto
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# ----------------------------------------------------------------------
|
46
|
+
|
47
|
+
def initialize(path, bunto = nil)
|
48
|
+
bunto, path = path, nil if path.is_a?(Bunto::Site)
|
49
|
+
@bunto = bunto
|
50
|
+
@used = Set.new
|
51
|
+
|
52
|
+
path ? super(path) : super()
|
53
|
+
Hook.trigger :env, :init do |hook|
|
54
|
+
hook.arity > 0 || 0 > hook.arity ? hook.call(self) : instance_eval(&hook)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# ----------------------------------------------------------------------
|
59
|
+
|
60
|
+
def liquid_proxies
|
61
|
+
self.class.liquid_proxies
|
62
|
+
end
|
63
|
+
|
64
|
+
# ----------------------------------------------------------------------
|
65
|
+
# Make sure a path falls withint our cache dir.
|
66
|
+
# ----------------------------------------------------------------------
|
67
|
+
|
68
|
+
def in_cache_dir(*paths)
|
69
|
+
cache_dir = asset_config["cache"] || ".asset-cache"
|
70
|
+
bunto.in_source_dir(cache_dir, *paths)
|
71
|
+
end
|
72
|
+
|
73
|
+
# ----------------------------------------------------------------------
|
74
|
+
# Merged form of `#extra_assets`
|
75
|
+
# ----------------------------------------------------------------------
|
76
|
+
|
77
|
+
def all_assets
|
78
|
+
Set.new(@used).merge extra_assets
|
79
|
+
end
|
80
|
+
|
81
|
+
# ----------------------------------------------------------------------
|
82
|
+
# Assets you tell us you want to always compile, even if you do not
|
83
|
+
# use them. Just like Rails this is probably normally used.
|
84
|
+
# ----------------------------------------------------------------------
|
85
|
+
|
86
|
+
def extra_assets
|
87
|
+
assets = asset_config["assets"] ||= []
|
88
|
+
each_logical_path(*assets).map do |v|
|
89
|
+
find_asset v
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# ----------------------------------------------------------------------
|
94
|
+
|
95
|
+
def cdn?
|
96
|
+
!dev? && asset_config.key?("cdn") && \
|
97
|
+
asset_config["cdn"]
|
98
|
+
end
|
99
|
+
|
100
|
+
# ----------------------------------------------------------------------
|
101
|
+
|
102
|
+
def baseurl
|
103
|
+
ary = []
|
104
|
+
|
105
|
+
ary << bunto.config["baseurl"] unless cdn? && asset_config["skip_baseurl_with_cdn"]
|
106
|
+
ary << asset_config[ "prefix"] unless cdn? && asset_config[ "skip_prefix_with_cdn"]
|
107
|
+
|
108
|
+
File.join(*ary.delete_if do |val|
|
109
|
+
val.nil? || val.empty?
|
110
|
+
end)
|
111
|
+
end
|
112
|
+
|
113
|
+
# ----------------------------------------------------------------------
|
114
|
+
|
115
|
+
def dev?
|
116
|
+
%W(development test).include?(Bunto.env)
|
117
|
+
end
|
118
|
+
|
119
|
+
# ----------------------------------------------------------------------
|
120
|
+
|
121
|
+
def compress?(what)
|
122
|
+
!!asset_config["compress"] \
|
123
|
+
.fetch(what, false)
|
124
|
+
end
|
125
|
+
|
126
|
+
# ----------------------------------------------------------------------
|
127
|
+
|
128
|
+
def asset_config
|
129
|
+
bunto.config["assets"] ||= {}
|
130
|
+
end
|
131
|
+
|
132
|
+
# ----------------------------------------------------------------------
|
133
|
+
|
134
|
+
def digest?
|
135
|
+
!!asset_config["digest"]
|
136
|
+
end
|
137
|
+
|
138
|
+
# ----------------------------------------------------------------------
|
139
|
+
# Prefix path prefixes the path with the baseurl and the cdn if it
|
140
|
+
# exists and is in the right mode to use it. Otherwise it will only use
|
141
|
+
# the baseurl and asset prefix. All of these can be adjusted.
|
142
|
+
# ----------------------------------------------------------------------
|
143
|
+
|
144
|
+
def prefix_path(path = nil)
|
145
|
+
cdn = asset_config["cdn"]
|
146
|
+
base_url = baseurl
|
147
|
+
|
148
|
+
path_ = []
|
149
|
+
path_ << base_url unless base_url.empty?
|
150
|
+
path_ << path unless path.nil?
|
151
|
+
|
152
|
+
url = cdn && cdn?? File.join(cdn, *path_) : File.join(*path_)
|
153
|
+
url.chomp("/")
|
154
|
+
end
|
155
|
+
|
156
|
+
# ----------------------------------------------------------------------
|
157
|
+
|
158
|
+
def cached
|
159
|
+
Cached.new(self)
|
160
|
+
end
|
161
|
+
|
162
|
+
# ----------------------------------------------------------------------
|
163
|
+
|
164
|
+
def write_all
|
165
|
+
past = self.class.past ||= Set.new
|
166
|
+
(@used.any?? all_assets : past).each do |obj|
|
167
|
+
if past.add(obj) && path = as_path(obj)
|
168
|
+
obj.write_to path
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# ----------------------------------------------------------------------
|
174
|
+
|
175
|
+
private
|
176
|
+
def strip_path(path)
|
177
|
+
path.sub(bunto.in_source_dir("/"), "")
|
178
|
+
end
|
179
|
+
|
180
|
+
# ----------------------------------------------------------------------
|
181
|
+
|
182
|
+
private
|
183
|
+
def as_path(v)
|
184
|
+
path = digest?? v.digest_path : v.logical_path
|
185
|
+
bunto.in_dest_dir(File.join(asset_config[ "prefix"], path))
|
186
|
+
end
|
187
|
+
|
188
|
+
# ----------------------------------------------------------------------
|
189
|
+
|
190
|
+
class << self
|
191
|
+
def context_patches
|
192
|
+
Proc.new do
|
193
|
+
alias _old_asset_path asset_path
|
194
|
+
def asset_path(asset, _ = {})
|
195
|
+
rtn = _old_asset_path asset
|
196
|
+
|
197
|
+
return unless rtn
|
198
|
+
path = environment.find_asset(resolve(asset))
|
199
|
+
environment.parent.used.add(path)
|
200
|
+
rtn
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|