jekyll-assets 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ lib/**/*.rb - README.md HISTORY.md LICENSE
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 0.3.1 (2013-02-02)
2
+
3
+ * Preprocess CSS/JS assets with Liquid processor.
4
+
5
+
1
6
  ### 0.3.0 (2013-01-08)
2
7
 
3
8
  * Add complimentary filters (same names as tags).
data/README.md CHANGED
@@ -35,6 +35,13 @@ information about amazing features it gives you.
35
35
  [sprockets]: https://github.com/sstephenson/sprockets#readme
36
36
  [extjs]: https://github.com/sstephenson/execjs#readme
37
37
 
38
+ For a quick start check out [jekyll-assets introduction][jekyll-assets-intro]
39
+ that shows how to use it step by step. Also you might want to take a look on
40
+ [my blog sources][ixti-blog-src] as a real-world example as well.
41
+
42
+ [jekyll-assets-intro]: http://ixti.net/software/2012/12/30/unleash-mr-hyde-introduction-of-jekyll-assets.html
43
+ [ixti-blog-src]: https://github.com/ixti/ixti.github.com
44
+
38
45
 
39
46
  ## Installation
40
47
 
data/lib/jekyll-assets.rb CHANGED
@@ -1 +1 @@
1
- require 'jekyll/assets_plugin'
1
+ require "jekyll/assets_plugin"
@@ -1,20 +1,4 @@
1
- require 'jekyll'
2
- require 'liquid'
3
-
4
-
5
- require 'jekyll/assets_plugin/site_patch'
6
- require 'jekyll/assets_plugin/filters'
7
- require 'jekyll/assets_plugin/tag'
8
- require 'jekyll/assets_plugin/version'
9
-
10
-
11
- Jekyll::Site.send :include, Jekyll::AssetsPlugin::SitePatch
12
-
13
-
14
- Liquid::Template.register_filter Jekyll::AssetsPlugin::Filters
15
-
16
-
17
- Liquid::Template.register_tag 'javascript', Jekyll::AssetsPlugin::Tag
18
- Liquid::Template.register_tag 'stylesheet', Jekyll::AssetsPlugin::Tag
19
- Liquid::Template.register_tag 'asset_path', Jekyll::AssetsPlugin::Tag
20
- Liquid::Template.register_tag 'asset', Jekyll::AssetsPlugin::Tag
1
+ require "jekyll/assets_plugin/site_patch"
2
+ require "jekyll/assets_plugin/filters"
3
+ require "jekyll/assets_plugin/tag"
4
+ require "jekyll/assets_plugin/version"
@@ -1,38 +1,38 @@
1
- # stdlib
2
- require 'set'
3
-
4
-
5
1
  module Jekyll
6
2
  module AssetsPlugin
7
- # Represents single asset that can be used as StaticFile for Site
8
- #
9
3
  class AssetFile
10
- class NotFound < StandardError; end
11
4
 
12
5
  @@mtimes = Hash.new
13
6
 
7
+
14
8
  attr_reader :asset
15
9
 
10
+
16
11
  def initialize site, asset
17
12
  @site, @asset = site, asset
18
13
  end
19
14
 
15
+
20
16
  def destination dest
21
17
  File.join(dest, @site.assets_config.dirname, @asset.digest_path)
22
18
  end
23
19
 
20
+
24
21
  def path
25
22
  @asset.pathname.to_s
26
23
  end
27
24
 
25
+
28
26
  def mtime
29
27
  @asset.mtime.to_i
30
28
  end
31
29
 
30
+
32
31
  def modified?
33
32
  @@mtimes[path] != mtime
34
33
  end
35
34
 
35
+
36
36
  def write dest
37
37
  dest_path = destination dest
38
38
 
@@ -43,6 +43,7 @@ module Jekyll
43
43
  true
44
44
  end
45
45
 
46
+
46
47
  def == other
47
48
  case other
48
49
  when AssetFile then same_asset? other.asset
@@ -51,15 +52,19 @@ module Jekyll
51
52
  end
52
53
  end
53
54
 
55
+
54
56
  def to_s
55
57
  "#<Jekyll::AssetsPlugin::AssetFile:#{asset.logical_path}>"
56
58
  end
57
59
 
60
+
58
61
  protected
59
62
 
63
+
60
64
  def same_asset? other
61
65
  other.pathname.cleanpath == asset.pathname.cleanpath
62
66
  end
67
+
63
68
  end
64
69
  end
65
70
  end
@@ -1,72 +1,46 @@
1
1
  # stdlib
2
- require 'ostruct'
2
+ require "ostruct"
3
3
 
4
4
 
5
5
  module Jekyll
