@@ -30,7 +30,7 @@ validator.addFormat('mustache', {
3030} ) ;
3131const _validateSchema = validator . compile ( tmplSchema ) ;
3232
33- class JSONViewTransform {
33+ class JSONParametersTransform {
3434 transform ( schema , value ) {
3535 if ( typeof value === 'undefined' ) {
3636 return value ;
@@ -59,14 +59,14 @@ class Template {
5959 this . description = '' ;
6060 this . definitions = { } ;
6161 this . typeDefinitions = { } ;
62- this . _viewSchema = { } ;
62+ this . _parametersSchema = { } ;
6363 this . target = 'as3' ;
6464 this . templateText = '' ;
65- this . defaultView = { } ;
65+ this . defaultParameters = { } ;
6666 this . sourceType = 'UNKNOWN' ;
6767 this . sourceText = '' ;
6868 this . sourceHash = '' ;
69- this . _viewValidator = undefined ;
69+ this . _parametersValidator = undefined ;
7070 }
7171
7272 _loadTypeSchemas ( schemaProvider ) {
@@ -340,13 +340,13 @@ class Template {
340340 return schema ;
341341 }
342342
343- _viewSchemaFromTemplate ( typeSchemas ) {
344- this . _viewSchema = this . _handleParsed ( Mustache . parse ( this . templateText ) , typeSchemas ) ;
343+ _parametersSchemaFromTemplate ( typeSchemas ) {
344+ this . _parametersSchema = this . _handleParsed ( Mustache . parse ( this . templateText ) , typeSchemas ) ;
345345
346346 // If we just ended up with an empty string type, then we have no types and we
347347 // should return an empty object instead.
348- if ( this . _viewSchema . type === 'string' && ! this . _viewSchema . properties ) {
349- this . _viewSchema . type = 'object' ;
348+ if ( this . _parametersSchema . type === 'string' && ! this . _parametersSchema . properties ) {
349+ this . _parametersSchema . type = 'object' ;
350350 }
351351 }
352352
@@ -359,7 +359,7 @@ class Template {
359359 this . sourceHash = hash . digest ( 'hex' ) ;
360360 }
361361
362- _createViewValidator ( ) {
362+ _createParametersValidator ( ) {
363363 const loadSchema = ( uri ) => {
364364 uri = url . parse ( uri ) ;
365365 const opts = {
@@ -383,9 +383,9 @@ class Template {
383383 ajv . addFormat ( 'text' , / .* / ) ;
384384 ajv . addFormat ( 'hidden' , / .* / ) ;
385385 ajv . addFormat ( 'password' , / .* / ) ;
386- return ajv . compileAsync ( this . getViewSchema ( ) )
386+ return ajv . compileAsync ( this . getParametersSchema ( ) )
387387 . then ( ( validate ) => {
388- this . _viewValidator = validate ;
388+ this . _parametersValidator = validate ;
389389 return Promise . resolve ( ) ;
390390 } ) ;
391391 }
@@ -398,9 +398,9 @@ class Template {
398398 return tmpl . _loadTypeSchemas ( schemaProvider )
399399 . then ( ( typeSchemas ) => {
400400 tmpl . _descriptionFromTemplate ( ) ;
401- tmpl . _viewSchemaFromTemplate ( typeSchemas ) ;
401+ tmpl . _parametersSchemaFromTemplate ( typeSchemas ) ;
402402 } )
403- . then ( ( ) => tmpl . _createViewValidator ( ) )
403+ . then ( ( ) => tmpl . _createParametersValidator ( ) )
404404 . then ( ( ) => tmpl ) ;
405405 }
406406
@@ -414,13 +414,13 @@ class Template {
414414 if ( yamldata . title ) tmpl . title = yamldata . title ;
415415 if ( yamldata . description ) tmpl . description = yamldata . description ;
416416 if ( yamldata . definitions ) tmpl . definitions = yamldata . definitions ;
417- if ( yamldata . view ) tmpl . defaultView = yamldata . view ;
417+ if ( yamldata . parameters ) tmpl . defaultParameters = yamldata . parameters ;
418418
419419 return tmpl . _loadTypeSchemas ( schemaProvider )
420420 . then ( ( typeSchemas ) => {
421- tmpl . _viewSchemaFromTemplate ( typeSchemas ) ;
421+ tmpl . _parametersSchemaFromTemplate ( typeSchemas ) ;
422422 } )
423- . then ( ( ) => tmpl . _createViewValidator ( ) )
423+ . then ( ( ) => tmpl . _createParametersValidator ( ) )
424424 . then ( ( ) => tmpl ) ;
425425 }
426426
@@ -431,7 +431,7 @@ class Template {
431431 const tmpl = new this ( ) ;
432432 Object . assign ( tmpl , obj ) ;
433433 return Promise . resolve ( )
434- . then ( ( ) => tmpl . _createViewValidator ( ) )
434+ . then ( ( ) => tmpl . _createParametersValidator ( ) )
435435 . then ( ( ) => tmpl ) ;
436436 }
437437
@@ -449,24 +449,24 @@ class Template {
449449 }
450450 }
451451
452- getViewSchema ( ) {
453- return Object . assign ( { } , this . _viewSchema , {
452+ getParametersSchema ( ) {
453+ return Object . assign ( { } , this . _parametersSchema , {
454454 title : this . title ,
455455 description : this . description ,
456456 definitions : this . typeDefinitions
457457 } ) ;
458458 }
459459
460- getCombinedView ( view ) {
461- const typeProps = this . getViewSchema ( ) . properties ;
460+ getCombinedParameters ( parameters ) {
461+ const typeProps = this . getParametersSchema ( ) . properties ;
462462 const typeDefaults = typeProps && Object . keys ( typeProps ) . reduce ( ( acc , key ) => {
463463 const value = typeProps [ key ] ;
464464 if ( value . default !== undefined ) {
465465 acc [ key ] = value . default ;
466466 }
467467 return acc ;
468468 } , { } ) ;
469- return Object . assign ( { } , typeDefaults || { } , this . defaultView , view || { } ) ;
469+ return Object . assign ( { } , typeDefaults || { } , this . defaultParameters , parameters || { } ) ;
470470 }
471471
472472 _getPartials ( ) {
@@ -479,18 +479,18 @@ class Template {
479479 } , { } ) ;
480480 }
481481
482- validateView ( view ) {
483- const combView = this . getCombinedView ( view ) ;
484- if ( ! this . _viewValidator ( combView ) ) {
485- throw new Error ( JSON . stringify ( this . _viewValidator . errors , null , 2 ) ) ;
482+ validateParameters ( parameters ) {
483+ const combParams = this . getCombinedParameters ( parameters ) ;
484+ if ( ! this . _parametersValidator ( combParams ) ) {
485+ throw new Error ( JSON . stringify ( this . _parametersValidator . errors , null , 2 ) ) ;
486486 }
487487 }
488488
489- transformView ( view ) {
490- const schema = this . getViewSchema ( ) ;
491- const transform = new JSONViewTransform ( ) ;
492- return Object . keys ( view ) . reduce ( ( acc , curr ) => {
493- const value = view [ curr ] ;
489+ transformParameters ( parameters ) {
490+ const schema = this . getParametersSchema ( ) ;
491+ const transform = new JSONParametersTransform ( ) ;
492+ return Object . keys ( parameters ) . reduce ( ( acc , curr ) => {
493+ const value = parameters [ curr ] ;
494494 const valueSchema = schema . properties && schema . properties [ curr ] ;
495495
496496 if ( valueSchema ) {
@@ -507,11 +507,11 @@ class Template {
507507 return text . replace ( / { { ( [ _ a - z A - Z 0 - 9 ] + ) : .* } } / g, '{{$1}}' ) ;
508508 }
509509
510- render ( view ) {
511- this . validateView ( view ) ;
512- const xfview = this . transformView ( this . getCombinedView ( view ) ) ;
510+ render ( parameters ) {
511+ this . validateParameters ( parameters ) ;
512+ const xfparams = this . transformParameters ( this . getCombinedParameters ( parameters ) ) ;
513513 const partials = this . _getPartials ( ) ;
514- return Mustache . render ( this . _cleanTemplateText ( this . templateText ) , xfview , partials ) ;
514+ return Mustache . render ( this . _cleanTemplateText ( this . templateText ) , xfparams , partials ) ;
515515 }
516516}
517517
0 commit comments