-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app generator): include a default api-services collection
To be used as a place to declare known api-services
- Loading branch information
Showing
6 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
generators/app/templates/src/collections/api-services.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
( ( factory ) -> | ||
if typeof exports is 'object' | ||
module.exports = factory( | ||
require( 'backbone' ) | ||
require( './../models/api-service.coffee' ) | ||
|
||
require( 'madlib-settings' ) | ||
) | ||
else if typeof define is 'function' and define.amd | ||
define( [ | ||
'backbone' | ||
'./../models/api-service.coffee' | ||
|
||
'madlib-settings' | ||
], factory ) | ||
return | ||
)(( | ||
Backbone | ||
ApiServiceModel | ||
|
||
settings | ||
) -> | ||
|
||
###* | ||
# @author David Bouman | ||
# @module App | ||
# @submodule Collections | ||
### | ||
|
||
'use strict' | ||
|
||
|
||
###* | ||
# A collection of services available on the API. | ||
# | ||
# @class ApiServicesCollection | ||
# @extends Backbone.Collection | ||
# @static | ||
### | ||
|
||
class ApiServicesCollection extends Backbone.Collection | ||
|
||
###* | ||
# The collection's `{{#crossLink "ApiServiceModel"}}{{/crossLink}}`. | ||
# | ||
# @property model | ||
# | ||
# @default ApiServiceModel | ||
# @type Backbone.Model | ||
# @static | ||
# @final | ||
### | ||
|
||
model: ApiServiceModel | ||
|
||
|
||
|
||
###* | ||
# The app's globally sharable configuration settings. | ||
# | ||
# These are exposed through the `madlib-settings` singleton object. Simply `require(...)` it wherever you have a need for them. | ||
# | ||
# @class Settings | ||
# @static | ||
### | ||
|
||
appBaseUrl = settings.get( 'appBaseUrl' ) | ||
|
||
apiServices = | ||
new ApiServicesCollection( | ||
|
||
[ | ||
|
||
## | ||
## NOTE: | ||
## | ||
## Before using any of the services below, the target-environment settings need to have been retrieved first in order to have an API base url | ||
## to base these values off of. | ||
## | ||
|
||
] | ||
) | ||
|
||
|
||
###* | ||
# The services available on the API. | ||
# | ||
# @property services | ||
# @type Object | ||
### | ||
|
||
settings.init( 'services', apiServices.reduce( ( ( memo, service ) -> memo[ service.id ] = service.get( 'url' ); return memo ), {} ) ) | ||
|
||
|
||
###* | ||
# @class ApiServicesCollection | ||
### | ||
|
||
|
||
## Export singleton. | ||
## | ||
return apiServices | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
( ( factory ) -> | ||
if typeof exports is 'object' | ||
module.exports = factory( | ||
require( 'backbone' ) | ||
) | ||
else if typeof define is 'function' and define.amd | ||
define( [ | ||
'backbone' | ||
], factory ) | ||
return | ||
)(( | ||
Backbone | ||
) -> | ||
|
||
###* | ||
# @author David Bouman | ||
# @module App | ||
# @submodule Models | ||
### | ||
|
||
'use strict' | ||
|
||
|
||
###* | ||
# Model for the `{{#crossLink "ApiServicesCollection"}}{{/crossLink}}`. | ||
# | ||
# @class ApiServiceModel | ||
# @extends Backbone.Model | ||
# @constructor | ||
### | ||
|
||
class ApiServiceModel extends Backbone.Model | ||
|
||
###* | ||
# List of [valid attribute names](#attrs). | ||
# | ||
# @property schema | ||
# | ||
# @type Array[String] | ||
# @static | ||
# @final | ||
### | ||
|
||
###* | ||
# The `ApiServiceModel`'s unique identifier. | ||
# | ||
# @attribute id | ||
# | ||
# @type String | ||
### | ||
|
||
###* | ||
# A url base path for accessing this API service. | ||
# | ||
# @attribute url | ||
# | ||
# @type String | ||
### | ||
|
||
schema: [ | ||
|
||
'id' | ||
'url' | ||
] | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
|
||
'use strict' | ||
|
||
|
||
###*<% if ( description ) { %> | ||
# <%- description %> | ||
#<% } %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
|
||
'use strict' | ||
|
||
|
||
###*<% if ( description ) { %> | ||
# <%- description %> | ||
#<% } %> | ||
|