All Projects → stve → Bower

stve / Bower

Licence: mit
Bower integration for your ruby/rails apps.

Programming Languages

ruby
36898 projects - #4 most used programming language

Bower

Gem Version Build Status

Bower integration for your ruby apps.

Usage with Sprockets

Rails

Add bower to your application's Gemfile:

gem 'bower'

Rails 4 ships with an updated version of Sprockets that supports bower's bower.json file. If you are running, Rails 3, then you need to require Sprockets 2.2.2.backport1:

gem 'sprockets', '2.2.2.backport1'

The gem includes a generator that sets up your project:

rails generate bower:install

This will install a configuration file (.bowerrc) in your project's root. The configuration file tells bower where to install components and where it expects bower.json.

{
  "directory"  : "bower_components"
}

You can change the destination directory if you like, though putting Bower components under app/assets/ can cause problems (see rails/rails#7968). Add your dependencies to bower.json or use bower install as you would in any other project.

Non-Rails Projects

While offering less capability than when used in Rails' asset pipeline, you can still use the bower gem in a non-Rails project. Just require the gem and append the corresponding directory to Sprocket's load path:

require 'sprockets'
require 'bower'

environment = Sprockets::Environment.new
environment.append_path Bower.environment.directory

Additional Tutorials

How this gem differs from other techniques

For Rails apps, integrating bower components into lib/assets and/or vendor/assets seems like the wrong approach. Since bower can support multiple searchpaths, the need to make a distinction between external dependencies and frameworks does not exist. It can all be managed in once place. This gem takes a more opinionated approach and installs components to bower_components/ in your project's root by default. You can always change it to another location.

If this approach isn't to your liking, you may want to take a look at bower-rails.

TODO

When used with Sprockets, you still need to use a require directive in order to require a component's files. This seems like something that should just work.

Contributing

Pull requests welcome: fork, make a topic branch, commit (squash when possible) with tests and I'll happily consider merging your contributions.

Copyright

Copyright (c) 2015 Steve Agalloco. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].