Skip to content

Commit

Permalink
First public release
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed Oct 21, 2012
0 parents commit 0be5ccb
Show file tree
Hide file tree
Showing 36 changed files with 891 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--require ./lib/jekyll-assets --color --format documentation
2 changes: 2 additions & 0 deletions .travis.yml
@@ -0,0 +1,2 @@
language: ruby
rvm: [ 1.9.3 ]
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in jekyll-assets.gemspec
gemspec
6 changes: 6 additions & 0 deletions Guardfile
@@ -0,0 +1,6 @@
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end

22 changes: 22 additions & 0 deletions LICENSE
@@ -0,0 +1,22 @@
Copyright (c) 2012 Aleksey V Zapparov (http://ixti.net/)

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
120 changes: 120 additions & 0 deletions README.md
@@ -0,0 +1,120 @@
# Jekyll::AssetsPlugin

Jekyll plugin, that adds Rails-alike assets pipelines.


## Installation

Add this line to your application's Gemfile:

gem 'jekyll-assets'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jekyll-assets


## Usage

Add this line to your sites `_plugins/ext.rb`:

require 'jekyll-assets'

Put your assets under following paths:

- `_assets/javascripts`
- `_assets/stylesheets`
- `_assets/images`

Name your "main" asset files `app.js` and `app.css` and use liquid tags:

- `{% javascript app %}` to output `<script>` tag for `app.js`
- `{% stylesheet app %}` to output `<link>` tag for `app.css`
- `{% asset_path logo.jpg %}` to output URL for `logo.jpg`

In order to use these tags, assets must be "bundled". By default only `app.js`,
`app.css`, and all files with extensions `.jpg`, `.png` or `.gif` are bundled.
You can change this by tuning up you `_config.yml` (see below).


## Configuration

You can fine-tune configuration by editing your `_config.yml`:

assets:
#
# Pathname of the destination of generated (bundled) assets relative
# to the destination of the root.
#
dirname: assets
#
# Pathnames where to find assets relative to the root of the site.
#
sources:
- _assets/javascripts
- _assets/stylesheets
- _assets/images
#
# Array of filenames or filename patterns that needs to be generated for
# the generated site. You can use `*` and `**` wildcards in patterns:
#
# 'foobar.jpg' will match 'foobar.jpg' only
# '*.jpg' will match 'foo.jpg', but not 'foo/bar.jpg'
# '**.jpg' will match 'foo.jpg', 'foo/bar.jpg', etc.
#
bundles:
- 'app.css'
- 'app.js'
- '**.jpg'
- '**.png'
- '**.gif'
#
# Sets compressors for the specific types of file: `js`, or `css`.
# No compression by default.
#
# Possible variants:
#
# css => 'yui', 'sass', nil
# js => 'yui', 'unglifier', nil
#
compress:
js: ~
css: ~


## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request


## License

Copyright (C) 2012 Aleksey V Zapparov (http://ixti.net/)

The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions Rakefile
@@ -0,0 +1,9 @@
#!/usr/bin/env rake

require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new

task :default => :spec
task :test => :spec
27 changes: 27 additions & 0 deletions jekyll-assets.gemspec
@@ -0,0 +1,27 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/jekyll/assets_plugin/version', __FILE__)


Gem::Specification.new do |gem|
gem.name = "jekyll-assets"
gem.version = Jekyll::AssetsPlugin::VERSION
gem.homepage = "http://ixti.github.com/jekyll-assets"
gem.authors = %w{Aleksey V Zapparov}
gem.email = %w{ixti@member.fsf.org}
gem.summary = "jekyll-assets-#{Jekyll::AssetsPlugin::VERSION}"
gem.description = %q{Adds assets pipelines for Jekyll}

gem.add_dependency "jekyll"
gem.add_dependency "sprockets", "~> 2.8"

gem.add_development_dependency "rake"
gem.add_development_dependency "rspec"
gem.add_development_dependency "guard-rspec"
gem.add_development_dependency "rb-inotify"

gem.files = `git ls-files`.split($\)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})

