Skip to content

Commit

Permalink
Merge pull request #524 from oddbird/fix-web-loader
Browse files Browse the repository at this point in the history
Fix creating WebLoader without opts.
  • Loading branch information
carljm committed Sep 18, 2015
2 parents 059aa10 + 28769f5 commit 970a833
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/web-loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ var PrecompiledLoader = require('./precompiled-loader.js');
var WebLoader = Loader.extend({
init: function(baseURL, opts) {
this.baseURL = baseURL || '.';
opts = opts || {};

// By default, the cache is turned off because there's no way
// to "watch" templates over HTTP, so they are re-downloaded
// and compiled each time. (Remember, PRECOMPILE YOUR
// TEMPLATES in production!)
this.useCache = opts.useCache;
this.useCache = !!opts.useCache;

// We default `async` to false so that the simple synchronous
// API can be used when you aren't doing anything async in
// your templates (which is most of the time). This performs a
// sync ajax request, but that's ok because it should *only*
// happen in development. PRECOMPILE YOUR TEMPLATES.
this.async = opts.async;
this.async = !!opts.async;
},

resolve: function(from, to) { // jshint ignore:line
Expand Down
17 changes: 15 additions & 2 deletions tests/loader.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
(function() {
'use strict';

var expect, Environment, Loader, templatesPath;
var expect, Environment, WebLoader, FileSystemLoader, templatesPath;

if(typeof require !== 'undefined') {
expect = require('expect.js');
Environment = require('../src/environment').Environment;
WebLoader = require('../src/web-loaders').WebLoader;
FileSystemLoader = require('../src/node-loaders').FileSystemLoader;
templatesPath = 'tests/templates';
}
else {
expect = window.expect;
Environment = nunjucks.Environment;
Loader = nunjucks.WebLoader;
WebLoader = nunjucks.WebLoader;
FileSystemLoader = nunjucks.FileSystemLoader;
templatesPath = '../templates';
}

describe('loader', function() {
it('should have default opts', function() {
var webLoader = new WebLoader(templatesPath);
var fileSystemLoader = new FileSystemLoader(templatesPath);
expect(webLoader).to.be.a(WebLoader);
expect(webLoader.useCache).to.be(false);
expect(webLoader.async).to.be(false);
expect(fileSystemLoader).to.be.a(FileSystemLoader);
expect(fileSystemLoader.noCache).to.be(false);
});

it('should allow a simple loader to be created', function() {
// From Docs: http://mozilla.github.io/nunjucks/api.html#writing-a-loader
// We should be able to create a loader that only exposes getSource
Expand Down

0 comments on commit 970a833

Please sign in to comment.