jekyll-minibundle 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +35 -25
- data/Rakefile +6 -6
- data/jekyll-minibundle.gemspec +11 -11
- data/lib/jekyll/minibundle/asset_bundle.rb +19 -16
- data/lib/jekyll/minibundle/asset_file_operations.rb +3 -3
- data/lib/jekyll/minibundle/asset_file_paths.rb +2 -6
- data/lib/jekyll/minibundle/asset_file_registry.rb +28 -30
- data/lib/jekyll/minibundle/asset_stamp.rb +1 -1
- data/lib/jekyll/minibundle/asset_tag_markup.rb +16 -14
- data/lib/jekyll/minibundle/bundle_file.rb +10 -9
- data/lib/jekyll/minibundle/development_file.rb +6 -6
- data/lib/jekyll/minibundle/development_file_collection.rb +6 -6
- data/lib/jekyll/minibundle/environment.rb +10 -8
- data/lib/jekyll/minibundle/mini_bundle_block.rb +4 -4
- data/lib/jekyll/minibundle/mini_stamp_tag.rb +2 -2
- data/lib/jekyll/minibundle/stamp_file.rb +8 -7
- data/lib/jekyll/minibundle/version.rb +1 -1
- data/test/fixture/site/_bin/with_count +1 -1
- data/test/integration/minibundle_development_mode_test.rb +62 -40
- data/test/integration/minibundle_production_mode_test.rb +78 -70
- data/test/integration/ministamp_test.rb +23 -23
- data/test/integration/static_files_as_asset_sources_test.rb +11 -11
- data/test/support/fixture_config.rb +4 -4
- data/test/support/test_case.rb +18 -14
- data/test/unit/asset_bundle_test.rb +4 -4
- data/test/unit/asset_file_registry_test.rb +7 -7
- data/test/unit/asset_tag_markup_test.rb +1 -1
- data/test/unit/bundle_file_test.rb +43 -33
- data/test/unit/development_file_collection_test.rb +44 -0
- data/test/unit/stamp_file_test.rb +30 -18
- metadata +26 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 477c2a1ad9364dfb5457b7b2b7894d74a0d5dcf8
|
4
|
+
data.tar.gz: 3212bf6bb364f63ad2e565c2eff35fed43c984b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c563707b1fa6b8cb468b96b22e3bc5ac99ec11d6cf0ef7eb4d520af3a1909744ef6c18d9beb646939d5f72efb83d3b28912fe44a3e66e402ea144183e64a8d43
|
7
|
+
data.tar.gz: bdf079e3b4af862ba04f19c17b1ec832cbfc4994af873ffefea3c7f500327a9ec2769d85eefc275810dd133417faaa99e95a2840b70cc32bacfb046b6b8a6216
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# 1.4.3 / 2014-01-16
|
2
|
+
|
3
|
+
* Do not leak read pipe file descriptor upon minifier command failure
|
4
|
+
* Loosen version constraints for development gem dependencies
|
5
|
+
* Clarify documentation
|
6
|
+
* Fix some Ruby coding style issues
|
7
|
+
* Minor internal state handling improvements
|
8
|
+
* Clarify tests, increase test coverage
|
9
|
+
|
1
10
|
# 1.4.2 / 2013-12-28
|
2
11
|
|
3
12
|
* Ensure touching asset source triggers destination write. This was an
|
data/README.md
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
A straightforward asset bundling plugin for [Jekyll][Jekyll],
|
4
4
|
utilizing external minification tool of your choice. It provides asset
|
5
5
|
concatenation for bundling and asset fingerprinting with MD5 digest
|
6
|
-
for cache busting.
|
7
|
-
|
6
|
+
for cache busting.
|
7
|
+
|
8
|
+
There are no runtime dependencies, except for the minification tool
|
9
|
+
used for bundling (fingerprinting has no dependencies).
|
8
10
|
|
9
11
|
Tested with Ruby MRI 1.9.3, 2.0, and 2.1. Ruby 1.8 is *not* supported.
|
10
12
|
|
@@ -46,7 +48,7 @@ The plugin is shipped as a
|
|
46
48
|
$ gem install jekyll-minibundle
|
47
49
|
```
|
48
50
|
|
49
|
-
Add
|
51
|
+
Add `_plugins/minibundle.rb` file to your Jekyll site project with
|
50
52
|
this line:
|
51
53
|
|
52
54
|
``` ruby
|
@@ -58,16 +60,11 @@ You must allow Jekyll to use custom plugins. In
|
|
58
60
|
|
59
61
|
## Asset fingerprinting
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
tools that have their own configuration for input sources.
|
64
|
-
|
65
|
-
Configure Compass to take inputs from `_assets/styles/*.scss` and to
|
66
|
-
put output to `_tmp/site.css`. Use `ministamp` tag to copy the
|
67
|
-
processed style asset to the generated site:
|
63
|
+
If you just want to have a fingerprint in your asset's path, use
|
64
|
+
`ministamp` tag:
|
68
65
|
|
69
66
|
``` html
|
70
|
-
<link href="{% ministamp
|
67
|
+
<link href="{% ministamp _assets/site.css assets/site.css %}" rel="stylesheet" media="screen, projection">
|
71
68
|
```
|
72
69
|
|
73
70
|
Output, containing the MD5 digest of the file in the filename:
|
@@ -76,7 +73,18 @@ Output, containing the MD5 digest of the file in the filename:
|
|
76
73
|
<link href="assets/site-390be921ee0eff063817bb5ef2954300.css" rel="stylesheet" media="screen, projection">
|
77
74
|
```
|
78
75
|
|
79
|
-
|
76
|
+
Jekyll's output directory will have the asset file at that path.
|
77
|
+
|
78
|
+
This feature is useful when combined with asset generation tools
|
79
|
+
external to Jekyll. For example, you can configure
|
80
|
+
[Compass](http://compass-style.org/) to take inputs from
|
81
|
+
`_assets/styles/*.scss` and to produce output to
|
82
|
+
`_tmp/site.css`. Then, you use `ministamp` tag to copy the file with a
|
83
|
+
fingerprint to Jekyll's output directory:
|
84
|
+
|
85
|
+
``` html
|
86
|
+
<link href="{% ministamp _tmp/site.css assets/site.css %}" rel="stylesheet">
|
87
|
+
```
|
80
88
|
|
81
89
|
## Asset bundling
|
82
90
|
|
@@ -85,8 +93,8 @@ tool that supports reading input from STDIN and writing the output to
|
|
85
93
|
STDOUT. You write the configuration for input sources directly into
|
86
94
|
the content file where you want the markup tag for the bundle file to
|
87
95
|
appear. The outcome will be a markup tag containing the path to the
|
88
|
-
bundle file, and the
|
89
|
-
path. The
|
96
|
+
bundle file, and the Jekyll's output directory will have the bundle
|
97
|
+
file at that path. The path will contain a fingerprint.
|
90
98
|
|
91
99
|
Place `minibundle` block with configuration into your content file
|
92
100
|
where you want the generated markup to appear. For example, to bundle
|
@@ -157,12 +165,13 @@ result, there will be both `src.css` and `dest-<md5>.css` files in
|
|
157
165
|
|
158
166
|
In order to avoid this, exclude the asset source file from
|
159
167
|
Jekyll. Because Jekyll excludes directories beginning with underscore
|
160
|
-
character (`_`), consider the following directory layout:
|
168
|
+
character (`_`), consider using the following directory layout:
|
161
169
|
|
162
|
-
* `_assets/` for
|
163
|
-
version control
|
164
|
-
* `_tmp/` for temporary
|
165
|
-
are not in version control (for example, Compass output
|
170
|
+
* `_assets/` for JavaScript and CSS assets handled by the plugin that
|
171
|
+
are in version control
|
172
|
+
* `_tmp/` for temporary JavaScript and CSS assets handled by the
|
173
|
+
plugin that are not in version control (for example, Compass output
|
174
|
+
files)
|
166
175
|
* `assets/` for images and other assets handled by Jekyll directly
|
167
176
|
|
168
177
|
See [Jekyll configuration][JekyllConf] for more about excluding files
|
@@ -170,12 +179,13 @@ and directories.
|
|
170
179
|
|
171
180
|
## Development mode
|
172
181
|
|
173
|
-
The plugin has one more trick in its sleeves. If you set
|
174
|
-
|
175
|
-
will copy asset files as is to
|
176
|
-
|
177
|
-
|
178
|
-
|
182
|
+
The plugin has one more trick in its sleeves. If you set
|
183
|
+
`$JEKYLL_MINIBUNDLE_MODE` environment variable to `development`, then
|
184
|
+
the plugin will copy asset files as is to Jekyll's output directory
|
185
|
+
and omit fingerprinting. The `destination_path` setting in
|
186
|
+
`minibundle` block sets the destination directory for bundled
|
187
|
+
files. This is useful in development workflow, where you need the
|
188
|
+
filenames and line numbers of the original asset sources.
|
179
189
|
|
180
190
|
``` bash
|
181
191
|
$ JEKYLL_MINIBUNDLE_MODE=development jekyll serve --watch
|
data/Rakefile
CHANGED
@@ -14,8 +14,8 @@ def get_minibundle_env(overrides = {})
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def run_jekyll_in_fixture_site(command)
|
17
|
-
Dir.chdir
|
18
|
-
FileUtils.rm_rf
|
17
|
+
Dir.chdir('test/fixture/site')
|
18
|
+
FileUtils.rm_rf('_site')
|
19
19
|
sh get_minibundle_env, "jekyll #{command}"
|
20
20
|
end
|
21
21
|
|
@@ -40,7 +40,7 @@ namespace :gem do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
desc 'Run tests'
|
43
|
+
desc 'Run tests; envars: tests=<test_path> to select a particular suite, debug=1 to require Pry and PP'
|
44
44
|
task :test do
|
45
45
|
glob = ENV['tests'] || 'test/{unit,integration}/*_test.rb'
|
46
46
|
files = Dir[glob].
|
@@ -49,7 +49,7 @@ task :test do
|
|
49
49
|
opts = ENV['debug'] ? '-rpp -rpry' : ''
|
50
50
|
eval = %{-e 'ARGV.each { |f| require f }'}
|
51
51
|
cmd = "ruby #{opts} #{eval} #{files}"
|
52
|
-
env = get_minibundle_env
|
52
|
+
env = get_minibundle_env('RUBYLIB' => 'lib:test')
|
53
53
|
sh env, cmd
|
54
54
|
end
|
55
55
|
|
@@ -58,12 +58,12 @@ namespace :fixture do
|
|
58
58
|
|
59
59
|
desc 'Generate fixture site'
|
60
60
|
task :build do
|
61
|
-
run_jekyll_in_fixture_site
|
61
|
+
run_jekyll_in_fixture_site('build')
|
62
62
|
end
|
63
63
|
|
64
64
|
desc 'Generate fixture site in watch mode'
|
65
65
|
task :watch do
|
66
|
-
run_jekyll_in_fixture_site
|
66
|
+
run_jekyll_in_fixture_site('build --watch')
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
data/jekyll-minibundle.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'lib/jekyll/minibundle/version'))
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name
|
5
|
-
s.version
|
6
|
-
s.summary
|
7
|
-
s.authors
|
8
|
-
s.email
|
9
|
-
s.homepage
|
10
|
-
s.
|
4
|
+
s.name = 'jekyll-minibundle'
|
5
|
+
s.version = Jekyll::Minibundle::VERSION
|
6
|
+
s.summary = 'A minimalistic asset bundling plugin for Jekyll'
|
7
|
+
s.authors = ['Tuomas Kareinen']
|
8
|
+
s.email = 'tkareine@gmail.com'
|
9
|
+
s.homepage = 'https://github.com/tkareine/jekyll-minibundle'
|
10
|
+
s.license = 'MIT'
|
11
11
|
|
12
12
|
s.description = <<-END
|
13
13
|
A straightforward asset bundling plugin for Jekyll, utilizing external
|
@@ -27,10 +27,10 @@ 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', '~> 1.4
|
31
|
-
s.add_development_dependency 'minitest', '~> 5.2
|
32
|
-
s.add_development_dependency 'nokogiri', '~> 1.6
|
33
|
-
s.add_development_dependency 'rake', '~> 10.1
|
30
|
+
s.add_development_dependency 'jekyll', '~> 1.4'
|
31
|
+
s.add_development_dependency 'minitest', '~> 5.2'
|
32
|
+
s.add_development_dependency 'nokogiri', '~> 1.6'
|
33
|
+
s.add_development_dependency 'rake', '~> 10.1'
|
34
34
|
|
35
35
|
s.required_ruby_version = '>= 1.9.3'
|
36
36
|
|
@@ -5,7 +5,7 @@ module Jekyll::Minibundle
|
|
5
5
|
class AssetBundle
|
6
6
|
def initialize(type, assets, site_dir)
|
7
7
|
@type, @assets, @site_dir = type, assets, site_dir
|
8
|
-
@temp_file = Tempfile.new
|
8
|
+
@temp_file = Tempfile.new("jekyll-minibundle-#{@type}-")
|
9
9
|
at_exit { @temp_file.close! }
|
10
10
|
end
|
11
11
|
|
@@ -14,15 +14,17 @@ module Jekyll::Minibundle
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def make_bundle
|
17
|
-
|
17
|
+
cmd = get_minifier_cmd
|
18
|
+
exit_status = spawn_minifier(cmd) do |input|
|
18
19
|
$stdout.puts # place newline after "(Re)generating..." log messages
|
19
|
-
log
|
20
|
+
log("Bundling #{@type} assets:")
|
20
21
|
@assets.each do |asset|
|
21
|
-
log
|
22
|
-
IO.foreach(asset) { |line|
|
23
|
-
|
22
|
+
log(asset)
|
23
|
+
IO.foreach(asset) { |line| input.write(line) }
|
24
|
+
input.puts(';') if @type == :js
|
24
25
|
end
|
25
26
|
end
|
27
|
+
fail "Bundling #{@type} assets failed with exit status #{exit_status}, command: #{cmd}" if exit_status != 0
|
26
28
|
self
|
27
29
|
end
|
28
30
|
|
@@ -30,30 +32,31 @@ module Jekyll::Minibundle
|
|
30
32
|
|
31
33
|
if defined? ::Jekyll.logger # introduced in Jekyll 1.0.0
|
32
34
|
def log(msg)
|
33
|
-
::Jekyll.logger.info
|
35
|
+
::Jekyll.logger.info('Minibundle:', msg)
|
34
36
|
end
|
35
37
|
else
|
36
38
|
def log(msg)
|
37
|
-
$stdout.puts
|
39
|
+
$stdout.puts(msg)
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
41
|
-
def
|
42
|
-
Environment.command_for
|
43
|
+
def get_minifier_cmd
|
44
|
+
Environment.command_for(@type)
|
43
45
|
end
|
44
46
|
|
45
|
-
def
|
47
|
+
def spawn_minifier(cmd)
|
46
48
|
pid = nil
|
47
49
|
rd, wr = IO.pipe
|
48
|
-
Dir.chdir
|
49
|
-
pid = spawn
|
50
|
+
Dir.chdir(@site_dir) do
|
51
|
+
pid = spawn(cmd, out: [@temp_file.path, 'w'], in: rd)
|
50
52
|
end
|
53
|
+
rd.close
|
51
54
|
yield wr
|
52
55
|
wr.close
|
53
|
-
_, status = Process.waitpid2
|
54
|
-
|
56
|
+
_, status = Process.waitpid2(pid)
|
57
|
+
status.exitstatus
|
55
58
|
ensure
|
56
|
-
wr.close unless
|
59
|
+
[rd, wr].each { |io| io.close unless io.closed? }
|
57
60
|
end
|
58
61
|
end
|
59
62
|
end
|
@@ -9,9 +9,9 @@ module Jekyll::Minibundle
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def write_destination(site_destination_dir)
|
12
|
-
destination_path = destination
|
13
|
-
FileUtils.mkdir_p
|
14
|
-
FileUtils.cp
|
12
|
+
destination_path = destination(site_destination_dir)
|
13
|
+
FileUtils.mkdir_p(File.dirname(destination_path))
|
14
|
+
FileUtils.cp(path, destination_path)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -5,15 +5,11 @@ module Jekyll::Minibundle
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def asset_destination_path
|
8
|
-
File.join
|
8
|
+
File.join(asset_destination_dir, asset_destination_basename)
|
9
9
|
end
|
10
10
|
|
11
11
|
def destination(site_destination_dir)
|
12
|
-
File.join
|
13
|
-
end
|
14
|
-
|
15
|
-
def destination_exists?(site_destination_dir)
|
16
|
-
File.exists? destination(site_destination_dir)
|
12
|
+
File.join(site_destination_dir, asset_destination_path)
|
17
13
|
end
|
18
14
|
|
19
15
|
def mtime
|
@@ -5,45 +5,43 @@ require 'jekyll/minibundle/stamp_file'
|
|
5
5
|
|
6
6
|
module Jekyll::Minibundle
|
7
7
|
module AssetFileRegistry
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
clear
|
13
|
-
|
14
|
-
def self.bundle_file(config)
|
15
|
-
asset_destination_path = "#{config['destination_path']}.#{config['type']}"
|
16
|
-
@@_instances[asset_destination_path] ||= register_bundle_file config
|
17
|
-
end
|
8
|
+
class << self
|
9
|
+
def clear
|
10
|
+
@_instances = {}
|
11
|
+
end
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
def bundle_file(config)
|
14
|
+
asset_destination_path = "#{config['destination_path']}.#{config['type']}"
|
15
|
+
@_instances[asset_destination_path] ||= register_bundle_file(config)
|
16
|
+
end
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
DevelopmentFileCollection.new config
|
26
|
-
else
|
27
|
-
BundleFile.new config
|
18
|
+
def stamp_file(asset_source_path, asset_destination_path)
|
19
|
+
@_instances[asset_destination_path] ||= register_stamp_file(asset_source_path, asset_destination_path)
|
28
20
|
end
|
29
|
-
end
|
30
21
|
|
31
|
-
|
22
|
+
private
|
32
23
|
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
def register_bundle_file(config)
|
25
|
+
if Environment.development?
|
26
|
+
DevelopmentFileCollection.new(config)
|
27
|
+
else
|
28
|
+
BundleFile.new(config)
|
29
|
+
end
|
30
|
+
end
|
36
31
|
|
37
|
-
|
32
|
+
def register_stamp_file(asset_source_path, asset_destination_path)
|
33
|
+
StampFile.new(asset_source_path, asset_destination_path, &get_stamp_file_basenamer)
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
def get_stamp_file_basenamer
|
37
|
+
if Environment.development?
|
38
|
+
->(base, ext, _) { base + ext }
|
39
|
+
else
|
40
|
+
->(base, ext, stamper) { "#{base}-#{stamper.call}#{ext}" }
|
41
|
+
end
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
|
-
|
45
|
+
clear
|
48
46
|
end
|
49
47
|
end
|
@@ -2,23 +2,25 @@ require 'cgi'
|
|
2
2
|
|
3
3
|
module Jekyll::Minibundle
|
4
4
|
module AssetTagMarkup
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
class << self
|
6
|
+
def make_markup(type, path, attributes)
|
7
|
+
case type
|
8
|
+
when :js
|
9
|
+
%{<script type="text/javascript" src="#{path}"#{make_attributes(attributes)}></script>}
|
10
|
+
when :css
|
11
|
+
%{<link rel="stylesheet" href="#{path}"#{make_attributes(attributes)}>}
|
12
|
+
else
|
13
|
+
fail "Unknown type for generating bundle markup: #{type}, #{path}"
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def make_attributes(attributes)
|
18
|
+
attributes.map { |name, value| make_attribute(name, value) }.join('')
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def make_attribute(name, value)
|
22
|
+
%{ #{name}="#{CGI.escape_html(value)}"}
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|