Ruby : Gems : Make jQuery-plugin gems / Gems to integrate jQuery Plugins

How to create and publish gems?

If you are new to this topic please follow my older post. https://cbabhusal.wordpress.com/2015/03/08/ruby-how-to-create-a-gem-for-beginner/

How to integrate jQuery Plugins with Ruby Gems?

To make your gem assets available to your user’s application.js / .css files you need to modify your module. Suppose your gems name is momentjs_modified-rails then you need to add a Rails::Engine subclass in your main module. For Example:

require "momentjs_modified-rails/version"

module MomentjsModified  
  module Rails
    class Engine < ::Rails::Engine
    end
  end
end  

Adding the following snippet will cause rails to add its directories to the load path when the gem is required.

 class Engine < ::Rails::Engine
 end

Now you will keep you asset files in proper directories

Add The Assets

Download the asset files you want to include in the gem. If availble, I prefer to use the uncompressed, non-minified versions. They’ll actually be readable if you need to dig into them and you can rely on the asset pipeline to minify them in production or on precompilation. In the case of the Moment.js library, I downloaded the release version to my desktop and ran the following commands:

$ mkdir -p vendor/assets/javascripts
$ cp ~/Downloads/moment.js vendor/assets/javascripts/moment.js

I used the vendor/assets directory here because these aren’t assets I’m maintaining directly. If they were assets I was responsible for maintaining, I would put them in app/assets though the difference is purely semantic.

Sources:

http://prioritized.net/blog/gemify-assets-for-rails/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s