voltron 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f75ee10db1c67be76630fbde0171570e47148831be889eb03e88c6bac48d4dc6
4
+ data.tar.gz: 3ce73bd1a9018ec0cd5a5141245388fb9cb779b742964b21bf6e7caa180c19c8
5
+ SHA512:
6
+ metadata.gz: 85234a7d92da9c47826948272ffaedefce7a836a5e3679bd90000eeb127c72460fbc8a872264c3aa68c6002d6f4ff29579d0e47415420fba8db2d6c2e2083ae2
7
+ data.tar.gz: '08d7f7db6cacce3aff55bc7fdaf531ffdfb37eac0ba7dffd0c55ff658cb47dec68e6dae6301ed58368f1efc446e4d18b5344f65af4d4ad91a56faf5c681bec59'
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ tmp/
10
+ log/
11
+ voltron-*.gem
12
+ *.bak
13
+ *.sqlite3
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ - 2.3.1
6
+ - 2.3.3
7
+ - 2.4.1
8
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at eric.hainer@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in voltron.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'sass'
8
+ end
9
+
10
+ group :test do
11
+ gem 'coveralls', require: false
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Eric
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Eric Hainer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ [![Coverage Status](https://coveralls.io/repos/github/ehainer/voltron/badge.svg?branch=master)](https://coveralls.io/github/ehainer/voltron?branch=master)
2
+ [![Build Status](https://travis-ci.org/ehainer/voltron.svg?branch=master)](https://travis-ci.org/ehainer/voltron)
3
+ [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)
4
+
5
+ # Voltron
6
+
7
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/voltron`. To experiment with that code, run `bin/console` for an interactive prompt.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'voltron', '~> 0.2.6'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install voltron
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/voltron. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
32
+
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [GNU General Public License](https://www.gnu.org/licenses/gpl-3.0.en.html).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,282 @@
1
+ window.Voltron = (function(cmd){
2
+ var command = cmd.split('/', 2);
3
+ var module = command[0];
4
+ var method = command[1] || 'initialize';
5
+
6
+ if(Voltron.hasModule(module)){
7
+ var mod = Voltron.getModule(module);
8
+ if($.isFunction(mod[method])){
9
+ return mod[method].apply(mod, Array.prototype.slice.call(arguments, 1));
10
+ }else{
11
+ Voltron.debug('error', 'Module %o does not define the method %o', module, method);
12
+ }
13
+ }else{
14
+ Voltron.debug('error', 'Module with name %o does not exist.', module);
15
+ }
16
+ return false;
17
+ });
18
+
19
+ $.extend(Voltron, {
20
+ _config: {},
21
+ _observer: {},
22
+ _modules: {},
23
+ _classes: {},
24
+ _logLevels: ['debug', 'info', 'warn', 'error', 'fatal', 'unknown'],
25
+ _logMapping: {
26
+ log: 0,
27
+ info: 1,
28
+ warn: 2,
29
+ error: 3
30
+ },
31
+
32
+ _inherited: {
33
+ _name: null,
34
+
35
+ name: function(){
36
+ return this._name;
37
+ },
38
+
39
+ getDependencies: function(){
40
+ return this._dependencies;
41
+ },
42
+
43
+ canReceiveEvents: function(){
44
+ return Voltron.canRun(this.name());
45
+ },
46
+ },
47
+
48
+ initialize: function(conf){
49
+ if(!conf) conf = {};
50
+ $.extend(this._config, conf);
51
+
52
+ // Try and create a module with the name of the current controller
53
+ //if(this.hasModule(this.getConfig('controller'))){
54
+ // this.ready(Voltron.loadModule, this.getConfig('controller'));
55
+ //}
56
+ },
57
+
58
+ // When ready, fire the callback function, passing in any additional args
59
+ ready: function(callback, args){
60
+ $(document).ready(function(){
61
+ if(!$.isArray(args)) args = [args];
62
+ callback.apply(Voltron, args);
63
+ });
64
+ return this;
65
+ },
66
+
67
+ debug: function(){
68
+ // IE/Edge only expose console when dev tools is open. Check for it's existence before attempting to call log/warn/error/info
69
+ if(this.isDebugging() && console){
70
+ var logLevelDefined = arguments.length > 2 && typeof arguments[1] == 'number';
71
+ var method = arguments[0];
72
+ var level = (logLevelDefined ? arguments[1] : this._logMapping[method]);
73
+ var args = Array.prototype.slice.call(arguments, (logLevelDefined ? 2 : 1));
74
+ if(level >= this.getLogLevel()){
75
+ console[method].apply(console, args);
76
+ }
77
+ }
78
+ return this;
79
+ },
80
+
81
+ getLogLevel: function(){
82
+ var level = this.getConfig('log_level', 0);
83
+ if(typeof level == 'number'){
84
+ return (level >= 0 && level <= 5 ? level : 5); // If in range, return the number, otherwise: 'unknown'
85
+ }
86
+ var index = this._logLevels.indexOf(level);
87
+ return (index >= 0 && index <= 5 ? index : 5); // Return the index of the defined level, otherwise: 'unknown'
88
+ },
89
+
90
+ getBaseUrl: function(){
91
+ if(!location.origin) location.origin = location.protocol + '//' + location.host;
92
+ return location.origin;
93
+ },
94
+
95
+ getPath: function(url){
96
+ if(!url) url = window.location.href;
97
+ return url.replace(this.getBaseUrl(), '');
98
+ },
99
+
100
+ // Get a config value, optionally define a default value in the event the config param is not defined
101
+ getConfig: function(key, def){
102
+ var out = this._config;
103
+ if(!key) return out;
104
+ var paths = key.replace(/(^\/+)|(\/+$)/g, '').split('/');
105
+
106
+ $.each(paths, function(index, path){
107
+ if(out[path] != undefined){
108
+ out = out[path];
109
+ }else{
110
+ out = def;
111
+ return false;
112
+ }
113
+ });
114
+
115
+ return out;
116
+ },
117
+
118
+ canRun: function(name){
119
+ var module = this._modules[name.toLowerCase()];
120
+ return module['run'] === true || ((this.isController(module['run']) || this.isController(name)) && module['run'] !== false);
121
+ },
122
+
123
+ // Set a config value. Supports xpath syntax to change nested key values
124
+ // i.e. setConfig('a/b/c', true); will change the value of "c" to true
125
+ setConfig: function(key, value){
126
+ var out = this._config;
127
+ var paths = key.replace(/(^\/+)|(\/+$)/g, '').split('/');
128
+ var change = paths.pop();
129
+
130
+ $.each(paths, function(index, path){
131
+ if(out[path] != undefined){
132
+ out = out[path];
133
+ }else{
134
+ out = out[path] = {};
135
+ }
136
+ });
137
+
138
+ out[change] = value;
139
+ return this;
140
+ },
141
+
142
+ // Similar to setConfig, except this will instead treat the config `key` value as an array, and add the value to it
143
+ addConfig: function(key, value){
144
+ if(!this._config[key]) this._config[key] = [];
145
+ this._config[key].push(value);
146
+ return this;
147
+ },
148
+
149
+ getAuthToken: function(){
150
+ return this.getConfig('auth_token', '');
151
+ },
152
+
153
+ // Are we in debug mode?
154
+ isDebugging: function(){
155
+ return this.getConfig('debug', false);
156
+ },
157
+
158
+ isController: function(controllers){
159
+ return $.map([controllers].flatten().compact(), function(c){ return c.toLowerCase(); }).includes(this.getConfig('controller'));
160
+ },
161
+
162
+ // Dispatch an event, optionally providing some additional params to pass to the event listener callback
163
+ dispatch: function(event, params, modules){
164
+ if(!$.isPlainObject(params)) params = {};
165
+ if(!modules) modules = Object.keys(this._modules);
166
+ var method = Voltron('Dispatch/getDispatchMethod', event, '');
167
+ params = $.extend(true, { element: null, event: $.Event(event), data: {} }, params);
168
+
169
+ $.each([modules].flatten(), $.proxy(function(index, module){
170
+ var mod = this.getModule(module);
171
+ if(mod){
172
+ if($.isFunction(mod[method])){
173
+ Voltron.debug('info', 'Dispatching %o to %o module with observer object: %o', method, mod.name(), params);
174
+ mod[method].call(mod, params);
175
+ }else{
176
+ Voltron.debug('log', 'Attempted to dispatch %o in %o module with observer object: %o', method, mod.name(), params);
177
+ }
178
+ }
179
+ }, this));
180
+ return null;
181
+ },
182
+
183
+ // Check if a module with the given name has been added
184
+ hasModule: function(id){
185
+ return this._modules[id.toLowerCase()] && $.isFunction(this._modules[id.toLowerCase()]['module']);
186
+ },
187
+
188
+ // Add a module, specifying the name (id), the module itself (should be an object or a function that returns such)
189
+ // Optionally provide `true`, or an array of controller names as the last argument to auto instantiate when added either
190
+ // all the time (if true), or on the specified controllers
191
+ addModule: function(){
192
+ var id = arguments[0];
193
+ var depends = $.isFunction(arguments[1]) ? [] : arguments[1];
194
+ var module = $.isFunction(arguments[1]) ? arguments[1] : arguments[2];
195
+ var run = $.isFunction(arguments[1]) ? arguments[2] : arguments[3];
196
+
197
+ if(!this.hasModule(id)){
198
+ id = $.camelCase(id).replace(/\b[a-z]/g, function(letter){
199
+ return letter.toUpperCase();
200
+ });
201
+ this[id] = module;
202
+ this._modules[id.toLowerCase()] = { module: module, run: run, depends: [depends].flatten() };
203
+ }
204
+
205
+ this.ready(function(){
206
+ var sortedModules = Object.keys(Voltron._modules);
207
+ sortedModules.sort();
208
+
209
+ for(var i=0; i<sortedModules.length; i++){
210
+ this.loadModule(sortedModules[i]);
211
+ }
212
+ });
213
+ return this;
214
+ },
215
+
216
+ // Get a module with the given name from the list of modules
217
+ getModule: function(name, args){
218
+ var id = name.toLowerCase();
219
+ var module = this._modules[id];
220
+
221
+ name = $.camelCase(name).replace(/\b[a-z]/g, function(letter){
222
+ return letter.toUpperCase();
223
+ });
224
+
225
+ if(this.hasModule(id)){
226
+ return this.loadModule(name, true, args);
227
+ }else{
228
+ this.debug('warn', 'Module with name %o does not exist.', name);
229
+ }
230
+ return false;
231
+ },
232
+
233
+ loadModule: function(name, force, args){
234
+ var id = name.toLowerCase();
235
+
236
+ name = $.camelCase(name).replace(/\b[a-z]/g, function(letter){
237
+ return letter.toUpperCase();
238
+ });
239
+
240
+ if(!args) args = [];
241
+ if(!this._classes[id]){
242
+ var module = new this._modules[id]['module']($);
243
+ // Add some inherited methods... shortcuts, if you will
244
+ module = $.extend(module, this._inherited);
245
+ // Add the name to the module
246
+ module._name = name;
247
+ // Add the dependencies to the module
248
+ module._dependencies = this._modules[id]['depends'];
249
+
250
+ if(force || this.canRun(name)){
251
+ this._classes[id] = module;
252
+
253
+ var dependencies = this._classes[id].getDependencies();
254
+ for(var i=0; i<dependencies.length; i++){
255
+ if(dependencies[i] == '*'){
256
+ var sortedModules = Object.keys(this._modules);
257
+ sortedModules.sort();
258
+ for(var j=0; j<sortedModules.length; j++){
259
+ this.loadModule(sortedModules[j], true);
260
+ }
261
+ }else{
262
+ this.loadModule(dependencies[i], true);
263
+ }
264
+ }
265
+
266
+ // If there is an initialize function, call it, dispatching before/after events
267
+ if($.isFunction(this._classes[id].initialize)){
268
+ this._classes[id].initialize.apply(this._classes[id], args);
269
+ }
270
+ // Tell the user we've created the module
271
+ this.debug('info', 'Instantiated %o', name);
272
+ }
273
+ }
274
+ return this._classes[id]
275
+ }
276
+ });
277
+
278
+ if(typeof V != 'undefined'){
279
+ if(console) console.warn('The window variable %o is already defined, so shortcut to %o will not be defined.', 'V', 'Voltron');
280
+ }else{
281
+ window.V = window.Voltron;
282
+ }