6
6
  module AssetsPlugin
7
- # Plugin configuration class.
8
- #
9
- #
10
- # ##### sources
11
- #
12
- # Pathnames where to find assets relative to the root of the site.
13
- #
14
- # Default: ['_assets/javascripts', '_assets/stylesheets', '_assets/images']
15
- #
16
- #
17
- # ##### compress
18
- #
19
- # Sets compressors for the specific types of file: `js`, or `css`.
20
- #
21
- # Possible variants:
22
- #
23
- # css => 'yui', 'sass', nil
24
- # js => 'yui', 'uglifier', nil
25
- #
26
- # Default: { 'css' => nil, 'js' => nil } (no compression at all)
27
- #
28
- #
29
- # ##### dirname
30
- #
31
- # Destination pathname of processed assets relative to the compiled site
32
- # root (which is `_site` by default).
33
- #
34
- # Default: 'assets'
35
- #
36
- #
37
- # ##### baseurl
38
- #
39
- # Base URL for assets paths. By default equals dirname surrunded with
40
- # slashes. You ight want to change it if your blog has baseurl configuration
41
- # and served not from the root of the server, or if you want to keep your
42
- # assets on CDN.
43
- #
44
- class Configuration < OpenStruct
45
- @@defaults = {
46
- :dirname => 'assets',
7
+ class Configuration
8
+ DEFAULTS = {
9
+ :dirname => "assets",
47
10
  :sources => %w{_assets/javascripts _assets/stylesheets _assets/images},
48
11
  :compress => { :css => nil, :js => nil }
49
- }
12
+ }.freeze
13
+
50
14
 
51
15
  def initialize config = {}
52
- super @@defaults.merge(config)
16
+ @data = OpenStruct.new DEFAULTS.merge(config)
53
17
 
54
- self.sources = [ self.sources ] if self.sources.is_a? String
55
- self.compress = OpenStruct.new(self.compress)
56
- self.dirname = self.dirname.gsub(/^\/+|\/+$/, '')
18
+ @data.sources = [ @data.sources ] if @data.sources.is_a? String
19
+ @data.compress = OpenStruct.new @data.compress
20
+ @data.dirname = @data.dirname.gsub(/^\/+|\/+$/, "")
57
21
 
58
22
  # if baseurl not given - autoguess base on dirname
59
- self.baseurl ||= "/#{self.dirname}/".squeeze '/'
23
+ @data.baseurl ||= "/#{@data.dirname}/".squeeze '/'
60
24
  end
61
25
 
26
+
27
+ def baseurl
28
+ @data.baseurl.chomp "/"
29
+ end
30
+
31
+
62
32
  def js_compressor
63
- return compress.js.to_sym if compress.js
64
- false
33
+ @data.compress.js ? @data.compress.js.to_sym : false
65
34
  end
66
35
 
36
+
67
37
  def css_compressor
68
- return compress.css.to_sym if compress.css
69
- false
38
+ @data.compress.css ? @data.compress.css.to_sym : false
39
+ end
40
+
41
+
42
+ def method_missing name, *args, &block
43
+ @data.send name, *args, &block
70
44
  end
71
45
  end
72
46
  end
@@ -0,0 +1,73 @@
1
+ # 3rd-party
2
+ require "sprockets"
3
+
4
+
5
+ # internal
6
+ require "jekyll/assets_plugin/asset_file"
7
+ require "jekyll/assets_plugin/liquid_processor"
8
+
9
+
10
+ module Jekyll
11
+ module AssetsPlugin
12
+ class Environment < Sprockets::Environment
13
+
14
+ class AssetNotFound < StandardError
15
+ def initialize path
16
+ super "Couldn't find file '#{path}'"
17
+ end
18
+ end
19
+
20
+
21
+ autoload :ContextPatch, "jekyll/assets_plugin/environment/context_patch"
22
+
23
+
24
+ attr_reader :site
25
+
26
+
27
+ def initialize site
28
+ super site.source
29
+
30
+ @site = site
31
+
32
+ # append asset paths
33
+ @site.assets_config.sources.each { |p| append_path p }
34
+
35
+ self.js_compressor = @site.assets_config.js_compressor
36
+ self.css_compressor = @site.assets_config.css_compressor
37
+
38
+ register_preprocessor "text/css", LiquidProcessor
39
+ register_preprocessor "application/javascript", LiquidProcessor
40
+
41
+ # bind jekyll and Sprockets context together
42
+ context_class.instance_variable_set :@site, @site
43
+
44
+ context_class.send :include, ContextPatch
45
+ end
46
+
47
+
48
+ def find_asset path, *args
49
+ super or raise AssetNotFound, path
50
+ end
51
+
52
+
53
+ def index
54
+ super.tap do |index|
55
+ index.instance_eval do
56
+ def find_asset path, options = {}
57
+ site = @environment.site
58
+ asset = super
59
+ bundle = options[:bundle]
60
+
61
+ if asset and bundle and not site.static_files.include? asset
62
+ site.static_files << AssetFile.new(site, asset)
63
+ end
64
+
65
+ asset
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,18 @@
1
+ module Jekyll
2
+ module AssetsPlugin
3
+ class Environment
4
+ module ContextPatch
5
+
6
+ def site
7
+ self.class.instance_variable_get :@site
8
+ end
9
+
10
+
11
+ def asset_path *args
12
+ "#{site.assets_config.baseurl}/#{site.assets[*args].digest_path}"
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -5,6 +5,7 @@ require 'jekyll/assets_plugin/renderer'
5
5
  module Jekyll
