stormfront-rails 0.1.0 → 0.2.3

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/lib/stormfront/rails/version.rb +2 -2
  4. data/lib/stormfront/rails.rb +2 -0
  5. data/stormfront-rails.gemspec +3 -3
  6. data/vendor/assets/javascripts/src/handlebars.js +4604 -0
  7. data/vendor/assets/javascripts/src/stormfront.js +1137 -0
  8. data/vendor/assets/javascripts/stormfront.js +3 -32
  9. metadata +24 -47
  10. data/vendor/assets/javascripts/stormfront/Alert.js +0 -17
  11. data/vendor/assets/javascripts/stormfront/Container.js +0 -31
  12. data/vendor/assets/javascripts/stormfront/Entity.js +0 -53
  13. data/vendor/assets/javascripts/stormfront/Errors.js +0 -25
  14. data/vendor/assets/javascripts/stormfront/KeyboardEvents.js +0 -52
  15. data/vendor/assets/javascripts/stormfront/Layout.js +0 -60
  16. data/vendor/assets/javascripts/stormfront/List.js +0 -123
  17. data/vendor/assets/javascripts/stormfront/MouseEvents.js +0 -146
  18. data/vendor/assets/javascripts/stormfront/Namespaces.js +0 -5
  19. data/vendor/assets/javascripts/stormfront/Overlay.js +0 -178
  20. data/vendor/assets/javascripts/stormfront/Reducer.js +0 -9
  21. data/vendor/assets/javascripts/stormfront/Request.js +0 -39
  22. data/vendor/assets/javascripts/stormfront/View.js +0 -55
  23. data/vendor/assets/javascripts/stormfront/ViewBase.js +0 -57
  24. data/vendor/assets/javascripts/stormfront/mixin/Dispatch.js +0 -19
  25. data/vendor/assets/javascripts/stormfront/mixin/Other.js +0 -25
  26. data/vendor/assets/javascripts/stormfront/support/Chaperone.js +0 -69
  27. data/vendor/assets/javascripts/stormfront/support/Template.js +0 -75
  28. data/vendor/assets/javascripts/stormfront/types/Arguments.js +0 -27
  29. data/vendor/assets/javascripts/stormfront/types/Class.js +0 -25
  30. data/vendor/assets/javascripts/stormfront/types/Hash.js +0 -23
  31. data/vendor/assets/javascripts/stormfront/types/Number.js +0 -15
  32. data/vendor/assets/javascripts/stormfront/types/Response.js +0 -31
  33. data/vendor/assets/javascripts/stormfront/types/String.js +0 -44
  34. data/vendor/assets/javascripts/stormfront/types/Time.js +0 -29
