autoexec_bat 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +12 -0
- data/Rakefile +5 -0
- data/autoexec_bat.gemspec +2 -0
- data/autoexec_bat.js +27 -17
- data/lib/assets/javascripts/autoexec_bat.coffee +16 -13
- data/lib/autoexec_bat/version.rb +1 -1
- data/test/autoexecBatTest.coffee +84 -0
- data/test/mocha.opts +2 -0
- metadata +23 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9456ddb6200e4852332f22cdfce6ff20b3667d54
|
4
|
+
data.tar.gz: f73ece4e3f1f78534570edd25a25943adfa26d81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a5cdeac97d98aa2a3cf346723de284587e1bb736849eadd3279076880de7dfdc4e8e42a1ea2e0162491a32a418fff336f41847ecb780be016e01043541cd224
|
7
|
+
data.tar.gz: 1a4c3da6dc24b9126a47b318f22cf325df87617a4a71220d13cb35f131ef572ca137f80644205f80c1f56880c026e7d655aa6649fdf13f9e261501d842e10516
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -105,6 +105,18 @@ For Rails 3:
|
|
105
105
|
jQuery ->
|
106
106
|
$('[data-autoexec]').autoexec()
|
107
107
|
|
108
|
+
## Testing
|
109
|
+
|
110
|
+
Install mocha and chai:
|
111
|
+
|
112
|
+
# npm install -g mocha coffee-script
|
113
|
+
# npm install chai jack
|
114
|
+
|
115
|
+
And run the test suite:
|
116
|
+
|
117
|
+
# mocha -R spec --watch (or)
|
118
|
+
# rake test
|
119
|
+
|
108
120
|
## Contributing
|
109
121
|
|
110
122
|
1. Fork it
|
data/Rakefile
CHANGED
data/autoexec_bat.gemspec
CHANGED
data/autoexec_bat.js
CHANGED
@@ -1,21 +1,32 @@
|
|
1
|
-
// Generated by CoffeeScript 1.
|
1
|
+
// Generated by CoffeeScript 1.6.2
|
2
2
|
(function() {
|
3
|
-
// Generated by CoffeeScript 1.3.3
|
4
3
|
var $, AutoexecBat, root,
|
5
4
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
6
5
|
|
7
|
-
root = typeof exports !== "undefined" && exports !== null ? exports : window;
|
8
|
-
|
9
6
|
AutoexecBat = {
|
10
7
|
topLevel: "App",
|
11
|
-
debug:
|
8
|
+
debug: false,
|
9
|
+
autoRequire: false,
|
12
10
|
log: function(msg) {
|
13
11
|
if (AutoexecBat.debug) {
|
14
12
|
return typeof console !== "undefined" && console !== null ? console.log(msg) : void 0;
|
15
13
|
}
|
16
14
|
},
|
15
|
+
require: function(dependencies) {
|
16
|
+
var lib, _i, _len, _results;
|
17
|
+
|
18
|
+
if (dependencies) {
|
19
|
+
_results = [];
|
20
|
+
for (_i = 0, _len = dependencies.length; _i < _len; _i++) {
|
21
|
+
lib = dependencies[_i];
|
22
|
+
_results.push(AutoexecBat.initializeModule(lib));
|
23
|
+
}
|
24
|
+
return _results;
|
25
|
+
}
|
26
|
+
},
|
17
27
|
define: function(name) {
|
18
28
|
var arg, block, dependencies, module, target, top, _i, _j, _len, _len1;
|
29
|
+
|
19
30
|
dependencies = [];
|
20
31
|
if (AutoexecBat.autoRequire && name !== AutoexecBat.autoRequire) {
|
21
32
|
dependencies.push(AutoexecBat.autoRequire);
|
@@ -43,8 +54,12 @@
|
|
43
54
|
target.autoexec = function() {};
|
44
55
|
target.dependencies = dependencies;
|
45
56
|
target.init = function(options) {
|
57
|
+
options || (options = {
|
58
|
+
idempotent: false,
|
59
|
+
callee: null
|
60
|
+
});
|
46
61
|
if (!(options.idempotent && this.loaded)) {
|
47
|
-
require(dependencies);
|
62
|
+
AutoexecBat.require(dependencies);
|
48
63
|
if (typeof this.autoexec === 'function') {
|
49
64
|
this.autoexec(options.callee);
|
50
65
|
}
|
@@ -58,19 +73,9 @@
|
|
58
73
|
};
|
59
74
|
return block(target, top);
|
60
75
|
},
|
61
|
-
require: function(dependencies) {
|
62
|
-
var lib, _i, _len, _results;
|
63
|
-
if (dependencies) {
|
64
|
-
_results = [];
|
65
|
-
for (_i = 0, _len = dependencies.length; _i < _len; _i++) {
|
66
|
-
lib = dependencies[_i];
|
67
|
-
_results.push(AutoexecBat.initializeModule(lib));
|
68
|
-
}
|
69
|
-
return _results;
|
70
|
-
}
|
71
|
-
},
|
72
76
|
namespace: function(name) {
|
73
77
|
var item, target, _i, _len, _ref;
|
78
|
+
|
74
79
|
target = root;
|
75
80
|
_ref = name.split('.');
|
76
81
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
@@ -81,6 +86,7 @@
|
|
81
86
|
},
|
82
87
|
findModule: function(ns) {
|
83
88
|
var item, module, _i, _len;
|
89
|
+
|
84
90
|
if (!ns) {
|
85
91
|
return;
|
86
92
|
}
|
@@ -101,6 +107,7 @@
|
|
101
107
|
},
|
102
108
|
initializeModule: function(nameOrModule, options) {
|
103
109
|
var module;
|
110
|
+
|
104
111
|
module = typeof nameOrModule === "string" ? AutoexecBat.findModule(nameOrModule) : nameOrModule;
|
105
112
|
if (typeof module !== 'undefined' && typeof module.init !== 'undefined') {
|
106
113
|
return module.init(options);
|
@@ -108,11 +115,14 @@
|
|
108
115
|
},
|
109
116
|
run: function(name, options) {
|
110
117
|
var module;
|
118
|
+
|
111
119
|
module = AutoexecBat.findModule(name);
|
112
120
|
return AutoexecBat.initializeModule(module, options);
|
113
121
|
}
|
114
122
|
};
|
115
123
|
|
124
|
+
root = typeof exports !== "undefined" && exports !== null ? exports : window;
|
125
|
+
|
116
126
|
root.AutoexecBat = AutoexecBat;
|
117
127
|
|
118
128
|
root.define = AutoexecBat.define;
|
@@ -1,27 +1,28 @@
|
|
1
|
-
root = exports ? window
|
2
|
-
|
3
1
|
AutoexecBat =
|
4
2
|
topLevel: "App"
|
5
|
-
debug:
|
6
|
-
|
7
|
-
|
3
|
+
debug: false
|
4
|
+
autoRequire: false
|
5
|
+
|
8
6
|
log: (msg) ->
|
9
7
|
console?.log msg if AutoexecBat.debug
|
10
8
|
|
9
|
+
require: (dependencies) ->
|
10
|
+
(AutoexecBat.initializeModule(lib) for lib in dependencies) if dependencies
|
11
|
+
|
11
12
|
define: (name) ->
|
12
13
|
dependencies = []
|
13
14
|
dependencies.push AutoexecBat.autoRequire if AutoexecBat.autoRequire && name != AutoexecBat.autoRequire
|
14
15
|
|
15
16
|
for arg in arguments
|
16
|
-
if typeof arg is "object"
|
17
|
+
if typeof arg is "object"
|
17
18
|
for module in arg
|
18
19
|
dependencies.push module unless module in dependencies && module != name
|
19
20
|
|
20
|
-
else if typeof arg is "function"
|
21
|
+
else if typeof arg is "function"
|
21
22
|
block = arg
|
22
23
|
|
23
24
|
block ?= -> # empty function
|
24
|
-
top = AutoexecBat.topLevel
|
25
|
+
top = AutoexecBat.topLevel
|
25
26
|
target = AutoexecBat.namespace name
|
26
27
|
|
27
28
|
target.name = name
|
@@ -29,17 +30,18 @@ AutoexecBat =
|
|
29
30
|
target.autoexec = -> # make sure the autoexec function exists
|
30
31
|
target.dependencies = dependencies
|
31
32
|
target.init = (options) ->
|
33
|
+
options or=
|
34
|
+
idempotent: false
|
35
|
+
callee: null
|
36
|
+
|
32
37
|
unless options.idempotent and @loaded
|
33
|
-
require dependencies
|
38
|
+
AutoexecBat.require dependencies
|
34
39
|
@autoexec(options.callee) if typeof @autoexec is 'function'
|
35
40
|
if options.idempotent
|
36
41
|
@autoexec = -> AutoexecBat.log "Module already initialized"
|
37
42
|
@loaded = true
|
38
43
|
|
39
|
-
block target, top
|
40
|
-
|
41
|
-
require: (dependencies) ->
|
42
|
-
(AutoexecBat.initializeModule(lib) for lib in dependencies) if dependencies
|
44
|
+
block target, top
|
43
45
|
|
44
46
|
namespace: (name) ->
|
45
47
|
target = root
|
@@ -66,6 +68,7 @@ AutoexecBat =
|
|
66
68
|
|
67
69
|
|
68
70
|
# Globals
|
71
|
+
root = exports ? window
|
69
72
|
root.AutoexecBat = AutoexecBat
|
70
73
|
root.define = AutoexecBat.define
|
71
74
|
root.require = AutoexecBat.require
|
data/lib/autoexec_bat/version.rb
CHANGED
@@ -0,0 +1,84 @@
|
|
1
|
+
chai = require 'chai'
|
2
|
+
jack = require 'jack'
|
3
|
+
|
4
|
+
chai.use jack.chai
|
5
|
+
should = chai.should()
|
6
|
+
expect = chai.expect
|
7
|
+
|
8
|
+
autoexec = require '../lib/assets/javascripts/autoexec_bat'
|
9
|
+
|
10
|
+
describe 'AutoexecBat', ->
|
11
|
+
|
12
|
+
describe "global variables", ->
|
13
|
+
it "should define AutoexecBat", -> autoexec.AutoexecBat.should.be.a 'object'
|
14
|
+
it "should have a define function", -> autoexec.define.should.be.a 'function'
|
15
|
+
it "should have a require function", -> autoexec.require.should.be.a 'function'
|
16
|
+
it "should have a namespace function", -> autoexec.namespace.should.be.a 'function'
|
17
|
+
|
18
|
+
describe "namespace", ->
|
19
|
+
|
20
|
+
it "declares function namespaces", ->
|
21
|
+
autoexec.namespace('App.Foo.Bar').should.equal autoexec.App.Foo.Bar
|
22
|
+
autoexec.namespace('App.Foo').should.equal autoexec.App.Foo
|
23
|
+
autoexec.namespace('App.Foo').should.be.a 'object'
|
24
|
+
|
25
|
+
describe "define", ->
|
26
|
+
beforeEach ->
|
27
|
+
autoexec.define 'App.Foo', (exports) ->
|
28
|
+
exports.autoexec = ->
|
29
|
+
"do something"
|
30
|
+
|
31
|
+
privateMethod = ->
|
32
|
+
'I am hidden'
|
33
|
+
|
34
|
+
it "defines a function that can be called", ->
|
35
|
+
autoexec.App.Foo.autoexec().should.equal "do something"
|
36
|
+
|
37
|
+
it "can be executed", ->
|
38
|
+
autoexec.AutoexecBat.run('App.Foo').should.equal true
|
39
|
+
|
40
|
+
it "private methods are unavailable", ->
|
41
|
+
expect(autoexec.App.Foo.privateMethod).to.not.be.ok
|
42
|
+
|
43
|
+
it "should not be loaded", ->
|
44
|
+
autoexec.App.Foo.loaded.should.equal false
|
45
|
+
|
46
|
+
describe "dependencies", ->
|
47
|
+
it "should be empty when not defined", ->
|
48
|
+
autoexec.App.Foo.dependencies.should.be.empty
|
49
|
+
|
50
|
+
it "can be specified", ->
|
51
|
+
autoexec.define 'App.Bar', ["App.Foo"], (exports) ->
|
52
|
+
autoexec.App.Bar.dependencies.should.deep.equal(["App.Foo"])
|
53
|
+
|
54
|
+
it "ignores non-existing dependencies", ->
|
55
|
+
autoexec.define 'App.Bar', ["App.Bullshit"], (exports) ->
|
56
|
+
autoexec.App.Bar.dependencies.should =~ ['App.Bullshit']
|
57
|
+
|
58
|
+
describe "autoRequire", ->
|
59
|
+
|
60
|
+
it "should be disabled by default", ->
|
61
|
+
autoexec.AutoexecBat.autoRequire.should.not.be.ok
|
62
|
+
autoexec.App.Foo.dependencies.should.be.empty
|
63
|
+
|
64
|
+
it "autoRequired modules are automatically added to the dependency list", ->
|
65
|
+
autoexec.AutoexecBat.autoRequire = "App.Always"
|
66
|
+
autoexec.define "App.Bar", -> exports.autoexec = -> 'something here'
|
67
|
+
autoexec.App.Bar.dependencies.should.include "App.Always"
|
68
|
+
|
69
|
+
it "has support for idempotency"
|
70
|
+
|
71
|
+
it "knows the callee"
|
72
|
+
|
73
|
+
describe "require", ->
|
74
|
+
beforeEach ->
|
75
|
+
autoexec.define 'App.Foo', (exports) ->
|
76
|
+
exports.autoexec = -> "do something"
|
77
|
+
|
78
|
+
it "loads the modules"
|
79
|
+
|
80
|
+
it "ignores undefined modules", ->
|
81
|
+
autoexec.require(["App.BareFoot"])
|
82
|
+
|
83
|
+
it "ignores empty argument", ->
|
84
|
+
autoexec.require()
|
data/test/mocha.opts
ADDED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autoexec_bat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gudleik Rasch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
12
|
-
dependencies:
|
11
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: Autoexecution of javascript based on data attribute
|
14
28
|
email:
|
15
29
|
- gudleik@gmail.com
|
@@ -28,6 +42,8 @@ files:
|
|
28
42
|
- lib/autoexec_bat.rb
|
29
43
|
- lib/autoexec_bat/helper.rb
|
30
44
|
- lib/autoexec_bat/version.rb
|
45
|
+
- test/autoexecBatTest.coffee
|
46
|
+
- test/mocha.opts
|
31
47
|
homepage: https://github.com/Skalar/autoexec_bat
|
32
48
|
licenses: []
|
33
49
|
metadata: {}
|
@@ -47,9 +63,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
63
|
version: '0'
|
48
64
|
requirements: []
|
49
65
|
rubyforge_project:
|
50
|
-
rubygems_version: 2.0.
|
66
|
+
rubygems_version: 2.0.2
|
51
67
|
signing_key:
|
52
68
|
specification_version: 4
|
53
69
|
summary: Autoexecution of javascript based on data attribute
|
54
|
-
test_files:
|
55
|
-
|
70
|
+
test_files:
|
71
|
+
- test/autoexecBatTest.coffee
|
72
|
+
- test/mocha.opts
|