6
6
  module AssetsPlugin
7
7
  module Filters
8
+
8
9
  %w{ asset asset_path javascript stylesheet }.each do |name|
9
10
  module_eval <<-RUBY, __FILE__, __LINE__
10
11
  def #{name} path # def stylesheet logical_path
@@ -13,6 +14,10 @@ module Jekyll
13
14
  end # end
14
15
  RUBY
15
16
  end
17
+
16
18
  end
17
19
  end
18
20
  end
21
+
22
+
23
+ Liquid::Template.register_filter Jekyll::AssetsPlugin::Filters
@@ -0,0 +1,18 @@
1
+ # 3rd-party
2
+ require 'tilt'
3
+
4
+
5
+ module Jekyll
6
+ module AssetsPlugin
7
+ class LiquidProcessor < Tilt::LiquidTemplate
8
+ def evaluate context, locals, &block
9
+ @engine.render locals, {
10
+ :filters => [Jekyll::Filters],
11
+ :registers => {
12
+ :site => context.site
13
+ }
14
+ }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,47 +1,40 @@
1
1
  module Jekyll
2
2
  module AssetsPlugin
3
3
  class Renderer
4
+
4
5
  STYLESHEET = '<link rel="stylesheet" type="text/css" href="%s">'
5
6
  JAVASCRIPT = '<script type="text/javascript" src="%s"></script>'
6
7
 
8
+
7
9
  def initialize context, logical_path
8
10
  @site = context.registers[:site]
9
11
  @path = logical_path.strip
10
12
  end
11
13
 
14
+
12
15
  def render_asset
13
- asset.to_s
16
+ @site.assets[@path].to_s
14
17
  end
15
18
 
16
- def render_asset_path
17
- unless @site.static_files.include? asset
18
- @site.static_files << AssetFile.new(@site, asset)
19
- end
20
19
 
21
- return "#{@site.assets_config.baseurl.chomp '/'}/#{asset.digest_path}"
20
+ def render_asset_path
21
+ "#{@site.assets_config.baseurl}/#{@site.assets[@path].digest_path}"
22
22
  end
23
23
 
24
+
24
25
  def render_javascript
25
- @path << '.js' if File.extname(@path).empty?
26
+ @path << ".js" if File.extname(@path).empty?
26
27
 
27
28
  JAVASCRIPT % render_asset_path
28
29
  end
29
30
 
31
+
30
32
  def render_stylesheet
31
- @path << '.css' if File.extname(@path).empty?
33
+ @path << ".css" if File.extname(@path).empty?
32
34
 
33
35
  STYLESHEET % render_asset_path
34
36
  end
35
37
 
36
- protected
37
-
38
- def asset
39
- unless @asset ||= @site.assets[@path]
40
- raise AssetFile::NotFound, "couldn't find file '#{@path}'"
41
- end
42
-
43
- @asset
44
- end
45
38
  end
46
39
  end
47
40
  end
@@ -1,58 +1,28 @@
1
1
  # 3rd-party
2
- require 'sprockets'
2
+ require "jekyll"
3
3
 
4
4
 
5
5
  # internal
6
- require 'jekyll/assets_plugin/asset_file'
7
- require 'jekyll/assets_plugin/configuration'
6
+ require "jekyll/assets_plugin/configuration"
7
+ require "jekyll/assets_plugin/environment"
8
8
 
9
9
 
10
10
  module Jekyll
11
11
  module AssetsPlugin
12
- # Patch that provides #assets and #assets_config to Site
13
- #
14
12
  module SitePatch
13
+
15
14
  def assets_config
16
- @assets_config ||= Configuration.new(self.config['assets'] || {})
15
+ @assets_config ||= Configuration.new(self.config["assets"] || {})
17
16
  end
