Easymarklet is a new ruby gem that makes it super easy to build bookmarklets that interact wtih your rails app.
I've been working on a project lately that is making use of a bookmarklet to make it easier to collect URLs of interest from users of the system. It's a little more complicated than just collecting a URL, so we need some pretty extensive UI to be able to capture all of the info that the user wants to associate with that URL. After getting all of the bits and pieces for our bookmarklet worked out I realized that all of the resulting code fell into one of two categories. 1) Code that is unique to our application. 2) Code that deals with setting up and delivering a bookmarklet. I decided that the code that just deals with setting up and delivering a bookmarklet could be extracted out into a ruby gem, and so, Easmarklet was born.
Add this to your Gemfile:
Then, of course, you need to run:
For the purposes of keeping this post short I'm going to create the simplest bookmarklet possible. Please see Foo vs Baz for many detailed explanations of several types of bookmarklets.
Easymarklet comes with a number of generators that will create the scaffolding needed for various types of bookmarklets. We'll use the 'bare' generator which is the simplest.
$ rails g easymarklet:bare demo
This will generate a new file at :
You can link to your new bookmarklet with this :
<%= link_to 'Demo', easymarklet_js('demo_bookmarklet.js') %>
Now you can update
demo_bookmarklet.js to do something interesting.