Sha256: 3777b1f03f49b9eced6c006d4275d38609369396c22b0fec290d08bdac947e7a

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

sprockets-plugin
================

Package assets into gems for non-Rails Sprockets 2.x applications.


Installation
------------

``` bash
$ gem install sprockets-plugin
```


Usage in Applications
---------------------

To use Sprockets plugins, you only need to do 3 things:

1. Require "sprockets-plugin" to hook everything up.
   _This may be required by the plugins themselves, but it's best practice to also require this in your application._
2. Require any plugins you want to use.
3. Call Sprockets::Environment#append_plugin_paths after setting up your application paths.
   _Sprockets::Plugin **does not** automatically append paths to the environment. This is because the plugin paths would take precedence over your application's paths._
   
Here's an example:
   
``` ruby
require "sprockets"
require "sprockets-plugin" # 1.
require "my_plugin"        # 2.

map "/assets" do
  env = Sprockets::Environment.new
  env.append_path "assets/images"
  env.append_path "assets/javascripts"
  env.append_path "assets/stylesheets"
  env.append_plugin_paths # 3.
  run env
end
```

Usage in Gems
-------------

Sprockets::Plugin is meant to be used within gems, to package assets for reuse. Again, there's only 3 things to do to set this up.

1. Add it as a dependency in your gemspec.
2. Extend Sprockets::Plugin.
3. Add the necessary paths.

`my_plugin.gemspec`:

``` ruby
Gem::Specification.new do |s|
  # ...
  s.add_runtime_dependency "sprockets-plugin" # 1.
end
```

`my_plugin.rb`:

``` ruby
require "sprockets-plugin"

class MyPlugin < Sprockets::Plugin # 2.
  # Set the root path to use relative paths in `.append_path`
  root File.expand_path("../..", __FILE__)
  
  append_path "lib/assets/images"      # 3.
  append_path "lib/assets/javascripts" # 3.
  append_path "lib/assets/stylesheets" # 3.
end 
```


Copyright
---------

Copyright (c) 2011 [Peter Browne](http://petebrowne.com). See LICENSE for details.

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sprockets-plugin-0.3.0 README.md
sprockets-plugin-0.2.1 README.md
sprockets-plugin-0.2.0 README.md