18
17
 
19
- def assets
20
- unless @assets
21
- @assets = Sprockets::Environment.new(self.source)
22
-
23
- assets_config.sources.each(&@assets.method(:append_path))
24
-
25
- @assets.js_compressor = assets_config.js_compressor
26
- @assets.css_compressor = assets_config.css_compressor
27
-
28
- # bind jekyll and Sprockets context together
29
- @assets.context_class.instance_variable_set :@site, self
30
-
31
- @assets.context_class.class_eval do
32
- def site
33
- self.class.instance_variable_get :@site
34
- end
35
-
36
- def asset_baseurl
37
- site.assets_config.baseurl.chomp "/"
38
- end
39
18
 
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 site.static_files.include? asset
46
- site.static_files << AssetFile.new(site, asset)
47
- end
48
-
49
- "#{asset_baseurl}/#{asset.digest_path}".squeeze "/"
50
- end
51
- end
52
- end
53
-
54
- @assets
19
+ def assets
20
+ @assets ||= Environment.new self
55
21
  end
22
+
56
23
  end
57
24
  end
58
25
  end
26
+
27
+
28
+ Jekyll::Site.send :include, Jekyll::AssetsPlugin::SitePatch
@@ -1,55 +1,24 @@
1
1
  # 3rd-party
2
- require 'liquid'
2
+ require "liquid"
3
3
 
4
4
 
5
5
  # internal
6
- require 'jekyll/assets_plugin/renderer'
6
+ require "jekyll/assets_plugin/renderer"
7
7
 
8
8
 
9
9
  module Jekyll
10
10
  module AssetsPlugin
11
- # Class that implements some useful liquid tags:
12
- #
13
- #
14
- # ##### stylesheet
15
- #
16
- # Renders `<link>` tag for a logical path:
17
- #
18
- # {% stylesheet foo.css %}
19
- # # => '<link type="text/css" rel="stylesheet"
20
- # href="/assets/foo-b39e528efc3afe2def4bbc39de17f2b82cd8bd0d.css">
21
- #
22
- # You may omit extension so the following will give same result as above:
23
- #
24
- # {% stylesheet foo %}
25
- #
26
- #
27
- # ##### javascript
28
- #
29
- # Renders `<script>` tag for a logical path:
30
- #
31
- # {% javascript foo.js %}
32
- # # => '<script type="text/javascript"
33
- # src="/assets/foo-b39e528efc3afe2def4bbc39de17f2b82cd8bd0d.js">
34
- # </script>
35
- #
36
- # You may omit extension so the following will give same result as above:
37
- #
38
- # {% javascript foo %}
39
- #
40
- #
41
- # ##### asset_path
42
- #
43
- # Renders asset path for an asset (useful for images):
44
- #
45
- # {% asset_path foo.jpg %}
46
- # # => '/assets/foo-b39e528efc3afe2def4bbc39de17f2b82cd8bd0d.jpg"
47
- #
48
- #
49
11
  class Tag < Liquid::Tag
12
+
50
13
  def render context
51
14
  Renderer.new(context, @markup).send :"render_#{@tag_name}"
52
15
  end
16
+
53
17
  end
54
18
  end
55
19
  end
20
+
21
+
22
+ %w{ javascript stylesheet asset asset_path }.each do |tag|
23
+ Liquid::Template.register_tag tag, Jekyll::AssetsPlugin::Tag
24
+ end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module AssetsPlugin
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -1 +1,3 @@
1
1
  //= require vapor
2
+
3
+ var noise = '{% asset_path noise.png %}';
@@ -1,11 +1,11 @@
1
- require 'spec_helper'
2
- require 'jekyll-assets/bourbon'
1
+ require "spec_helper"
2
+ require "jekyll-assets/bourbon"
3
3
 
4
4
 
5
5
  module Jekyll::AssetsPlugin
6
- describe 'Bourbon integration' do
6
+ describe "Bourbon integration" do
7
7
  it "should globally append bourbon paths into Sprockets environment" do
8
- asset = @site.assets['vendor/bourbon.css'].to_s
8
+ asset = @site.assets["vendor/bourbon.css"].to_s
9
9
 
10
10
  asset.should =~ /-webkit-box-shadow/
11
11
  asset.should =~ /box-shadow/
@@ -1,11 +1,11 @@
1
- require 'spec_helper'
2
- require 'jekyll-assets/compass'
1
+ require "spec_helper"
2
+ require "jekyll-assets/compass"
3
3
 
4
4
 
5
5
  module Jekyll::AssetsPlugin
6
- describe 'Compass integration' do
6
+ describe "Compass integration" do
7
7
  it "should globally append compass paths into Sprockets environment" do