@@ -1,9 +0,0 @@
1
- Stormfront.Reducer = Stormfront.Class.extend({
2
- type: Stormfront.Errors.NOT_IMPLEMENTED,
3
- initialize: function(){
4
- _.extend(this, Stormfront.Mixin.Dispatch);
5
- },
6
- execute: function(model, event){
7
- throw Stormfront.Errors.UseCases.NOT_IMPLEMENTED;
8
- }
9
- });
@@ -1,39 +0,0 @@
1
- Stormfront.Request = function(model, request, options){
2
- var startTime = stormfront.time.now();
3
- var overlay = new Stormfront.Overlay(options);
4
- function tryRequest(){
5
- return shouldWait() ? delayRequest() : sendRequest();
6
- }
7
- function shouldWait(){
8
- //TODO: This is a dependency upon the Indigo behavior
9
- return options.wait && $.xhrPool.length > 0;
10
- }
11
- function delayRequest(){
12
- if (stormfront.time.now() - startTime < 5000)
13
- setTimeout(tryRequest, 1000);
14
- else
15
- overlay.error('Request timed out. Please try again soon.');
16
- return null;
17
- }
18
- function sendRequest(){
19
- function onComplete(){
20
- removeListeners();
21
- overlay.close();
22
- }
23
- function onError(model, xhr){
24
- removeListeners();
25
- overlay.error(xhr);
26
- }
27
- function removeListeners(){
28
- model.off('error', onError);
29
- model.off('sync', onComplete);
30
- model.off('invalid', onComplete);
31
- }
32
- model.once('invalid', onError);
33
- model.once('error', onError);
34
- model.once('sync', onComplete);
35
-
36
- return request.call(model, options.args, options.options);
37
- }
38
- return tryRequest();
39
- };
@@ -1,55 +0,0 @@
1
- Stormfront.View = Stormfront.ViewBase.extend({
2
- initialize: function(options){
3
- Stormfront.ViewBase.prototype.initialize.call(this, options);
4
- this.when = this.when || { };
5
- this.addPublisher(this);
6
- this.addSubscriber(this.when);
7
- this.transition.apply(this, stormfront.arguments(arguments).prepend('initializing').get());
8
- },
9
- render: function(){
10
- Stormfront.ViewBase.prototype.render.call(this);
11
- this.transition.apply(this, stormfront.arguments(arguments).prepend('rendering').get());
12
- return this;
13
- },
14
- addPublisher: function(publisher, identity){
15
- function notify(event){
16
- var args = stormfront.arguments(arguments).skip(1).get();
17
- function executeHandler(subscriber){
18
- var handler = stormfront.hash(subscriber).findNestedValue(event.split(':'));
19
- if (_.isFunction(handler))
20
- handler.apply(this, args);
21
- }
22
- _.each(this._subscribers, executeHandler, this);
23
- }
24
- function prepend(identity){
25
- return function(event){
26
- var newEvent = identity + ':' + event;
27
- var args = stormfront.arguments(arguments).skip(1).prepend(newEvent).get();
28
- notify.apply(this, args);
29
- }
30
- }
31
- if (publisher === this)
32
- this.listenTo(publisher, 'transition', notify);
33
- else if (this.model && publisher === this.model)
34
- this.listenTo(publisher, 'all', prepend('model'));
35
- else if (this.collection && publisher === this.collection)
36
- this.listenTo(publisher, 'all', prepend('collection'));
37
- else if (publisher.className)
38
- this.listenTo(publisher, 'transition', prepend(publisher.getIdentity()));
39
- else
40
- this.listenTo(publisher, 'all', prepend(identity));
41
- },
42
- addSubscriber: function(whenBlock){
43
- this._subscribers = this._subscribers || [];
44
- if (whenBlock)
45
- this._subscribers.push(whenBlock);
46
- },
47
- transition: function(){
48
- var args = stormfront.arguments(arguments).prepend('transition').get();
49
- this.trigger.apply(this, args);
50
- },
51
- close: function(){
52
- this.transition.apply(this, stormfront.arguments(arguments).prepend('closing').get());
53
- Stormfront.ViewBase.prototype.close.call(this);
54
- }
55
- });
@@ -1,57 +0,0 @@
1
- Stormfront.ViewBase = Backbone.View.extend({
2
- initialize: function(){
3
- this.errors = [];
4
- },
5
- render: function(){
6
- try {
7
- this.$el.html(new Stormfront.Template(this).render());
8
- }
9
- catch(e) {
10
- this.handleException(e);
11
- }
12
- return this;
13
- },
14
- getViewModel: function(){
15
- return this.model ? this.model.toJSON ? this.model.toJSON() : this.model : {};
16
- },
17
- handleException: function(exception){
18
- if (exception.innerException)
19
- console.warn(exception.message, exception.innerException);
20
- else
21
- console.warn(exception.message);
22
-
23
- this.handleError(exception.message);
24
- },
25
- handleError: function(message){
26
- if (_.contains(this.errors, message))
27
- return;
28
- this.notifyUser(message);
29
- },
30
- notifyUser: function(message){
31
- this.alert && this.alert.close();
32
-
33
- this.errors.push(message);
34
- this.alert = new Stormfront.Alert({
35
- model: {
36
- summary: Stormfront.Errors.FEEDBACK,
37
- details: this.errors.join(', ')
38
- }
39
- });
40
-
41
- this.listenTo(this.alert, 'closing', this.removeNotification);
42
- this.$el.append(this.alert.render().$el);
43
- },
44
- removeNotification: function(){
45
- this.errors = [];
46
- this.stopListening(this.alert);
47
- },
48
- getIdentity: function(){
49
- return stormfront.string(this.className).firstWord();
50
- },
51
- toString: function(){
52
- return this.getIdentity();
53
- },
54
- close: function(){
55
- this.remove();
56
- }
57
- });
@@ -1,19 +0,0 @@
1
- Stormfront.Mixin.Dispatch = {
2
- hasEvents: function(){
3
- return this.trigger;
4
- },
5
- addEvents: function(){
6
- $.extend(this, Backbone.Events);
7
- },
8
- streamlineDispatch: function(event){
9
- this.dispatch = function(){
10
- this.trigger('dispatch', event)
11
- };
12
- this.dispatch(event);
13
- },
14
- dispatch: function(event){
15
- if (!this.hasEvents())
16
- this.addEvents();
17
- this.streamlineDispatch(event);
18
- }
19
- };
@@ -1,25 +0,0 @@
1
- Stormfront.Mixin.Other = {
2
- unauthorized: function(entity){
3
- function propagateUnauthorized(source, response, options){
4
- if (response.status === 403)
5
- this.trigger('unauthorized', source, response, options);
6
- }
7
- entity.on('error', propagateUnauthorized);
8
- },
9
- invalid: function(entity){
10
- function propagateInvalid(source, response, options){
11
- if (response.status === 400)
12
- this.trigger('invalid', source, response, options);
13
- }
14
- entity.on('error', propagateInvalid);
15
- },
16
- empty: function(collection){
17
- function determineEmpty(collection, response, options){
18
- if (collection.isEmpty())
19
- this.trigger('empty', collection, response, options);
20
- else
21
- this.trigger('populated', collection, response, options);
22
- }
23
- collection.on('sync', determineEmpty);
24
- }
25
- };
@@ -1,69 +0,0 @@
1
- Stormfront.Chaperone = Stormfront.Class.extend({
2
- initialize: function(){
3
- this.children = {};
4
- _.extend(this, Backbone.Events);
5
- this.throttle('create', 'created', Stormfront.Errors.INITIALIZING);
6
- this.throttle('render', 'rendered', Stormfront.Errors.RENDERING);
7
- this.throttle('attach', 'attached', Stormfront.Errors.ATTACHING);
8
- this.wrap('add', 'added', Stormfront.Errors.ADDING);
9
- this.wrap('remove', 'removed', Stormfront.Errors.CLOSING);
10
- },
11
-
12
- create: function(childClass, options, context){
13
- return new window[childClass](options.call(context));
14
- },
15
- find: function(identity){
16
- return this.children[identity];
17
- },
18
- add: function(child){
19
- var identity = child.getIdentity();
20
- this.remove(this.find(identity));
21
- this.children[identity] = child;
22
- return child;
23
- },
24
- remove: function(child){
25
- if (child)
26
- this.children = _.omit(this.children, child.getIdentity());
27
- return child;
28
- },
29
- render: function(child){
30
- return child.render();
31
- },
32
- attach: function(child, location, method){
33
- if (location.size() === 0)
34
- throw Stormfront.Errors.NO_LOCATION(child);
35
- else if (location.size() > 1)
36
- throw Stormfront.Errors.MULTIPLE_LOCATIONS(child);
37
-
38
- location[method](child.$el);
39
- return child;
40
- },
41
-
42
- wrap: function(field, event, error){
43
- var implementation = this[field];
44
- this[field] = function(){
45
- try {
46
- var result = implementation.apply(this, arguments);
47
- result && this.trigger(event, result);
48
- } catch (e) {
49
- this.trigger('error', error(arguments[0].toString()), e);
50
- }
51
- }
52
- },
53
- throttle: function(field, event, error){
54
- this.wrap(field, event, error);
55
- var implementation = this[field];
56
- this[field] = function(){
57
- var self = this;
58
- var capturedArguments = arguments;
59
- function func(){
60
- implementation.apply(self, capturedArguments);
61
- }
62
- setTimeout(func, 5);
63
- }
64
- },
65
-
66
- close: function(){
67
- _.each(this.children, this.remove, this);
68
- }
69
- });
@@ -1,75 +0,0 @@
1
- Stormfront.Template = Stormfront.Class.extend({
2
- initialize: function(view){
3
- this.view = view;
4
- },
5
- render: function(){
6
- function renderTemplate(view){
7
- function getTemplate(view){
8
- var selector = view.getIdentity();
9
- return $('#' + selector + '_template');
10
- }
11
- function compileTemplate(selection){
12
- return Handlebars.compile(selection.html());
13
- }
14
- function expandTemplate(template){
15
- return template(view.getViewModel());
16
- }
17
- return expandTemplate(compileTemplate(getTemplate(view)))
18
- }
19
- function findError(view){
20
- function getTemplate(view){
21
- if (!view.className)
22
- throw Stormfront.Errors.NO_SELECTOR();
23
- var selector = view.getIdentity();
24
- return $('#' + selector + '_template');
25
- }
26
- function compileTemplate(template){
27
- if (template.size() === 1)
28
- return template;
29
- if (template.size() === 0)
30
- throw Stormfront.Errors.NO_TEMPLATE(view.getIdentity());
31
-
32
- return Handlebars.compile(template.html());
33
- }
34
- function expandTemplate(template, vm){
35
- try {
36
- return template(vm);
37
- }
38
- catch(e) {
39
- throw Stormfront.Errors.INCOMPATIBLE_TEMPLATE(view.getIdentity());
40
- }
41
- }
42
- function getViewModel(view){
43
- try {
44
- return view.getViewModel();
45
- }
46
- catch (e){
47
- throw Stormfront.Errors.VIEW_MODEL(view.getIdentity());
48
- }
49
- }
50
- try {
51
- return expandTemplate(compileTemplate(getTemplate(view)), getViewModel(view));
52
- }
53
- catch(e) {
54
- return e;
55
- }
56
- }
57
- try {
58
- return renderTemplate(this.view);
59
- }
60
- catch(e) {
61
- throw new TemplateError(findError(this.view), e.message);
62
- }
63
- }
64
- });
65
-
66
- function TemplateError(message, innerException) {
67
- var error = Error.call(this, message);
68
- this.name = 'TemplateError';
69
- this.message = error.message;
70
- this.stack = error.stack;
71
- this.innerException = innerException;
72
- }
73
-
74
- TemplateError.prototype = Object.create(Error.prototype);
75
- TemplateError.prototype.constructor = TemplateError;
@@ -1,27 +0,0 @@
1
- stormfront.arguments = function(args){
2
- return new Stormfront.Arguments(args);
3
- };
4
-
5
- Stormfront.Arguments = Stormfront.Class.extend({
6
- initialize: function(array){
7
- if (array)
8
- this.array = [].slice.call(array);
9
- else
10
- this.array = [];
11
- },
12
- skip: function(start) {
13
- this.array = this.array.slice(start);
14
- return this;
15
- },
16
- prepend: function(item){
17
- this.array.unshift(item);
18
- return this;
19
- },
20
- at: function(index, value){
21
- this.array[index] = value;
22
- return this;
23
- },
24
- get: function(){
25
- return this.array;
26
- }
27
- });
@@ -1,25 +0,0 @@
1
- Stormfront.Class = function(options) {
2
- if (this.initialize)
3
- this.initialize.apply(this, arguments);
4
- };
5
-
6
- Stormfront.Class.extend = function(protoProps, staticProps) {
7
- var parent = this;
8
- var child;
9
-
10
- if (protoProps && _.has(protoProps, 'constructor'))
11
- child = protoProps.constructor;
12
- else
13
- child = function(){ return parent.apply(this, arguments); };
14
-
15
- _.extend(child, parent, staticProps);
16
-
17
- var Surrogate = function(){ this.constructor = child; };
18
- Surrogate.prototype = parent.prototype;
19
- child.prototype = new Surrogate;
20
-
21
- if (protoProps) _.extend(child.prototype, protoProps);
22
- child.__super__ = parent.prototype;
23
-
24
- return child;
25
- };
@@ -1,23 +0,0 @@
1
- stormfront.hash = function(hash){
2
- return new Stormfront.Hash(hash);
3
- };
4
-
5
- Stormfront.Hash = Stormfront.Class.extend({
6
- initialize: function(hash){
7
- this.hash = hash;
8
- },
9
- findNestedValue: function(keys){
10
- function retrieve(keys, context){
11
- if (!context)
12
- return null;
13
- if (keys.length === 0)
14
- return context;
15
- var current = keys.shift();
16
- return retrieve(keys, context[current]);
17
- }
18
- return retrieve(keys, this.hash);
19
- },
20
- subtract: function(values){
21
- return _.omit(this.hash, _.keys(values));
22
- }
23
- });
@@ -1,15 +0,0 @@
1
- stormfront.number = function(number){
2
- return new Stormfront.Number(number);
3
- };
4
-
5
- Stormfront.Number = Stormfront.Class.extend({
6
- initialize: function(number){
7
- this.number = number;
8
- },
9
- isWithin: function(range){
10
- return range[0] < this.number && range[1] > this.number;
11
- },
12
- compare: function(value){
13
- return this.number < value ? -1 : this.number > value ? 1 : 0;
14
- }
15
- });