项目作者: ales-vilchytski

项目描述 :
Lightweight JavaScript module system for Ruby on Rails 4
高级语言: Ruby
项目地址: git://github.com/ales-vilchytski/modulejs-rails.git
创建时间: 2014-11-25T09:05:39Z
项目社区:https://github.com/ales-vilchytski/modulejs-rails

开源协议:MIT License

下载


modulejs for Ruby on Rails 4 Assets Pipeline

Lightweight JavaScript module system (http://larsjung.de/modulejs/), v2.2.0.
Inspired by article: https://www.reinteractive.net/posts/172-a-better-way-to-modularise-your-js-in-rails

When you want to use modules in JavaScript you should solve next problems:

  1. Load scripts with dependencies, usually in big concatenated JavaScript file
  2. Execute scripts and dependencies in proper order

Rails solves problem #1 by Assets Pipeline, modulejs solves problem #2.

Installation

Add this line to your application’s Gemfile:

  1. gem 'modulejs-rails'

And then execute:

  1. $ bundle install

Or install it yourself as:

  1. $ gem install modulejs-rails

Usage

Require modulejs in Assets Pipeline manifest

  1. //= require 'modulejs'

Define your own modules (this in functions points to window):

  1. modulejs.define('bar', ['foo'], function (foo) {
  2. // module setup code and definitions
  3. return some_bar_object;
  4. });

Or setup 3rd party code:

  1. modulejs.define('foo', Foo);

And require them when needed:

  1. var bar = modulejs.require('bar');
  2. bar.doStuff();

See full documentation here: https://larsjung.de/modulejs/

Contributing

  1. Fork it ( https://github.com/ales-vilchytski/modulejs-rails/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request