Skip to content

Commit

Permalink
feat(app generator): include a default api-services collection
Browse files Browse the repository at this point in the history
To be used as a place to declare known api-services
  • Loading branch information
cueedee committed Aug 26, 2016
1 parent 2025943 commit 8ee884b
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 1 deletion.
5 changes: 5 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ var AppGenerator = generators.Base.extend(

, [ '@package.json' ]

// App source:

, [ 'src/collections/api-services.coffee' ]
, 'src/models/api-service.coffee'

// Style and Compass:

, 'src/sass/settings/_compass.sass'
Expand Down
12 changes: 11 additions & 1 deletion generators/app/templates/src/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,24 @@ $appRoot.attr( 'lang', locale = $( 'html' ).attr( 'lang' ) ? '<%= i18nLocaleDefa
settings.init( 'locale', locale )<% } %>


## ============================================================================
##
## [API]
##

## `require()` the API services here to ensure their endpoints have been defined on the madlib-settings object before they are used anywhere else.
##
services = require( './collections/api-services.coffee' )


## ============================================================================
##
## [App]
##

router = require( './router.coffee' )

initialized = Q.all(
initialized = Q.all(
[
## Wait until the DOM is ready.
##
Expand Down
104 changes: 104 additions & 0 deletions generators/app/templates/src/collections/api-services.coffee
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

)
66 changes: 66 additions & 0 deletions generators/app/templates/src/models/api-service.coffee
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'
]

)
1 change: 1 addition & 0 deletions generators/collection/templates/collection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

'use strict'


###*<% if ( description ) { %>
# <%- description %>
#<% } %>
Expand Down
1 change: 1 addition & 0 deletions generators/view/templates/view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

'use strict'


###*<% if ( description ) { %>
# <%- description %>
#<% } %>
Expand Down

0 comments on commit 8ee884b

Please sign in to comment.