diff --git a/middleware.js b/middleware.js deleted file mode 100644 index 9f0a972..0000000 --- a/middleware.js +++ /dev/null @@ -1,54 +0,0 @@ -/*───────────────────────────────────────────────────────────────────────────*\ - │ Copyright (C) 2014 eBay Software Foundation │ - │ │ - │hh ,'""`. │ - │ / _ _ \ Licensed under the Apache License, Version 2.0 (the "License"); │ - │ |(@)(@)| you may not use this file except in compliance with the License. │ - │ ) __ ( You may obtain a copy of the License at │ - │ /,'))((`.\ │ - │(( (( )) )) http://www.apache.org/licenses/LICENSE-2.0 │ - │ `\ `)(' /' │ - │ │ - │ Unless required by applicable law or agreed to in writing, software │ - │ distributed under the License is distributed on an "AS IS" BASIS, │ - │ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │ - │ See the License for the specific language governing permissions and │ - │ limitations under the License. │ - \*───────────────────────────────────────────────────────────────────────────*/ -"use strict"; - -var makeViewClass = require('./'); - -module.exports = function setupViewClass(options) { - var opts = {}; - opts['.properties'] = {}; - opts['.js'] = {}; - opts['.dust'] = {}; - - if (options.i18n) { - opts['.properties'].root = [].concat(options.i18n.contentPath); - opts['.properties'].i18n = { - fallback: options.i18n.fallback - }; - - opts['.js'].i18n = { - fallback: options.i18n.fallback - }; - } - - if (options.specialization) { - opts['.properties'].specialization = options.specialization; - opts['.js'].specialization = options.specialization; - opts['.dust'].specialization = options.specialization; - } - - var hasConfiguredApp = false; - return function (req, res, next) { - if (!hasConfiguredApp) { - req.app.set('view', makeViewClass(opts)); - hasConfiguredApp = true; - } - next(); - }; -}; - diff --git a/test/middleware.js b/test/middleware.js deleted file mode 100644 index 32b98ad..0000000 --- a/test/middleware.js +++ /dev/null @@ -1,54 +0,0 @@ -var test = require('tap').test; -var View = require('../')({}); -var setupViewClass = require('../middleware'); -var express = require('express'); -var supertest = require('supertest'); -var path = require('path'); - -test('first-run middleware', function (t) { - var app = express(); - var view, afterView; - - app.set('view engine', 'fake'); - app.engine('fake', fakeEngine); - app.use(function (req, res, next) { - view = app.get('view'); - t.ok(view); - next(); - }); - app.use(setupViewClass({ - i18n: { - contentPath: path.resolve(__dirname, 'fixtures', 'properties') - }, - specialization: { - 'spcl/jekyll': [ - { - is: 'spcl/hyde', - when: { - 'whoAmI': 'badGuy' - } - } - ] - } - })); - app.use(function (req, res, next) { - afterView = app.get('view'); - t.ok(afterView); - next(); - }); - app.get('/', function (req, res) { - res.end('got it'); - }); - - supertest(app).get('/').end(function (err, res) { - t.error(err); - t.ok(res); - t.notEqual(afterView, view); - t.end(); - }); - -}); - -function fakeEngine() { - console.log('fake engine called', arguments); -}