Permalink
Browse files

Added some examples to README

  • Loading branch information...
gudleik committed May 13, 2012
1 parent 9be5d02 commit ebeccde1381b7536bfe34efb1e66c50fd413967d
Showing with 58 additions and 10 deletions.
  1. +58 −10 README.md
View
@@ -1,24 +1,72 @@
# AutoexecBat
-TODO: Write a gem description
+AutoexecBat was written to aid organizing javascript code in Rails' asset pipeline.
-## Installation
+The main idea is to organize all javascript code into separate namespaces.
+Here are some examples:
+
+ define "App.Products", (exports) ->
+ exports.autoexec = ->
+ # this is the autoexec function that AutoexecBat looks for
+
+ # Module with private methods
+ define "App.Products.Index", (exports) ->
+ exports.autoexec = ->
+ setupEventListeners()
+ setupSomethingElse()
+ takeItAway()
+
+ setupEventListeners = ->
+ $('table tbody td').on 'click', -> # event handler
+ $('input').on 'click', -> # another event handler
+
+ takeItAway = ->
+ $('tag').doSomething()
-Add this line to your application's Gemfile:
+ setupSomethingElse = ->
+ $('.private').show()
+
+ # A module with dependencies
+ define "App.Products.Show", ["App.Products"], (exports) ->
+ exports.autoexec = ->
+ # this module has a dependency to App.Products,
+ # which will be executed first
- gem 'autoexec_bat'
+ # If all you want is to run the dependencies:
+ define "App.Gallery", ["App.UI.Fancybox", "App.UI.FileUpload"]
+
+ # A simple coffeescript class:
+ class namespace("App.Models").Product
+ # this class will be known as App.Models.Product
+
+
+ jQuery ->
+ # Run AutoexecBat on all tags with a data-autoexec attribute
+ $('[data-autoexec]').autoexec()
+
+Finally, just add the module name to a data-autoexec attribute:
-And then execute:
+ <body data-autoexec="App.Products.Index">
+
+If the given module doesn't exist, it tries to execute a parent module.
+In this case, the module App.Products.autoexec() will be executed:
- $ bundle
+ <div data-autoexec="App.Products.Dev.Null">..</div>
+
-Or install it yourself as:
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'autoexec_bat'
- $ gem install autoexec_bat
+Require your modules and activate autoexecution:
-## Usage
+ #= require autoexec_bat
+ #= require_tree ./folder-containing-your-modules
+ jQuery ->
+ $('[data-autoexec]').autoexec()
-TODO: Write usage instructions here
## Contributing

0 comments on commit ebeccde

Please sign in to comment.