The Rapid Rails Themes Kernel

Rapid Rails Themes ships with a super small internal API that you can also use. It's available globally on the window object as RRT. For example:

  RRT.jsLibs('gmaps');

It provides some simple, but handy functions:

  • hookOnPageLoad - A wrapper hook that will correctly initialize JS functions, automatically detecting whether you are using Turbolinks or standard jQuery.
  • debounce - A debounce function
  • getRootCssVariable - A function for returning a given CSS Variable from the document root
  • jsLibs - A getter function which returns an array of strings defined on the body tag under data-js-libs
  • jsLibIsActive - A function that returns a boolean saying whether a particular string is defined in data-js-libs

How the Kernel is used to enable JS plugins.

All external JS plugins shipped with Rapid Rails Themes are wrapped in a loader function:

//= require vendor/jasny/jasny_bootstrap

(function() {

  function initJasny() {
  }

  RRT.hookOnPageLoad( function() {
    RRT.jsLibIsActive('jasny') && initJasny.call(this)
  })

})()

This allows for any particular JS plugin to be turned on or off on a given page simply by putting the string on the body tag's data-js-libs attribute.