mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Code cleanup
This commit is contained in:
parent
9ceded3078
commit
f45d89b18c
@ -36,6 +36,5 @@
|
||||
"unused": "vars",
|
||||
"strict": false,
|
||||
|
||||
/* Relaxing options: */
|
||||
"eqnull": true
|
||||
}
|
||||
@ -1,29 +1,35 @@
|
||||
'use strict';
|
||||
var promiseUtil = require('raptor-promises/util');
|
||||
|
||||
var FRAGMENT_CACHE_CONFIG = {
|
||||
store: 'memory'
|
||||
};
|
||||
|
||||
var raptorCache;
|
||||
|
||||
module.exports = {
|
||||
render: function (input, context) {
|
||||
var attributes = context.attributes;
|
||||
var cacheProvider = attributes.cacheProvider;
|
||||
var cache;
|
||||
if (raptorCache === undefined) {
|
||||
try {
|
||||
raptorCache = require('raptor-cache');
|
||||
}
|
||||
catch(e) {
|
||||
throw new Error('The "raptor-cache" module should be installed as an application-level dependency when using caching tags');
|
||||
}
|
||||
}
|
||||
|
||||
var cacheKey = input.cacheKey;
|
||||
if (!cacheKey) {
|
||||
throw new Error('cache-key is required for <cached-fragment>');
|
||||
}
|
||||
if (!cacheProvider) {
|
||||
var raptorCacheModulePath;
|
||||
try {
|
||||
raptorCacheModulePath = require.resolve('raptor-cache');
|
||||
}
|
||||
catch(e) {
|
||||
throw new Error('The "raptor-cache" module should be installed as an application-level dependency when using caching tags');
|
||||
}
|
||||
cacheProvider = require(raptorCacheModulePath).getDefaultProvider();
|
||||
}
|
||||
cache = cacheProvider.getCache(input.cacheName);
|
||||
var cachePromise = cache.get(
|
||||
cacheKey,
|
||||
|
||||
// use the default cache manager
|
||||
var cacheManager = raptorCache.getDefaultCacheManager(context);
|
||||
|
||||
var cache = cacheManager.getCache(input.cacheName, FRAGMENT_CACHE_CONFIG);
|
||||
|
||||
var asyncContext = context.beginAsync();
|
||||
|
||||
cache.get(cacheKey,
|
||||
{
|
||||
builder: function() {
|
||||
var result = context.captureString(function () {
|
||||
@ -33,17 +39,12 @@ module.exports = {
|
||||
});
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}, function(err, result) {
|
||||
if (err) {
|
||||
return asyncContext.error(err);
|
||||
}
|
||||
|
||||
var asyncContext = context.beginAsync();
|
||||
|
||||
promiseUtil.immediateThen(
|
||||
cachePromise,
|
||||
function (result) {
|
||||
asyncContext.end(result);
|
||||
},
|
||||
function (e) {
|
||||
asyncContext.error(e);
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -47,6 +47,5 @@
|
||||
"latedef": true,
|
||||
"unused": "vars",
|
||||
|
||||
/* Relaxing options: */
|
||||
"eqnull": true
|
||||
}
|
||||
@ -158,7 +158,7 @@ describe('raptor-templates/rhtml' , function() {
|
||||
testRender("test-project/rhtml-templates/looping-props.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it.only("should allow for looping over ranges", function(done) {
|
||||
it("should allow for looping over ranges", function(done) {
|
||||
testRender("test-project/rhtml-templates/looping-range.rhtml", {}, done);
|
||||
});
|
||||
|
||||
@ -394,4 +394,3 @@ describe('raptor-templates/rhtml' , function() {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user