Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master


A small helper that helps you organize your JavaScript code by detecting some sort of identification, be it the value of a variable or id of an element.


I wrote this so I can have some sane structure for my JavaScript code in a Rails project. I have another JavaScript library call congee does a similar job but uses URL matching instead. Unfortunately it doesn't work well with Rails because the URL usually changes after a form request. While I wrote this to work with Rails in heart, but it should be pretty general that it will be applicable for other purposes. Here I will show you an example of how I would use it with my Rails projects.


  %body{ :data => { :controller => params[:controller], :action => params[:action] } }
      Sesame oil goes great with just about any food!



  sesame.add("home#index", function(){
      alert("You just clicked on a big ass button."); // courtesy of

  sesame.add(["blog#index", "resume#index"], function(){

  sesame.except("admin#login", function(){
    // track every mouse movement and keystroke

  });[$("body").data("controller"), $("body").data("action")].join("#"));

  // use this if you want to have common code for the whole controller
  var controller_detector =;
  controller.add("home", function(){
    // stuff


  • add(detections, function): detections can be a string or an array of strings, which will be detected by the run method
  • except(detections, function): The opposite of add. Executes in all cases except (hence the name) when detections matches.
  • before(function): this gets executed every time before all other functions that sesame handles get executed
  • after(function): similar to before, but after everything else is executed
  • run(detection): detection is expected to be a string of whatever you want to detect. this will trigger all the matching functions sesame handles to execute.
  • new: creates a new instance of the sesame object.


  • All methods except run is chainable. sesame.add("test", function(){ /*no op*/ }).run("");
Something went wrong with that request. Please try again.