From 8de51680b76b33baa8e38701d19e04f3ffaa1d60 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Sat, 9 Jan 2016 15:08:18 -0700 Subject: [PATCH 1/2] remove unused build file --- build/js/wp-api.min.js.map | 1 - 1 file changed, 1 deletion(-) delete mode 100644 build/js/wp-api.min.js.map diff --git a/build/js/wp-api.min.js.map b/build/js/wp-api.min.js.map deleted file mode 100644 index cea970e..0000000 --- a/build/js/wp-api.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../../js/app.js","../../js/utils.js","../../js/models.js","../../js/collections.js","../../js/load.js"],"names":["window","undefined","WP_API","this","models","collections","views","wp","api","versionString","utils","Date","prototype","toISOString","pad","number","r","String","length","getUTCFullYear","getUTCMonth","getUTCDate","getUTCHours","getUTCMinutes","getUTCSeconds","getUTCMilliseconds","toFixed","slice","parseISO8601","date","timestamp","struct","i","k","minutesOffset","numericKeys","exec","UTC","parse","NaN","getRootUrl","location","origin","protocol","host","capitalize","str","_","isUndefined","charAt","toUpperCase","extractRoutePart","route","part","replace","routeParts","split","reverse","extractParentName","name","lastSlash","lastIndexOf","substr","pop","WP_API_Settings","Backbone","WPApiBaseModel","Model","extend","sync","method","model","options","nonce","isNull","beforeSend","xhr","setRequestHeader","apply","arguments","save","attrs","contains","methods","call","destroy","Schema","url","root","WPApiBaseCollection","Collection","initialize","state","data","currentPage","totalPages","totalObjects","parent","self","clone","page","success","textStatus","request","parseInt","getResponseHeader","more","hasMore","fetch","init","apiRoot","schemaModel","apiConstructor","jQuery","Deferred","sessionStorage","getItem","JSON","constructFromSchema","newSchemaModel","setItem","stringify","error","promise","modelRoutes","collectionRoutes","schemaRoot","loadingObjects","each","get","index","endsWith","push","modelRoute","modelClassName","routeName","parentName","decorateFromRoute","endpoints","collectionRoute","collectionClassName","defer","resolve","routeEndpoints","modelInstance","routeEndpoint","isEmpty","args","defaults","union","theDefault","endpointLoading","done","endpoint"],"mappings":"CAAA,SAAWA,EAAQC,GAElB,Y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AW,YAC9BN,EAAcI,SAAUlB,GAAU,KAElCc,EAAcI,SAAUlB,GAAUoB,EAAW,cAQhD/I,GAAGC,IAAIkI,UAAY,GAAIzE,UAASyB,UAGhC,IAAI6D,GAAkBhJ,GAAGC,IAAIqG,MAG7B0C,GAAgBC,KAAM,SAAUC,GAE/BlJ,GAAGC,IAAIJ,OAAc2C,EAAEqB,OAAQqF,EAASrJ,OAAQG,GAAGC,IAAIJ,QACvDG,GAAGC,IAAIH,YAAc0C,EAAEqB,OAAQqF,EAASpJ,YAAaE,GAAGC,IAAIH,aAG5DE,GAAGC,IAAIkI,UAAUN,KAAMqB,MAGrBzJ","file":"wp-api.min.js"} \ No newline at end of file From 435bf974bc7f0ed6f20554894f068908537f4422 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Sat, 9 Jan 2016 15:30:34 -0700 Subject: [PATCH 2/2] Enable a mapping feature; remap our names --- js/load.js | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/js/load.js b/js/load.js index 49aaabd..52dc6ca 100644 --- a/js/load.js +++ b/js/load.js @@ -66,7 +66,42 @@ }, constructFromSchema: function() { - var routeModel = this, modelRoutes, collectionRoutes, schemaRoot, loadingObjects; + var routeModel = this, modelRoutes, collectionRoutes, schemaRoot, loadingObjects, + + /** + * Set up the model and collection name mapping options. As the schema is built, the + * model and collection names will be adjusted if they are found in the mapping object. + * + * Localizing a variable wpApiSettings.mapping will over-ride the default mapping options. + * + */ + mapping = wpApiSettings.mapping || { + models: { + 'Categories': 'Category', + 'Comments': 'Comment', + 'Pages': 'Page', + 'PagesMeta': 'PageMeta', + 'PagesRevisions': 'PageRevision', + 'Posts': 'Post', + 'PostsCategories': 'PostCategory', + 'PostsRevisions': 'PostRevision', + 'PostsTags': 'PostTag', + 'Schema': 'Schema', + 'Statuses': 'Status', + 'Tags': 'Tag', + 'Taxonomies': 'Taxonomy', + 'Types': 'Type', + 'Users': 'User' + }, + collections: { + 'PagesMeta': 'PageMeta', + 'PagesRevisions': 'PageRevisions', + 'PostsCategories': 'PostCategories', + 'PostsMeta': 'PostMeta', + 'PostsRevisions': 'PostRevisions', + 'PostsTags': 'PostTags' + } + }; /** * Iterate thru the routes, picking up models and collections to build. Builds two arrays, @@ -122,6 +157,7 @@ // If the model has a parent in its route, add that to its class name. if ( '' !== parentName && parentName !== routeName ) { modelClassName = wp.api.utils.capitalize( parentName ) + wp.api.utils.capitalize( routeName ); + modelClassName = mapping.models[ modelClassName ] || modelClassName; loadingObjects.models[ modelClassName ] = wp.api.WPApiBaseModel.extend( { // Function that returns a constructed url based on the parent and id. @@ -167,6 +203,7 @@ // This is a model without a parent in its route modelClassName = wp.api.utils.capitalize( routeName ); + modelClassName = mapping.models[ modelClassName ] || modelClassName; loadingObjects.models[ modelClassName ] = wp.api.WPApiBaseModel.extend( { // Function that returns a constructed url based on the id. @@ -210,6 +247,7 @@ if ( '' !== parentName && parentName !== routeName ) { collectionClassName = wp.api.utils.capitalize( parentName ) + wp.api.utils.capitalize( routeName ); + collectionClassName = mapping.collections[ collectionClassName ] || collectionClassName; loadingObjects.collections[ collectionClassName ] = wp.api.WPApiBaseCollection.extend( { // Function that returns a constructed url passed on the parent. @@ -235,6 +273,7 @@ // This is a collection without a parent in its route. collectionClassName = wp.api.utils.capitalize( routeName ); + collectionClassName = mapping.collections[ collectionClassName ] || collectionClassName; loadingObjects.collections[ collectionClassName ] = wp.api.WPApiBaseCollection.extend( { // For the url of a root level collection, use a string.