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

use custom module.export js renderer #9

Merged
merged 4 commits into from
Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 20 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,22 @@ app.use(express.static(__dirname + '/public'));

// views is directory for all template files
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

// custom renderer
app.engine('js', (filePath, options, callback) => {
const renderer = require(filePath);

let opts = {
manufacturers: manufacturers,
manufacturersIndex: manufacturersIndex,
typesIndex: typesIndex,
messages: getMessages()
};
Object.assign(opts, options);

callback(null, renderer(opts));
});
app.set('view engine', 'js');


// message objects to show to the user
Expand Down Expand Up @@ -65,8 +80,7 @@ app.use((request, response, next) => {

if (page in staticPages) {
response.render('pages' + page, {
title: staticPages[page],
messages: getMessages()
title: staticPages[page]
});
}
else {
Expand All @@ -76,17 +90,13 @@ app.use((request, response, next) => {

app.get('/manufacturers', (request, response) => {
response.render('pages/manufacturers', {
title: 'Manufacturers - Open Fixture Library',
messages: getMessages(),
manufacturers: manufacturers,
manufacturersIndex: manufacturersIndex
title: 'Manufacturers - Open Fixture Library'
});
});

app.get('/search', (request, response) => {
response.render('pages/search', {
title: 'Search - Open Fixture Library',
messages: getMessages()
title: 'Search - Open Fixture Library'
});
});

Expand All @@ -109,8 +119,7 @@ app.use((request, response, next) => {
}

response.status(404).render('pages/404', {
title: 'Page not found - Open Fixture Library',
messages: getMessages()
title: 'Page not found - Open Fixture Library'
})
});

Expand All @@ -129,7 +138,6 @@ function renderSingleManufacturer(response, man) {

response.render('pages/single_manufacturer', {
title: manufacturers[man].name + ' - Open Fixture Library',
messages: getMessages(),
manufacturer: manufacturers[man],
fixtures: fixtures
});
Expand All @@ -140,7 +148,6 @@ function renderSingleFixture(response, man, fix) {

response.render('pages/single_fixture', {
title: `${manufacturers[man].name} ${fixData.name} - Open Fixture Library`,
messages: getMessages(),
manufacturer: manufacturers[man],
manufacturerPath: '/' + man,
fixture: fixData
Expand Down
7 changes: 0 additions & 7 deletions views/pages/404.ejs

This file was deleted.

11 changes: 11 additions & 0 deletions views/pages/404.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = function(options) {
let str = require('../partials/header')(options);

str += '<h1>404 - Not found</h1>';

str += `<p>The requested page was not found. Maybe you've got the wrong URL? If not, consider <a href="https://github.com/FloEdelmann/open-fixture-library/issues">filing a bug</a>.</p>`;

str += require('../partials/footer')(options);

return str;
};
6 changes: 0 additions & 6 deletions views/pages/about.ejs

This file was deleted.

11 changes: 11 additions & 0 deletions views/pages/about.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = function(options) {
let str = require('../partials/header')(options);

str += '<h1>About</h1>';

str += '<p><em>Open Fixture Library</em> is a project by Florian Edelmann. It is <a href="http://github.com/FloEdelmann/open-fixture-library/">open source</a> (licensed under <a href="https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3)" title="Gnu General Public License v3">GPL-3</a>) and everybody is invited to contribute!</p>';

str += require('../partials/footer')(options);

return str;
};
6 changes: 0 additions & 6 deletions views/pages/categories.ejs

This file was deleted.

10 changes: 10 additions & 0 deletions views/pages/categories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = function(options) {
let str = require('../partials/header')(options);

str += '<h1>Categories</h1>'
str += '<p>list of all categories</p>';

str += require('../partials/footer')(options);

return str;
};
11 changes: 0 additions & 11 deletions views/pages/index.ejs

This file was deleted.

15 changes: 15 additions & 0 deletions views/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = function(options) {
let str = require('../partials/header')(options);

str += '<h1>Open Fixture Library</h1>';

str += '<p>To use lighting control software like <a href="http://www.qlcplus.org/">QLC+</a> or <a href="http://www.ecue.de/">e:cue</a>, you need fixture definition files for your specific hardware. Those can be difficult to create or find for your software or they may be wrong because nobody peer-reviewed them.</p>';

str += '<p><abbr title="Open Fixture Library">OFL</abbr> tries to solve those problems by collecting fixture definitions and making them downloadable in various formats. Everybody can <a href="https://github.com/FloEdelmann/open-fixture-library">contribute</a> and help to improve!</p>';

str += '<p>The project is still in a very early status, but you can still check out the progress on <a href="https://github.com/FloEdelmann/open-fixture-library">GitHub</a> and also already report issues or feature requests or even contribute some code. Thanks!</p>';

str += require('../partials/footer')(options);

return str;
};
25 changes: 0 additions & 25 deletions views/pages/manufacturers.ejs

This file was deleted.

35 changes: 35 additions & 0 deletions views/pages/manufacturers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = function(options) {
const {manufacturers, manufacturersIndex} = options;

let str = require('../partials/header')(options);

str += '<h1>Manufacturers</h1>';

for (man in manufacturers) {
let manufacturer = manufacturers[man];
let num = manufacturersIndex[man].length;
let numFixtures = `${num} fixture${num == 1 ? '' : 's'}`;

str += '<section class="manufacturer">';
str += '<h2>' + (num > 0 ? `<a href="${man}">${manufacturer.name}</a>` : manufacturer.name) + '</h2>';

if ('website' in manufacturer) {
str += `<div class="website"><a href="${manufacturer.website}">Website</a></div>`;
}
if ('comment' in manufacturer) {
str += `<p class="comment">${manufacturer.comment}</p>`;
}

str += '<div class="fixtures">' + numFixtures;
if (num > 0) {
str += ` - <a href="/${man}">View them</a>`;
}
str += '</div>';

str += '</section>';
}

str += require('../partials/footer')(options);

return str;
};
6 changes: 0 additions & 6 deletions views/pages/search.ejs

This file was deleted.

10 changes: 10 additions & 0 deletions views/pages/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = function(options) {
let str = require('../partials/header')(options);

str += '<h1>Search</h1>';
str += '<p>search results</p>';

str += require('../partials/footer')(options);

return str;
};
61 changes: 0 additions & 61 deletions views/pages/single_fixture.ejs

This file was deleted.

Loading