-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #318 - Make configuration a singleton object shared by all mark…
…o instances
- Loading branch information
1 parent
c26614f
commit cd79732
Showing
8 changed files
with
116 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
var NODE_ENV = process.env.NODE_ENV; | ||
var config; | ||
|
||
module.exports = { | ||
/** | ||
* If true, then the compiler will check the disk to see if a previously compiled | ||
* template is the same age or newer than the source template. If so, the previously | ||
* compiled template will be loaded. Otherwise, the template will be recompiled | ||
* and saved to disk. | ||
* | ||
* If false, the template will always be recompiled. If `writeToDisk` is false | ||
* then this option will be ignored. | ||
*/ | ||
checkUpToDate: process.env.MARKO_CLEAN ? false : true, | ||
/** | ||
* If true (the default) then compiled templates will be written to disk. If false, | ||
* compiled templates will not be written to disk (i.e., no `.marko.js` file will | ||
* be generated) | ||
*/ | ||
writeToDisk: true, | ||
/* globals window */ | ||
var g = typeof window === 'undefined' ? global : window; | ||
|
||
/** | ||
* If true, then the compiled template on disk will assumed to be up-to-date if it exists. | ||
*/ | ||
assumeUpToDate: process.env.MARKO_CLEAN != null || process.env.hasOwnProperty('MARKO_HOT_RELOAD') ? false : ( NODE_ENV == null ? false : (NODE_ENV !== 'development' && NODE_ENV !== 'dev')), | ||
|
||
/** | ||
* If true, whitespace will be preserved in templates. Defaults to false. | ||
* @type {Boolean} | ||
*/ | ||
preserveWhitespace: false | ||
}; | ||
if (g.__MARKO_CONFIG) { | ||
config = g.__MARKO_CONFIG; | ||
} else { | ||
config = g.__MARKO_CONFIG = { | ||
/** | ||
* If true, then the compiler will check the disk to see if a previously compiled | ||
* template is the same age or newer than the source template. If so, the previously | ||
* compiled template will be loaded. Otherwise, the template will be recompiled | ||
* and saved to disk. | ||
* | ||
* If false, the template will always be recompiled. If `writeToDisk` is false | ||
* then this option will be ignored. | ||
*/ | ||
checkUpToDate: process.env.MARKO_CLEAN ? false : true, | ||
/** | ||
* If true (the default) then compiled templates will be written to disk. If false, | ||
* compiled templates will not be written to disk (i.e., no `.marko.js` file will | ||
* be generated) | ||
*/ | ||
writeToDisk: true, | ||
|
||
/** | ||
* If true, then the compiled template on disk will assumed to be up-to-date if it exists. | ||
*/ | ||
assumeUpToDate: process.env.MARKO_CLEAN != null || process.env.hasOwnProperty('MARKO_HOT_RELOAD') ? false : ( NODE_ENV == null ? false : (NODE_ENV !== 'development' && NODE_ENV !== 'dev')), | ||
|
||
/** | ||
* If true, whitespace will be preserved in templates. Defaults to false. | ||
* @type {Boolean} | ||
*/ | ||
preserveWhitespace: false | ||
}; | ||
} | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
exports.check = function(marko, markoCompiler, expect, done) { | ||
var configModulePath = require.resolve('../../../../compiler/config'); | ||
var config = require(configModulePath); | ||
|
||
var globalConfig = global.__MARKO_CONFIG; | ||
expect(config).to.equal(globalConfig); | ||
|
||
delete require.cache[configModulePath]; | ||
|
||
config = require(configModulePath); | ||
expect(config).to.equal(globalConfig); | ||
|
||
done(); | ||
}; |
1 change: 1 addition & 0 deletions
1
test/autotests/api/writeToDisk-false-include/include-target.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Hello ${data.name}! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<include('./include-target.marko') name="Frank"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var nodePath = require('path'); | ||
var fs = require('fs'); | ||
|
||
exports.check = function(marko, markoCompiler, expect, done) { | ||
|
||
markoCompiler.configure({ | ||
writeToDisk: false | ||
}); | ||
|
||
var templatePath = nodePath.join(__dirname, 'template.marko'); | ||
var template = marko.load(templatePath); | ||
expect(template.renderSync({name: 'Frank'})).to.equal('Hello Frank!'); | ||
|
||
markoCompiler.configure({ | ||
writeToDisk: false | ||
}); | ||
|
||
var compiledTemplatePath = nodePath.join(__dirname, 'template.marko.js'); | ||
var compiledIncludeTemplatePath = nodePath.join(__dirname, 'include-target.marko.js'); | ||
|
||
expect(fs.existsSync(compiledTemplatePath)).to.equal(false); | ||
expect(fs.existsSync(compiledIncludeTemplatePath)).to.equal(false); | ||
|
||
// Revert back to defaults | ||
markoCompiler.configure(); | ||
|
||
done(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
<layout-placeholder name="body"></layout-placeholder> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<layout-use('./layout.marko')> | ||
<layout-put into="body">Hello ${data.name}!</layout-put> | ||
</layout-use> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var nodePath = require('path'); | ||
var fs = require('fs'); | ||
|
||
exports.check = function(marko, markoCompiler, expect, done) { | ||
|
||
markoCompiler.configure({ | ||
writeToDisk: false | ||
}); | ||
|
||
var templatePath = nodePath.join(__dirname, 'template.marko'); | ||
var template = marko.load(templatePath); | ||
expect(template.renderSync({name: 'Frank'})).to.equal('<div>Hello Frank!</div>'); | ||
|
||
markoCompiler.configure({ | ||
writeToDisk: false | ||
}); | ||
|
||
var compiledTemplatePath = nodePath.join(__dirname, 'template.marko.js'); | ||
var compiledIncludeTemplatePath = nodePath.join(__dirname, 'layout.marko.js'); | ||
|
||
expect(fs.existsSync(compiledTemplatePath)).to.equal(false); | ||
expect(fs.existsSync(compiledIncludeTemplatePath)).to.equal(false); | ||
|
||
// Revert back to defaults | ||
markoCompiler.configure(); | ||
|
||
done(); | ||
}; |