Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"requireBlocksOnNewline": 1,
"maximumLineLength": {
"value": 100,
"tabSize": 4,
"tabSize": 2,
"allowUrlComments": true,
"allowRegex": true
},
Expand Down
9 changes: 9 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ module.exports = function( grunt ) {
src: files.lib
},
tests: {
options: {
maximumLineLength: {
// Longer max line length in test files
value: 150,
tabSize: 2,
allowUrlComments: true,
allowRegex: true
}
},
src: files.tests
}
},
Expand Down
68 changes: 36 additions & 32 deletions lib/taxonomies.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,29 @@ function TaxonomiesRequest( options ) {
/**
* A hash of values to assemble into the API request path
*
* Default to requesting the taxonomies "collection" (dictionary of publicly-
* registered taxonomies) if no other collection is specified
*
* @property _path
* @type Object
* @private
* @default {}
*/
this._path = {};
this._path = { collection: 'taxonomies' };

/**
* The URL template that will be used to assemble endpoint paths
*
* There is no path validation for taxonomies requests: terms can be numeric
* (categories) or strings (tags), and the list of registered collections is
* not fixed (it can be augmented or modified through plugin and theme behavior).
*
* @property _template
* @type String
* @private
* @default 'taxonomies(/:taxonomy)(/:action)(/:term)'
* @default '(:collection)(/:term)'
*/
this._template = 'taxonomies(/:taxonomy)(/:action)(/:term)';
this._template = '(:collection)(/:term)';

/**
* @property _supportedMethods
Expand All @@ -83,35 +90,24 @@ function TaxonomiesRequest( options ) {
inherit( TaxonomiesRequest, CollectionRequest );

/**
* A hash of path keys to regex validators for those path elements
* Specify the name of the taxonomy collection to query
*
* @property _pathValidators
* @type Object
* @private
*/
TaxonomiesRequest.prototype._pathValidators = {

/**
* The only "action" permitted on a taxonomy is to get a list of terms
*
* @property _pathValidators.action
* @type {RegExp}
*/
action: /terms/

// No validation on :taxonomy or :term: they can be numeric or a string
};

/**
* Specify the name of the taxonomy to query
* The collections will not be a strict match to defined taxonomies: *e.g.*, to
* get the list of terms for the taxonomy "category," you must specify the
* collection name "categories" (similarly, specify "tags" to get a list of terms
* for the "post_tag" taxonomy).
*
* @method taxonomy
* To get the dictionary of all available taxonomies, specify the collection
* "taxonomy" (slight misnomer: this case will return an object, not the array
* that would usually be expected with a "collection" request).
*
* @method collection
* @chainable
* @param {String} taxonomyName The name of the taxonomy to query
* @param {String} taxonomyCollection The name of the taxonomy collection to query
* @return {TaxonomiesRequest} The TaxonomiesRequest instance (for chaining)
*/
TaxonomiesRequest.prototype.taxonomy = function( taxonomyName ) {
this._path.taxonomy = taxonomyName;
TaxonomiesRequest.prototype.collection = function( taxonomyCollection ) {
this._path.collection = taxonomyCollection;

return this;
};
Expand All @@ -125,21 +121,29 @@ TaxonomiesRequest.prototype.taxonomy = function( taxonomyName ) {
* @return {TaxonomiesRequest} The TaxonomiesRequest instance (for chaining)
*/
TaxonomiesRequest.prototype.term = function( term ) {
this._path.action = 'terms';
this._path.term = term;

return this;
};

/**
* Specify that we are requesting a collection of terms for a taxonomy
* Search for hierarchical taxonomy terms that are children of the parent term
* indicated by the provided term ID
*
* @example
*
* wp.categories().parent( 42 ).then(function( categories ) {
* console.log( 'all of these categories are sub-items of cat ID#42:' );
* console.log( categories );
* });
*
* @method terms
* @method parent
* @chainable
* @param {Number} parentId The ID of a (hierarchical) taxonomy term
* @return {TaxonomiesRequest} The TaxonomiesRequest instance (for chaining)
*/
TaxonomiesRequest.prototype.terms = function() {
this._path.action = 'terms';
TaxonomiesRequest.prototype.parent = function( parentId ) {
this.param( 'parent', parentId, true );

return this;
};
Expand Down
Loading