8
- asset = @site.assets['vendor/compass.css'].to_s
8
+ asset = @site.assets["vendor/compass.css"].to_s
9
9
 
10
10
  asset.should =~ /-webkit-box-shadow/
11
11
  asset.should =~ /-moz-box-shadow/
@@ -1,10 +1,10 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
 
4
4
  module Jekyll::AssetsPlugin
5
5
  describe AssetFile do
6
- context '#destination' do
7
- let(:file) { AssetFile.new(@site, @site.assets['app.css']) }
6
+ context "#destination" do
7
+ let(:file) { AssetFile.new(@site, @site.assets["app.css"]) }
8
8
  subject { file.destination @dest.to_s }
9
9
  it { should match %r{/app-[0-9a-f]{32}\.css$} }
10
10
  end
@@ -1,98 +1,86 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
 
4
4
  module Jekyll::AssetsPlugin
5
5
  describe Configuration do
6
- let(:defaults) do
7
- {
8
- :dirname => 'assets',
9
- :baseurl => '/assets/',
10
- :sources => %w{_assets/javascripts _assets/stylesheets _assets/images}
11
- }
12
- end
13
-
14
- context 'with defaults' do
6
+ context "with defaults" do
15
7
  let(:config){ Configuration.new }
16
8
 
17
- context 'output assets dirname' do
9
+ context "output assets dirname" do
18
10
  subject { config.dirname }
19
- it { should == defaults[:dirname] }
11
+ it { should == Configuration::DEFAULTS[:dirname] }
20
12
  end
21
13
 
22
- context 'assets baseurl' do
14
+ context "assets baseurl" do
23
15
  subject { config.baseurl }
24
- it { should == defaults[:baseurl] }
16
+ it { should == "/" + Configuration::DEFAULTS[:dirname] }
25
17
  end
26
18
 
27
- context 'sources list' do
19
+ context "sources list" do
28
20
  subject { config.sources }
29
- it { should =~ defaults[:sources] }
21
+ it { should =~ Configuration::DEFAULTS[:sources] }
30
22
  end
31
23
 
32
- context 'js compressor' do
24
+ context "js compressor" do
33
25
  subject { config.compress.js }
34
26
  it { should be_nil }
35
27
  end
36
28
 
37
- context 'css compressor' do
29
+ context "css compressor" do
38
30
  subject { config.compress.css }
39
31
  it { should be_nil }
40
32
  end
41
33
  end
42
34
 
43
- it 'should override specified options and leave defaults for missing' do
35
+ it "should override specified options and leave defaults for missing" do
44
36
  config = Configuration.new({
45
37
  :sources => %w{abc},
46
- :compress => { :css => 'sass' }
38
+ :compress => { :css => "sass" }
47
39
  })
48
40
 
49
- config.dirname.should == 'assets'
50
- config.sources.should =~ %w{abc}
51
- config.compress.js.should be_nil
52
- config.compress.css.should == 'sass'
41
+ config.dirname.should == "assets"
42
+ config.sources.should =~ %w{abc}
43
+ config.compress.js.should be_nil
44
+ config.compress.css.should == "sass"
53
45
  end
54
46
 
55
- context '#baseurl' do
56
- it 'should respect explicit overrides' do
57
- config = Configuration.new({
58
- :dirname => 'foo',
59
- :baseurl => '/bar/'
60
- })
61
-
62
- config.baseurl.should == '/bar/'
47
+ context "#baseurl" do
48
+ it "should respect explicit overrides" do
49
+ Configuration.new({
50
+ :dirname => "foo",
51
+ :baseurl => "/bar/"
52
+ }).baseurl.should == "/bar"
63
53
  end
64
54
 
65
- it 'should be auto-guessed from dirname' do
66
- config = Configuration.new({
67
- :dirname => 'foo'
68
- })
69
-
70
- config.baseurl.should == '/foo/'
55
+ it "should be auto-guessed from dirname" do
56
+ Configuration.new({
57
+ :dirname => "foo"
58
+ }).baseurl.should == "/foo"
71
59
  end
72
60
  end
73
61
 
74
- context '#js_compressor' do
75
- context 'when js compressor is given as "uglify"' do
76
- let(:config){ Configuration.new(:compress => {:js => 'uglify'}) }
62
+ context "#js_compressor" do
63
+ context "when js compressor is given as `uglify`" do
64
+ let(:config){ Configuration.new(:compress => {:js => "uglify"}) }
77
65
  subject { config.js_compressor }
78
66
  it { should be :uglify }
79
67
  end
80
68
 
81
- context 'otherwise' do
69
+ context "otherwise" do
82
70
  let(:config){ Configuration.new }
