From 96ad888a5cd582d34597feb2f5defac0ead6fe12 Mon Sep 17 00:00:00 2001 From: "david.bashford" Date: Tue, 28 Jan 2014 09:29:13 -0500 Subject: [PATCH] fixes #354, added writeLibrary config --- RELEASENOTES.md | 8 ++++++++ lib/modules/compilers/index.js | 4 +++- lib/modules/compilers/template.js | 8 +++++--- package.json | 2 +- src/modules/compilers/index.coffee | 5 +++++ src/modules/compilers/template.coffee | 9 +++++---- 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 46fb163c..3ef968e6 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,3 +1,11 @@ +## 2.0.4 - Jan 28 2014 + +### Major Changes +* __New Module: [mimosa-handlebars-on-window](https://github.com/dbasford/mimosa-handlebars-on-window). A dead simple module that will alter `handlebars.js` source slightly to attach `Handlebars` to the `window` object. Solves some current issues with Ember.js and r.js optimized builds. Also allows for managing Handlebars via Bower. + +### Minor Changes +* [mimosa #354](https://github.com/dbashford/mimosa/issues/354). Added `template.writeLibrary` config to allow for not writing template libraries, like `handlebars.js`. By default Mimosa's template compiler functionality will write an AMD version of the client library. + ## 2.0.3 - Jan 27 2014 ### Minor Changes diff --git a/lib/modules/compilers/index.js b/lib/modules/compilers/index.js index aca4b861..43ee1aeb 100644 --- a/lib/modules/compilers/index.js +++ b/lib/modules/compilers/index.js @@ -96,6 +96,7 @@ exports.registration = function(config, register) { exports.defaults = function() { return { template: { + writeLibrary: true, wrapType: "amd", commonLibPath: null, nameTransform: "fileName", @@ -105,13 +106,14 @@ exports.defaults = function() { }; exports.placeholder = function() { - return "\t\n\n # template: # overall template object can be set to null if no\n # templates being used\n # nameTransform: \"fileName\" # means by which Mimosa creates the name for each\n # template, options: default \"fileName\" is name of file,\n # \"filePath\" is path of file after watch.sourceDir\n # with the extension dropped, a supplied regex can be\n # used to remove any unwanted portions of the filePath,\n # and a provided function will be called with the\n # filePath as input\n # wrapType: \"amd\" # The type of module wrapping for the output templates\n # file. Possible values: \"amd\", \"common\", \"none\".\n # commonLibPath: null # Valid when wrapType is 'common'. The path to the\n # client library. Some libraries do not have clients\n # therefore this is not strictly required when choosing\n # the common wrapType.\n # outputFileName: \"javascripts/templates\" # the file all templates are compiled into,\n # is relative to watch.sourceDir.\n\n # outputFileName: # outputFileName Alternate Config 1\n # hogan:\"hogans\" # Optionally outputFileName can be provided an object of\n # jade:\"jades\" # compiler name to file name in the event you are using\n # multiple templating libraries.\n\n # output: [{ # output Alternate Config 2\n # folders:[\"\"] # Use output instead of outputFileName if you want\n # outputFileName: \"\" # to break up your templates into multiple files, for\n # }] # instance, if you have a two page app and want the\n # templates for each page to be built separately.\n # For each entry, provide an array of folders that\n # contain the templates to combine. folders entries are\n # relative to watch.sourceDir and must exist.\n # outputFileName works identically to outputFileName\n # above, including the alternate config, however, no\n # default file name is assumed. An output name must be\n # provided for each output entry, and the names\n # must be unique.\n"; + return "\t\n\n # template: # overall template object can be set to null if no\n # templates being used\n # writeLibrary: true # Whether or not to write a client library for\n # any template compilers\n # nameTransform: \"fileName\" # means by which Mimosa creates the name for each\n # template, options: default \"fileName\" is name of file,\n # \"filePath\" is path of file after watch.sourceDir\n # with the extension dropped, a supplied regex can be\n # used to remove any unwanted portions of the filePath,\n # and a provided function will be called with the\n # filePath as input\n # wrapType: \"amd\" # The type of module wrapping for the output templates\n # file. Possible values: \"amd\", \"common\", \"none\".\n # commonLibPath: null # Valid when wrapType is 'common'. The path to the\n # client library. Some libraries do not have clients\n # therefore this is not strictly required when choosing\n # the common wrapType.\n # outputFileName: \"javascripts/templates\" # the file all templates are compiled into,\n # is relative to watch.sourceDir.\n\n # outputFileName: # outputFileName Alternate Config 1\n # hogan:\"hogans\" # Optionally outputFileName can be provided an object of\n # jade:\"jades\" # compiler name to file name in the event you are using\n # multiple templating libraries.\n\n # output: [{ # output Alternate Config 2\n # folders:[\"\"] # Use output instead of outputFileName if you want\n # outputFileName: \"\" # to break up your templates into multiple files, for\n # }] # instance, if you have a two page app and want the\n # templates for each page to be built separately.\n # For each entry, provide an array of folders that\n # contain the templates to combine. folders entries are\n # relative to watch.sourceDir and must exist.\n # outputFileName works identically to outputFileName\n # above, including the alternate config, however, no\n # default file name is assumed. An output name must be\n # provided for each output entry, and the names\n # must be unique.\n"; }; exports.validate = function(config, validators) { var errors, fName, fileNames, folder, newFolders, outputConfig, tComp, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; errors = []; if (validators.ifExistsIsObject(errors, "template config", config.template)) { + validators.ifExistsIsBoolean(errors, "template.writeLibrary", config.template.writeLibrary); if (config.template.output && config.template.outputFileName) { delete config.template.outputFileName; } diff --git a/lib/modules/compilers/template.js b/lib/modules/compilers/template.js index 89f09268..e83c5033 100644 --- a/lib/modules/compilers/template.js +++ b/lib/modules/compilers/template.js @@ -103,12 +103,14 @@ module.exports = TemplateCompiler = (function() { register(['add', 'update', 'remove'], 'init', this._gatherFiles, this.extensions); register(['buildExtension'], 'compile', this._compile, [this.extensions[0]]); register(['add', 'update', 'remove'], 'compile', this._compile, this.extensions); - register(['remove'], 'init', this._testForRemoveClientLibrary, this.extensions); register(['cleanFile'], 'init', this._removeFiles, this.extensions); register(['buildExtension'], 'afterCompile', this._merge, [this.extensions[0]]); register(['add', 'update', 'remove'], 'afterCompile', this._merge, this.extensions); - register(['add', 'update'], 'afterCompile', this._readInClientLibrary, this.extensions); - return register(['buildExtension'], 'afterCompile', this._readInClientLibrary, [this.extensions[0]]); + if (config.template.writeLibrary) { + register(['remove'], 'init', this._testForRemoveClientLibrary, this.extensions); + register(['add', 'update'], 'afterCompile', this._readInClientLibrary, this.extensions); + return register(['buildExtension'], 'afterCompile', this._readInClientLibrary, [this.extensions[0]]); + } }; TemplateCompiler.prototype._gatherFiles = function(config, options, next) { diff --git a/package.json b/package.json index 33586783..7460798c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mimosa", "preferGlobal": "true", - "version": "2.0.3", + "version": "2.0.4", "homepage": "http://www.mimosa.io", "author": "David Bashford", "description": "A lighting-fast, modular, next generation browser development tool.", diff --git a/src/modules/compilers/index.coffee b/src/modules/compilers/index.coffee index 8ecf3f6f..40c3d476 100644 --- a/src/modules/compilers/index.coffee +++ b/src/modules/compilers/index.coffee @@ -63,6 +63,7 @@ exports.registration = (config, register) -> exports.defaults = -> template: + writeLibrary: true wrapType: "amd" commonLibPath: null nameTransform:"fileName" @@ -74,6 +75,8 @@ exports.placeholder = -> # template: # overall template object can be set to null if no # templates being used + # writeLibrary: true # Whether or not to write a client library for + # any template compilers # nameTransform: "fileName" # means by which Mimosa creates the name for each # template, options: default "fileName" is name of file, # "filePath" is path of file after watch.sourceDir @@ -115,6 +118,8 @@ exports.validate = (config, validators) -> errors = [] if validators.ifExistsIsObject(errors, "template config", config.template) + validators.ifExistsIsBoolean( errors, "template.writeLibrary", config.template.writeLibrary ) + if config.template.output and config.template.outputFileName delete config.template.outputFileName diff --git a/src/modules/compilers/template.coffee b/src/modules/compilers/template.coffee index baeecd82..8b818362 100644 --- a/src/modules/compilers/template.coffee +++ b/src/modules/compilers/template.coffee @@ -85,15 +85,16 @@ module.exports = class TemplateCompiler register ['buildExtension'], 'compile', @_compile, [@extensions[0]] register ['add','update','remove'], 'compile', @_compile, @extensions - register ['remove'], 'init', @_testForRemoveClientLibrary, @extensions - register ['cleanFile'], 'init', @_removeFiles, @extensions register ['buildExtension'], 'afterCompile', @_merge, [@extensions[0]] register ['add','update','remove'], 'afterCompile', @_merge, @extensions - register ['add','update'], 'afterCompile', @_readInClientLibrary, @extensions - register ['buildExtension'], 'afterCompile', @_readInClientLibrary, [@extensions[0]] + if config.template.writeLibrary + register ['remove'], 'init', @_testForRemoveClientLibrary, @extensions + + register ['add','update'], 'afterCompile', @_readInClientLibrary, @extensions + register ['buildExtension'], 'afterCompile', @_readInClientLibrary, [@extensions[0]] _gatherFiles: (config, options, next) => options.files = []