Skip to content

Avoid JS mayhem on your Rails app! js-initializers is an engine that adds a micro-framework for initializing and organizing client-side logic in a modular way

License

Notifications You must be signed in to change notification settings

ncuesta/js-initializers

Repository files navigation

js-initializers

Rails engine that provides a micro-framework for organizing in a modular way your client-side scripts, as well as it enables you to only run the necessary modules for each page.

(Better readme coming soon!)

Usage

Add js-initializers to your Gemfile

# Gemfile
gem 'js-initializers'

Add js-initializers to your Sprockets manifest:

//= require js-initializers

Et voilà! You're ready to add your initializers:

// app/assets/javascripts/initializers/rickroll.js
(function($) {
  function isRickrollable() {
    return window.user !== 'admin';
  }

  function rickroll() {
    $('a').on('click', function() { window.location = 'www.youtube.com/watch?v=dQw4w9WgXcQ'; return false; });
  }

  Initializers.register('rickroll', rickroll, isRickrollable);
}(jQuery));

For further instructions on how to use this library and defining your own initializers, you may refer to the source code of js-initializers.js.

Contributing

Contributions are welcome! Just fork, commit and send a pull request :)

Author

This skinny gem is brought to you by Nahuel Cuesta Luengo. You may reach him at @ncuestal on Twitter or by email at nahuelcuestaluengo@gmail.com.

About

Avoid JS mayhem on your Rails app! js-initializers is an engine that adds a micro-framework for initializing and organizing client-side logic in a modular way

Resources

License

Stars

Watchers

Forks

Packages

No packages published