83
71
  subject { config.js_compressor }
84
72
  it { should be_false }
85
73
  end
86
74
  end
87
75
 
88
- context '#css_compressor' do
89
- context 'when js compressor is given as "sass"' do
90
- let(:config){ Configuration.new(:compress => {:css => 'sass'}) }
76
+ context "#css_compressor" do
77
+ context "when css compressor is given as `sass`" do
78
+ let(:config){ Configuration.new(:compress => {:css => "sass"}) }
91
79
  subject { config.css_compressor }
92
80
  it { should be :sass }
93
81
  end
94
82
 
95
- context 'otherwise' do
83
+ context "otherwise" do
96
84
  let(:config){ Configuration.new }
97
85
  subject { config.css_compressor }
98
86
  it { should be_false }
@@ -27,7 +27,7 @@ module Jekyll::AssetsPlugin
27
27
 
28
28
  context "when <file> does not exists" do
29
29
  subject { render("{{ 'not-found.css' | stylesheet }}") }
30
- it { should match "Liquid error: couldn't find file 'not-found.css'" }
30
+ it { should match "Liquid error: Couldn't find file 'not-found.css'" }
31
31
  end
32
32
  end
33
33
 
@@ -49,7 +49,7 @@ module Jekyll::AssetsPlugin
49
49
 
50
50
  context "when <file> does not exists" do
51
51
  subject { render("{{ 'not-found.js' | javascript }}") }
52
- it { should match "Liquid error: couldn't find file 'not-found.js'" }
52
+ it { should match "Liquid error: Couldn't find file 'not-found.js'" }
53
53
  end
54
54
  end
55
55
 
@@ -61,7 +61,7 @@ module Jekyll::AssetsPlugin
61
61
 
62
62
  context "when <file> does not exists" do
63
63
  subject { render("{{ 'not-found.css' | asset_path }}") }
64
- it { should match "Liquid error: couldn't find file 'not-found.css'" }
64
+ it { should match "Liquid error: Couldn't find file 'not-found.css'" }
65
65
  end
66
66
 
67
67
  context "with baseurl given as /foobar/" do
@@ -79,7 +79,7 @@ module Jekyll::AssetsPlugin
79
79
 
80
80
  context "when <file> does not exists" do
81
81
  subject { render("{{ 'not-found.js' | asset }}") }
82
- it { should match "Liquid error: couldn't find file 'not-found.js'" }
82
+ it { should match "Liquid error: Couldn't find file 'not-found.js'" }
83
83
  end
84
84
  end
85
85
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
 
4
4
  module Jekyll::AssetsPlugin
@@ -13,9 +13,9 @@ module Jekyll::AssetsPlugin
13
13
 
14
14
  def config
