tentjs-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jonathan Clem
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Tentjs::Rails
2
+
3
+ Tent.js is a lightweight structure built on top of Backbone.js
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'tentjs-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install tentjs-rails
@@ -0,0 +1,10 @@
1
+ (function () {
2
+ Tent.App = function () {};
3
+
4
+ _.extend(Tent.App.prototype, Tent.PubSub, {
5
+ dispatcher: Tent.Dispatcher,
6
+ start: function () {
7
+ this.publish('tent:app:started');
8
+ }
9
+ });
10
+ })();
@@ -0,0 +1,7 @@
1
+ (function () {
2
+ Tent.Collection = Backbone.Collection.extend({
3
+ serialize: function () {
4
+ return JSON.stringify(this.toJSON());
5
+ }
6
+ });
7
+ })();
@@ -0,0 +1,50 @@
1
+ (function () {
2
+ Tent.CollectionView = Tent.View.extend({
3
+ initialize: function (options) {
4
+ var that = this;
5
+
6
+ options = _.extend({
7
+ modelView: Tent.ModelView
8
+ }, options);
9
+
10
+ this._modelViews = {};
11
+ this.bindTo(this.collection, 'add', this._collectionAdd);
12
+ this.bindTo(this.collection, 'remove', this._collectionRemove);
13
+
14
+ _.each(this.collection.models, function (model) {
15
+ that._modelViews[model.cid] = new options.modelView({ model: model });
16
+ });
17
+
18
+ this.render();
19
+ },
20
+
21
+ close: function () {
22
+ Tent.View.prototype.close.apply(this, arguments);
23
+
24
+ _.each(this._modelViews, function (view) {
25
+ view.close();
26
+ });
27
+ },
28
+
29
+ render: function () {
30
+ var that = this;
31
+
32
+ _.each(this._modelViews, function (view) {
33
+ that.$el.append(view.render().el);
34
+ });
35
+
36
+ return this;
37
+ },
38
+
39
+ _collectionAdd: function () {
40
+ var model = this.collection.last();
41
+ this._modelViews[model.cid] = new Tent.ModelView({ model: model });
42
+ this.$el.append(this._modelViews[model.cid].render().el);
43
+ },
44
+
45
+ _collectionRemove: function (model) {
46
+ this._modelViews[model.cid].close();
47
+ delete this._modelViews[model.cid];
48
+ }
49
+ });
50
+ })();
@@ -0,0 +1,3 @@
1
+ (function () {
2
+ Tent.Dispatcher = _.extend({}, Backbone.Events);
3
+ })();
@@ -0,0 +1,6 @@
1
+ //= require tent_object
2
+ //= require tent.dispatcher
3
+ //= require tent.pub_sub
4
+ //= require tent.app
5
+ //= require tent.view
6
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ (function () {
2
+ Tent.Model = Backbone.Model.extend({
3
+ serialize: function () {
4
+ return JSON.stringify(this.toJSON());
5
+ }
6
+ });
7
+ })();
@@ -0,0 +1,17 @@
1
+ (function () {
2
+ Tent.ModelView = Tent.View.extend({
3
+ initialize: function () {
4
+ this.el.setAttribute('data-tent-model-cid', this.model.cid);
5
+ this._setAttributes();
6
+ this.bindTo(this.model, 'change', this._modelChanged);
7
+ },
8
+ _setAttributes: function () {
9
+ var attributes = this.model.serialize();
10
+ this.el.setAttribute('data-tent-model-attributes', attributes);
11
+ },
12
+ _modelChanged: function () {
13
+ this._setAttributes();
14
+ this.render();
15
+ }
16
+ });
17
+ })();
@@ -0,0 +1,13 @@
1
+ (function () {
2
+ Tent.PubSub = {
3
+ publish: function () {
4
+ Tent.Dispatcher.trigger.apply(Tent.Dispatcher, arguments);
5
+ },
6
+ subscribe: function (events, callback) {
7
+ Tent.Dispatcher.on(events, callback, this);
8
+ },
9
+ unsubscribe: function (event, callback) {
10
+ Tent.Dispatcher.off(event, callback, this);
11
+ },
12
+ };
13
+ })();
@@ -0,0 +1,48 @@
1
+ (function () {
2
+ Tent.View = Backbone.View.extend({
3
+ bindTo: function (object, event, callback) {
4
+ this._bindings = this._bindings || [];
5
+
6
+ object.on(event, callback, this);
7
+
8
+ if (!_.contains(this._bindings)) {
9
+ this._bindings.push(object);
10
+ }
11
+ },
12
+
13
+ close: function () {
14
+ if (this.beforeClose) {
15
+ this.beforeClose();
16
+ }
17
+
18
+ this.unbindAll();
19
+ this.unsubscribe();
20
+ this.off();
21
+ this.remove();
22
+ },
23
+
24
+ unbindFrom: function (object) {
25
+ this._bindings = this._bindings || [];
26
+
27
+ object.off(null, null, this);
28
+
29
+ this._bindings = _.reject(this._bindings, function (binding) {
30
+ return binding === object;
31
+ });
32
+ },
33
+
34
+ unbindAll: function () {
35
+ this._bindings = this._bindings || [];
36
+
37
+ var that = this;
38
+
39
+ _.each(this._bindings, function (binding) {
40
+ binding.off(null, null, that);
41
+ });
42
+
43
+ this._bindings = [];
44
+ }
45
+ });
46
+
47
+ _.extend(Tent.View.prototype, Tent.PubSub);
48
+ })();
@@ -0,0 +1 @@
1
+ window.Tent = {};
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tentjs-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jonathan Clem
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: jasmine
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Tent.js is a lighweight application structure built on top of Backbone.
47
+ email:
48
+ - j@jclem.net
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - vendor/assets/javascripts/tent.app.js
54
+ - vendor/assets/javascripts/tent.collection.js
55
+ - vendor/assets/javascripts/tent.collection_view.js
56
+ - vendor/assets/javascripts/tent.dispatcher.js
57
+ - vendor/assets/javascripts/tent.js
58
+ - vendor/assets/javascripts/tent.model.js
59
+ - vendor/assets/javascripts/tent.model_view.js
60
+ - vendor/assets/javascripts/tent.pub_sub.js
61
+ - vendor/assets/javascripts/tent.view.js
62
+ - vendor/assets/javascripts/tent_object.js
63
+ - LICENSE
64
+ - README.md
65
+ homepage:
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.22
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: ! 'Tent.js: A lightweight application structure built on top of Backbone.'
89
+ test_files: []