Skip to content

Commit a8c756d

Browse files
committed
bemto
1 parent 003c288 commit a8c756d

9 files changed

Lines changed: 41 additions & 12 deletions

File tree

handlers/render.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,23 @@ exports.init = function(app) {
169169

170170
let templatePathResolved = resolvePath(templatePath, loc);
171171
ctx.log.debug("render file " + templatePathResolved);
172+
173+
174+
loc.plugins = [{
175+
resolve
176+
}];
177+
178+
function resolve(filename, source, loadOptions) {
179+
if (filename[0] === '/') {
180+
return path.join(loadOptions.basedir, filename);
181+
}
182+
if (filename[0] === '~') {
183+
return require.resolve(filename.slice(1));
184+
}
185+
186+
return path.join(path.dirname(source), filename);
187+
}
188+
172189
return pug.renderFile(templatePathResolved, loc);
173190
};
174191

handlers/tutorial/templates/_map.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include /bem/index
1+
include ~bemto.pug/lib/index
22

33
- console.log(roots)
44

handlers/tutorial/test/renderer/taskRenderer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const Task = require('../../models/task');
77

88
describe("TaskRenderer", function() {
99

10-
beforeEach(function* () {
10+
beforeEach(async function () {
1111
await Task.destroy();
1212
});
1313

14-
it("renderContent", function* () {
14+
it("renderContent", async function () {
1515

1616
const task = new Task({
1717
"content": "Content",
@@ -29,7 +29,7 @@ describe("TaskRenderer", function() {
2929
});
3030

3131

32-
it("renderSolution", function* () {
32+
it("renderSolution", async function () {
3333

3434
const task = new Task({
3535
"content": "# Title\n\nContent",

modules/client/notification/notification-popup.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include /bem/index
1+
include ~bemto.pug/lib/index
22

33
+b(class="notification notification_popup notification_" + type)
44
+e.content= html

modules/lib/serverPug/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const config = require('config');
44
const pug = require('pug');
55

66
/**
7-
* extension for require('file.jade'),
7+
* extension for require('file.pug'),
88
* works in libs that are shared between client & server
99
*/
1010
require.extensions['.pug'] = function(module, filename) {
@@ -14,13 +14,26 @@ require.extensions['.pug'] = function(module, filename) {
1414
Object.assign({}, config.pug, {
1515
pretty: false,
1616
compileDebug: false,
17-
filename: filename
17+
filename: filename,
18+
plugins: [{
19+
resolve
20+
}]
1821
})
1922
);
2023

24+
function resolve(filename, source, loadOptions) {
25+
if (filename[0] === '/') {
26+
return path.join(loadOptions.basedir, filename);
27+
}
28+
if (filename[0] === '~') {
29+
return require.resolve(filename.slice(1));
30+
}
31+
32+
return path.join(path.dirname(source), filename);
33+
}
34+
2135
module.exports = function(locals) {
2236
locals = locals || {};
23-
locals.bem = require('bemPug')();
2437

2538
return compiled(locals);
2639
};

modules/markit/templates/codeTabs.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include /bem/index
1+
include ~bemto.pug/lib/index
22

33
+b.code-tabs._result_on
44
+e.tools

templates/bem

Lines changed: 0 additions & 1 deletion
This file was deleted.

templates/blocks/mdeditor.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include /bem/index
1+
include ~bemto.pug/lib/index
22

33

44
mixin mdeditor(data)

templates/layouts/base.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//- bare layout with bem
22
doctype html
3-
include /bem/index
3+
include ~bemto.pug/lib/index
44

55
html(lang=lang)
66
block html

0 commit comments

Comments
 (0)