japr 0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/japr.png)](http://badge.fury.io/rb/japr) [![Build Status](https://secure.travis-ci.org/kitsched/japr.png)](https://travis-ci.org/kitsched/japr) [![Coverage Status](https://coveralls.io/repos/kitsched/japr/badge.png?branch=master)](https://coveralls.io/r/kitsched/japr?branch=master) [![Dependency Status](https://gemnasium.com/kitsched/japr.png)](https://gemnasium.com/kitsched/japr) [![Code Climate](https://codeclimate.com/github/kitsched/japr.png)](https://codeclimate.com/github/kitsched/japr)
4
4
 
5
- JAPR is a powerful asset pipeline that automatically collects, converts and compresses / minifies your site's JavaScript and CSS assets when you compile your Jekyll site.
5
+ JAPR is a powerful asset pipeline that automatically collects, converts and compresses / minifies your site's JavaScript and CSS assets when you compile your [Jekyll](http://jekyllrb.com/) site.
6
6
 
7
7
  This project is a fork of [Jekyll Asset Pipeline](https://github.com/matthodan/jekyll-asset-pipeline) by [Matt Hodan](https://github.com/matthodan) which, unfortunately, was pretty much abandonware.
8
8
 
@@ -46,7 +46,7 @@ JAPR is extremely easy to add to your Jekyll project and has no incremental depe
46
46
  1. Install the "japr" gem via [Rubygems](http://rubygems.org/).
47
47
 
48
48
  ``` bash
49
- $ gem install japr
49
+ $ gem install japr
50
50
  ```
51
51
 
52
52
  > *If you are using [Bundler](http://gembundler.com/) to manage your project's gems, you can just add "japr" to your Gemfile and run `bundle install`.*
@@ -153,6 +153,28 @@ You probably get the gist of how converters work, but here's an example of a SAS
153
153
 
154
154
  > *Don't forget to install the "sass" gem or add it to your Gemfile and run `bundle install` before you run the `jekyll build` command since the above SASS converter requires the "sass" library as a dependency.*
155
155
 
156
+ ### LESS
157
+
158
+ ``` ruby
159
+ module JAPR
160
+ class LessConverter < JAPR::Converter
161
+ require 'less'
162
+
163
+ def self.filetype
164
+ '.less'
165
+ end
166
+
167
+ def convert
168
+ return Less::Parser.new.parse(@content).to_css
169
+ end
170
+ end
171
+ end
172
+ ```
173
+
174
+ > *Don't forget to install the "less" gem or add it to your Gemfile and run
175
+ `bundle install` before you run the `jekyll build` command since the above
176
+ LESS converter requires the "less" library as a dependency.*
177
+
156
178
  ### Successive Preprocessing
157
179
 
158
180
  If you would like to run an asset through multiple preprocessors successively, you can do so by naming your assets with nested file extensions. Nest the extensions in the order (right to left) that the asset should be processed. For example, `.css.scss.erb` would first be processed by an "erb" preprocessor then by a "scss" preprocessor before being rendered. This convention is very similar to the convention used by the [Ruby on Rails asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html#preprocessing).
@@ -36,13 +36,13 @@ module JAPR
36
36
  # Default configuration settings for Jekyll Asset Pipeline
37
37
  # Strings used for keys to play nice when merging with _config.yml
38
38
  #
39
- # 'output_path' Destination for bundle file (within the '_site' directory)
40
- # 'display_path' Optional. Override path to assets for output HTML refs
41
- # 'staging_path' Destination for staged assets (within project root directory)
42
- # 'bundle' true = Bundle assets, false = Leave assets unbundled
43
- # 'compress' true = Minify assets, false = Leave assets unminified
44
- # 'gzip' true = Create gzip versions, false = Do not create gzip versions
45
- #
39
+ # 'output_path' Destination for bundle file (within the '_site' directory)
40
+ # 'display_path' Optional. Override path to assets for output HTML refs
41
+ # 'staging_path' Destination for staged assets (within project root directory)
42
+ # 'bundle' true = Bundle assets, false = Leave assets unbundled
43
+ # 'compress' true = Minify assets, false = Leave assets unminified
44
+ # 'gzip' true = Create gzip versions,
45
+ # false = Do not create gzip versions
46
46
  DEFAULTS = {
47
47
  'output_path' => 'assets',
48
48
  'display_path' => nil,
@@ -10,5 +10,6 @@ module JAPR
10
10
  end
11
11
 
12
12
  # Register JavaScriptAssetTag tag with Liquid
13
- ::Liquid::Template.register_tag(JAPR::JavaScriptAssetTag.tag_name, JAPR::JavaScriptAssetTag)
13
+ ::Liquid::Template.register_tag(JAPR::JavaScriptAssetTag.tag_name,
14
+ JAPR::JavaScriptAssetTag)
14
15
  end
@@ -24,7 +24,8 @@ module JAPR
24
24
  # Prevent Jekyll from cleaning up saved assets if new pipeline
25
25
  pipeline.assets.each do |asset|
26
26
  config = JAPR::DEFAULTS.merge(config)
27
- staging_path = File.expand_path(File.join(site.source, config['staging_path']))
27
+ staging_path = File.expand_path(File.join(site.source,
28
+ config['staging_path']))
28
29
  site.static_files << Jekyll::StaticFile.new(site, staging_path,
29
30
  asset.output_path,
30
31
  asset.filename)
@@ -1,6 +1,7 @@
1
1
  module JAPR
2
2
  module SubclassTracking
3
- # Record subclasses of this class (this method is automatically called by ruby)
3
+ # Record subclasses of this class (this method is automatically called by
4
+ # ruby)
4
5
  def inherited(base)
5
6
  subclasses << base
6
7
  end
@@ -9,7 +9,7 @@ module JAPR
9
9
  "#{path}#{File.mtime(File.join(source, path)).to_i}"
10
10
  end.join.concat(options.to_s))
11
11
  rescue Exception => e
12
- puts "Failed to generate hash from provided manifest."
12
+ puts "Failed to generate hash from provided manifest: #{e.message}"
13
13
  raise e
14
14
  end
15
15
  end
@@ -30,7 +30,8 @@ module JAPR
30
30
  # Create and process new pipeline
31
31
  pipeline = new(manifest, prefix, source, destination, type, config)
32
32
  pipeline.assets.each do |asset|
33
- puts "Saved '#{asset.filename}' to '#{destination}/#{asset.output_path}'"
33
+ puts "Saved '#{asset.filename}' to " \
34
+ "'#{destination}/#{asset.output_path}'"
34
35
  end
35
36
 
36
37
  # Add processed pipeline to cache
@@ -64,7 +65,7 @@ module JAPR
64
65
  staging_path = File.join(source, config['staging_path'])
65
66
  FileUtils.rm_rf(staging_path)
66
67
  rescue Exception => e
67
- puts "Failed to remove staged assets."
68
+ puts "Failed to remove staged assets: #{e.message}"
68
69
 
69
70
  # Re-raise the exception
70
71
  raise e
@@ -108,11 +109,13 @@ module JAPR
108
109
  @assets = YAML.load(@manifest).map! do |path|
109
110
  full_path = File.join(@source, path)
110
111
  File.open(File.join(@source, path)) do |file|
111
- JAPR::Asset.new(file.read, File.basename(path), File.dirname(full_path))
112
+ JAPR::Asset.new(file.read, File.basename(path),
113
+ File.dirname(full_path))
112
114
  end
113
115
  end
114
116
  rescue Exception => e
115
- puts "Asset Pipeline: Failed to load assets from provided manifest."
117
+ puts 'Asset Pipeline: Failed to load assets from provided ' \
118
+ "manifest: #{e.message}"
116
119
  raise e
117
120
  end
118
121
 
@@ -128,7 +131,9 @@ module JAPR
128
131
  end.last
129
132
 
130
133
  # Convert asset if converter is found
131
- unless klass.nil?
134
+ if klass.nil?
135
+ finished = true
136
+ else
132
137
  begin
133
138
  # Convert asset content
134
139
  converter = klass.new(asset)
@@ -138,13 +143,14 @@ module JAPR
138
143
  asset.filename = File.basename(asset.filename, '.*')
139
144
 
140
145
  # Add back the output extension if no extension left
141
- asset.filename = "#{asset.filename}#{@type}" if File.extname(asset.filename) == ''
146
+ if File.extname(asset.filename) == ''
147
+ asset.filename = "#{asset.filename}#{@type}"
148
+ end
142
149
  rescue Exception => e
143
- puts "Asset Pipeline: Failed to convert '#{asset.filename}' with '#{klass.to_s}'."
150
+ puts "Asset Pipeline: Failed to convert '#{asset.filename}' " \
151
+ "with '#{klass}': #{e.message}"
144
152
  raise e
145
153
  end
146
- else
147
- finished = true
148
154
  end
149
155
  end
150
156
  end
@@ -168,13 +174,14 @@ module JAPR
168
174
  c.filetype == @type
169
175
  end.last
170
176
 
171
- unless klass.nil?
172
- begin
173
- asset.content = klass.new(asset.content).compressed
174
- rescue Exception => e
175
- puts "Asset Pipeline: Failed to compress '#{asset.filename}' with '#{klass.to_s}'."
176
- raise e
177
- end
177
+ return unless klass
178
+
179
+ begin
180
+ asset.content = klass.new(asset.content).compressed
181
+ rescue Exception => e
182
+ puts "Asset Pipeline: Failed to compress '#{asset.filename}' " \
183
+ "with '#{klass}': #{e.message}"
184
+ raise e
178
185
  end
179
186
  end
180
187
  end
@@ -183,7 +190,10 @@ module JAPR
183
190
  def gzip
184
191
  @assets.map! do |asset|
185
192
  gzip_content = Zlib::Deflate.deflate(asset.content)
186
- [asset, JAPR::Asset.new(gzip_content, "#{asset.filename}.gz", asset.dirname)]
193
+ [
194
+ asset,
195
+ JAPR::Asset.new(gzip_content, "#{asset.filename}.gz", asset.dirname)
196
+ ]
187
197
  end.flatten!
188
198
  end
189
199
 
@@ -202,7 +212,8 @@ module JAPR
202
212
  file.write(asset.content)
203
213
  end
204
214
  rescue Exception => e
205
- puts "Asset Pipeline: Failed to save '#{asset.filename}' to disk."
215
+ puts "Asset Pipeline: Failed to save '#{asset.filename}' to " \
216
+ "disk: #{e.message}"
206
217
  raise e
207
218
  end
208
219
 
@@ -217,10 +228,10 @@ module JAPR
217
228
  display_path = @options['display_path'] || @options['output_path']
218
229
 
219
230
  @html = @assets.map do |asset|
220
- klass = JAPR::Template.subclasses.select do |t|
231
+ klasses = JAPR::Template.subclasses.select do |t|
221
232
  t.filetype == File.extname(asset.filename).downcase
222
- end.sort! { |x, y| x.priority <=> y.priority }.last
223
-
233
+ end
234
+ klass = klasses.sort! { |x, y| x.priority <=> y.priority }.last
224
235
  html = klass.new(display_path, asset.filename).html unless klass.nil?
225
236
 
226
237
  html
@@ -1,3 +1,3 @@
1
1
  module JAPR
2
- VERSION = '0.3'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: japr
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
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: 2014-05-08 00:00:00.000000000 Z
12
+ date: 2014-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
@@ -75,9 +75,9 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: '5.2'
78
- description: Jekyll Asset Pipeline reborn adds asset preprocessing (CoffeeScript,
79
- Sass, Less, ERB, etc.) and asset compression/minification/gzip (Yahoo YUI Compressor,
80
- Google Closure Compiler, etc.) to Jekyll.
78
+ description: ! " Jekyll Asset Pipeline reborn adds asset preprocessing (CoffeeScript,
79
+ Sass,\n Less, ERB, etc.) and asset compression / minification / gzip (Yahoo YUI\n
80
+ \ Compressor, Google Closure Compiler, etc.) to Jekyll.'\n"
81
81
  email: japr@clicktrackheart.com
82
82
  executables: []
83
83
  extensions: []