Making a javascript asset rails gem with jeweler.
Step one)
Use the Jeweler gem.
Seriously this is a brilliant piece of work. It allows you to concentrate on building your gem.
Step two)
Create a file for bundler to load
1 |
lib/gem_name.rb |
I am using ‘_’ as a convention for filenames as ClassName to class_name
has been a convention in the rails community and the ruby community for a
long while. I have seen ‘-’ as well I prefer ‘_’ as ctags will interpret
‘something-thing’ as ‘something minus thing’ and i won’t get tab complete
in my editor.
This file’s name needs to match the name of your gem (gem_name) with ‘.rb’ after it
This file will need to require your engine
1 |
require 'gem_name/engine.rb' |
Step three)
Create a file namespaced to the gem_name directory with a the filename ‘engine’
1 |
lib/gem_name/engine.rb |
This file will hold the following code
1 2 3 4 5 6 7 |
module GemName
class Engine < ::Rails::Engine
end
end |
Step four)
create a directory
1 |
vendor/assets/javascript/gem_name.js |
Step five)
modify the Rakefile Summary and Description and commit your changes
Step six)
release your gem
1 |
rake release |
Step seven)
include your gem in your rails application’s Gemfile
1 |
gem 'gem_name' |
Step eight)
require any asset files you need from the gem in application.js
1 |
//=require gem_name |
Step nine)
send a message to [email protected] telling me that you got it working