Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

workign on splitting out the source files, and building a grunt task …

…to rig them all together
  • Loading branch information...
commit f62da85247d4e57c6a0d4988b9aa1cacdde90835 1 parent f7888a9
@derickbailey authored
View
16 grunt.js
@@ -12,17 +12,16 @@ module.exports = function(grunt) {
'// Distributed under MIT license\n' +
'// http://github.com/derickbailey/backbone.syphon'
},
+
lint: {
files: ['src/backbone.syphon.js']
},
- concat: {
- dist: {
- src: ['<banner:meta.banner>', '<file_strip_banner:src/backbone.syphon.js>'],
- dest: 'lib/backbone.syphon.js'
- }
- },
rig: {
+ build: {
+ src: ['<banner:meta.banner>', 'src/backbone.syphon.js'],
+ dest: 'lib/backbone.syphon.js'
+ },
amd: {
src: ['<banner:meta.banner>', 'src/amd.js'],
dest: 'lib/amd/backbone.syphon.js'
@@ -31,7 +30,7 @@ module.exports = function(grunt) {
min: {
standard: {
- src: ['<banner:meta.banner>', '<config:concat.dist.dest>'],
+ src: ['<banner:meta.banner>', '<config:rig.standard.dest>'],
dest: 'lib/backbone.syphon.min.js'
},
amd: {
@@ -39,6 +38,7 @@ module.exports = function(grunt) {
dest: 'lib/amd/backbone.syphon.min.js'
}
},
+
jshint: {
options: {
curly: true,
@@ -63,6 +63,6 @@ module.exports = function(grunt) {
});
// Default task.
- grunt.registerTask('default', 'lint concat rig min');
+ grunt.registerTask('default', 'lint rig min');
};
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "Backbone.syphon",
- "version": "0",
+ "version": "0.0.1",
"dependencies": {
"grunt": "*",
"grunt-rigger": "*"
View
4 spec/javascripts/support/jasmine.yml
@@ -15,6 +15,10 @@ src_files:
- public/javascripts/underscore.js
- public/javascripts/backbone.js
- src/backbone.syphon.js
+ - src/backbone.syphon.typeregistry.js
+ - src/backbone.syphon.keyextractors.js
+ - src/backbone.syphon.inputreaders.js
+ - src/backbone.syphon.keyassignmentvalidators.js
# stylesheets
#
View
22 src/backbone.syphon.inputreaders.js
@@ -0,0 +1,22 @@
+// Input Readers
+// -------------
+
+// Input Readers are used to extract the value from
+// an input element, for the serialized object result
+Backbone.Syphon.InputReaderSet = Backbone.Syphon.TypeRegistry.extend();
+
+// Built-in Input Readers
+Backbone.Syphon.InputReaders = new Backbone.Syphon.InputReaderSet();
+
+// The default input reader, which uses an input
+// element's "value"
+Backbone.Syphon.InputReaders.registerDefault(function($el){
+ return $el.val();
+});
+
+// Checkbox reader, returning a boolean value for
+// whether or not the checkbox is checked.
+Backbone.Syphon.InputReaders.register("checkbox", function($el){
+ var checked = $el.prop("checked");
+ return checked;
+});
View
117 src/backbone.syphon.js
@@ -51,114 +51,6 @@ Backbone.Syphon = (function(Backbone, $, _){
return data;
};
- // Type Registry
- // -------------
-
- // Type Registries allow you to register something to
- // an input type, and retrieve either the item registered
- // for a specific type or the default registration
- Syphon.TypeRegistry = function(){
- this.registeredTypes = {};
- };
-
- // Borrow Backbone's `extend` keyword for our TypeRegistry
- Syphon.TypeRegistry.extend = Backbone.Model.extend;
-
- _.extend(Syphon.TypeRegistry.prototype, {
-
- // Get the registered item by type. If nothing is
- // found for the specified type, the default is
- // returned.
- get: function(type){
- var item = this.registeredTypes[type];
-
- if (!item){
- item = this.registeredTypes["default"];
- }
-
- return item;
- },
-
- // Register a new item for a specified type
- register: function(type, item){
- this.registeredTypes[type] = item;
- },
-
- // Register a default item to be used when no
- // item for a specified type is found
- registerDefault: function(item){
- this.registeredTypes["default"] = item;
- },
-
- // Remove an item from a given type registration
- unregister: function(type){
- if (this.registeredTypes[type]){
- delete this.registeredTypes[type];
- }
- }
- });
-
- // Key Extractors
- // --------------
-
- // Key extractors produce the "key" in `{key: "value"}`
- // pairs, when serializing.
- Syphon.KeyExtractorSet = Syphon.TypeRegistry.extend();
-
- // Built-in Key Extractors
- Syphon.KeyExtractors = new Syphon.KeyExtractorSet();
-
- // The default key extractor, which uses the
- // input element's "id" attribute
- Syphon.KeyExtractors.registerDefault(function($el){
- return $el.prop("name");
- });
-
- // Input Readers
- // -------------
-
- // Input Readers are used to extract the value from
- // an input element, for the serialized object result
- Syphon.InputReaderSet = Syphon.TypeRegistry.extend();
-
- // Built-in Input Readers
- Syphon.InputReaders = new Syphon.InputReaderSet();
-
- // The default input reader, which uses an input
- // element's "value"
- Syphon.InputReaders.registerDefault(function($el){
- return $el.val();
- });
-
- // Checkbox reader, returning a boolean value for
- // whether or not the checkbox is checked.
- Syphon.InputReaders.register("checkbox", function($el){
- var checked = $el.prop("checked");
- return checked;
- });
-
- // Key Assignment Validators
- // -------------------------
-
- // Key Assignment Validators are used to determine whether or not a
- // key should be assigned to a value, after the key and value have been
- // extracted from the element. This is the last opportunity to prevent
- // bad data from getting serialized to your object.
-
- Syphon.KeyAssignmentValidatorSet = Syphon.TypeRegistry.extend();
-
- // Build-in Key Assignment Validators
- Syphon.KeyAssignmentValidators = new Syphon.KeyAssignmentValidatorSet();
-
- // Everything is valid by default
- Syphon.KeyAssignmentValidators.registerDefault(function(){ return true; });
-
- // But only the "checked" radio button for a given
- // radio button group is valid
- Syphon.KeyAssignmentValidators.register("radio", function($el, key, value){
- return $el.prop("checked");
- });
-
// Helpers
// -------
@@ -221,3 +113,12 @@ Backbone.Syphon = (function(Backbone, $, _){
return Syphon;
})(Backbone, jQuery, _);
+
+//= backbone.syphon.typeregistry.js
+
+//= backbone.syphon.keyextractors.js
+
+//= backbone.syphon.inputreaders.js
+
+//= backbone.syphon.keyassignmentvalidators.js
+
View
21 src/backbone.syphon.keyassignmentvalidators.js
@@ -0,0 +1,21 @@
+// Key Assignment Validators
+// -------------------------
+
+// Key Assignment Validators are used to determine whether or not a
+// key should be assigned to a value, after the key and value have been
+// extracted from the element. This is the last opportunity to prevent
+// bad data from getting serialized to your object.
+
+Backbone.Syphon.KeyAssignmentValidatorSet = Backbone.Syphon.TypeRegistry.extend();
+
+// Build-in Key Assignment Validators
+Backbone.Syphon.KeyAssignmentValidators = new Backbone.Syphon.KeyAssignmentValidatorSet();
+
+// Everything is valid by default
+Backbone.Syphon.KeyAssignmentValidators.registerDefault(function(){ return true; });
+
+// But only the "checked" radio button for a given
+// radio button group is valid
+Backbone.Syphon.KeyAssignmentValidators.register("radio", function($el, key, value){
+ return $el.prop("checked");
+});
View
15 src/backbone.syphon.keyextractors.js
@@ -0,0 +1,15 @@
+// Key Extractors
+// --------------
+
+// Key extractors produce the "key" in `{key: "value"}`
+// pairs, when serializing.
+Backbone.Syphon.KeyExtractorSet = Backbone.Syphon.TypeRegistry.extend();
+
+// Built-in Key Extractors
+Backbone.Syphon.KeyExtractors = new Backbone.Syphon.KeyExtractorSet();
+
+// The default key extractor, which uses the
+// input element's "id" attribute
+Backbone.Syphon.KeyExtractors.registerDefault(function($el){
+ return $el.prop("name");
+});
View
48 src/backbone.syphon.typeregistry.js
@@ -0,0 +1,48 @@
+// Type Registry
+// -------------
+
+// Type Registries allow you to register something to
+// an input type, and retrieve either the item registered
+// for a specific type or the default registration
+Backbone.Syphon.TypeRegistry = function(){
+ this.registeredTypes = {};
+};
+
+// Borrow Backbone's `extend` keyword for our TypeRegistry
+Backbone.Syphon.TypeRegistry.extend = Backbone.Model.extend;
+
+_.extend(Backbone.Syphon.TypeRegistry.prototype, {
+
+ // Get the registered item by type. If nothing is
+ // found for the specified type, the default is
+ // returned.
+ get: function(type){
+ var item = this.registeredTypes[type];
+
+ if (!item){
+ item = this.registeredTypes["default"];
+ }
+
+ return item;
+ },
+
+ // Register a new item for a specified type
+ register: function(type, item){
+ this.registeredTypes[type] = item;
+ },
+
+ // Register a default item to be used when no
+ // item for a specified type is found
+ registerDefault: function(item){
+ this.registeredTypes["default"] = item;
+ },
+
+ // Remove an item from a given type registration
+ unregister: function(type){
+ if (this.registeredTypes[type]){
+ delete this.registeredTypes[type];
+ }
+ }
+});
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.