radiojs-rails 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a45da9e186a79fcbf7bfac1ffa4c62c62f2f475
4
+ data.tar.gz: 3bdb487f78244f661f675d924062aedb2e0ab74e
5
+ SHA512:
6
+ metadata.gz: e6e5b5b0c10da52bc33b44c27ca79401525c22a2d48a100559b0736d5bcb850dad5fb6c9007ed7deadb79385f9b7aec2cbb23f78f54d376f3496a40097f27a32
7
+ data.tar.gz: a0e32ecb2ddc3d422d8ba85225391614a1e207cfed48f8a33f5cb72d692aaf732024bd8c5a3b0f056d3510002ff933c9aa167e97f7fd385d386f1d3a3c802bd9
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RadiojsRails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
@@ -0,0 +1,4 @@
1
+ require "radiojs-rails/engine"
2
+
3
+ module RadiojsRails
4
+ end
@@ -0,0 +1,4 @@
1
+ module RadiojsRails
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RadiojsRails
2
+ VERSION = '0.2.1'
3
+ end
@@ -0,0 +1,176 @@
1
+ /**
2
+ Radio.js - Chainable, Dependency Free Publish/Subscribe for Javascript
3
+ http://radio.uxder.com
4
+ Author: Scott Murphy 2011
5
+ twitter: @hellocreation, github: uxder
6
+
7
+ Permission is hereby granted, free of charge, to any person
8
+ obtaining a copy of this software and associated documentation
9
+ files (the "Software"), to deal in the Software without
10
+ restriction, including without limitation the rights to use,
11
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the
13
+ Software is furnished to do so, subject to the following
14
+ conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26
+ OTHER DEALINGS IN THE SOFTWARE.
27
+ */
28
+ (function (name, global, definition) {
29
+ if (typeof module !== 'undefined') module.exports = definition(name, global);
30
+ else if (typeof define === 'function' && typeof define.amd === 'object') define(definition);
31
+ else global[name] = definition(name, global);
32
+ })('radio', this, function (name, global) {
33
+
34
+ "use strict";
35
+
36
+ /**
37
+ * Main Wrapper for radio.$ and create a function radio to accept the channelName
38
+ * @param {String} channelName topic of event
39
+ */
40
+ function radio(channelName) {
41
+ arguments.length ? radio.$.channel(channelName) : radio.$.reset();
42
+ return radio.$;
43
+ }
44
+
45
+ radio.$ = {
46
+ version: '0.2',
47
+ channelName: "",
48
+ channels: [],
49
+
50
+ /**
51
+ * Reset global state, by removing all channels
52
+ * @example
53
+ * radio()
54
+ */
55
+ reset: function() {
56
+ radio.$.channelName = "";
57
+ radio.$.channels = [];
58
+ },
59
+
60
+ /**
61
+ * Broadcast (publish)
62
+ * Iterate through all listeners (callbacks) in current channel and pass arguments to subscribers
63
+ * @param arguments data to be sent to listeners
64
+ * @example
65
+ * //basic usage
66
+ * radio('channel1').broadcast('my message');
67
+ * //send an unlimited number of parameters
68
+ * radio('channel2').broadcast(param1, param2, param3 ... );
69
+ */
70
+ broadcast: function() {
71
+ var i, c = this.channels[this.channelName],
72
+ l = c.length,
73
+ subscriber, callback, context;
74
+ //iterate through current channel and run each subscriber
75
+ for (i = 0; i < l; i++) {
76
+ subscriber = c[i];
77
+ //if subscriber was an array, set the callback and context.
78
+ if ((typeof(subscriber) === 'object') && (subscriber.length)) {
79
+ callback = subscriber[0];
80
+ //if user set the context, set it to the context otherwise, it is a globally scoped function
81
+ context = subscriber[1] || global;
82
+ }
83
+ callback.apply(context, arguments);
84
+ }
85
+ return this;
86
+ },
87
+
88
+ /**
89
+ * Create the channel if it doesn't exist and set the current channel/event name
90
+ * @param {String} name the name of the channel
91
+ * @example
92
+ * radio('channel1');
93
+ */
94
+ channel: function(name) {
95
+ var c = this.channels;
96
+ //create a new channel if it doesn't exists
97
+ if (!c[name]) c[name] = [];
98
+ this.channelName = name;
99
+ return this;
100
+ },
101
+
102
+ /**
103
+ * Add Subscriber to channel
104
+ * Take the arguments and add it to the this.channels array.
105
+ * @param {Function|Array} arguments list of callbacks or arrays[callback, context] separated by commas
106
+ * @example
107
+ * //basic usage
108
+ * var callback = function() {};
109
+ * radio('channel1').subscribe(callback);
110
+ *
111
+ * //subscribe an endless amount of callbacks
112
+ * radio('channel1').subscribe(callback, callback2, callback3 ...);
113
+ *
114
+ * //adding callbacks with context
115
+ * radio('channel1').subscribe([callback, context],[callback1, context], callback3);
116
+ *
117
+ * //subscribe by chaining
118
+ * radio('channel1').subscribe(callback).radio('channel2').subscribe(callback).subscribe(callback2);
119
+ */
120
+ subscribe: function() {
121
+ var a = arguments,
122
+ c = this.channels[this.channelName],
123
+ i, l = a.length,
124
+ p, ai = [];
125
+
126
+ //run through each arguments and subscribe it to the channel
127
+ for (i = 0; i < l; i++) {
128
+ ai = a[i];
129
+ //if the user sent just a function, wrap the fucntion in an array [function]
130
+ p = (typeof(ai) === "function") ? [ai] : ai;
131
+ if ((typeof(p) === 'object') && (p.length)) c.push(p);
132
+ }
133
+ return this;
134
+ },
135
+
136
+ /**
137
+ * Remove subscriber from channel
138
+ * Take arguments with functions and unsubscribe it if there is a match against existing subscribers.
139
+ * @param {Function} arguments callbacks separated by commas
140
+ * @example
141
+ * //basic usage
142
+ * radio('channel1').unsubscribe(callback);
143
+ * //you can unsubscribe as many callbacks as you want
144
+ * radio('channel1').unsubscribe(callback, callback2, callback3 ...);
145
+ * //removing callbacks with context is the same
146
+ * radio('channel1').subscribe([callback, context]).unsubscribe(callback);
147
+ */
148
+ unsubscribe: function() {
149
+ var a = arguments,
150
+ i, j, c = this.channels[this.channelName],
151
+ l = a.length,
152
+ cl = c.length,
153
+ offset = 0,
154
+ jo;
155
+ //loop through each argument
156
+ for (i = 0; i < l; i++) {
157
+ //need to reset vars that change as the channel array items are removed
158
+ offset = 0;
159
+ cl = c.length;
160
+ //loop through the channel
161
+ for (j = 0; j < cl; j++) {
162
+ jo = j - offset;
163
+ //if there is a match with the argument and the channel function, unsubscribe it from the channel array
164
+ if (c[jo][0] === a[i]) {
165
+ //unsubscribe matched item from the channel array
166
+ c.splice(jo, 1);
167
+ offset++;
168
+ }
169
+ }
170
+ }
171
+ return this;
172
+ }
173
+ };
174
+
175
+ return radio;
176
+ });
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiojs-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Knowledge Foundry
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ description: |
42
+ Radio.js is a small dependency-free publish/subscribe javascript library. Use it
43
+ to implement the observer pattern in your code to help decouple your application
44
+ architecture for greater maintainability.
45
+ email:
46
+ - yuva@codemancers.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - MIT-LICENSE
52
+ - Rakefile
53
+ - lib/radiojs-rails.rb
54
+ - lib/radiojs-rails/engine.rb
55
+ - lib/radiojs-rails/version.rb
56
+ - vendor/assets/javascripts/radio.js
57
+ homepage: http://github.com/kfoundry/radiojs-rails
58
+ licenses: []
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.2.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Radio js for rails asset pipeline
80
+ test_files: []