I use Rails & Middleman a lot. Rubygems and Bundler makes it a breeze to manage all Ruby dependencies, but things get fuzzy when it comes to JS and CSS. In the past I’ve simply committed the dependencies together with the source code, or used git submodules, both of which have been bulky and inflexible.
Rails and Middleman use Sprockets to compile assets and it’s become popular to distribute JS libraries as small Sprockets-compatible gems which I think is great!
The problem however, is that not all JS libraries & CSS frameworks are distributed as gems, nor would it make sense if they were.
Package the libs in a microgem
A microgem is just a regular gem, but with a small and specific function. Microgems should not be hosted on Rubygems.org, instead they can be installed directly from a git repository.
The only function of the gem is to make these JS & CSS files available to Sprockets compatible applications. This allows me include them in my projects without having to vendor them and I can use the version of the microgem to represent the collective version of my current lib snapshot.
I can easily switch out a JS lib and keep on going without having to worry about breaking old projects. Also, I can use branches to try out new stuff and experiment.
gem "web-lib", :git => 'https://github.com/jpettersson/web-lib.git'
/*Require all libs*/ //= require_tree 'web-lib' /*Or be selective*/ //= require 'web-lib/SomeJsFile'
The workflow and the microgem itself are easily forked. The idea behing the generic namespace ‘web-lib’ is that anyone can customize the contents to suit their needs. It also implies that there should be only one jslib per project to keep things manageable.