jekyll-minibundle 1.4.6 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +102 -29
- data/Rakefile +12 -14
- data/jekyll-minibundle.gemspec +1 -1
- data/lib/jekyll/minibundle/asset_bundle.rb +17 -10
- data/lib/jekyll/minibundle/asset_file_registry.rb +10 -10
- data/lib/jekyll/minibundle/asset_tag_markup.rb +1 -1
- data/lib/jekyll/minibundle/bundle_file.rb +7 -1
- data/lib/jekyll/minibundle/environment.rb +23 -5
- data/lib/jekyll/minibundle/mini_bundle_block.rb +20 -11
- data/lib/jekyll/minibundle/mini_stamp_tag.rb +6 -0
- data/lib/jekyll/minibundle/version.rb +1 -1
- data/test/fixture/site/_config.yml +1 -0
- data/test/integration/minibundle_development_mode_test.rb +18 -4
- data/test/integration/minibundle_production_mode_test.rb +73 -18
- data/test/support/test_case.rb +22 -26
- data/test/unit/asset_bundle_test.rb +12 -13
- data/test/unit/asset_file_registry_test.rb +2 -1
- data/test/unit/asset_tag_markup_test.rb +9 -2
- data/test/unit/bundle_file_test.rb +54 -59
- data/test/unit/environment_test.rb +38 -0
- data/test/unit/jekyll_payload_test.rb +6 -5
- data/test/unit/mini_bundle_block_test.rb +13 -0
- data/test/unit/mini_stamp_tag_test.rb +31 -0
- metadata +11 -7
- data/test/fixture/site/_plugins/minibundle.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f6bdd5c8d86c6ae46c876c1898698012e141a55
|
4
|
+
data.tar.gz: b6e02cb3cccb431144eb9570f3b55e583b2b67fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5935d3fd4affcc1c72011f4efeaf4aa2b4b825a40bb1deeca44e5a546d2c5f0b8daf91932bed9922e4af8989aafc1e2277c496cc60ebc4bc679ab6c701d7f8fe
|
7
|
+
data.tar.gz: 3ed84507cb56cf1d6a1b5604085d11f09e7a39c446f6fc67bcc6991405da09181d290d1e7f28a2dc7cae47e9c10167f44fc3e19dbe1bfac48abd04319a018fa8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# 1.5.0 / 2014-07-27
|
2
|
+
|
3
|
+
* Support minifier command specification in `_config.yml` and inside
|
4
|
+
`minibundle` block (#4, @phillipadsmith)
|
5
|
+
* Support enabling development mode from `_config.yml`
|
6
|
+
* Add argument validation to `minibundle` block and `ministamp` tag
|
7
|
+
* Document how to load the gem with Jekyll's `gems` config setting
|
8
|
+
|
1
9
|
# 1.4.6 / 2014-05-10
|
2
10
|
|
3
11
|
* Handle compatibility issues with safe_yaml and logger flexibly. This
|
data/README.md
CHANGED
@@ -23,17 +23,17 @@ feature.
|
|
23
23
|
|
24
24
|
Asset bundling consists of concatenation and minification. The plugin
|
25
25
|
implements concatenation and leaves choosing the minification tool up
|
26
|
-
to you. [UglifyJS2]
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
to you. [UglifyJS2][UglifyJS2] is a good and fast minifier, for
|
27
|
+
example. The plugin connects to the minifier with standard unix pipe,
|
28
|
+
feeding asset file contents to it in desired order via standard input,
|
29
|
+
and reads the result from standard output.
|
30
30
|
|
31
31
|
Why is this good? A fingerprint in asset's path is the
|
32
|
-
[recommended way]
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
[recommended way][GoogleCachingBestPractices] to handle caching of
|
33
|
+
static resources, because you can allow caching the asset
|
34
|
+
forever. Calculating MD5 digest over the contents of the asset is fast
|
35
|
+
and the resulting digest is reasonably unique to be generated
|
36
|
+
automatically.
|
37
37
|
|
38
38
|
Asset bundling is good for reducing the number of requests to the
|
39
39
|
backend upon page load. The minification of stylesheets and JavaScript
|
@@ -42,22 +42,33 @@ network.
|
|
42
42
|
|
43
43
|
# Usage
|
44
44
|
|
45
|
-
The plugin
|
46
|
-
[RubyGem](https://rubygems.org/gems/jekyll-minibundle):
|
45
|
+
The plugin ships as a
|
46
|
+
[RubyGem](https://rubygems.org/gems/jekyll-minibundle). To install:
|
47
47
|
|
48
48
|
``` bash
|
49
49
|
$ gem install jekyll-minibundle
|
50
50
|
```
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
(You should use [Bundler][GemBundler] to manage the gems in your
|
53
|
+
project.)
|
54
|
+
|
55
|
+
Then, instruct Jekyll to load the gem by adding this line to the
|
56
|
+
[configuration file][JekyllConf] of your Jekyll site project
|
57
|
+
(`_config.yml`):
|
58
|
+
|
59
|
+
``` yaml
|
60
|
+
gems: ['jekyll/minibundle']
|
61
|
+
```
|
62
|
+
|
63
|
+
An alternative to using the `gems` configuration setting is to add
|
64
|
+
`_plugins/minibundle.rb` file to your site project with this line:
|
54
65
|
|
55
66
|
``` ruby
|
56
67
|
require 'jekyll/minibundle'
|
57
68
|
```
|
58
69
|
|
59
|
-
You must allow Jekyll to use custom plugins.
|
60
|
-
|
70
|
+
You must allow Jekyll to use custom plugins. That is, do not enable
|
71
|
+
Jekyll's `safe` setting.
|
61
72
|
|
62
73
|
## Asset fingerprinting
|
63
74
|
|
@@ -77,9 +88,8 @@ Output, containing the MD5 digest of the file in the filename:
|
|
77
88
|
Jekyll's output directory will have the asset file at that path.
|
78
89
|
|
79
90
|
This feature is useful when combined with asset generation tools
|
80
|
-
external to Jekyll. For example, you can configure
|
81
|
-
|
82
|
-
`_assets/styles/*.scss` and to produce output to
|
91
|
+
external to Jekyll. For example, you can configure [Compass][Compass]
|
92
|
+
to take inputs from `_assets/styles/*.scss` and to produce output to
|
83
93
|
`_tmp/site.css`. Then, you use `ministamp` tag to copy the file with a
|
84
94
|
fingerprint to Jekyll's output directory:
|
85
95
|
|
@@ -113,24 +123,25 @@ attributes:
|
|
113
123
|
{% endminibundle %}
|
114
124
|
```
|
115
125
|
|
116
|
-
Then, specify the command for launching your favorite minifier in
|
117
|
-
`$JEKYLL_MINIBUNDLE_CMD_JS` environment variable. For example, when
|
118
|
-
launching Jekyll:
|
126
|
+
Then, specify the command for launching your favorite minifier in `_config.yml`:
|
119
127
|
|
120
|
-
```
|
121
|
-
|
128
|
+
``` yaml
|
129
|
+
minibundle:
|
130
|
+
minifier_commands:
|
131
|
+
js: ./node_modules/.bin/uglifyjs -
|
122
132
|
```
|
123
133
|
|
124
|
-
You can pass custom attributes to the generated markup with
|
125
|
-
`attributes` map in the configuration.
|
126
|
-
|
127
134
|
Output in the content file:
|
128
135
|
|
129
136
|
``` html
|
130
137
|
<script src="assets/site-8e764372a0dbd296033cb2a416f064b5.js" type="text/javascript" id="my-scripts"></script>
|
131
138
|
```
|
132
139
|
|
133
|
-
|
140
|
+
You can pass custom attributes, like `id="my-scripts"` above, to the
|
141
|
+
generated markup with `attributes` map inside the `minibundle` block.
|
142
|
+
|
143
|
+
For bundling CSS assets, you use `css` as the argument to the
|
144
|
+
`minibundle` block:
|
134
145
|
|
135
146
|
``` text
|
136
147
|
{% minibundle css %}
|
@@ -144,8 +155,56 @@ attributes:
|
|
144
155
|
{% endminibundle %}
|
145
156
|
```
|
146
157
|
|
147
|
-
And then specify the command
|
148
|
-
|
158
|
+
And then specify the minifier command in `_config.yml`:
|
159
|
+
|
160
|
+
``` yaml
|
161
|
+
minibundle:
|
162
|
+
minifier_commands:
|
163
|
+
css: _bin/remove_whitespace
|
164
|
+
js: ./node_modules/.bin/uglifyjs -
|
165
|
+
```
|
166
|
+
|
167
|
+
### Minifier command specification
|
168
|
+
|
169
|
+
You can specify minifier commands in three places:
|
170
|
+
|
171
|
+
1. in `_config.yml` (as shown earlier):
|
172
|
+
|
173
|
+
``` yaml
|
174
|
+
minibundle:
|
175
|
+
minifier_commands:
|
176
|
+
css: _bin/remove_whitespace
|
177
|
+
js: ./node_modules/.bin/uglifyjs -
|
178
|
+
```
|
179
|
+
|
180
|
+
2. as environment variables:
|
181
|
+
|
182
|
+
``` bash
|
183
|
+
export JEKYLL_MINIBUNDLE_CMD_CSS=_bin/remove_whitespace
|
184
|
+
export JEKYLL_MINIBUNDLE_CMD_JS="./node_modules/.bin/uglifyjs -"
|
185
|
+
```
|
186
|
+
|
187
|
+
3. inside the minibundle block with `minifier_cmd` setting, allowing
|
188
|
+
blocks to have different commands from each other:
|
189
|
+
|
190
|
+
``` text
|
191
|
+
{% minibundle js %}
|
192
|
+
source_dir: _assets/scripts
|
193
|
+
destination_path: assets/site
|
194
|
+
minifier_cmd: ./node_modules/.bin/uglifyjs -
|
195
|
+
assets:
|
196
|
+
- dependency
|
197
|
+
- app
|
198
|
+
attributes:
|
199
|
+
id: my-scripts
|
200
|
+
{% endminibundle %}
|
201
|
+
```
|
202
|
+
|
203
|
+
These ways of specification are listed in increasing order of
|
204
|
+
specificity. Should multiple commands apply to a block, the most
|
205
|
+
specific one wins. For example, the `minifier_cmd` setting inside
|
206
|
+
`minibundle js` block overrides the setting in
|
207
|
+
`$JEKYLL_MINIBUNDLE_CMD_JS` environment variable.
|
149
208
|
|
150
209
|
## Recommended directory layout
|
151
210
|
|
@@ -192,6 +251,16 @@ filenames and line numbers of the original asset sources.
|
|
192
251
|
$ JEKYLL_MINIBUNDLE_MODE=development jekyll serve --watch
|
193
252
|
```
|
194
253
|
|
254
|
+
Alternatively, you can enable development mode from `_config.yml`:
|
255
|
+
|
256
|
+
``` yaml
|
257
|
+
minibundle:
|
258
|
+
mode: development
|
259
|
+
```
|
260
|
+
|
261
|
+
Should both be defined, the setting from the environment variable
|
262
|
+
wins.
|
263
|
+
|
195
264
|
# Example site
|
196
265
|
|
197
266
|
See the contents of `test/fixture/site` directory.
|
@@ -200,5 +269,9 @@ See the contents of `test/fixture/site` directory.
|
|
200
269
|
|
201
270
|
MIT. See `LICENSE.txt`.
|
202
271
|
|
272
|
+
[Compass]: http://compass-style.org/
|
273
|
+
[GemBundler]: http://bundler.io/
|
274
|
+
[GoogleCachingBestPractices]: https://developers.google.com/speed/docs/best-practices/caching
|
203
275
|
[Jekyll]: http://jekyllrb.com/
|
204
276
|
[JekyllConf]: http://jekyllrb.com/docs/configuration/
|
277
|
+
[UglifyJS2]: https://github.com/mishoo/UglifyJS2
|
data/Rakefile
CHANGED
@@ -4,19 +4,19 @@ require 'shellwords'
|
|
4
4
|
|
5
5
|
require_relative 'lib/jekyll/minibundle/version'
|
6
6
|
|
7
|
-
def get_minibundle_env(overrides = {})
|
8
|
-
bundle_cmd = File.expand_path(File.join(File.dirname(__FILE__), 'test/fixture/site/_bin/remove_comments'))
|
9
|
-
{
|
10
|
-
'JEKYLL_MINIBUNDLE_CMD_JS' => bundle_cmd,
|
11
|
-
'JEKYLL_MINIBUNDLE_CMD_CSS' => bundle_cmd,
|
12
|
-
'RUBYLIB' => File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
|
13
|
-
}.merge(overrides)
|
14
|
-
end
|
15
|
-
|
16
7
|
def run_jekyll_in_fixture_site(command)
|
17
8
|
Dir.chdir('test/fixture/site')
|
18
9
|
FileUtils.rm_rf('_site')
|
19
|
-
|
10
|
+
|
11
|
+
minifier_cmd = File.expand_path(File.join(File.dirname(__FILE__), 'test/fixture/site/_bin/remove_comments'))
|
12
|
+
env = {
|
13
|
+
'JEKYLL_MINIBUNDLE_CMD_JS' => minifier_cmd,
|
14
|
+
'JEKYLL_MINIBUNDLE_CMD_CSS' => minifier_cmd,
|
15
|
+
'RUBYLIB' => File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
|
16
|
+
}
|
17
|
+
jekyll_cmd = "jekyll #{command}"
|
18
|
+
|
19
|
+
sh env, jekyll_cmd
|
20
20
|
end
|
21
21
|
|
22
22
|
namespace :gem do
|
@@ -46,11 +46,9 @@ task :test do
|
|
46
46
|
files = Dir[glob].
|
47
47
|
map { |file| %r{^test/(.+)\.rb$}.match(file)[1] }.
|
48
48
|
shelljoin
|
49
|
-
|
49
|
+
extra_opts = ENV['debug'] ? '-w -rpp -rpry' : ''
|
50
50
|
eval = %{-e 'ARGV.each { |f| require f }'}
|
51
|
-
|
52
|
-
env = get_minibundle_env('RUBYLIB' => 'lib:test')
|
53
|
-
sh env, cmd
|
51
|
+
sh "ruby -I lib:test #{extra_opts} #{eval} #{files}"
|
54
52
|
end
|
55
53
|
|
56
54
|
namespace :fixture do
|
data/jekyll-minibundle.gemspec
CHANGED
@@ -27,7 +27,7 @@ minification tool (not even other gems).
|
|
27
27
|
|
28
28
|
s.test_files = `git ls-files -- test`.split("\n")
|
29
29
|
|
30
|
-
s.add_development_dependency 'jekyll', '~> 2.
|
30
|
+
s.add_development_dependency 'jekyll', '~> 2.1'
|
31
31
|
s.add_development_dependency 'minitest', '~> 5.3'
|
32
32
|
s.add_development_dependency 'nokogiri', '~> 1.6'
|
33
33
|
s.add_development_dependency 'rake', '~> 10.3'
|
@@ -1,11 +1,23 @@
|
|
1
1
|
require 'tempfile'
|
2
|
-
require 'jekyll/minibundle/environment'
|
3
2
|
require 'jekyll/minibundle/compatibility'
|
4
3
|
|
5
4
|
module Jekyll::Minibundle
|
6
5
|
class AssetBundle
|
7
|
-
def initialize(
|
8
|
-
@type
|
6
|
+
def initialize(config)
|
7
|
+
@type = config.fetch(:type)
|
8
|
+
@asset_paths = config.fetch(:asset_paths)
|
9
|
+
@site_dir = config.fetch(:site_dir)
|
10
|
+
@minifier_cmd = config.fetch(:minifier_cmd)
|
11
|
+
|
12
|
+
unless @minifier_cmd
|
13
|
+
fail <<-END
|
14
|
+
Missing minification command for bundling #{@type} assets. Specify it in
|
15
|
+
1) minibundle.minifier_commands.#{@type} setting in _config.yml,
|
16
|
+
2) $JEKYLL_MINIBUNDLE_CMD_#{@type.to_s.upcase} environment variable, or
|
17
|
+
3) minifier_cmd setting inside minibundle block.
|
18
|
+
END
|
19
|
+
end
|
20
|
+
|
9
21
|
@temp_file = Tempfile.new("jekyll-minibundle-#{@type}-")
|
10
22
|
at_exit { @temp_file.close! }
|
11
23
|
end
|
@@ -15,8 +27,7 @@ module Jekyll::Minibundle
|
|
15
27
|
end
|
16
28
|
|
17
29
|
def make_bundle
|
18
|
-
|
19
|
-
exit_status = spawn_minifier(cmd) do |input|
|
30
|
+
exit_status = spawn_minifier(@minifier_cmd) do |input|
|
20
31
|
$stdout.puts # place newline after "(Re)generating..." log messages
|
21
32
|
Compatibility.log_info("Bundling #{@type} assets:")
|
22
33
|
@asset_paths.each do |asset|
|
@@ -25,7 +36,7 @@ module Jekyll::Minibundle
|
|
25
36
|
input.puts(';') if @type == :js
|
26
37
|
end
|
27
38
|
end
|
28
|
-
fail "Bundling #{@type} assets failed with exit status #{exit_status}, command: #{
|
39
|
+
fail "Bundling #{@type} assets failed with exit status #{exit_status}, command: #{@minifier_cmd}" if exit_status != 0
|
29
40
|
self
|
30
41
|
end
|
31
42
|
|
@@ -35,10 +46,6 @@ module Jekyll::Minibundle
|
|
35
46
|
path.sub(/\A#{base}\//, '')
|
36
47
|
end
|
37
48
|
|
38
|
-
def get_minifier_cmd
|
39
|
-
Environment.command_for(@type)
|
40
|
-
end
|
41
|
-
|
42
49
|
def spawn_minifier(cmd)
|
43
50
|
pid = nil
|
44
51
|
rd, wr = IO.pipe
|
@@ -10,9 +10,9 @@ module Jekyll::Minibundle
|
|
10
10
|
@_instances = {}
|
11
11
|
end
|
12
12
|
|
13
|
-
def bundle_file(site,
|
14
|
-
asset_destination_path = "#{
|
15
|
-
@_instances[asset_destination_path] ||= register_bundle_file(site,
|
13
|
+
def bundle_file(site, bundle_config)
|
14
|
+
asset_destination_path = "#{bundle_config.fetch('destination_path')}.#{bundle_config.fetch('type')}"
|
15
|
+
@_instances[asset_destination_path] ||= register_bundle_file(site, bundle_config)
|
16
16
|
end
|
17
17
|
|
18
18
|
def stamp_file(site, asset_source_path, asset_destination_path)
|
@@ -21,20 +21,20 @@ module Jekyll::Minibundle
|
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
def register_bundle_file(site,
|
25
|
-
if Environment.development?
|
26
|
-
DevelopmentFileCollection.new(site,
|
24
|
+
def register_bundle_file(site, bundle_config)
|
25
|
+
if Environment.development?(site)
|
26
|
+
DevelopmentFileCollection.new(site, bundle_config)
|
27
27
|
else
|
28
|
-
BundleFile.new(site,
|
28
|
+
BundleFile.new(site, bundle_config)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
def register_stamp_file(site, asset_source_path, asset_destination_path)
|
33
|
-
StampFile.new(site, asset_source_path, asset_destination_path, &get_stamp_file_basenamer)
|
33
|
+
StampFile.new(site, asset_source_path, asset_destination_path, &get_stamp_file_basenamer(site))
|
34
34
|
end
|
35
35
|
|
36
|
-
def get_stamp_file_basenamer
|
37
|
-
if Environment.development?
|
36
|
+
def get_stamp_file_basenamer(site)
|
37
|
+
if Environment.development?(site)
|
38
38
|
->(base, ext, _) { base + ext }
|
39
39
|
else
|
40
40
|
->(base, ext, stamper) { "#{base}-#{stamper.call}#{ext}" }
|
@@ -10,7 +10,7 @@ module Jekyll::Minibundle
|
|
10
10
|
when :css
|
11
11
|
%{<link rel="stylesheet" href="#{path}"#{make_attributes(attributes)}>}
|
12
12
|
else
|
13
|
-
fail "Unknown type for generating bundle markup: #{type}, #{path}"
|
13
|
+
fail ArgumentError, "Unknown type for generating bundle markup: #{type}, #{path}"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -17,6 +17,7 @@ module Jekyll::Minibundle
|
|
17
17
|
@asset_paths = config.fetch('assets').map { |asset_path| File.join(asset_source_dir, "#{asset_path}.#{@type}") }
|
18
18
|
@destination_path = config.fetch('destination_path')
|
19
19
|
@attributes = config.fetch('attributes')
|
20
|
+
@minifier_cmd = config.fetch('minifier_cmd')
|
20
21
|
@stamped_at = nil
|
21
22
|
@is_modified = false
|
22
23
|
end
|
@@ -65,7 +66,12 @@ module Jekyll::Minibundle
|
|
65
66
|
end
|
66
67
|
|
67
68
|
def asset_bundle
|
68
|
-
@_asset_bundle ||= AssetBundle.new(
|
69
|
+
@_asset_bundle ||= AssetBundle.new(
|
70
|
+
type: @type,
|
71
|
+
asset_paths: @asset_paths,
|
72
|
+
site_dir: @site.source,
|
73
|
+
minifier_cmd: @minifier_cmd
|
74
|
+
)
|
69
75
|
end
|
70
76
|
end
|
71
77
|
end
|
@@ -1,13 +1,31 @@
|
|
1
1
|
module Jekyll::Minibundle
|
2
2
|
module Environment
|
3
3
|
class << self
|
4
|
-
def
|
5
|
-
|
6
|
-
ENV.
|
4
|
+
def minifier_command(site, type)
|
5
|
+
type = type.to_s
|
6
|
+
ENV["JEKYLL_MINIBUNDLE_CMD_#{type.upcase}"] || Environment.find_site_config(site, ['minibundle', 'minifier_commands', type], String)
|
7
7
|
end
|
8
8
|
|
9
|
-
def development?
|
10
|
-
ENV['JEKYLL_MINIBUNDLE_MODE']
|
9
|
+
def development?(site)
|
10
|
+
mode = ENV['JEKYLL_MINIBUNDLE_MODE'] || Environment.find_site_config(site, ['minibundle', 'mode'], String)
|
11
|
+
mode == 'development'
|
12
|
+
end
|
13
|
+
|
14
|
+
def find_site_config(site, keys, type)
|
15
|
+
value = traverse_hash(site.config, keys)
|
16
|
+
if value && !value.is_a?(type)
|
17
|
+
fail "Invalid site configuration for key #{keys.join('.')}; expecting type #{type}"
|
18
|
+
end
|
19
|
+
value
|
20
|
+
end
|
21
|
+
|
22
|
+
def traverse_hash(hash, keys)
|
23
|
+
value = hash
|
24
|
+
keys.each do |key|
|
25
|
+
return nil unless value
|
26
|
+
value = value[key]
|
27
|
+
end
|
28
|
+
value
|
11
29
|
end
|
12
30
|
end
|
13
31
|
end
|
@@ -1,37 +1,46 @@
|
|
1
1
|
require 'jekyll/minibundle/asset_file_registry'
|
2
2
|
require 'jekyll/minibundle/compatibility'
|
3
|
+
require 'jekyll/minibundle/environment'
|
3
4
|
|
4
5
|
module Jekyll::Minibundle
|
5
6
|
class MiniBundleBlock < Liquid::Block
|
6
7
|
def initialize(tag_name, type, _tokens)
|
7
8
|
super
|
8
|
-
@type = type.strip.to_sym
|
9
|
+
@type = type.strip.downcase.to_sym
|
10
|
+
if @type.empty?
|
11
|
+
fail ArgumentError, "No asset type for minibundle block; pass value such as 'css' or 'js' as the argument"
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
def render(context)
|
12
16
|
site = context.registers.fetch(:site)
|
13
|
-
|
14
|
-
file = AssetFileRegistry.bundle_file(site,
|
17
|
+
bundle_config = get_current_bundle_config(Compatibility.load_yaml(super), site)
|
18
|
+
file = AssetFileRegistry.bundle_file(site, bundle_config)
|
15
19
|
file.add_as_static_file_to(site)
|
16
20
|
file.destination_path_for_markup
|
17
21
|
end
|
18
22
|
|
19
|
-
def self.
|
23
|
+
def self.default_bundle_config
|
20
24
|
{
|
21
|
-
'source_dir'
|
22
|
-
'destination_path'
|
23
|
-
'assets'
|
24
|
-
'attributes'
|
25
|
+
'source_dir' => '_assets',
|
26
|
+
'destination_path' => 'assets/site',
|
27
|
+
'assets' => [],
|
28
|
+
'attributes' => {}
|
25
29
|
}
|
26
30
|
end
|
27
31
|
|
28
32
|
private
|
29
33
|
|
30
|
-
def
|
31
|
-
MiniBundleBlock.
|
32
|
-
merge(
|
34
|
+
def get_current_bundle_config(local_bundle_config, site)
|
35
|
+
MiniBundleBlock.default_bundle_config.
|
36
|
+
merge(environment_bundle_config(site)).
|
37
|
+
merge(local_bundle_config).
|
33
38
|
merge('type' => @type)
|
34
39
|
end
|
40
|
+
|
41
|
+
def environment_bundle_config(site)
|
42
|
+
{ 'minifier_cmd' => Environment.minifier_command(site, @type) }
|
43
|
+
end
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
@@ -5,6 +5,12 @@ module Jekyll::Minibundle
|
|
5
5
|
def initialize(tag_name, text, _tokens)
|
6
6
|
super
|
7
7
|
@asset_source, @asset_destination = text.split(/\s+/, 3)[0, 2]
|
8
|
+
if !@asset_source || @asset_source.empty?
|
9
|
+
fail ArgumentError, "No asset source for ministamp tag; pass value such as '/_assets/site.css' as the first argument"
|
10
|
+
end
|
11
|
+
if !@asset_destination || @asset_destination.empty?
|
12
|
+
fail ArgumentError, "No asset destination for ministamp tag; pass value such as '/assets/site.css' as the second argument"
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
16
|
def render(context)
|
@@ -111,10 +111,8 @@ module Jekyll::Minibundle::Test
|
|
111
111
|
|
112
112
|
def test_does_not_require_bundling_commands
|
113
113
|
with_site_dir do
|
114
|
-
|
115
|
-
|
116
|
-
pass
|
117
|
-
end
|
114
|
+
generate_site(:development, minifier_cmd_css: nil, minifier_cmd_js: nil)
|
115
|
+
pass
|
118
116
|
end
|
119
117
|
end
|
120
118
|
|
@@ -135,6 +133,22 @@ module Jekyll::Minibundle::Test
|
|
135
133
|
end
|
136
134
|
end
|
137
135
|
|
136
|
+
def test_gets_development_mode_from_site_configuration
|
137
|
+
with_site_dir do
|
138
|
+
merge_to_yaml_file('_config.yml', 'minibundle' => {'mode' => 'development'})
|
139
|
+
generate_site(nil)
|
140
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js'))
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_development_mode_from_environment_overrides_mode_from_site_configuration
|
145
|
+
with_site_dir do
|
146
|
+
merge_to_yaml_file('_config.yml', 'minibundle' => {'mode' => 'production'})
|
147
|
+
generate_site(:development)
|
148
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js'))
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
138
152
|
private
|
139
153
|
|
140
154
|
def find_css_elements_from_index
|
@@ -166,34 +166,89 @@ module Jekyll::Minibundle::Test
|
|
166
166
|
|
167
167
|
def test_bundles_assets_only_once_at_startup
|
168
168
|
with_site_dir do
|
169
|
-
|
170
|
-
|
171
|
-
end
|
172
|
-
assert_equal 1, get_cmd_count
|
169
|
+
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
170
|
+
assert_equal 1, get_minifier_cmd_count
|
173
171
|
end
|
174
172
|
end
|
175
173
|
|
176
174
|
def test_does_not_rebundle_assets_when_nonsource_files_change
|
177
175
|
with_site_dir do
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
176
|
+
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
177
|
+
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
178
|
+
last_mtime = mtime_of(expected_js_path)
|
179
|
+
|
180
|
+
assert_equal 1, get_minifier_cmd_count
|
182
181
|
|
183
|
-
|
182
|
+
ensure_file_mtime_changes { File.write(source_path(CSS_BUNDLE_SOURCE_DIR, 'common.css'), 'h1 {}') }
|
183
|
+
generate_site(:production, clear_cache: false, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
184
184
|
|
185
|
-
|
186
|
-
|
185
|
+
assert_equal last_mtime, mtime_of(expected_js_path)
|
186
|
+
assert_equal 1, get_minifier_cmd_count
|
187
187
|
|
188
|
-
|
189
|
-
|
188
|
+
ensure_file_mtime_changes { FileUtils.touch('index.html') }
|
189
|
+
generate_site(:production, clear_cache: false, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
190
190
|
|
191
|
-
|
192
|
-
|
191
|
+
assert_equal last_mtime, mtime_of(expected_js_path)
|
192
|
+
assert_equal 1, get_minifier_cmd_count
|
193
|
+
end
|
194
|
+
end
|
193
195
|
|
194
|
-
|
195
|
-
|
196
|
-
|
196
|
+
def test_gets_minifier_command_from_site_configuration
|
197
|
+
with_site_dir do
|
198
|
+
merge_to_yaml_file('_config.yml', 'minibundle' => {'minifier_commands' => {'js' => minifier_cmd_to_remove_comments_and_count('minifier_cmd_config_count')}})
|
199
|
+
|
200
|
+
generate_site(:production, minifier_cmd_js: nil)
|
201
|
+
|
202
|
+
assert_equal 0, get_minifier_cmd_count
|
203
|
+
assert_equal 1, get_minifier_cmd_count('minifier_cmd_config_count')
|
204
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_minifier_command_from_environment_overrides_command_from_site_configuration
|
209
|
+
with_site_dir do
|
210
|
+
merge_to_yaml_file('_config.yml', 'minibundle' => {'minifier_commands' => {'js' => minifier_cmd_to_remove_comments_and_count('minifier_cmd_config_count')}})
|
211
|
+
|
212
|
+
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count('minifier_cmd_env_count'))
|
213
|
+
|
214
|
+
assert_equal 0, get_minifier_cmd_count('minifier_cmd_config_count')
|
215
|
+
assert_equal 1, get_minifier_cmd_count('minifier_cmd_env_count')
|
216
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_minifier_command_in_local_block_overrides_command_from_environment
|
221
|
+
with_site_dir do
|
222
|
+
IO.write('test.html', <<-END)
|
223
|
+
---
|
224
|
+
layout: override
|
225
|
+
title: Test
|
226
|
+
---
|
227
|
+
END
|
228
|
+
|
229
|
+
IO.write('_layouts/override.html', <<-END)
|
230
|
+
<!DOCTYPE html>
|
231
|
+
<html>
|
232
|
+
<body>
|
233
|
+
{% minibundle js %}
|
234
|
+
source_dir: _assets/scripts
|
235
|
+
destination_path: assets/deps
|
236
|
+
assets:
|
237
|
+
- dependency
|
238
|
+
minifier_cmd: #{minifier_cmd_to_remove_comments_and_count('minifier_cmd_local_count')}
|
239
|
+
{% endminibundle %}
|
240
|
+
</body>
|
241
|
+
<title>{{ page.title }}</title>
|
242
|
+
</html>
|
243
|
+
END
|
244
|
+
|
245
|
+
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count('minifier_cmd_global_count'))
|
246
|
+
|
247
|
+
assert_equal 1, get_minifier_cmd_count('minifier_cmd_local_count')
|
248
|
+
assert File.exist?(destination_path('assets/deps-71042d0b7c86c04e015fde694dd9f409.js'))
|
249
|
+
|
250
|
+
assert_equal 1, get_minifier_cmd_count('minifier_cmd_global_count')
|
251
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
197
252
|
end
|
198
253
|
end
|
199
254
|
|
data/test/support/test_case.rb
CHANGED
@@ -34,6 +34,10 @@ module Jekyll::Minibundle::Test
|
|
34
34
|
File.write(file, new_content)
|
35
35
|
end
|
36
36
|
|
37
|
+
def merge_to_yaml_file(file, hash)
|
38
|
+
IO.write(file, YAML.load_file(file).merge(hash).to_yaml)
|
39
|
+
end
|
40
|
+
|
37
41
|
def mtime_of(path)
|
38
42
|
File.stat(path).mtime
|
39
43
|
end
|
@@ -59,13 +63,13 @@ module Jekyll::Minibundle::Test
|
|
59
63
|
end
|
60
64
|
|
61
65
|
def new_fake_site(dir)
|
62
|
-
OpenStruct.new(:
|
66
|
+
OpenStruct.new(source: dir, static_files: [])
|
63
67
|
end
|
64
68
|
|
65
69
|
def new_real_site
|
66
70
|
config = nil
|
67
71
|
capture_io do
|
68
|
-
config = Jekyll.configuration(
|
72
|
+
config = Jekyll.configuration('source' => Dir.pwd, 'destination' => '_site')
|
69
73
|
end
|
70
74
|
Jekyll::Site.new(config)
|
71
75
|
end
|
@@ -81,9 +85,12 @@ module Jekyll::Minibundle::Test
|
|
81
85
|
end
|
82
86
|
|
83
87
|
def generate_site(mode, options = {})
|
84
|
-
|
85
|
-
|
86
|
-
|
88
|
+
env = {
|
89
|
+
'JEKYLL_MINIBUNDLE_MODE' => mode && mode.to_s,
|
90
|
+
'JEKYLL_MINIBUNDLE_CMD_CSS' => options.fetch(:minifier_cmd_css, minifier_cmd_to_remove_comments),
|
91
|
+
'JEKYLL_MINIBUNDLE_CMD_JS' => options.fetch(:minifier_cmd_js, minifier_cmd_to_remove_comments)
|
92
|
+
}
|
93
|
+
with_env(env) { _generate_site(options) }
|
87
94
|
end
|
88
95
|
|
89
96
|
def ensure_file_mtime_changes(&block)
|
@@ -91,13 +98,17 @@ module Jekyll::Minibundle::Test
|
|
91
98
|
yield
|
92
99
|
end
|
93
100
|
|
94
|
-
def
|
95
|
-
site_fixture_path('_bin/
|
101
|
+
def minifier_cmd_to_remove_comments
|
102
|
+
site_fixture_path('_bin/remove_comments')
|
96
103
|
end
|
97
104
|
|
98
|
-
def
|
99
|
-
|
100
|
-
|
105
|
+
def minifier_cmd_to_remove_comments_and_count(count_file = 'minifier_cmd_count')
|
106
|
+
"#{site_fixture_path('_bin/with_count')} #{count_file} _bin/remove_comments"
|
107
|
+
end
|
108
|
+
|
109
|
+
def get_minifier_cmd_count(count_file = 'minifier_cmd_count')
|
110
|
+
if File.exist?(count_file)
|
111
|
+
File.read(count_file).to_i
|
101
112
|
else
|
102
113
|
0
|
103
114
|
end
|
@@ -127,24 +138,9 @@ module Jekyll::Minibundle::Test
|
|
127
138
|
end
|
128
139
|
|
129
140
|
def _generate_site(test_options)
|
130
|
-
AssetFileRegistry.clear if test_options.fetch(:clear_cache)
|
141
|
+
AssetFileRegistry.clear if test_options.fetch(:clear_cache, true)
|
131
142
|
site = new_real_site
|
132
143
|
capture_io { site.process }
|
133
144
|
end
|
134
|
-
|
135
|
-
def _get_site_generation_test_options(options)
|
136
|
-
TestCase.site_generation_test_options.merge(options)
|
137
|
-
end
|
138
|
-
|
139
|
-
def self.site_generation_test_options
|
140
|
-
{ clear_cache: true }
|
141
|
-
end
|
142
|
-
|
143
|
-
def self.site_generation_jekyll_options
|
144
|
-
{
|
145
|
-
'source' => Dir.pwd,
|
146
|
-
'destination' => '_site'
|
147
|
-
}
|
148
|
-
end
|
149
145
|
end
|
150
146
|
end
|
@@ -5,30 +5,29 @@ module Jekyll::Minibundle::Test
|
|
5
5
|
class AssetBundleTest < TestCase
|
6
6
|
def test_raise_exception_if_bundle_command_fails
|
7
7
|
capture_io do
|
8
|
-
|
9
|
-
|
10
|
-
assert_equal 'Bundling js assets failed with exit status 1, command: false', err.to_s
|
11
|
-
end
|
8
|
+
err = assert_raises(RuntimeError) { make_bundle('false') }
|
9
|
+
assert_equal 'Bundling js assets failed with exit status 1, command: false', err.to_s
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
13
|
def test_raise_exception_if_bundle_command_not_found
|
16
|
-
|
17
|
-
assert_raises(Errno::ENOENT) { make_bundle }
|
18
|
-
end
|
14
|
+
assert_raises(Errno::ENOENT) { make_bundle('no-such-jekyll-minibundle-cmd') }
|
19
15
|
end
|
20
16
|
|
21
17
|
def test_raise_exception_if_bundle_command_not_configured
|
22
|
-
|
23
|
-
|
24
|
-
assert_equal 'You need to set command for minification in $JEKYLL_MINIBUNDLE_CMD_JS', err.to_s
|
25
|
-
end
|
18
|
+
err = assert_raises(RuntimeError) { make_bundle(nil) }
|
19
|
+
assert_match(/\AMissing minification command for bundling js assets. Specify it in/, err.to_s)
|
26
20
|
end
|
27
21
|
|
28
22
|
private
|
29
23
|
|
30
|
-
def make_bundle
|
31
|
-
bundle = AssetBundle.new(
|
24
|
+
def make_bundle(minifier_cmd)
|
25
|
+
bundle = AssetBundle.new(
|
26
|
+
type: :js,
|
27
|
+
asset_paths: [site_fixture_path('_assets/scripts/dependency.js')],
|
28
|
+
site_dir: site_fixture_path,
|
29
|
+
minifier_cmd: minifier_cmd
|
30
|
+
)
|
32
31
|
bundle.make_bundle
|
33
32
|
end
|
34
33
|
end
|
@@ -5,9 +5,16 @@ module Jekyll::Minibundle::Test
|
|
5
5
|
class AssetTagMarkupTest < TestCase
|
6
6
|
def test_escapes_attribute_values
|
7
7
|
attributes = { media: 'screen, projection', extra: '">attack<br' }
|
8
|
-
actual = AssetTagMarkup.make_markup(:css, '
|
9
|
-
expected = %{<link rel="stylesheet" href="
|
8
|
+
actual = AssetTagMarkup.make_markup(:css, '/asset', attributes)
|
9
|
+
expected = %{<link rel="stylesheet" href="/asset" media="screen, projection" extra="">attack<br">}
|
10
10
|
assert_equal expected, actual
|
11
11
|
end
|
12
|
+
|
13
|
+
def test_raise_exception_if_unknown_type
|
14
|
+
err = assert_raises(ArgumentError) do
|
15
|
+
AssetTagMarkup.make_markup(:unknown, '/asset', {})
|
16
|
+
end
|
17
|
+
assert_equal "Unknown type for generating bundle markup: unknown, /asset", err.to_s
|
18
|
+
end
|
12
19
|
end
|
13
20
|
end
|
@@ -8,91 +8,85 @@ module Jekyll::Minibundle::Test
|
|
8
8
|
|
9
9
|
def test_calling_markup_determines_fingerprint_and_destination_write
|
10
10
|
with_fake_site do |site|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
capture_io { org_markup = bundle_file.destination_path_for_markup }
|
11
|
+
bundle_file = BundleFile.new(site, bundle_config(minifier_cmd_to_remove_comments_and_count))
|
12
|
+
source = source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')
|
13
|
+
old_destination = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
14
|
+
org_markup, last_markup = nil
|
15
|
+
capture_io { org_markup = bundle_file.destination_path_for_markup }
|
17
16
|
|
18
|
-
|
17
|
+
assert bundle_file.write('_site')
|
19
18
|
|
20
|
-
|
19
|
+
org_mtime = mtime_of(old_destination)
|
21
20
|
|
22
|
-
|
21
|
+
assert_equal 1, get_minifier_cmd_count
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
last_markup = bundle_file.destination_path_for_markup
|
24
|
+
ensure_file_mtime_changes { File.write(source, '(function() {})()') }
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
# preserve fingerprint and content seen in last markup phase
|
27
|
+
refute bundle_file.write('_site')
|
28
|
+
assert_equal org_markup, last_markup
|
29
|
+
assert_equal org_mtime, mtime_of(old_destination)
|
30
|
+
assert_equal 1, get_minifier_cmd_count
|
32
31
|
|
33
|
-
|
32
|
+
capture_io { last_markup = bundle_file.destination_path_for_markup }
|
34
33
|
|
35
|
-
|
34
|
+
assert bundle_file.write('_site')
|
36
35
|
|
37
|
-
|
36
|
+
new_destination = destination_path('assets/site-375a0b430b0c5555d0edd2205d26c04d.js')
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
38
|
+
# see updated fingerprint in the next round
|
39
|
+
refute_equal org_markup, last_markup
|
40
|
+
assert_operator mtime_of(new_destination), :>, org_mtime
|
41
|
+
assert_equal 2, get_minifier_cmd_count
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
45
|
def test_many_consecutive_markup_calls_trigger_one_destination_write
|
48
46
|
with_fake_site do |site|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
bundle_file.destination_path_for_markup
|
47
|
+
bundle_file = BundleFile.new(site, bundle_config(minifier_cmd_to_remove_comments_and_count))
|
48
|
+
source = source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')
|
49
|
+
destination = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
50
|
+
org_markup, last_markup = nil
|
51
|
+
capture_io { org_markup = bundle_file.destination_path_for_markup }
|
52
|
+
bundle_file.destination_path_for_markup
|
56
53
|
|
57
|
-
|
54
|
+
assert bundle_file.write('_site')
|
58
55
|
|
59
|
-
|
56
|
+
org_mtime = mtime_of(destination)
|
60
57
|
|
61
|
-
|
58
|
+
assert_equal 1, get_minifier_cmd_count
|
62
59
|
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
ensure_file_mtime_changes { FileUtils.touch(source) }
|
61
|
+
capture_io { last_markup = bundle_file.destination_path_for_markup }
|
62
|
+
bundle_file.destination_path_for_markup
|
66
63
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
64
|
+
assert bundle_file.write('_site')
|
65
|
+
assert_equal org_markup, last_markup
|
66
|
+
assert_operator mtime_of(destination), :>, org_mtime
|
67
|
+
assert_equal 2, get_minifier_cmd_count
|
72
68
|
end
|
73
69
|
end
|
74
70
|
|
75
71
|
def test_calling_write_before_destination_path_for_markup_has_no_effect
|
76
72
|
with_fake_site do |site|
|
77
|
-
|
78
|
-
bundle_file = BundleFile.new(site, bundle_config)
|
73
|
+
bundle_file = BundleFile.new(site, bundle_config(minifier_cmd_to_remove_comments_and_count))
|
79
74
|
|
80
|
-
|
81
|
-
|
82
|
-
|
75
|
+
refute bundle_file.write('_site')
|
76
|
+
assert_empty Dir[destination_path('assets/*.js')]
|
77
|
+
assert_equal 0, get_minifier_cmd_count
|
83
78
|
|
84
|
-
|
79
|
+
capture_io { bundle_file.destination_path_for_markup }
|
85
80
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
81
|
+
assert bundle_file.write('_site')
|
82
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
83
|
+
assert_equal 1, get_minifier_cmd_count
|
90
84
|
end
|
91
85
|
end
|
92
86
|
|
93
87
|
def test_to_liquid
|
94
88
|
with_fake_site do |site|
|
95
|
-
hash = BundleFile.new(site, bundle_config).to_liquid
|
89
|
+
hash = BundleFile.new(site, bundle_config(minifier_cmd_to_remove_comments)).to_liquid
|
96
90
|
assert_match(/jekyll-minibundle-js-/, hash['path'])
|
97
91
|
refute_empty hash['modified_time']
|
98
92
|
end
|
@@ -100,13 +94,14 @@ module Jekyll::Minibundle::Test
|
|
100
94
|
|
101
95
|
private
|
102
96
|
|
103
|
-
def bundle_config
|
97
|
+
def bundle_config(minifier_cmd)
|
104
98
|
{
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
99
|
+
'type' => :js,
|
100
|
+
'source_dir' => JS_BUNDLE_SOURCE_DIR,
|
101
|
+
'assets' => %w{dependency app},
|
102
|
+
'destination_path' => JS_BUNDLE_DESTINATION_PATH,
|
103
|
+
'attributes' => {},
|
104
|
+
'minifier_cmd' => minifier_cmd
|
110
105
|
}
|
111
106
|
end
|
112
107
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'support/test_case'
|
2
|
+
require 'jekyll/minibundle/environment'
|
3
|
+
|
4
|
+
module Jekyll::Minibundle::Test
|
5
|
+
class EnvironmentTest < TestCase
|
6
|
+
def test_hash_traverse_returns_value_when_found
|
7
|
+
assert_equal 1, Environment.traverse_hash({top: {middle: {leaf: 1}}}, [:top, :middle, :leaf])
|
8
|
+
assert_equal({leaf: 1}, Environment.traverse_hash({top: {middle: {leaf: 1}}}, [:top, :middle]))
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_hash_traverse_returns_nil_when_not_found
|
12
|
+
assert_nil Environment.traverse_hash({}, [:top, :no_such_leaf])
|
13
|
+
assert_nil Environment.traverse_hash({top: {}}, [:top, :no_such_leaf])
|
14
|
+
assert_nil Environment.traverse_hash({top: {leaf: 1}}, [:top, :no_such_leaf])
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_find_site_config_returns_value_when_found
|
18
|
+
assert_equal 1, Environment.find_site_config(new_site(top: {leaf: 1}), [:top, :leaf], Integer)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_find_site_config_returns_nil_when_not_found
|
22
|
+
assert_nil Environment.find_site_config(new_site, [:top, :leaf], Integer)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_find_site_config_raises_exception_if_found_value_is_of_unexpected_type
|
26
|
+
err = assert_raises(RuntimeError) do
|
27
|
+
Environment.find_site_config(new_site(top: {leaf: '1'}), [:top, :leaf], Integer)
|
28
|
+
end
|
29
|
+
assert_equal 'Invalid site configuration for key top.leaf; expecting type Integer', err.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def new_site(config = {})
|
35
|
+
OpenStruct.new(config: config)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -52,11 +52,12 @@ module Jekyll::Minibundle::Test
|
|
52
52
|
|
53
53
|
def bundle_config
|
54
54
|
{
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
'type' => :js,
|
56
|
+
'source_dir' => JS_BUNDLE_SOURCE_DIR,
|
57
|
+
'assets' => %w{dependency app},
|
58
|
+
'destination_path' => JS_BUNDLE_DESTINATION_PATH,
|
59
|
+
'attributes' => {},
|
60
|
+
'minifier_cmd' => 'unused_minifier_cmd'
|
60
61
|
}
|
61
62
|
end
|
62
63
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'support/test_case'
|
2
|
+
require 'jekyll/minibundle/mini_bundle_block'
|
3
|
+
|
4
|
+
module Jekyll::Minibundle::Test
|
5
|
+
class MiniBundleBlockTest < TestCase
|
6
|
+
def test_raise_exception_if_no_type_argument
|
7
|
+
err = assert_raises(ArgumentError) do
|
8
|
+
Liquid::Template.parse("{% minibundle %} {% endminibundle %}")
|
9
|
+
end
|
10
|
+
assert_equal "No asset type for minibundle block; pass value such as 'css' or 'js' as the argument", err.to_s
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'support/test_case'
|
2
|
+
require 'support/fixture_config'
|
3
|
+
require 'jekyll/minibundle/mini_stamp_tag'
|
4
|
+
|
5
|
+
module Jekyll::Minibundle::Test
|
6
|
+
class MiniStampTagTest < TestCase
|
7
|
+
include FixtureConfig
|
8
|
+
|
9
|
+
def test_raise_exception_if_no_asset_source_argument
|
10
|
+
err = assert_raises(ArgumentError) do
|
11
|
+
Liquid::Template.parse("{% ministamp %}")
|
12
|
+
end
|
13
|
+
assert_equal "No asset source for ministamp tag; pass value such as '/_assets/site.css' as the first argument", err.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_raise_exception_if_no_asset_destination_argument
|
17
|
+
err = assert_raises(ArgumentError) do
|
18
|
+
Liquid::Template.parse("{% ministamp /_assets/site.css %}")
|
19
|
+
end
|
20
|
+
assert_equal "No asset destination for ministamp tag; pass value such as '/assets/site.css' as the second argument", err.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_ignore_rest_arguments
|
24
|
+
AssetFileRegistry.clear
|
25
|
+
template = Liquid::Template.parse("{% ministamp #{STAMP_SOURCE_PATH} #{STAMP_DESTINATION_PATH} rest %}")
|
26
|
+
context = {}
|
27
|
+
options = {registers: {site: new_fake_site(site_fixture_path)}}
|
28
|
+
assert_equal STAMP_DESTINATION_FINGERPRINT_PATH, template.render(context, options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-minibundle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tuomas Kareinen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,7 +106,6 @@ files:
|
|
106
106
|
- test/fixture/site/_bin/with_count
|
107
107
|
- test/fixture/site/_config.yml
|
108
108
|
- test/fixture/site/_layouts/default.html
|
109
|
-
- test/fixture/site/_plugins/minibundle.rb
|
110
109
|
- test/fixture/site/_tmp/site.css
|
111
110
|
- test/fixture/site/about.html
|
112
111
|
- test/fixture/site/assets/site.css
|
@@ -122,8 +121,11 @@ files:
|
|
122
121
|
- test/unit/asset_tag_markup_test.rb
|
123
122
|
- test/unit/bundle_file_test.rb
|
124
123
|
- test/unit/development_file_collection_test.rb
|
124
|
+
- test/unit/environment_test.rb
|
125
125
|
- test/unit/jekyll_payload_test.rb
|
126
126
|
- test/unit/jekyll_static_file_api_test.rb
|
127
|
+
- test/unit/mini_bundle_block_test.rb
|
128
|
+
- test/unit/mini_stamp_tag_test.rb
|
127
129
|
- test/unit/stamp_file_test.rb
|
128
130
|
homepage: https://github.com/tkareine/jekyll-minibundle
|
129
131
|
licenses:
|
@@ -150,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
152
|
version: '0'
|
151
153
|
requirements: []
|
152
154
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.4.1
|
154
156
|
signing_key:
|
155
157
|
specification_version: 4
|
156
158
|
summary: A minimalistic asset bundling plugin for Jekyll
|
@@ -163,7 +165,6 @@ test_files:
|
|
163
165
|
- test/fixture/site/_bin/with_count
|
164
166
|
- test/fixture/site/_config.yml
|
165
167
|
- test/fixture/site/_layouts/default.html
|
166
|
-
- test/fixture/site/_plugins/minibundle.rb
|
167
168
|
- test/fixture/site/_tmp/site.css
|
168
169
|
- test/fixture/site/about.html
|
169
170
|
- test/fixture/site/assets/site.css
|
@@ -179,6 +180,9 @@ test_files:
|
|
179
180
|
- test/unit/asset_tag_markup_test.rb
|
180
181
|
- test/unit/bundle_file_test.rb
|
181
182
|
- test/unit/development_file_collection_test.rb
|
183
|
+
- test/unit/environment_test.rb
|
182
184
|
- test/unit/jekyll_payload_test.rb
|
183
185
|
- test/unit/jekyll_static_file_api_test.rb
|
186
|
+
- test/unit/mini_bundle_block_test.rb
|
187
|
+
- test/unit/mini_stamp_tag_test.rb
|
184
188
|
- test/unit/stamp_file_test.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'jekyll/minibundle'
|