Skip to content

Commit

Permalink
fixes #354, added writeLibrary config
Browse files Browse the repository at this point in the history
  • Loading branch information
dbashford committed Jan 28, 2014
1 parent c7d90a8 commit 96ad888
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
8 changes: 8 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/modules/compilers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ exports.registration = function(config, register) {
exports.defaults = function() {
return {
template: {
writeLibrary: true,
wrapType: "amd",
commonLibPath: null,
nameTransform: "fileName",
Expand All @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions lib/modules/compilers/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
5 changes: 5 additions & 0 deletions src/modules/compilers/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ exports.registration = (config, register) ->

exports.defaults = ->
template:
writeLibrary: true
wrapType: "amd"
commonLibPath: null
nameTransform:"fileName"
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions src/modules/compilers/template.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down

0 comments on commit 96ad888

Please sign in to comment.