15
15
  @config ||= {
16
- 'dirname' => 'foobar',
17
- 'assets' => {
18
- 'sources' => [ 'foobar', '_assets' ]
16
+ "dirname" => "foobar",
17
+ "assets" => {
18
+ "sources" => [ "foobar", "_assets" ]
19
19
  }
20
20
  }
21
21
  end
@@ -26,26 +26,26 @@ module Jekyll::AssetsPlugin
26
26
  end.new
27
27
  end
28
28
 
29
- context '#assets' do
29
+ context "#assets" do
30
30
  subject { site.assets }
31
- it { should be_an_instance_of Sprockets::Environment }
31
+ it { should be_a_kind_of Sprockets::Environment }
32
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
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
36
  Proc.new do
37
37
  site.assets["should_fail.css"]
38
- end.should raise_error(AssetFile::NotFound)
38
+ end.should raise_error(Environment::AssetNotFound)
39
39
  end
40
40
  end
41
41
 
42
- context 'when requested file found' do
43
- it 'should have proper asset path' do
42
+ context "when requested file found" do
43
+ it "should have proper asset path" do
44
44
  noise_img_re = %r{url\(/assets/noise-[a-f0-9]{32}\.png\)}
45
45
  site.assets["app.css"].to_s.should match(noise_img_re)
46
46
  end
47
47
 
48
- it 'should be appended to the static files list' do
48
+ it "should be appended to the static files list" do
49
49
  asset = site.assets["app.css"] # make sure main asset was compiled
50
50
  asset = site.assets["noise.png"]
51
51
 
@@ -53,19 +53,25 @@ module Jekyll::AssetsPlugin
53
53
  end
54
54
  end
55
55
  end
56
+
57
+ context "with Liquid markup within assets" do
58
+ it "should be rendered" do
59
+ site.assets["app.js"].to_s.should match(/noise-[a-f0-9]{32}\.png/)
60
+ end
61
+ end
56
62
  end
57
63
 
58
- context '#assets_config' do
64
+ context "#assets_config" do
59
65
  subject { site.assets_config }
60
66
  it { should be_an_instance_of Configuration }
61
67
 
62
- it 'should been populated with `assets` section of config' do
63
- site.assets_config.dirname.should_not == 'foobar'
64
- site.assets_config.sources.should include 'foobar'
68
+ it "should been populated with `assets` section of config" do
69
+ site.assets_config.dirname.should_not == "foobar"
70
+ site.assets_config.sources.should include "foobar"
65
71
  end
66
72
  end
67
73
 
68
- it 'should be included into Jekyll::Site' do
74
+ it "should be included into Jekyll::Site" do
69
75
  Jekyll::Site.included_modules.should include SitePatch
70
76
  end
71
77
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
 
4
4
  module Jekyll::AssetsPlugin
@@ -9,77 +9,77 @@ module Jekyll::AssetsPlugin
9
9
  Liquid::Template.parse(content).render({}, context)
10
10
  end
11
11
 
12
- context '{% stylesheet <file> %}' do
12
+ context "{% stylesheet <file> %}" do
13
13
  def tag_re name
14
14
  file = "/assets/#{name}-[a-f0-9]{32}\.css"
15
15
  Regexp.new "^#{Renderer::STYLESHEET % file}$"
16
16
  end
17
17
 
18
- context 'when <file> exists' do
19
- subject { render('{% stylesheet app.css %}') }
18
+ context "when <file> exists" do
19
+ subject { render("{% stylesheet app.css %}") }
20
20
  it { should match tag_re("app") }
21
21
  end
22
22
 
23
- context 'when <file> extension is omited' do
24
- subject { render('{% stylesheet app %}') }
23
+ context "when <file> extension is omited" do
24
+ subject { render("{% stylesheet app %}") }
25
25
  it { should match tag_re("app") }
26
26
  end
27
27
 
28
- context 'when <file> does not exists' do
29
- subject { render('{% stylesheet not-found.css %}') }
30
- it { should match "Liquid error: couldn't find file 'not-found.css'" }
28
+ context "when <file> does not exists" do
29
+ subject { render("{% stylesheet not-found.css %}") }
30
+ it { should match "Liquid error: Couldn't find file 'not-found.css'" }
31
31
  end
32
32
  end
33
33
 
34
- context '{% javascript <file> %}' do
34
+ context "{% javascript <file> %}" do
35
35
  def tag_re name
36
36
  file = "/assets/#{name}-[a-f0-9]{32}\.js"
37
37
  Regexp.new "^#{Renderer::JAVASCRIPT % file}$"
38
38
  end
39
39
 
40
- context 'when <file> exists' do
41
- subject { render('{% javascript app.js %}') }
40
+ context "when <file> exists" do
41
+ subject { render("{% javascript app.js %}") }
42
42
  it { should match tag_re("app") }
43
43
  end
44
44
 
45
- context 'when <file> extension omited' do
46
- subject { render('{% javascript app %}') }
45
+ context "when <file> extension omited" do
46
+ subject { render("{% javascript app %}") }
47
47
  it { should match tag_re("app") }
48
48
  end
49
49
 
50
- context 'when <file> does not exists' do
51
- subject { render('{% javascript not-found.js %}') }
52
- it { should match "Liquid error: couldn't find file 'not-found.js'" }
50
+ context "when <file> does not exists" do
51
+ subject { render("{% javascript not-found.js %}") }
52
+ it { should match "Liquid error: Couldn't find file 'not-found.js'" }
53
53
  end
54
54
  end
55
55
 
56
- context '{% asset_path <file.ext> %}' do
57
- context 'when <file> exists' do
58
- subject { render('{% asset_path app.css %}') }
56
+ context "{% asset_path <file.ext> %}" do
57
+ context "when <file> exists" do
58
+ subject { render("{% asset_path app.css %}") }
59
59
  it { should match(%r{^/assets/app-[a-f0-9]{32}\.css$}) }
60
60
  end
61
61
 
62
- context 'when <file> does not exists' do
63
- subject { render('{% asset_path not-found.js %}') }
64
- it { should match "Liquid error: couldn't find file 'not-found.js'" }
62
+ context "when <file> does not exists" do
63
+ subject { render("{% asset_path not-found.js %}") }
64
+ it { should match "Liquid error: Couldn't find file 'not-found.js'" }
65
65
  end
66
66
 
67
- context 'with baseurl given as /foobar/' do
68
- before { context[:registers][:site].assets_config.baseurl = '/foobar/' }
69
- subject { render('{% asset_path app.css %}') }
67
+ context "with baseurl given as /foobar/" do
68
+ before { context[:registers][:site].assets_config.baseurl = "/foobar/" }
69
+ subject { render("{% asset_path app.css %}") }
70
70
  it { should match(%r{^/foobar/app-[a-f0-9]{32}\.css$}) }
71
71
  end
72
72
  end
73
73
 
74
- context '{% asset <file.ext> %}' do
75
- context 'when <file> exists' do
76
- subject { render('{% asset app.css %}') }
74
+ context "{% asset <file.ext> %}" do
75
+ context "when <file> exists" do
76
+ subject { render("{% asset app.css %}") }
77
77
  it { should match(/body \{ background-image: url\(.+?\) \}/) }
78
78
  end
79
79
 
80
- context 'when <file> does not exists' do
81
- subject { render('{% asset_path not-found.js %}') }
82
- it { should match "Liquid error: couldn't find file 'not-found.js'" }
80
+ context "when <file> does not exists" do
81
+ subject { render("{% asset_path not-found.js %}") }
82
+ it { should match "Liquid error: Couldn't find file 'not-found.js'" }
83
83
  end
84
84
  end
85
85
  end
data/spec/spec_helper.rb CHANGED
@@ -1,24 +1,24 @@
1
- require 'rubygems'
1
+ require "rubygems"
2
2
 
3
3
 
4
- require 'jekyll'
5
- require 'liquid'
6
- require 'sprockets'
4
+ require "jekyll"
5
+ require "liquid"
6
+ require "sprockets"
7
7
 
8
8
 
9
9
  # Requires supporting ruby files with custom matchers and macros, etc,
10
10
  # in spec/support/ and its subdirectories.
11
- Dir[File.expand_path('../support', __FILE__) + "/**/*.rb"].each {|f| require f}
11
+ Dir[File.expand_path("../support", __FILE__) + "/**/*.rb"].each {|f| require f}
12
12
 
13
13
 
14
14
  RSpec.configure do |config|
15
15
  config.include Jekyll::AssetsPlugin::RSpecHelpers
16
16
 
17
17
  config.before(:all) do
18
- @dest = fixtures_path.join('_site')
18
+ @dest = fixtures_path.join("_site")
19
19
  @site = Jekyll::Site.new(Jekyll.configuration({
20
- 'source' => fixtures_path.to_s,
21
- 'destination' => @dest.to_s
20
+ "source" => fixtures_path.to_s,
21
+ "destination" => @dest.to_s
22
22
  }))
23
23
 
24
24
  @dest.rmtree if @dest.exist?
@@ -1,4 +1,4 @@
1
- require 'pathname'
1
+ require "pathname"
2
2
 
3
3
 
4
4
  module Jekyll::AssetsPlugin
@@ -6,7 +6,7 @@ module Jekyll::AssetsPlugin
6
6
  extend self
7
7
 
8
8
  def fixtures_path
9
- @fixtures_path ||= Pathname.new(__FILE__).parent.parent.join('fixtures')
9
+ @fixtures_path ||= Pathname.new(__FILE__).parent.parent.join("fixtures")
10
10
  end
11
11
  end
12
12
  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.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-08 00:00:00.000000000 Z
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
@@ -151,6 +151,7 @@ files:
151
151
  - .gitignore
152
152
  - .rspec
153
153
  - .travis.yml
154
+ - .yardopts
154
155
  - Gemfile
155
156
  - Guardfile
156
157
  - HISTORY.md
@@ -164,7 +165,10 @@ files:
164
165
  - lib/jekyll/assets_plugin.rb
165
166
  - lib/jekyll/assets_plugin/asset_file.rb
166
167
  - lib/jekyll/assets_plugin/configuration.rb
168
+ - lib/jekyll/assets_plugin/environment.rb
169
+ - lib/jekyll/assets_plugin/environment/context_patch.rb
167
170
  - lib/jekyll/assets_plugin/filters.rb
171
+ - lib/jekyll/assets_plugin/liquid_processor.rb
168
172
  - lib/jekyll/assets_plugin/renderer.rb
169
173
  - lib/jekyll/assets_plugin/site_patch.rb
170
174
  - lib/jekyll/assets_plugin/tag.rb
@@ -214,7 +218,7 @@ rubyforge_project:
214
218
  rubygems_version: 1.8.23
215
219
  signing_key:
216
220
  specification_version: 3
217
- summary: jekyll-assets-0.3.0
221
+ summary: jekyll-assets-0.3.1
218
222
  test_files:
219
223
  - spec/fixtures/.gitignore
220
224
  - spec/fixtures/_assets/app.css.erb