backbone_extensions 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Ryan Dy
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/README.markdown ADDED
@@ -0,0 +1,17 @@
1
+ Backbone Extensions
2
+ =====================
3
+
4
+ [![Build Status](https://secure.travis-ci.org/rdy/backbone_extensions.png)](http://travis-ci.org/rdy/backbone_extensions)
5
+
6
+ Adds extensions to the Backbone javascript library. It adds the javascript as a rails engine to be included in to a Rails 3+ project. To use it make sure require underscore, and backbone.
7
+
8
+ Installing
9
+ ==========
10
+
11
+ 1. Add the gem to bundler or install: gem 'backbone_extensions' or `gem install backbone_extensions`
12
+ 2. In your application.js //= require underscore
13
+ 3. In your application.js //= require backbone
14
+ 4. In your application.js //= require underscore_extensions/include
15
+ 5. In your application.js //= require underscore_extensions/decorator
16
+
17
+ Copyright (c) 2012 Ryan Dy, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'BackboneExtensions'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'jshint/tasks'
26
+
27
+ begin
28
+ require 'jasmine'
29
+ load 'jasmine/tasks/jasmine.rake'
30
+ rescue LoadError
31
+ task :jasmine do
32
+ abort 'Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine'
33
+ end
34
+ end
35
+
36
+ JSHint.config_path = 'config/jshint.yml'
37
+ task :default => [:jshint, :'jasmine:ci']
38
+
data/config/jshint.yml ADDED
@@ -0,0 +1,95 @@
1
+ # ------------ rake task options ------------
2
+
3
+ # JS files to check by default, if no parameters are passed to rake jshint
4
+ # (you may want to limit this only to your own scripts and exclude any external scripts and frameworks)
5
+
6
+ # this can be overridden by adding 'paths' and 'exclude_paths' parameter to rake command:
7
+ # rake jshint paths=path1,path2,... exclude_paths=library1,library2,...
8
+
9
+ paths:
10
+ - lib/assets/javascripts/**/*.js
11
+
12
+ exclude_paths:
13
+
14
+
15
+ # ------------ jshint options ------------
16
+ # visit http://jshint.com/ for complete documentation
17
+
18
+ # "enforce" type options (true means potentially more warnings)
19
+
20
+ adsafe: false # true if ADsafe rules should be enforced. See http://www.ADsafe.org/
21
+ bitwise: true # true if bitwise operators should not be allowed
22
+ newcap: true # true if Initial Caps must be used with constructor functions
23
+ eqeqeq: false # true if === should be required (for ALL equality comparisons)
24
+ immed: false # true if immediate function invocations must be wrapped in parens
25
+ nomen: false # true if initial or trailing underscore in identifiers should be forbidden
26
+ onevar: false # true if only one var statement per function should be allowed
27
+ plusplus: false # true if ++ and -- should not be allowed
28
+ regexp: false # true if . and [^...] should not be allowed in RegExp literals
29
+ safe: false # true if the safe subset rules are enforced (used by ADsafe)
30
+ strict: false # true if the ES5 "use strict"; pragma is required
31
+ undef: true # true if variables must be declared before used
32
+ white: false # true if strict whitespace rules apply (see also 'indent' option)
33
+
34
+ # "allow" type options (false means potentially more warnings)
35
+
36
+ cap: false # true if upper case HTML should be allowed
37
+ css: false # true if CSS workarounds should be tolerated
38
+ debug: false # true if debugger statements should be allowed (set to false before going into production)
39
+ es5: false # true if ECMAScript 5 syntax should be allowed
40
+ evil: false # true if eval should be allowed
41
+ forin: false # true if unfiltered 'for in' statements should be allowed
42
+ fragment: false # true if HTML fragments should be allowed
43
+ laxbreak: false # true if statement breaks should not be checked
44
+ on: false # true if HTML event handlers (e.g. onclick="...") should be allowed
45
+ sub: false # true if subscript notation may be used for expressions better expressed in dot notation
46
+
47
+ # other options
48
+
49
+ maxlen: 160 # Maximum line length
50
+ indent: 2 # Number of spaces that should be used for indentation - used only if 'white' option is set
51
+ maxerr: 50 # The maximum number of warnings reported (per file)
52
+ passfail: false # true if the scan should stop on first error (per file)
53
+ # following are relevant only if undef = true
54
+ predef: # Names of predefined global variables - comma-separated string or a YAML array
55
+ - _
56
+ - Backbone
57
+ - jQuery
58
+
59
+ browser: true # true if the standard browser globals should be predefined
60
+ rhino: false # true if the Rhino environment globals should be predefined
61
+ windows: false # true if Windows-specific globals should be predefined
62
+ widget: false # true if the Yahoo Widgets globals should be predefined
63
+ devel: false # true if functions like alert, confirm, console, prompt etc. are predefined
64
+
65
+ # jshint options
66
+ loopfunc: true # true if functions should be allowed to be defined within loops
67
+ asi: true # true if automatic semicolon insertion should be tolerated
68
+ boss: true # true if advanced usage of assignments and == should be allowed
69
+ couch: true # true if CouchDB globals should be predefined
70
+ curly: false # true if curly braces around blocks should be required (even in if/for/while)
71
+ noarg: true # true if arguments.caller and arguments.callee should be disallowed
72
+ node: true # true if the Node.js environment globals should be predefined
73
+ noempty: true # true if empty blocks should be disallowed
74
+ nonew: true # true if using `new` for side-effects should be disallowed
75
+
76
+
77
+ # ------------ jshint_on_rails custom lint options (switch to true to disable some annoying warnings) ------------
78
+
79
+ # ignores "missing semicolon" warning at the end of a function; this lets you write one-liners
80
+ # like: x.map(function(i) { return i + 1 }); without having to put a second semicolon inside the function
81
+ lastsemic: false
82
+
83
+ # allows you to use the 'new' expression as a statement (without assignment)
84
+ # so you can call e.g. new Ajax.Request(...), new Effect.Highlight(...) without assigning to a dummy variable
85
+ newstat: false
86
+
87
+ # ignores the "Expected an assignment or function call and instead saw an expression" warning,
88
+ # if the expression contains a proper statement and makes sense; this lets you write things like:
89
+ # element && element.show();
90
+ # valid || other || lastChance || alert('OMG!');
91
+ # selected ? show() : hide();
92
+ # although these will still cause a warning:
93
+ # element && link;
94
+ # selected ? 5 : 10;
95
+ statinexp: false
@@ -0,0 +1,50 @@
1
+ //= require backbone_extensions/include
2
+ (function(Backbone, $) {
3
+ function Decorator(models, options) {
4
+ var self = this,
5
+ decoratee = models, proto = _(Object.getPrototypeOf(this)).omit('collection', 'constructor', 'initialize', 'model');
6
+ if (models instanceof Backbone.Collection) {
7
+ decoratee = decoratee.models;
8
+ }
9
+ if (decoratee instanceof Array) {
10
+ _(proto).each(function(fn, name) {
11
+ self[name] = function() {
12
+ var args = arguments;
13
+ return _(decoratee).map(function(model) {
14
+ return fn.apply(model, args);
15
+ });
16
+ };
17
+ });
18
+ } else {
19
+ _(proto).each(function(fn, name) {
20
+ self[name] = function() {
21
+ return fn.apply(decoratee, arguments);
22
+ };
23
+ });
24
+ }
25
+ self.initialize.apply(self, arguments);
26
+ }
27
+
28
+ _(Decorator).extend({
29
+ extend: function(protoProps, classProps) {
30
+ var Klass = Backbone.Model.extend.apply(this, arguments);
31
+ if (protoProps.model) {
32
+ protoProps.model.prototype.decorator = function() {
33
+ return new Klass(this);
34
+ };
35
+ }
36
+
37
+ if (protoProps.collection) {
38
+ protoProps.collection.prototype.decorator = function() {
39
+ return new Klass(this);
40
+ };
41
+ }
42
+
43
+ return Klass;
44
+ }
45
+ }, Backbone.include ? Backbone.include : {});
46
+
47
+ _(Decorator.prototype).extend({initialize: $.noop});
48
+
49
+ Backbone.Decorator = Decorator;
50
+ })(Backbone, jQuery);
@@ -0,0 +1,15 @@
1
+ (function(Backbone) {
2
+ var include = {
3
+ include: function() {
4
+ var self = this;
5
+ _(arguments).chain().toArray().each(function(module) {
6
+ if (module && module.included && _(module.included).isFunction()) {
7
+ module.included(self);
8
+ }
9
+ });
10
+ return this;
11
+ }
12
+ };
13
+
14
+ Backbone.include = include;
15
+ })(Backbone);
@@ -0,0 +1,3 @@
1
+ module BackboneExtensions
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ module BackboneExtensions
2
+ class Engine < Rails::Engine
3
+
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backbone_extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Dy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fuubar
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
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: 1.2.1
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: jshint_on_rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: thin
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rails
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '3.1'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '3.1'
94
+ description: Adds extensions to the backbone javascript library. It adds the javascript
95
+ as a rails engine to be included in to a Rails 3+ project. To use it make sure require
96
+ underscore, backbone and the extensions you need.
97
+ email:
98
+ - ryan.dy@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - config/jshint.yml
104
+ - lib/assets/javascripts/underscore_extensions/decorator.js
105
+ - lib/assets/javascripts/underscore_extensions/include.js
106
+ - lib/backbone_extensions/version.rb
107
+ - lib/backbone_extensions.rb
108
+ - MIT-LICENSE
109
+ - Rakefile
110
+ - README.markdown
111
+ homepage: http://github.com/rdy/underscore_extensions
112
+ licenses: []
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ segments:
124
+ - 0
125
+ hash: 4213041243078294066
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ segments:
133
+ - 0
134
+ hash: 4213041243078294066
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.19
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Extensions to backbone javascript library as a rails engine
141
+ test_files: []