Commit 2d9ccc26 authored by Björn Bartels's avatar Björn Bartels

PATLAB-7 assigning Patternlibrary.layout tests

parent bd624f4b
Pipeline #62 passed with stage
......@@ -86,7 +86,7 @@ class Patternlibrary {
layoutSource = fs.readFileSync(layoutfile).toString();
this._layoutName = layoutname;
} catch (e) {
this.log.warn('Error loading Patternlibrary layoutfile file "'+layoutname+'"');
this.log.warn('Error loading Patternlibrary layoutfile "'+layoutname+'"');
throw new Error(e.message);
}
}
......@@ -99,7 +99,13 @@ class Patternlibrary {
* if no page template is set yet, returns the default
* gui doc-page template
*
* @function layout
* it retrieves a compiled Handlebars template and
* returns the rendred page content when invoked
* ```
* var rendered = P.pagetemplate(pagevars);
* ```
*
* @function pagetemplate
* @param {object} data - template data
* @returns {string}
*/
......@@ -116,6 +122,13 @@ class Patternlibrary {
* if `page` is a '.md' or '.markdown' file, it is also
* passed through the markdown renderer
*
* the content is compiled into a Handlebars template and
* retrieves the rendred page content when invoked
* ```
* var rendered = P.pagetemplate(pagevars);
* ```
*
*
* @param {string} page - the file basename of the page-file
* @var {function} pagetemplate - a precompiled (handlebars) template
*/
......@@ -134,19 +147,15 @@ class Patternlibrary {
if ( fs.existsSync(guipage) ) {
// file from gui pages
pageSource = fs.readFileSync(guipage).toString();
//markdown = isMD(guipage);
} else {
if ( fs.existsSync(pageSource) ) {
// file from `pageSource` as a file-path by it self
pageSource = fs.readFileSync(pageSource).toString();
//markdown = isMD(pageSource);
}
}
} else {
// file from pages
pageSource = fs.readFileSync(pagefile).toString();
//markdown = isMD(pagefile);
}
} catch (e) {
this.log.warn('Error loading Patternlibrary pagefile "'+pagefile+'"');
......@@ -162,9 +171,11 @@ class Patternlibrary {
if (markdown) {
this.log.info('Rendering Markdown content...');
pageSource = '{{#md}}'+pageSource+'{{/md}}'; //this.markdown.render(pageSource.replace('{', '{'));
//this.handlebars.registerPartial('body', this.markdown.render(pageSource) );
// interestingly, just rendering with MarkdownIt seems to do too much escaping
// and renders some special characters useless for to be interpreted by
// Handlebars, like `{{> ...`, so we wrap it with Handlebars and let its
// MarkdownIt helper there do it...
pageSource = '{{#md}}'+pageSource+'{{/md}}';
}
......
......@@ -251,22 +251,57 @@ describe('Patternlibrary instanciation and configuration:', function() {
});
describe('Patternlibrary.init()', function() {
it('should contain no \'handlebars\' instance before first execution', function () {
expect(Patternlibrary.handlebars).to.be.undefined;
});
it('should contain no \'markdowm-it\' instance before first execution', function () {
expect(Patternlibrary.markdown).to.be.undefined;
});
it('should contain a \'handlebars\' instance after instantiation', function () {
var p = new Patternlibrary.Patternlibrary();
expect(p.handlebars).not.to.be.undefined;
expect(p.handlebars).to.be.a('object');
});
it('should contain a \'markdowm-it\' instance after instantiation', function () {
it('should contain no \'markdown-it\' instance before first execution', function () {
expect(Patternlibrary.markdown).to.be.undefined;
});
it('should contain a \'markdown-it\' instance after instantiation', function () {
var p = new Patternlibrary.Patternlibrary();
expect(p.markdown).not.to.be.undefined;
expect(p.markdown).to.be.a('object');
});
});
describe('Patternlibrary.layout', function() {
it('assings a handlebars default layout "{{> body}}" from an empty template name', function() {
var p = new Patternlibrary.Patternlibrary();
p.layout = '';
expect(p.layout).to.be.a('function');
p.handlebars.registerPartial('body', 'I am here');
var rendered = p.layout({});
expect(rendered).to.equal('I am here')
});
it('assings a handlebars layout from template name', function() {
var p = new Patternlibrary.Patternlibrary();
p.layout = 'ajax';
expect(p.layout).to.be.a('function');
p.handlebars.registerPartial('body', 'I am here');
var rendered = p.layout({});
expect(rendered).to.equal('I am here')
});
it('throws an error if layout could not be found by template name', function() {
var p = new Patternlibrary.Patternlibrary();
expect(function() {
p.layout = 'some_unknown_templatefile';
}).to.throw(Error);
});
});
describe('Patternlibrary.adapter()', function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment