jekyll-assets 0.1.2 → 0.2.0

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.
data/README.md CHANGED
@@ -4,7 +4,31 @@
4
4
  [![Dependency Status](https://gemnasium.com/ixti/jekyll-assets.png)](https://gemnasium.com/ixti/jekyll-assets)
5
5
  [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/ixti/jekyll-assets)
6
6
 
7
- Jekyll plugin, that adds Rails-alike assets pipelines.
7
+ Jekyll plugin, that adds Rails-alike assets pipeline, that means that:
8
+
9
+ - It allows you to write these assets in other languages such as CoffeeScript,
10
+ Sass, Less and ERB.
11
+ - It allows you to specify dependencies between your assets and automatically
12
+ concatenates them.
13
+ - It allows you to minify/compress your JavaScript and CSS assets using
14
+ compressor you like: YUI, SASS, Uglifier or no compression at all.
15
+ - It supports JavaScript templates for client-side rendering of strings or
16
+ markup. JavaScript templates have the special format extension `.jst` and are
17
+ compiled to JavaScript functions.
18
+ - Automaticaly adds MD5 fingerprint suffix for _cache busting_. That means
19
+ that your `app.css` will become `app-908e25f4bf641868d8683022a5b62f54.css`.
20
+
21
+ Jekyll-Assets uses fabulous [Sprockets][sprockets] under the hood, so you may
22
+ refer to Rails guide about [Asset Pipeline][rails-guide] for detailed
23
+ information about amazing features it gives you.
24
+
25
+ *Notice:* You must have an [ExecJS][extjs] supported runtime in order to use
26
+ CoffeeScript.
27
+
28
+
29
+ [rails-guide]: http://guides.rubyonrails.org/asset_pipeline.html
30
+ [sprockets]: https://github.com/sstephenson/sprockets#readme
31
+ [extjs]: https://github.com/sstephenson/execjs#readme
8
32
 
9
33
 
10
34
  ## Installation
@@ -22,33 +46,128 @@ Or install it yourself as:
22
46
  $ gem install jekyll-assets
23
47
 
24
48
 
25
- ## Usage
49
+ ## How to Use Jekyll-Assets
50
+
51
+ First of all make sure to require it. Common practice is to add following line
52
+ into `_plugins/ext.rb` file:
53
+
54
+ ``` ruby
55
+ require "jekyll-assets"
56
+ ```
57
+
58
+ Once plugin installed, you'll have following liquid tags available:
59
+
60
+ - `javascript app`: Generates `<script>` tag for `app.js`
61
+ - `stylesheet app`: Generates `<link>` tag for `app.css`
62
+ - `asset_path logo.png`: Returns _resulting_ URL for `logo.png`
63
+ - `asset app.css`: Returns _compiled_ body of `app.css`
64
+
65
+ All compiled assets will be stored under `assets/` dir of generated site.
66
+
67
+ Pipeline assets should be under your sources directory of Jekyll site. When a
68
+ file is referenced with liquid tag or with helper from another asset, Sprockets
69
+ searches the three default asset locations for it: `_assets/images`,
70
+ `_assets/javascripts` and `_assets/stylesheets`.
71
+
72
+ For example these files:
73
+
74
+ ```
75
+ _assets/stylesheets/app.css
76
+ _assets/javascripts/app.js
77
+ _assets/javascripts/vendor/jquery.js
78
+ ```
79
+
80
+ would be referenced like this:
81
+
82
+ ``` html
83
+ {% stylesheet app %}
84
+ {% javascript app %}
85
+ {% javascript vendor/jquery %}
86
+ ```
87
+
88
+ You might want to require `vendor/jquery.js` into your `app.js`. To do so, just
89
+ put following line in the beginning of your `app.js` to get it concatenated:
90
+
91
+ ``` javascript
92
+ //= require vendor/jquery
26
93
 
27
- Add this line to your sites `_plugins/ext.rb`:
94
+ $(function () {
95
+ alert('I love BIG BOOKS!');
96
+ });
97
+ ```
28
98
 
29
- require 'jekyll-assets'
99
+ Now, if you want to use CoffeScript, just add `.coffee` suffix to the file you
100
+ want and you good to go. For example, here's how your `app.js.coffe` might look
101
+ like:
30
102
 
31
- Put your assets under following paths:
103
+ ``` coffeescript
104
+ #= require vendor/jquery
32
105
 
33
- - `_assets/javascripts`
34
- - `_assets/stylesheets`
35
- - `_assets/images`
106
+ $ ->
107
+ alert 'I love BIG BOOKS! And small ones too!'
108
+ ```
36
109
 
37
- Name your "main" asset files `app.js` and `app.css` and use liquid tags:
110
+ Now, you might want your stylesheets and javascripts to be minified. In this
111
+ case just install `uglifier` gem and add following lines into your `config.yml`:
38
112
 
39
- - `{% javascript app %}` to output `<script>` tag for `app.js`
40
- - `{% stylesheet app %}` to output `<link>` tag for `app.css`
41
- - `{% asset_path logo.jpg %}` to output URL for `logo.jpg`
113
+ ``` yaml
114
+ assets:
115
+ compress:
116
+ js: uglifier
117
+ css: sass
118
+ ```
42
119
 
43
- In order to use these tags, assets must be "bundled". By default only `app.js`,
44
- `app.css`, and all files with extensions `.jpg`, `.png` or `.gif` are bundled.
45
- You can change this by tuning up you `_config.yml` (see below).
120
+ You might want to use YUI compressor for minification. In this case install
121
+ `yui-compressor` gem and put `yui` in place of `uglifier` and/or `sass` in the
122
+ config file.
123
+
124
+ Let's go crazy now! Assume you want your blog's `body` background color to be
125
+ white all the time, but red in December. Just add `.erb` suffix extension and
126
+ you can use ruby to "pre-process" asset, something like this:
127
+
128
+ ```
129
+ # file: _assets/stylesheets/app.css.sass.erb
130
+
131
+ body
132
+ background-color: <%= (12 == Date.today.month) ? "red" : "white" %>
133
+ ```
134
+
135
+ Want more? Sure, here you are. You can use JavaScript templating with EJS or ECO
136
+ for example. Create a file `_assets/javascripts/hello.jst.ejs` with following
137
+ contents:
138
+
139
+ ``` html
140
+ <p>Hello, <span><%= name %></span>!</p>
141
+ <p><%= info %></p>
142
+ ```
143
+
144
+ Then use it in your `app.js` file like this:
145
+
146
+ ``` coffeescript
147
+ #= require vendor/jquery
148
+ #= require hello
149
+
150
+ $ ->
151
+ $("body").html JST["hello"]
152
+ name: "ixti"
153
+ info: "I love BIG BOOKS! And small ones too!"
154
+ ```
155
+
156
+ That's all. Feel free to ask questions if any on [twitter][twitter],
157
+ [jabber][jabber] or [e-mail][e-mail].
158
+
159
+ [twitter]: https://twitter.com/zapparov
160
+ [jabber]: xmpp://zapparov@jabber.ru
161
+ [e-mail]: mailto://ixti@member.fsf.org
46
162
 
47
163
 
48
164
  ## Configuration
49
165
 
50
166
  You can fine-tune configuration by editing your `_config.yml`:
51
167
 
168
+ #
169
+ # Plugin: jekyll-assets
170
+ #
52
171
  assets:
53
172
  #
54
173
  # Pathname of the destination of generated (bundled) assets relative
@@ -67,33 +186,26 @@ You can fine-tune configuration by editing your `_config.yml`:
67
186
  - _assets/stylesheets
68
187
  - _assets/images
69
188
  #
70
- # Array of filenames or filename patterns that needs to be generated for
71
- # the generated site. You can use `*` and `**` wildcards in patterns:
72
- #
73
- # 'foobar.jpg' will match 'foobar.jpg' only
74
- # '*.jpg' will match 'foo.jpg', but not 'foo/bar.jpg'
75
- # '**.jpg' will match 'foo.jpg', 'foo/bar.jpg', etc.
76
- #
77
- bundles:
78
- - 'app.css'
79
- - 'app.js'
80
- - '**.jpg'
81
- - '**.png'
82
- - '**.gif'
83
- #
84
189
  # Sets compressors for the specific types of file: `js`, or `css`.
85
190
  # No compression by default.
86
191
  #
87
192
  # Possible variants:
88
193
  #
89
194
  # css => 'yui', 'sass', nil
90
- # js => 'yui', 'unglifier', nil
195
+ # js => 'yui', 'uglifier', nil
91
196
  #
92
197
  compress:
93
198
  js: ~
94
199
  css: ~
95
200
 
96
201
 
202
+ ## "Ben, I need help!" (c) Brother 2
203
+
204
+ Feel free to send me any comments, recommendations, suggestions. Improve this
205
+ README, as I really suck in documenting things (thanks @imathis for pointing
206
+ this out).
207
+
208
+
97
209
  ## Contributing
98
210
 
99
211
  1. Fork it
@@ -2,7 +2,6 @@ require 'jekyll'
2
2
  require 'liquid'
3
3
 
4
4
 
5
- require 'jekyll/assets_plugin/generator'
6
5
  require 'jekyll/assets_plugin/site_patch'
7
6
  require 'jekyll/assets_plugin/tag'
8
7
  require 'jekyll/assets_plugin/version'
@@ -7,6 +7,8 @@ module Jekyll
7
7
  # Represents single asset that can be used as StaticFile for Site
8
8
  #
9
9
  class AssetFile
10
+ class NotFound < StandardError; end
11
+
10
12
  @@mtimes = Hash.new
11
13
 
12
14
  attr_reader :asset
@@ -40,6 +42,18 @@ module Jekyll
40
42
  @asset.write_to dest_path
41
43
  true
42
44
  end
45
+
46
+ def == other
47
+ case other
48
+ when AssetFile then other.asset.logical_path == asset.logical_path
49
+ when Sprockets::Asset then other.logical_path == asset.logical_path
50
+ else false
51
+ end
52
+ end
53
+
54
+ def to_s
55
+ "#<Jekyll::AssetsPlugin::AssetFile:#{asset.logical_path}>"
56
+ end
43
57
  end
44
58
  end
45
59
  end
@@ -14,18 +14,6 @@ module Jekyll
14
14
  # Default: ['_assets/javascripts', '_assets/stylesheets', '_assets/images']
15
15
  #
16
16
  #
17
- # ##### bundles
18
- #
19
- # Array of filenames or filename patterns that needs to be generated for the
20
- # generated site. You can use `*` and `**` wildcards in filename patterns:
21
- #
22
- # 'foobar.jpg' will match 'foobar.jpg' only
23
- # '*.jpg' will match 'foo.jpg', but not 'foo/bar.jpg'
24
- # '**.jpg' will match 'foo.jpg', 'foo/bar.jpg', etc.
25
- #
26
- # Default: ['app.css', 'app.js', '**.jpg', '**.png', '**.gif']
27
- #
28
- #
29
17
  # ##### compress
30
18
  #
31
19
  # Sets compressors for the specific types of file: `js`, or `css`.
@@ -33,7 +21,7 @@ module Jekyll
33
21
  # Possible variants:
34
22
  #
35
23
  # css => 'yui', 'sass', nil
36
- # js => 'yui', 'unglifier', nil
24
+ # js => 'yui', 'uglifier', nil
37
25
  #
38
26
  # Default: { 'css' => nil, 'js' => nil } (no compression at all)
39
27
  #
@@ -57,7 +45,6 @@ module Jekyll
57
45
  @@defaults = {
58
46
  :dirname => 'assets',
59
47
  :sources => %w{_assets/javascripts _assets/stylesheets _assets/images},
60
- :bundles => %w{app.css app.js **.jpg **.png **.gif},
61
48
  :compress => { :css => nil, :js => nil }
62
49
  }
63
50
 
@@ -65,7 +52,6 @@ module Jekyll
65
52
  super @@defaults.merge(config)
66
53
 
67
54
  self.sources = [ self.sources ] if self.sources.is_a? String
68
- self.bundles = [ self.bundles ] if self.bundles.is_a? String
69
55
  self.compress = OpenStruct.new(self.compress)
70
56
  self.dirname = self.dirname.gsub(/^\/+|\/+$/, '')
71
57
 
@@ -73,28 +59,6 @@ module Jekyll
73
59
  self.baseurl ||= "/#{self.dirname}/".squeeze '/'
74
60
  end
75
61
 
76
- # Returns bundles array with pattern strings converted to RegExps
77
- #
78
- # 'foobar.jpg' => 'foobar.jpg'
79
- # '*.png' => /[^\]+\.png/
80
- # '**.gif' => /.+?\.gif/
81
- #
82
- def bundle_filenames
83
- bundles.map do |pattern|
84
- if pattern =~ /^\*/
85
- pattern = pattern.dup
86
-
87
- pattern.gsub!(/\./, '\\.')
88
- pattern.sub!(/\*{2}/, '.+?')
89
- pattern.sub!(/\*{1}/, '[^/]+')
90
-
91
- pattern = /^#{pattern}$/
92
- end
93
-
94
- pattern
95
- end
96
- end
97
-
98
62
  def js_compressor
99
63
  return compress.js.to_sym if compress.js
100
64
  false
@@ -25,26 +25,33 @@ module Jekyll
25
25
  @assets.js_compressor = assets_config.js_compressor
26
26
  @assets.css_compressor = assets_config.css_compressor
27
27
 
28
- @assets.context_class.class_eval <<-RUBY, __FILE__, __LINE__
29
- def asset_path(path, options = {})
30
- asset = environment.find_asset path, options
31
- raise FileNotFound, "couldn't find file '\#{path}'" unless asset
32
- "/#{assets_config.dirname}/\#{asset.digest_path}".squeeze "/"
28
+ # bind jekyll and Sprockets context together
29
+ @assets.context_class.instance_variable_set :@jekyll_site, self
30
+
31
+ @assets.context_class.class_eval do
32
+ def jekyll_site
33
+ self.class.instance_variable_get :@jekyll_site
33
34
  end
34
- RUBY
35
- end
36
35
 
37
- @assets
38
- end
36
+ def asset_baseurl
37
+ jekyll_site.assets_config.baseurl.chomp "/"
38
+ end
39
39
 
40
- def has_bundled_asset? asset
41
- if asset.is_a? String
42
- asset = assets[asset]
40
+ def asset_path(path, options = {})
41
+ unless (asset = environment.find_asset path, options)
42
+ raise AssetFile::NotFound, "couldn't find file '#{path}'"
43
+ end
44
+
45
+ unless jekyll_site.static_files.include? asset
46
+ jekyll_site.static_files << AssetFile.new(jekyll_site, asset)
47
+ end
48
+
49
+ "#{asset_baseurl}/#{asset.digest_path}".squeeze "/"
50
+ end
51
+ end
43
52
  end
44
53
 
45
- !self.static_files.index do |file|
46
- file.is_a? AssetFile and file.asset == asset
47
- end.nil?
54
+ @assets
48
55
  end
49
56
  end
50
57
  end
@@ -6,10 +6,6 @@ require 'liquid'
6
6
  require 'set'
7
7
 
8
8
 
9
- # internal
10
- require 'jekyll/assets_plugin/logging'
11
-
12
-
13
9
  module Jekyll
14
10
  module AssetsPlugin
15
11
  # Class that implements some useful liquid tags:
@@ -51,8 +47,6 @@ module Jekyll
51
47
  #
52
48
  #
53
49
  class Tag < Liquid::Tag
54
- include Logging
55
-
56
50
  STYLESHEET = '<link rel="stylesheet" type="text/css" href="%s">'
57
51
  JAVASCRIPT = '<script type="text/javascript" src="%s"></script>'
58
52
  EXTENSIONS = { 'stylesheet' => '.css', 'javascript' => '.js' }
@@ -78,23 +72,12 @@ module Jekyll
78
72
  EXTENSIONS[@tag_name].to_s
79
73
  end
80
74
 
81
- def asset_not_found
82
- if @@errors.add? @logical_path
83
- log :error, "File not found: #{@logical_path}"
84
- end
85
- end
86
-
87
- def asset_not_bundled
88
- if @@errors.add? @logical_path
89
- log :warn, "File was not bundled: #{@logical_path}"
90
- end
91
- end
92
-
93
75
  def with_asset context, &block
94
- site = context.registers[:site]
95
- asset = site.assets[@logical_path]
76
+ site = context.registers[:site]
77
+ path = @logical_path
78
+ asset = site.assets[path]
96
79
 
97
- return asset_not_found unless asset
80
+ raise AssetFile::NotFound, "couldn't find file '#{path}'" unless asset
98
81
 
99
82
  yield asset, site
100
83
  end
@@ -107,7 +90,10 @@ module Jekyll
107
90
 
108
91
  def render_asset_path context
109
92
  with_asset context do |asset, site|
110
- return asset_not_bundled unless site.has_bundled_asset? asset
93
+ unless site.static_files.include? asset
94
+ site.static_files << AssetFile.new(site, asset)
95
+ end
96
+
111
97
  return "#{site.assets_config.baseurl.chomp '/'}/#{asset.digest_path}"
112
98
  end
113
99
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module AssetsPlugin
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ body { background-image: url(<%= image_path 'not-found.png' %>) }
@@ -7,8 +7,7 @@ module Jekyll::AssetsPlugin
7
7
  {
8
8
  :dirname => 'assets',
9
9
  :baseurl => '/assets/',
10
- :sources => %w{_assets/javascripts _assets/stylesheets _assets/images},
11
- :bundles => %w{app.css app.js **.jpg **.png **.gif}
10
+ :sources => %w{_assets/javascripts _assets/stylesheets _assets/images}
12
11
  }
13
12
  end
14
13
 
@@ -30,11 +29,6 @@ module Jekyll::AssetsPlugin
30
29
  it { should =~ defaults[:sources] }
31
30
  end
32
31
 
33
- context 'bundles list' do
34
- subject { config.bundles }
35
- it { should =~ defaults[:bundles] }
36
- end
37
-
38
32
  context 'js compressor' do
39
33
  subject { config.compress.js }
40
34
  it { should be_nil }
@@ -54,7 +48,6 @@ module Jekyll::AssetsPlugin
54
48
 
55
49
  config.dirname.should == 'assets'
56
50
  config.sources.should =~ %w{abc}
57
- config.bundles.should =~ defaults[:bundles]
58
51
  config.compress.js.should be_nil
59
52
  config.compress.css.should == 'sass'
60
53
  end
@@ -4,18 +4,24 @@ require 'spec_helper'
4
4
  module Jekyll::AssetsPlugin
5
5
  describe SitePatch do
6
6
  let(:site) do
7
- Class.new do
7
+ Class.new(Jekyll::Site) do
8
8
  include SitePatch
9
9
 
10
+ def initialize
11
+ self.reset
12
+ end
13
+
10
14
  def config
11
15
  @config ||= {
12
- 'bundles' => 'foobar',
13
- 'assets' => { 'sources' => 'foobar' }
16
+ 'dirname' => 'foobar',
17
+ 'assets' => {
18
+ 'sources' => [ 'foobar', '_assets' ]
19
+ }
14
20
  }
15
21
  end
16
22
 
17
23
  def source
18
- @soure ||= '.'
24
+ @source ||= RSpecHelpers.fixtures_path.to_s
19
25
  end
20
26
  end.new
21
27
  end
@@ -23,6 +29,30 @@ module Jekyll::AssetsPlugin
23
29
  context '#assets' do
24
30
  subject { site.assets }
25
31
  it { should be_an_instance_of Sprockets::Environment }
32
+
33
+ context 'calling #asset_path within assets' do
34
+ context 'when requested file not found' do
35
+ it 'should raise a NotFound error' do
36
+ Proc.new do
37
+ site.assets["should_fail.css"]
38
+ end.should raise_error(AssetFile::NotFound)
39
+ end
40
+ end
41
+
42
+ context 'when requested file found' do
43
+ it 'should have proper asset path' do
44
+ noise_img_re = %r{url\(/assets/noise-[a-f0-9]{32}\.png\)}
45
+ site.assets["app.css"].to_s.should match(noise_img_re)
46
+ end
47
+
48
+ it 'should be appended to the static files list' do
49
+ asset = site.assets["app.css"] # make sure main asset was compiled
50
+ asset = site.assets["noise.png"]
51
+
52
+ site.static_files.include?(asset).should be_true
53
+ end
54
+ end
55
+ end
26
56
  end
27
57
 
28
58
  context '#assets_config' do
@@ -30,18 +60,13 @@ module Jekyll::AssetsPlugin
30
60
  it { should be_an_instance_of Configuration }
31
61
 
32
62
  it 'should been populated with `assets` section of config' do
33
- site.assets_config.bundles.should_not =~ %w{foobar}
34
- site.assets_config.sources.should =~ %w{foobar}
63
+ site.assets_config.dirname.should_not == 'foobar'
64
+ site.assets_config.sources.should include 'foobar'
35
65
  end
36
66
  end
37
67
 
38
68
  it 'should be included into Jekyll::Site' do
39
69
  Jekyll::Site.included_modules.should include SitePatch
40
70
  end
41
-
42
- it 'should respond to #has_bundled_asset?' do
43
- @site.has_bundled_asset?(@site.assets['app.css']).should be_true
44
- @site.has_bundled_asset?(@site.assets['normalize.css']).should be_false
45
- end
46
71
  end
47
72
  end
@@ -10,54 +10,56 @@ module Jekyll::AssetsPlugin
10
10
  end
11
11
 
12
12
  context '{% stylesheet <file> %}' do
13
- let(:tag_re) do
14
- %r{^#{Tag::STYLESHEET % ['/assets/app-[a-f0-9]{32}\.css']}$}
13
+ def tag_re name
14
+ file = "/assets/#{name}-[a-f0-9]{32}\.css"
15
+ Regexp.new "^#{Tag::STYLESHEET % file}$"
15
16
  end
16
17
 
17
18
  context 'when <file> is bundled' do
18
19
  subject { render('{% stylesheet app.css %}') }
19
- it { should match tag_re }
20
+ it { should match tag_re("app") }
21
+ end
22
+
23
+ context 'when <file> is not explicitly bundled' do
24
+ subject { render('{% stylesheet vapor.css %}') }
25
+ it { should match tag_re("vapor") }
20
26
  end
21
27
 
22
28
  context 'when <file> extension is omited' do
23
29
  subject { render('{% stylesheet app %}') }
24
- it { should match tag_re }
30
+ it { should match tag_re("app") }
25
31
  end
26
32
 
27
33
  context 'when <file> is not found' do
28
34
  subject { render('{% stylesheet not-found.css %}') }
29
- it { should be_empty }
30
- end
31
-
32
- context 'when <file> is not bundled' do
33
- subject { render('{% stylesheet vapor.css %}') }
34
- it { should be_empty }
35
+ it { should match "Liquid error: couldn't find file 'not-found.css'" }
35
36
  end
36
37
  end
37
38
 
38
- context '{% javasript <file> %}' do
39
- let(:tag_re) do
40
- %r{^#{Tag::JAVASCRIPT % ['/assets/app-[a-f0-9]{32}\.js']}$}
39
+ context '{% javascript <file> %}' do
40
+ def tag_re name
41
+ file = "/assets/#{name}-[a-f0-9]{32}\.js"
42
+ Regexp.new "^#{Tag::JAVASCRIPT % file}$"
41
43
  end
42
44
 
43
45
  context 'when <file> is bundled' do
44
46
  subject { render('{% javascript app.js %}') }
45
- it { should match tag_re }
47
+ it { should match tag_re("app") }
48
+ end
49
+
50
+ context 'when <file> is not explicitly bundled' do
51
+ subject { render('{% javascript vapor.js %}') }
52
+ it { should match tag_re("vapor") }
46
53
  end
47
54
 
48
55
  context 'when <file> extension omited' do
49
56
  subject { render('{% javascript app %}') }
50
- it { should match tag_re }
57
+ it { should match tag_re("app") }
51
58
  end
52
59
 
53
60
  context 'when <file> is not found' do
54
61
  subject { render('{% javascript not-found.js %}') }
55
- it { should be_empty }
56
- end
57
-
58
- context 'when <file> is not bundled' do
59
- subject { render('{% javascript vapor.js %}') }
60
- it { should be_empty }
62
+ it { should match "Liquid error: couldn't find file 'not-found.js'" }
61
63
  end
62
64
  end
63
65
 
@@ -67,14 +69,27 @@ module Jekyll::AssetsPlugin
67
69
  it { should match(%r{^/assets/app-[a-f0-9]{32}\.css$}) }
68
70
  end
69
71
 
70
- context 'when <file> is not found' do
71
- subject { render('{% asset_path not-found.js %}') }
72
- it { should be_empty }
72
+ context 'when <file> is not explicitly bundled, but required' do
73
+ subject { render('{% asset_path vapor.js %}') }
74
+ it { should match(%r{^/assets/vapor-[a-f0-9]{32}\.js$}) }
75
+
76
+ it "should be appended to the static files list" do
77
+ asset = context[:registers][:site].assets["vapor.js"]
78
+
79
+ context[:registers][:site].static_files.include?(asset).should be_true
80
+ end
81
+
82
+ it "should be bundled file automagically upon site#write" do
83
+ context[:registers][:site].cleanup
84
+ context[:registers][:site].write
85
+
86
+ File.exist?("#{fixtures_path.join '_site'}#{subject}").should be_true
87
+ end
73
88
  end
74
89
 
75
- context 'when <file> is not bundled' do
76
- subject { render('{% asset_path vapor.js %}') }
77
- it { should be_empty }
90
+ context 'when <file> is not found' do
91
+ subject { render('{% asset_path not-found.js %}') }
92
+ it { should match "Liquid error: couldn't find file 'not-found.js'" }
78
93
  end
79
94
 
80
95
  context 'with baseurl given as /foobar/' do
@@ -92,7 +107,7 @@ module Jekyll::AssetsPlugin
92
107
 
93
108
  context 'when <file> is not found' do
94
109
  subject { render('{% asset_path not-found.js %}') }
95
- it { should be_empty }
110
+ it { should match "Liquid error: couldn't find file 'not-found.js'" }
96
111
  end
97
112
  end
98
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-12-20 00:00:00.000000000 Z
14
+ date: 2012-12-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: jekyll
@@ -129,8 +129,6 @@ files:
129
129
  - lib/jekyll/assets_plugin.rb
130
130
  - lib/jekyll/assets_plugin/asset_file.rb
131
131
  - lib/jekyll/assets_plugin/configuration.rb
132
- - lib/jekyll/assets_plugin/generator.rb
133
- - lib/jekyll/assets_plugin/logging.rb
134
132
  - lib/jekyll/assets_plugin/site_patch.rb
135
133
  - lib/jekyll/assets_plugin/tag.rb
136
134
  - lib/jekyll/assets_plugin/version.rb
@@ -138,6 +136,7 @@ files:
138
136
  - spec/fixtures/_assets/app.css.erb
139
137
  - spec/fixtures/_assets/app.js
140
138
  - spec/fixtures/_assets/noise.png
139
+ - spec/fixtures/_assets/should_fail.css.erb
141
140
  - spec/fixtures/_assets/vapor.css
142
141
  - spec/fixtures/_assets/vapor.js
143
142
  - spec/fixtures/_config.yml
@@ -146,8 +145,6 @@ files:
146
145
  - spec/fixtures/index.html
147
146
  - spec/lib/jekyll/assets_plugin/asset_file_spec.rb
148
147
  - spec/lib/jekyll/assets_plugin/configuration_spec.rb
149
- - spec/lib/jekyll/assets_plugin/generator_spec.rb
150
- - spec/lib/jekyll/assets_plugin/logging_spec.rb
151
148
  - spec/lib/jekyll/assets_plugin/site_patch_spec.rb
152
149
  - spec/lib/jekyll/assets_plugin/tag_spec.rb
153
150
  - spec/spec_helper.rb
@@ -175,12 +172,13 @@ rubyforge_project:
175
172
  rubygems_version: 1.8.23
176
173
  signing_key:
177
174
  specification_version: 3
178
- summary: jekyll-assets-0.1.2
175
+ summary: jekyll-assets-0.2.0
179
176
  test_files:
180
177
  - spec/fixtures/.gitignore
181
178
  - spec/fixtures/_assets/app.css.erb
182
179
  - spec/fixtures/_assets/app.js
183
180
  - spec/fixtures/_assets/noise.png
181
+ - spec/fixtures/_assets/should_fail.css.erb
184
182
  - spec/fixtures/_assets/vapor.css
185
183
  - spec/fixtures/_assets/vapor.js
186
184
  - spec/fixtures/_config.yml
@@ -189,8 +187,6 @@ test_files:
189
187
  - spec/fixtures/index.html
190
188
  - spec/lib/jekyll/assets_plugin/asset_file_spec.rb
191
189
  - spec/lib/jekyll/assets_plugin/configuration_spec.rb
192
- - spec/lib/jekyll/assets_plugin/generator_spec.rb
193
- - spec/lib/jekyll/assets_plugin/logging_spec.rb
194
190
  - spec/lib/jekyll/assets_plugin/site_patch_spec.rb
195
191
  - spec/lib/jekyll/assets_plugin/tag_spec.rb
196
192
  - spec/spec_helper.rb
@@ -1,26 +0,0 @@
1
- # internal
2
- require 'jekyll/assets_plugin/logging'
3
- require 'jekyll/assets_plugin/asset_file'
4
-
5
-
6
- module Jekyll
7
- module AssetsPlugin
8
- # Jekyll hook that bundles all files specified in `bundles` config
9
- #
10
- class Generator < ::Jekyll::Generator
11
- include Logging
12
-
13
- safe false
14
- priority :low
15
-
16
- def generate site
17
- filenames = site.assets_config.bundle_filenames
18
- site.assets.each_logical_path(filenames).each do |logical_path|
19
- if asset = site.assets.find_asset(logical_path)
20
- site.static_files << AssetFile.new(site, asset) if asset
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,10 +0,0 @@
1
- module Jekyll
2
- module AssetsPlugin
3
- module Logging
4
- protected
5
- def log level, message
6
- puts "[AssetsPlugin] #{level.to_s.upcase} #{message}"
7
- end
8
- end
9
- end
10
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- module Jekyll::AssetsPlugin
5
- describe Generator do
6
- it 'should output bundled files only' do
7
- files = []
8
- @dest.join('assets').each_child(false, &files.method(:push))
9
- files.map(&:to_s).should have(3).thing
10
- end
11
- end
12
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- module Jekyll::AssetsPlugin
5
- describe Logging do
6
- it 'puts strings with [AssetsPlugin] prefix' do
7
- loggable = Class.new do
8
- include Logging
9
- # make sure #log is public
10
- def log(*args) super; end
11
- end.new
12
-
13
- loggable.should_receive(:puts).with(match %r{^\[AssetsPlugin\]})
14
- loggable.log :info, 'test'
15
- end
16
- end
17
- end