Skip to content

Commit

Permalink
complete rewrite, bump to v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
matthodan committed Dec 14, 2012
1 parent 820335d commit 688d87d
Show file tree
Hide file tree
Showing 46 changed files with 1,069 additions and 343 deletions.
34 changes: 23 additions & 11 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ Jekyll Asset Pipeline is extremely easy to add to your Jekyll project and has no
5. Run the `jekyll` command to compile your site. You should see an output that includes the following Jekyll Asset Pipeline status messages. 5. Run the `jekyll` command to compile your site. You should see an output that includes the following Jekyll Asset Pipeline status messages.


``` bash ``` bash
Asset Pipeline: Compiling bundle... compiled 'global-md5hash.css'. Asset Pipeline: Processing 'css_asset_tag' manifest 'global'
Asset Pipeline: Compiling bundle... compiled 'global-md5hash.js'. Asset Pipeline: Saved 'global-md5hash.css' to '_site/assets'
Asset Pipeline: Processing 'javascript_asset_tag' manifest 'global'
Asset Pipeline: Saved 'global-md5hash.js' to '_site/assets'
``` ```


> *If you do not see these messages, check that you have __not__ set Jekyll's "safe" option to "true" in your site's "_config.yml". If the "safe" option is set to "true", Jekyll will not run plugins.* > *If you do not see these messages, check that you have __not__ set Jekyll's "safe" option to "true" in your site's "_config.yml". If the "safe" option is set to "true", Jekyll will not run plugins.*
Expand All @@ -92,11 +94,11 @@ In the following example, we will add a preprocessor that converts CoffeeScript
module JekyllAssetPipeline module JekyllAssetPipeline
class CoffeeScriptConverter < JekyllAssetPipeline::Converter class CoffeeScriptConverter < JekyllAssetPipeline::Converter
require 'coffee-script' require 'coffee-script'
def self.filetype def self.filetype
'.coffee' '.coffee'
end end
def convert def convert
return CoffeeScript.compile(@content) return CoffeeScript.compile(@content)
end end
Expand Down Expand Up @@ -137,9 +139,14 @@ module JekyllAssetPipeline
end end
end end
``` ```

> *Don't forget to install the "sass" gem before you run the `jekyll` command since the above SASS converter requires the "sass" library as a dependency.* > *Don't forget to install the "sass" gem before you run the `jekyll` command since the above SASS converter requires the "sass" library as a dependency.*
### Successive Preprocessing
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).
> *Don't forget to define preprocessors for the extensions you use in your filenames, otherwise Jekyll Asset Pipeline will not process your asset.*

## Asset Compression ## Asset Compression


Asset compression allows us to decrease the size of our assets and increase the speed of our site. One of Jekyll Asset Pipeline's key strengths is that it works with __any__ compression library that has a ruby wrapper. Adding asset compression is straightforward, but requires a small amount of additional code. Asset compression allows us to decrease the size of our assets and increase the speed of our site. One of Jekyll Asset Pipeline's key strengths is that it works with __any__ compression library that has a ruby wrapper. Adding asset compression is straightforward, but requires a small amount of additional code.
Expand Down Expand Up @@ -243,25 +250,30 @@ That is it! Your asset pipeline used your template to generate an HTML "link" t


## Configuration ## Configuration


