Skip to content

Commit

Permalink
feat(subgenerators): prepare for using Backbone derivatives
Browse files Browse the repository at this point in the history
  • Loading branch information
cueedee committed Aug 26, 2016
1 parent 20f95d3 commit cfeb477
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 39 deletions.
3 changes: 3 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ var AppGenerator = generators.Base.extend(

data.copyrightYear = new Date().getFullYear();
data.packageDescription = data.description;
data.backbone = ( this.config.get( 'backbone' ) || { className: 'Backbone', modulePath: 'backbone' } );

//
// Save a '.yo-rc.json' config file.
Expand All @@ -305,6 +306,8 @@ var AppGenerator = generators.Base.extend(

, ie8: data.ie8
, i18n: data.i18n

, backbone: data.backbone
}
);

Expand Down
12 changes: 6 additions & 6 deletions generators/app/templates/src/collections/api-services.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
if typeof exports is 'object'
module.exports = factory(
require( 'backbone' )
require( './../models/api-service.coffee' )

require( 'madlib-settings' )

require( './../models/api-service.coffee' )
)
else if typeof define is 'function' and define.amd
define( [
'backbone'
'./../models/api-service.coffee'

'madlib-settings'

'./../models/api-service.coffee'
], factory )
return
)((
Backbone
ApiServiceModel

settings

ApiServiceModel
) ->

###*
Expand Down
14 changes: 9 additions & 5 deletions generators/app/templates/src/views/index.coffee
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
( ( factory ) ->
if typeof exports is 'object'
module.exports = factory(
require( 'backbone' )
require( '<%- backbone.modulePath %>' )

require( './index.hbs' )
)
else if typeof define is 'function' and define.amd
define( [
'backbone'
'<%- backbone.modulePath %>'

'./index.hbs'
], factory )
return
)((
Backbone
<%- backbone.className %>

template
) ->

Expand All @@ -23,15 +26,16 @@

'use strict'


###*
# Default index view of BAT
#
# @class IndexView
# @extends Backbone.View
# @extends <%- backbone.className %>.View
# @constructor
###

class IndexView extends Backbone.View
class IndexView extends <%- backbone.className %>.View

###*
# Expose this view's name to the router.
Expand Down
12 changes: 7 additions & 5 deletions generators/collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,15 @@ var CollectionGenerator = generators.Base.extend(
_.extend(
data
, {
className: _.capitalize( collectionName ) + 'Collection'
, fileBase: _.kebabCase( _.deburr( collectionName ))
className: _.capitalize( collectionName ) + 'Collection'
, fileBase: _.kebabCase( _.deburr( collectionName ))

, modelClassName: _.capitalize( modelName ) + 'Model'
, modelFileName: _.kebabCase( _.deburr( modelName )) + '.coffee'
, modelClassName: _.capitalize( modelName ) + 'Model'
, modelFileName: _.kebabCase( _.deburr( modelName )) + '.coffee'

, userName: this.user.git.name()
, userName: this.user.git.name()

, backbone: ( this.config.get( 'backbone' ) || { className: 'Backbone', modulePath: 'backbone' } )
}
);
}
Expand Down
15 changes: 9 additions & 6 deletions generators/collection/templates/collection.coffee
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
( ( factory ) ->
if typeof exports is 'object'
module.exports = factory(
require( 'backbone' )
require( '<%- backbone.modulePath %>' )

require( './../models/<%- modelFileName %>' )
)
else if typeof define is 'function' and define.amd
define( [
'backbone'
'<%- backbone.modulePath %>'

'./../models/<%- modelFileName %>'
], factory )
return
)((
Backbone
<%- backbone.className %>

<%- modelClassName %>
) ->

Expand All @@ -28,18 +31,18 @@
# <%- description %>
#<% } %>
# @class <%- className %>
# @extends Backbone.Collection<% if ( singleton ) { %>
# @extends <%- backbone.className %>.Collection<% if ( singleton ) { %>
# @static<% } else { %>
# @constructor<% } %>
###

class <%- className %> extends Backbone.Collection
class <%- className %> extends <%- backbone.className %>.Collection

###*
# The collection's `{{#crossLink "<%- modelClassName %>"}}{{/crossLink}}`.
#
# @property model
# @type Backbone.Model
# @type <%- backbone.className %>.Model
# @protected
# @static
# @final
Expand Down
8 changes: 5 additions & 3 deletions generators/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ var ModelGenerator = generators.Base.extend(
_.extend(
data
, {
className: _.capitalize( modelName ) + 'Model'
, fileBase: _.kebabCase( _.deburr( modelName ))
className: _.capitalize( modelName ) + 'Model'
, fileBase: _.kebabCase( _.deburr( modelName ))

, userName: this.user.git.name()
, userName: this.user.git.name()

, backbone: ( this.config.get( 'backbone' ) || { className: 'Backbone', modulePath: 'backbone' } )
}
);
}
Expand Down
10 changes: 5 additions & 5 deletions generators/model/templates/model.coffee
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
( ( factory ) ->
if typeof exports is 'object'
module.exports = factory(
require( 'backbone' )
require( '<%- backbone.modulePath %>' )
)
else if typeof define is 'function' and define.amd
define( [
'backbone'
'<%- backbone.modulePath %>'
], factory )
return
)((
Backbone
<%- backbone.className %>
) ->

###*
Expand All @@ -25,12 +25,12 @@
# <%- description %>
#<% } %>
# @class <%- className %>
# @extends Backbone.Model<% if ( singleton ) { %>
# @extends <%- backbone.className %>.Model<% if ( singleton ) { %>
# @static<% } else { %>
# @constructor<% } %>
###

class <%- className %> extends Backbone.Model
class <%- className %> extends <%- backbone.className %>.Model

###*
# List of [valid attribute names](#attrs).
Expand Down
10 changes: 6 additions & 4 deletions generators/view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ var ViewGenerator = generators.Base.extend(
_.extend(
data
, {
className: _.capitalize( viewName ) + 'View'
, cssClassName: _.kebabCase( viewName ) + '-view'
, fileBase: _.kebabCase( _.deburr( viewName ))
className: _.capitalize( viewName ) + 'View'
, cssClassName: _.kebabCase( viewName ) + '-view'
, fileBase: _.kebabCase( _.deburr( viewName ))

, userName: this.user.git.name()
, userName: this.user.git.name()

, backbone: ( this.config.get( 'backbone' ) || { className: 'Backbone', modulePath: 'backbone' } )
}
);
}
Expand Down
13 changes: 8 additions & 5 deletions generators/view/templates/view.coffee
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
( ( factory ) ->
if typeof exports is 'object'
module.exports = factory(
require( 'backbone' )
require( '<%- backbone.modulePath %>' )

require( './<%- fileBase %>.hbs' )
)
else if typeof define is 'function' and define.amd
define( [
'backbone'
'<%- backbone.modulePath %>'

'./<%- fileBase %>.hbs'
], factory )
return
)((
Backbone
<%- backbone.className %>

template
) ->

Expand All @@ -28,11 +31,11 @@
# <%- description %>
#<% } %>
# @class <%- className %>
# @extends Backbone.View
# @extends <%- backbone.className %>.View
# @constructor
###

class <%- className %> extends Backbone.View
class <%- className %> extends <%- backbone.className %>.View

###*
# Expose this view's name to the router.
Expand Down

0 comments on commit cfeb477

Please sign in to comment.