Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix creating WebLoader without opts. #524

Merged
merged 1 commit into from
Sep 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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