jekyll-assets 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Jekyll::AssetsPlugin
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/ixti/jekyll-assets.png)](http://travis-ci.org/ixti/jekyll-assets)
4
+ [![Dependency Status](https://gemnasium.com/ixti/jekyll-assets.png)](https://gemnasium.com/ixti/jekyll-assets)
5
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/ixti/jekyll-assets)
6
+
3
7
  Jekyll plugin, that adds Rails-alike assets pipelines.
4
8
 
5
9
 
@@ -14,3 +14,4 @@ Jekyll::Site.send :include, Jekyll::AssetsPlugin::SitePatch
14
14
  Liquid::Template.register_tag('javascript', Jekyll::AssetsPlugin::Tag)
15
15
  Liquid::Template.register_tag('stylesheet', Jekyll::AssetsPlugin::Tag)
16
16
  Liquid::Template.register_tag('asset_path', Jekyll::AssetsPlugin::Tag)
17
+ Liquid::Template.register_tag('asset', Jekyll::AssetsPlugin::Tag)
@@ -58,8 +58,8 @@ module Jekyll
58
58
 
59
59
  self.sources = [ self.sources ] if self.sources.is_a? String
60
60
  self.bundles = [ self.bundles ] if self.bundles.is_a? String
61
-
62
61
  self.compress = OpenStruct.new(self.compress)
62
+ self.dirname = self.dirname.gsub(/^\/+|\/+$/, '')
63
63
  end
64
64
 
65
65
  # Returns bundles array with pattern strings converted to RegExps
@@ -22,13 +22,8 @@ module Jekyll
22
22
 
23
23
  assets_config.sources.each(&@assets.method(:append_path))
24
24
 
25
- if js_compressor = assets_config.js_compressor
26
- @assets.js_compressor = js_compressor
27
- end
28
-
29
- if css_compressor = assets_config.css_compressor
30
- @assets.css_compressor = css_compressor
31
- end
25
+ @assets.js_compressor = assets_config.js_compressor
26
+ @assets.css_compressor = assets_config.css_compressor
32
27
 
33
28
  @assets.context_class.class_eval <<-RUBY, __FILE__, __LINE__
34
29
  def asset_path(path, options = {})
@@ -68,6 +68,12 @@ module Jekyll
68
68
  @logical_path << default_extension if File.extname(@logical_path).empty?
69
69
  end
70
70
 
71
+ def render context
72
+ send :"render_#{@tag_name}", context
73
+ end
74
+
75
+ protected
76
+
71
77
  def default_extension
72
78
  EXTENSIONS[@tag_name].to_s
73
79
  end
@@ -84,19 +90,37 @@ module Jekyll
84
90
  end
85
91
  end
86
92
 
87
- def render context
93
+ def with_asset context, &block
88
94
  site = context.registers[:site]
89
95
  asset = site.assets[@logical_path]
90
96
 
91
97
  return asset_not_found unless asset
92
- return asset_not_bundled unless site.has_bundled_asset? asset
93
98
 
94
- url = "/#{site.assets_config.dirname}/#{asset.digest_path}".squeeze "/"
99
+ yield asset, site
100
+ end
101
+
102
+ def render_asset context
103
+ with_asset context do |asset|
104
+ return asset.to_s
105
+ end
106
+ end
107
+
108
+ def render_asset_path context
109
+ with_asset context do |asset, site|
110
+ return asset_not_bundled unless site.has_bundled_asset? asset
111
+ return "/#{site.assets_config.dirname}/#{asset.digest_path}"
112
+ end
113
+ end
114
+
115
+ def render_javascript context
116
+ if url = render_asset_path(context)
117
+ return JAVASCRIPT % [url]
118
+ end
119
+ end
95
120
 
96
- case @tag_name
97
- when 'stylesheet' then STYLESHEET % [url]
98
- when 'javascript' then JAVASCRIPT % [url]
99
- else url
121
+ def render_stylesheet context
122
+ if url = render_asset_path(context)
123
+ return STYLESHEET % [url]
100
124
  end
101
125
  end
102
126
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module AssetsPlugin
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -77,5 +77,17 @@ module Jekyll::AssetsPlugin
77
77
  it { should be_empty }
78
78
  end
79
79
  end
80
+
81
+ context '{% asset <file.ext> %}' do
82
+ context 'when <file> exists' do
83
+ subject { render('{% asset app.css %}') }
84
+ it { should match(/body \{ background-image: url\(.+?\) \}/) }
85
+ end
86
+
87
+ context 'when <file> is not found' do
88
+ subject { render('{% asset_path not-found.js %}') }
89
+ it { should be_empty }
90
+ end
91
+ end
80
92
  end
81
93
  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.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -166,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
166
  version: '0'
167
167
  segments:
168
168
  - 0
169
- hash: -929384781
169
+ hash: 346987987
170
170
  required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
@@ -175,13 +175,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
175
  version: '0'
176
176
  segments:
177
177
  - 0
178
- hash: -929384781
178
+ hash: 346987987
179
179
  requirements: []
180
180
  rubyforge_project:
181
181
  rubygems_version: 1.8.23
182
182
  signing_key:
183
183
  specification_version: 3
184
- summary: jekyll-assets-0.1.0
184
+ summary: jekyll-assets-0.1.1
185
185
  test_files:
186
186
  - spec/fixtures/.gitignore
187
187
  - spec/fixtures/_assets/app.css.erb