From bc32f206e9b3e332c5ba0c35731d8e7a79bc367c Mon Sep 17 00:00:00 2001 From: cueedee Date: Mon, 13 Apr 2015 15:45:55 +0200 Subject: [PATCH] feat(app generator,view subgenerator): normalize template expansion Make template part a view class property. Add renderData method. --- .../templates/demo/views/buildscript.coffee | 31 +++++++++++++++- .../templates/demo/views/documentation.coffee | 31 +++++++++++++++- .../app/templates/demo/views/i18n.coffee | 37 ++++++++++++++++--- .../app/templates/demo/views/index.coffee | 31 +++++++++++++++- .../templates/demo/views/navigation.coffee | 30 ++++++++++++++- .../app/templates/src/views/index.coffee | 31 +++++++++++++++- generators/view/templates/view.coffee | 31 +++++++++++++++- 7 files changed, 211 insertions(+), 11 deletions(-) diff --git a/generators/app/templates/demo/views/buildscript.coffee b/generators/app/templates/demo/views/buildscript.coffee index 2430702a..ef933010 100644 --- a/generators/app/templates/demo/views/buildscript.coffee +++ b/generators/app/templates/demo/views/buildscript.coffee @@ -61,6 +61,20 @@ className: 'buildscript-view' + ###* + # The compiled handlebars template expander function. + # + # @property template + # + # @type Function + # @protected + # @static + # @final + ### + + template: template + + ###* # @method render # @@ -72,10 +86,25 @@ ## Expand the handlebars template into this view's container element. ## - @$el.html( template() ) + @$el.html( @template( @renderData() ) ) ## This method is chainable. ## return @ + + ###* + # Collect and return all data needed to expand the handlebars `@template` with + # + # @method renderData + # @protected + # + # @return {Object} + # + ### + + renderData: () -> + + return {} + ) diff --git a/generators/app/templates/demo/views/documentation.coffee b/generators/app/templates/demo/views/documentation.coffee index c63b37f1..fff9999b 100644 --- a/generators/app/templates/demo/views/documentation.coffee +++ b/generators/app/templates/demo/views/documentation.coffee @@ -59,6 +59,20 @@ className: 'documentation-view' + ###* + # The compiled handlebars template expander function. + # + # @property template + # + # @type Function + # @protected + # @static + # @final + ### + + template: template + + ###* # @method render # @@ -70,10 +84,25 @@ ## Expand the handlebars template into this view's container element. ## - @$el.html( template() ) + @$el.html( @template( @renderData() ) ) ## This method is chainable. ## return @ + + ###* + # Collect and return all data needed to expand the handlebars `@template` with + # + # @method renderData + # @protected + # + # @return {Object} + # + ### + + renderData: () -> + + return {} + ) diff --git a/generators/app/templates/demo/views/i18n.coffee b/generators/app/templates/demo/views/i18n.coffee index 4d53c13d..a44aedb0 100644 --- a/generators/app/templates/demo/views/i18n.coffee +++ b/generators/app/templates/demo/views/i18n.coffee @@ -64,6 +64,20 @@ className: 'i18n-view' + ###* + # The compiled handlebars template expander function. + # + # @property template + # + # @type Function + # @protected + # @static + # @final + ### + + template: template + + ###* # Setup UI event handler definitions. # @@ -90,11 +104,7 @@ ## Expand the handlebars template into this view's container element. ## - @$el.html( template( - date: new Date() - money: 100000 - number: 1090870987 - )) + @$el.html( @template( @renderData() ) ) ## Set the current locale as selected option. ## @@ -105,6 +115,23 @@ return @ + ###* + # Collect and return all data needed to expand the handlebars `@template` with + # + # @method renderData + # @protected + # + # @return {Object} + # + ### + + renderData: () -> + + date: new Date() + money: 100000 + number: 1090870987 + + ###* # Handles changes to the selected language. # diff --git a/generators/app/templates/demo/views/index.coffee b/generators/app/templates/demo/views/index.coffee index 62c3dd57..3d9f74c1 100644 --- a/generators/app/templates/demo/views/index.coffee +++ b/generators/app/templates/demo/views/index.coffee @@ -61,6 +61,20 @@ className: 'index-view' + ###* + # The compiled handlebars template expander function. + # + # @property template + # + # @type Function + # @protected + # @static + # @final + ### + + template: template + + ###* # @method render # @@ -72,10 +86,25 @@ ## Expand the handlebars template into this view's container element. ## - @$el.html( template() ) + @$el.html( @template( @renderData() ) ) ## This method is chainable. ## return @ + + ###* + # Collect and return all data needed to expand the handlebars `@template` with + # + # @method renderData + # @protected + # + # @return {Object} + # + ### + + renderData: () -> + + return {} + ) diff --git a/generators/app/templates/demo/views/navigation.coffee b/generators/app/templates/demo/views/navigation.coffee index 9084df6b..94585c82 100644 --- a/generators/app/templates/demo/views/navigation.coffee +++ b/generators/app/templates/demo/views/navigation.coffee @@ -47,6 +47,20 @@ className: 'navigation-view' + ###* + # The compiled handlebars template expander function. + # + # @property template + # + # @type Function + # @protected + # @static + # @final + ### + + template: template + + ###* # @method render # @@ -58,7 +72,7 @@ ## Expand the handlebars template into this view's container element. ## - @$el.html( template() ) + @$el.html( @template( @renderData() ) ) # Set reference to the navbar # @@ -69,6 +83,20 @@ return @ + ###* + # Collect and return all data needed to expand the handlebars `@template` with + # + # @method renderData + # @protected + # + # @return {Object} + # + ### + + renderData: () -> + + return {} + ###* # Set the activeMenuItem based on the url passed. # diff --git a/generators/app/templates/src/views/index.coffee b/generators/app/templates/src/views/index.coffee index 51bfb77c..79fef291 100644 --- a/generators/app/templates/src/views/index.coffee +++ b/generators/app/templates/src/views/index.coffee @@ -61,6 +61,20 @@ className: 'index-view' + ###* + # The compiled handlebars template expander function. + # + # @property template + # + # @type Function + # @protected + # @static + # @final + ### + + template: template + + ###* # @method initialize # @protected @@ -95,10 +109,25 @@ ## Expand the handlebars template into this view's container element. ## - @$el.html( template() ) + @$el.html( @template( @renderData() ) ) ## This method is chainable. ## return @ + + ###* + # Collect and return all data needed to expand the handlebars `@template` with + # + # @method renderData + # @protected + # + # @return {Object} + # + ### + + renderData: () -> + + return {} + ) diff --git a/generators/view/templates/view.coffee b/generators/view/templates/view.coffee index c04f4376..7d02f519 100644 --- a/generators/view/templates/view.coffee +++ b/generators/view/templates/view.coffee @@ -61,6 +61,20 @@ className: '<%= fileName %>-view' + ###* + # The compiled handlebars template expander function. + # + # @property template + # + # @type Function + # @protected + # @static + # @final + ### + + template: template + + ###* # @method initialize # @protected @@ -95,10 +109,25 @@ ## Expand the handlebars template into this view's container element. ## - @$el.html( template() ) + @$el.html( @template( @renderData() ) ) ## This method is chainable. ## return @ + + ###* + # Collect and return all data needed to expand the handlebars `@template` with + # + # @method renderData + # @protected + # + # @return {Object} + # + ### + + renderData: () -> + + return {} + )