gem.require_paths = ["lib"]
end
1 change: 1 addition & 0 deletions lib/jekyll-assets.rb
@@ -0,0 +1 @@
require 'jekyll/assets_plugin'
16 changes: 16 additions & 0 deletions lib/jekyll/assets_plugin.rb
@@ -0,0 +1,16 @@
require 'jekyll'
require 'liquid'


require 'jekyll/assets_plugin/generator'
require 'jekyll/assets_plugin/site_patch'
require 'jekyll/assets_plugin/tag'
require 'jekyll/assets_plugin/version'


Jekyll::Site.send :include, Jekyll::AssetsPlugin::SitePatch


Liquid::Template.register_tag('javascript', Jekyll::AssetsPlugin::Tag)
Liquid::Template.register_tag('stylesheet', Jekyll::AssetsPlugin::Tag)
Liquid::Template.register_tag('asset_path', Jekyll::AssetsPlugin::Tag)
45 changes: 45 additions & 0 deletions lib/jekyll/assets_plugin/asset_file.rb
@@ -0,0 +1,45 @@
# stdlib
require 'set'


module Jekyll
module AssetsPlugin
# Represents single asset that can be used as StaticFile for Site
#
class AssetFile
@@mtimes = Hash.new

attr_reader :asset

def initialize site, asset
@site, @asset = site, asset
end

def destination dest
File.join(dest, @site.assets_config.dirname, @asset.digest_path)
end

def path
@asset.pathname.to_s
end

def mtime
@asset.mtime.to_i
end

def modified?
@@mtimes[path] != mtime
end

def write dest
dest_path = destination dest

return false if File.exist?(dest_path) and !modified?
@@mtimes[path] = mtime

@asset.write_to dest_path
true
end
end
end
end
98 changes: 98 additions & 0 deletions lib/jekyll/assets_plugin/configuration.rb
@@ -0,0 +1,98 @@
# stdlib
require 'ostruct'


module Jekyll
module AssetsPlugin
# Plugin configuration class.
#
#
# ##### sources
#
# Pathnames where to find assets relative to the root of the site.
#
# Default: ['_assets/javascripts', '_assets/stylesheets', '_assets/images']
#
#
# ##### bundles
#
# Array of filenames or filename patterns that needs to be generated for the
# generated site. You can use `*` and `**` wildcards in filename patterns:
#
# 'foobar.jpg' will match 'foobar.jpg' only
# '*.jpg' will match 'foo.jpg', but not 'foo/bar.jpg'
# '**.jpg' will match 'foo.jpg', 'foo/bar.jpg', etc.
#
# Default: ['app.css', 'app.js', '**.jpg', '**.png', '**.gif']
#
#
# ##### compress
#
# Sets compressors for the specific types of file: `js`, or `css`.
#
# Possible variants:
#
# css => 'yui', 'sass', nil
# js => 'yui', 'unglifier', nil
#
# Default: { 'css' => nil, 'js' => nil } (no compression at all)
#
#
# ##### dirname
#
# Pathname of the destination of generated (bundled) assets relative to the
# destination of the root.
#
# Default: 'assets'
#
class Configuration < OpenStruct
@@defaults = {
:dirname => 'assets',
:sources => %w{_assets/javascripts _assets/stylesheets _assets/images},
:bundles => %w{app.css app.js **.jpg **.png **.gif},
:compress => { :css => nil, :js => nil }
}

def initialize config = {}
super @@defaults.merge(config)

self.sources = [ self.sources ] if self.sources.is_a? String
self.bundles = [ self.bundles ] if self.bundles.is_a? String

self.compress = OpenStruct.new(self.compress)
end

# Returns bundles array with pattern strings converted to RegExps
#
# 'foobar.jpg' => 'foobar.jpg'
# '*.png' => /[^\]+\.png/
# '**.gif' => /.+?\.gif/
#
def bundle_filenames
bundles.map do |pattern|
if pattern =~ /^\*/
pattern = pattern.dup

pattern.gsub!(/\./, '\\.')
pattern.sub!(/\*{2}/, '.+?')
pattern.sub!(/\*{1}/, '[^/]+')

pattern = /^#{pattern}$/
end

pattern
end
end

def js_compressor
return compress.js.to_sym if compress.js
false
end

def css_compressor
return compress.css.to_sym if compress.css
false
end
end
end
end

0 comments on commit 0be5ccb

Please sign in to comment.