Jekyll Asset Pipeline provides the following two configuration options that can be controlled by adding the following to the end of your project's "\_config.yml" file. Jekyll Asset Pipeline provides the following configuration options that can be controlled by adding the following to the end of your project's "\_config.yml" file.
``` yaml ``` yaml
asset_pipeline: asset_pipeline:
bundle: true # Default = true
compress: true # Default = true compress: true # Default = true
output_path: assets # Default = assets output_path: assets # Default = assets
gzip: false # Default = false
``` ```
> *If you don't have a "\_config.yml" file, consider reading the [configuration section](https://github.com/mojombo/jekyll/wiki/Configuration) of the Jekyll documentation.* > *If you don't have a "\_config.yml" file, consider reading the [configuration section](https://github.com/mojombo/jekyll/wiki/Configuration) of the Jekyll documentation.*

>
> The "compress" setting tells Jekyll Asset Pipeline whether or not to compress the bundled assets. It is useful to set this setting to "false" while you are debugging your site's JavaScript. The "output\_path" setting defines where generated bundles should be saved within the "\_site" folder of your project. > - The "bundle" setting controls whether Jekyll Asset Pipeline bundles the assets defined in each manifest. If "bundle" is set to false, each asset will be saved individually and individual html tags pointing to each unbundled asset will be produced when you compile your site. It is useful to set this to false while you are debugging your site.
> - The "compress" setting tells Jekyll Asset Pipeline whether or not to compress the bundled assets. It is useful to set this setting to "false" while you are debugging your site.
> - The "output\_path" setting defines where generated bundles should be saved within the "\_site" folder of your project.
> - The "gzip" setting controls whether Jekyll Asset Pipeline saves gzipped versions of your assets alongside un-gzipped versions.


## Contribute ## Contribute


You can contribute to the Jekyll Asset Pipeline by submitting a pull request [via GitHub](https://github.com/matthodan/jekyll-asset-pipeline). I have identified the following areas for improvement: You can contribute to the Jekyll Asset Pipeline by submitting a pull request [via GitHub](https://github.com/matthodan/jekyll-asset-pipeline). I have identified the following areas for improvement:


- __Tests, tests, tests.__ I'm embarrassed to say that I didn't write a single test while building Jekyll Asset Pipeline. This started as a hack for my blog and quickly grew into a library as I tweaked it to support my own needs. - __Tests, tests, tests.__ I'm embarrassed to say that I didn't write a single test while building Jekyll Asset Pipeline. This started as a hack for my blog and quickly grew into a library as I tweaked it to support my own needs. **This project is now fully tested.**
- __Handle remote assets.__ Right now, Jekyll Asset Pipeline does not provide any way to include remote assets in bundles unless you save them locally before generating your site. Moshen's [Jekyll Asset Bundler](https://github.com/moshen/jekyll-asset_bundler) allows you to include remote assets, which I thought was pretty interesting. That said, I think it is generally better to keep remote assets separate so that they load asynchronously. - __Handle remote assets.__ Right now, Jekyll Asset Pipeline does not provide any way to include remote assets in bundles unless you save them locally before generating your site. Moshen's [Jekyll Asset Bundler](https://github.com/moshen/jekyll-asset_bundler) allows you to include remote assets, which I thought was pretty interesting. That said, I think it is generally better to keep remote assets separate so that they load asynchronously. **After some thought, I've decided that this is not a priority. If you disagree, let me know.**
- __Successive preprocessing.__ Currently you can only preprocess a file once. It would be better if you could run an asset through multiple preprocessors before it gets compressed and bundled. - __Successive preprocessing.__ Currently you can only preprocess a file once. It would be better if you could run an asset through multiple preprocessors before it gets compressed and bundled. **As of v0.1.0, Jekyll Asset Pipeline now supports successive preprocessing.**


Feel free to message me on [Twitter](http://twitter.com/matthodan) or [Facebook](http://facebook.com/matthodan). Feel free to message me on [Twitter](http://twitter.com/matthodan) or [Facebook](http://facebook.com/matthodan).


Expand Down
2 changes: 1 addition & 1 deletion jekyll_asset_pipeline.gemspec
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Gem::Specification.new do |s|
s.version = JekyllAssetPipeline::VERSION s.version = JekyllAssetPipeline::VERSION
s.date = Time.now s.date = Time.now
s.summary = 'A powerful asset pipeline for Jekyll that bundles, converts, and minifies CSS and JavaScript assets.' s.summary = 'A powerful asset pipeline for Jekyll that bundles, converts, and minifies CSS and JavaScript assets.'
s.description = 'Jekyll Asset Pipeline adds asset preprocessing (CoffeeScript, Sass, Less, ERB, etc.), asset compression/minification (Yahoo YUI Compressor, Google Closure Compiler, etc.) to Jekyll. Jekyll Asset Pipeline can be extended to support any preprocessing or compression library.' s.description = 'Adds asset preprocessing (CoffeeScript, Sass, Less, ERB, etc.), asset compression/minification/gzip (Yahoo YUI Compressor, Google Closure Compiler, etc.) to Jekyll.'
s.authors = ['Matt Hodan'] s.authors = ['Matt Hodan']
s.email = 'matthew.c.hodan@gmail.com' s.email = 'matthew.c.hodan@gmail.com'
s.homepage = 'http://www.matthodan.com/2012/11/22/jekyll-asset-pipeline.html' s.homepage = 'http://www.matthodan.com/2012/11/22/jekyll-asset-pipeline.html'
Expand Down
32 changes: 22 additions & 10 deletions lib/jekyll_asset_pipeline.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,31 +3,43 @@
require 'fileutils' require 'fileutils'
require 'time' require 'time'
require 'yaml' require 'yaml'
require 'zlib'


# Third-party dependencies # Third-party dependencies
require 'jekyll' require 'jekyll'
require 'liquid' require 'liquid'


# Jekyll extensions # Jekyll extensions
require 'jekyll_asset_pipeline/extensions/jekyll/static_file_extensions'
require 'jekyll_asset_pipeline/extensions/jekyll/static_asset_file'

# Liquid extensions
require 'jekyll_asset_pipeline/extensions/liquid/liquid_block_extensions'
require 'jekyll_asset_pipeline/extensions/liquid/asset_tag'
require 'jekyll_asset_pipeline/extensions/liquid/asset_tags/css_asset_tag'
require 'jekyll_asset_pipeline/extensions/liquid/asset_tags/javascript_asset_tag'

# Ruby extensions
require 'jekyll_asset_pipeline/extensions/ruby/subclass_tracking'

# Jekyll Asset Pipeline
require 'jekyll_asset_pipeline/version' require 'jekyll_asset_pipeline/version'
require 'jekyll_asset_pipeline/extendable' require 'jekyll_asset_pipeline/asset'
require 'jekyll_asset_pipeline/asset_file'
require 'jekyll_asset_pipeline/bundler'
require 'jekyll_asset_pipeline/compressor'
require 'jekyll_asset_pipeline/converter' require 'jekyll_asset_pipeline/converter'
require 'jekyll_asset_pipeline/compressor'
require 'jekyll_asset_pipeline/template' require 'jekyll_asset_pipeline/template'
require 'jekyll_asset_pipeline/templates/javascript_tag_template' require 'jekyll_asset_pipeline/templates/javascript_tag_template'
require 'jekyll_asset_pipeline/templates/css_tag_template' require 'jekyll_asset_pipeline/templates/css_tag_template'

require 'jekyll_asset_pipeline/cache'
# Liquid extensions require 'jekyll_asset_pipeline/pipeline'
require 'jekyll_asset_pipeline/css_asset_tag'
require 'jekyll_asset_pipeline/javascript_asset_tag'


module JekyllAssetPipeline module JekyllAssetPipeline
# Default configuration settings for Jekyll Asset Bundler # Default configuration settings for Jekyll Asset Pipeline
# Strings used for keys to play nice when merging with _config.yml # Strings used for keys to play nice when merging with _config.yml
DEFAULTS = { DEFAULTS = {
'output_path' => 'assets', # Destination for bundle file (within the '_site' directory) 'output_path' => 'assets', # Destination for bundle file (within the '_site' directory)
'compress' => true # true = Compress assets, false = Leave assets uncompressed 'bundle' => true, # true = Bundle assets, false = Leave assets unbundled
'compress' => true, # true = Minify assets, false = Leave assets unminified
'gzip' => false # true = Create gzip versions, false = Do not create gzip versions
} }
end end
10 changes: 10 additions & 0 deletions lib/jekyll_asset_pipeline/asset.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,10 @@
module JekyllAssetPipeline
class Asset
def initialize(content, filename)
@content = content
@filename = filename
end

attr_accessor :content, :filename, :output_path
end
end
150 changes: 0 additions & 150 deletions lib/jekyll_asset_pipeline/bundler.rb

This file was deleted.

17 changes: 17 additions & 0 deletions lib/jekyll_asset_pipeline/cache.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,17 @@
module JekyllAssetPipeline
class Cache
@@cache = {}

def self.add(key, value)
@@cache[key] = value
end

def self.has_key?(key)
@@cache.has_key?(key)
end

def self.get(key)
@@cache[key]
end
end
end
4 changes: 3 additions & 1 deletion lib/jekyll_asset_pipeline/compressor.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
module JekyllAssetPipeline module JekyllAssetPipeline
class Compressor < JekyllAssetPipeline::Extendable class Compressor
extend JekyllAssetPipeline::SubclassTracking

def initialize(content) def initialize(content)
@content = content @content = content
begin begin
Expand Down
13 changes: 7 additions & 6 deletions lib/jekyll_asset_pipeline/converter.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,13 +1,14 @@
module JekyllAssetPipeline module JekyllAssetPipeline
class Converter < JekyllAssetPipeline::Extendable class Converter
def initialize(file) extend JekyllAssetPipeline::SubclassTracking
@file = file
@content = file.read def initialize(asset)
@type = File.extname(@file).downcase @content = asset.content
@type = File.extname(asset.filename).downcase
begin begin
@converted = self.convert @converted = self.convert
rescue Exception => e rescue Exception => e
puts "Failed to convert asset '#{@file.path}'." puts "Failed to convert asset '#{asset.filename}'."
raise e raise e
end end
end end
Expand Down
19 changes: 0 additions & 19 deletions lib/jekyll_asset_pipeline/css_asset_tag.rb

This file was deleted.

Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
module JekyllAssetPipeline
class StaticAssetFile < ::Jekyll::StaticFile
include JekyllAssetPipeline::JekyllStaticFileExtensions
end
end
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
module JekyllAssetPipeline module JekyllAssetPipeline
class AssetFile < Jekyll::StaticFile module JekyllStaticFileExtensions
# Override #write method since the asset file is dynamically created # Override #write method since the asset file is dynamically created
def write(dest) def write(dest)
true true
Expand Down
6 changes: 6 additions & 0 deletions lib/jekyll_asset_pipeline/extensions/liquid/asset_tag.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,6 @@
module JekyllAssetPipeline
class AssetTag < ::Liquid::Block
extend JekyllAssetPipeline::LiquidBlockExtensions::ClassMethods
include JekyllAssetPipeline::LiquidBlockExtensions
end
end
Loading

0 comments on commit 688d87d

Please sign in to comment.