Commit 22873c21 authored by Björn Bartels's avatar Björn Bartels 👩🏻
Browse files

PATLAB-7 add page-template tests

parent 6345db90
Loading
Loading
Loading
Loading
+36 −36
Original line number Diff line number Diff line
@@ -97,7 +97,8 @@ class Patternlibrary {
	 * Retrieves (handlebars) page template
	 * 
	 * if no page template is set yet, returns the default 
	 * gui doc-page template
	 * gui doc-page templateto be used in a series of similar 
	 * pages with iterating data
	 * 
	 * it retrieves a compiled Handlebars template and
     * returns the rendred page content when invoked
@@ -118,6 +119,8 @@ class Patternlibrary {
	
    /**
     * Sets and compiles (handlebars) page by page filename
     * for a *Patternlibrary* page template to be used in a 
     * series of similar pages with iterating data
     * 
     * if `page` is a '.md' or '.markdown' file, it is also 
     * passed through the markdown renderer
@@ -128,6 +131,14 @@ class Patternlibrary {
     * var rendered = P.pagetemplate(pagevars);
     * ```
     * 
     * if the parameter does not correspond to a readable file
     * the parameter's string value is assigned as page template 
     * 
     * look-up order:
     * - project's doc pages dir (pages src dir + basepath)
     * - project's `gui` pages dir
     * - module's `gui` pages dir
     * - file path
     * 
     * @param {string} page - the file basename of the page-file
     * @var {function} pagetemplate - a precompiled (handlebars) template
@@ -142,7 +153,6 @@ class Patternlibrary {
    		var pagefile = path.join(this.options.root, this.options.basepath, page);
    		var guipage  = resolvePath(path.join(this.options.gui.pages, this.options.basepath, page));
    		
        	try {
    		if ( !fs.existsSync(pagefile) ) {
        		if ( fs.existsSync(guipage) ) {
        			// file from gui pages
@@ -157,16 +167,10 @@ class Patternlibrary {
    			// file from pages
        		pageSource = fs.readFileSync(pagefile).toString();
    		}
        	} catch (e) {
        		this.log.warn('Error loading Patternlibrary pagefile "'+pagefile+'"');
        		throw new Error(e.message);
        	}
    	}
    	// strip yml data in the beginning
    	pageSource = fm(pageSource).body;
    		
    	try {
    		
		// finally compile Markdown content, if we have a markdown file here...
		if (markdown) {
            
@@ -175,14 +179,10 @@ class Patternlibrary {
    		// 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}}'; 
    		pageSource = '{{#markdown}}'+pageSource+'{{/markdown}}'; 
            
		}

    	} catch (e) {
    		this.log.warn('Error rendering Markdown content');
    		throw new Error(e.message);
    	}
    	this._pageTemplate = this.handlebars.compile(pageSource, {noEscape: true});
    }
    
Loading