I want to write a gem that, once bundled to a Rails 3.1 Gemfile, includes some boilerplate CSS and JS files.
I know about generators, but how could I do this without them so that the gem's effects can be added and removed without anything more than editing one line in the Rails Gemfile?
Ideally, I'd like the gem to include its default CSS/JS upon installation, then let the user use the generator to generate the CSS/JS files if they want to make any modifications.
Here's a sample gem that I copied from jquery-rails, which includes javascript files without generators.
css_gem/
lib/
css_gem.rb {1}
css_gem/
engine.rb {2}
app/
assets/
stylesheets/
css_gem/
index.css {3}
base.css {4}
{1} lib/css_gem.rb
module CssGem
require "css_gem/engine"
end
{2} lib/css_gem/engine.rb
module CSSGem
class Engine < Rails::Engine
end
end
{3} app/assets/stylesheets/css_gem/index.css
/*
*= require base
*/
{4} app/assets/stylesheets/css_gem/base.css
.custom { color: red; }
Rails Gemfile
gem 'css_gem', :path => 'path_to_my_local_gem'
This isn't working for me and Rails doesn't see the CSS file. What am I doing wrong?
Solution: Thankfully, I found a video to hold my hand: http://house9.blogspot.com/2011/06/rails-31-asset-gem.html
I had to still manually add *= require css_gem
to my Rails stylesheet manifest (app/assets/stylesheets/application.css). Duh.