Project

midge

0.0
No commit activity in last 3 years
No release in over 3 years
Quick and cheap javascript modules for the rails asset pipeline.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

>= 3.1
 Project Readme

Midge

Midge is a quick and cheap javascript module system for the rails asset pipeline. You can setup multiple namespaces and use them simalar to how Node.js modules work.

Installation

Add this line to your application's Gemfile:

gem 'midge'

And then execute:

$ bundle

Or install it yourself as:

$ gem install midge

Usage

First run the install.

$ rails generate midge:install

In the initializer you setup what file extensions will go to what "module".

# config/initializers/midge.rb
Midge.setup do |config|
  config.jst_processor ".midge_template", "Midge"
  config.js_processor ".midge", "Midge"
end

With this setup you can create a file with the extension of ".midge.js" or ".midge.coffee" and it will be module enabled. In the file attach public functionality onto the exports object. For example:

// app/assets/javascripts/person.midge.js
exports.Person = function() {
  this.name = "A guy";
};

The output for this after running through the asset pipeline would be something like:

(function(exports) {
  exports.Person = function() {
    this.name = "A guy";
  };
}).call(this, (this.Midge || (this.Midge = {})));

So with this in place you can access the Person object on the Midge namespace.

var guy = new Midge.Person;

Voila! Simple albeit limited javascript modules.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request