Commit 68f62dd9 authored by Björn Bartels's avatar Björn Bartels

PATLAB-8 update handlebars helpers

parent 22873c21
/**
* simple text helper to provide consistent test-data over all patterns
*
* usage:
* {{#texthelper $mode}}
*
* provides text samples for
* - text
* - date/time
* - contact info
* - product info
*
* default mode: short (text)
*
*/
const TextHelper_Texts = {
// product
'product-name' : 'An Awesome Product Name',
'product-id' : '98765-432109',
'product-ean' : '987-65432-109-8',
// contact
'name' : 'Marianne Mustermann',
'name-rev' : 'Mustermann, Marianne',
'prename' : 'Marianne',
'lastname' : 'Mustermann',
'street' : 'Musterstraße',
'housenumber' : '12a',
'streetnr' : 'Musterstraße 12a',
'zipcode' : '12345',
'city' : 'Musterstadt',
'zipcity' : '12345 Musterstadt',
'cityzip' : 'Musterstadt, 12345',
'country' : 'Deutschland',
'iso' : 'DE',
'phone' : '+49 1234 5678-9012',
'email' : 'contact@example.com',
'url' : 'http://example.com',
'social' : '@twitter_user',
// date/time
'time' : '13:54h',
'date' : '12.06.2017',
'date-long' : '12. Juni 2017',
// text
'word' : 'Loremipsum',
'word-dashed' : 'Lorem-ipsum',
'words' : 'Lorem ipsum dolor sit amet',
'normal' : 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
'long' : 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
'xlong' : 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet,',
'short' : 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.',
'default' : 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.'
};
module.exports = TextHelper_Texts;
\ No newline at end of file
......@@ -11,7 +11,11 @@ var hljs = require('highlight.js');
* @returns The HTML inside the helper, with highlight.js classes added.
*/
function formatCode (language, options) {
if (typeof language === 'undefined') language = 'html';
if (typeof options === 'undefined') {
var options = language;
language = 'html';
}
var code = hljs.highlight(language, options.fn(this)).value;
......
var handlebars = require('handlebars');
/**
* simple condition checker
*
* USAGE:
*
* {{#cond "this.myvar == 'hallo'"}}
* $myvar ist gleich '{{myvar}}'
* {{else}}
* $myvar ist nicht gleich 'hallo'
* {{/cond}}
*
*/
handlebars.registerHelper('cond', function() {
var condition = `${arguments[0]}`;
var options = arguments[1];
var result = eval(condition.toString()); // .bind(this);
if (result === true) return options.fn(this);
else return options.inverse(this);
});
......@@ -40,7 +40,9 @@ handlebars.registerHelper('escape', escape);
* @returns {string} A capitalized string.
*/
handlebars.registerHelper('toUpper', function(str) {
if (typeof str === 'undefined') str = '';
if (typeof str !== 'string') {
return '';
}
return str[0].toUpperCase() + str.slice(1);
});
......@@ -50,7 +52,9 @@ handlebars.registerHelper('toUpper', function(str) {
* @returns {string} A lowercase string.
*/
handlebars.registerHelper('toLower', function(str) {
if (typeof str === 'undefined') str = '';
if (typeof str !== 'string') {
return '';
}
return str.toLowerCase();
});
......
var handlebars = require('handlebars');
var hljs = require('highlight.js');
var $markdown = require('../vendor/markdown-it');
function highlightCode(code, language) {
if (typeof language === 'undefined') language = 'html';
var renderedCode = hljs.highlight(language, code).value;
var output = `<div class="code-example"><pre><code class="${language}">${renderedCode}</code></pre></div>`;
return output;
};
function markdown(options) {
return $markdown.render(options.fn(this));
......
var handlebars = require('handlebars');
var texts = require('../config/texthelper');
/**
* simple text helper to provide consistent test-data over all patterns
*
......@@ -16,108 +18,14 @@ var handlebars = require('handlebars');
*/
handlebars.registerHelper('texthelper', function(mode) {
switch (mode) {
// product
case 'product-name' :
return 'An Awesome Product Name';
break;
case 'product-id' :
return '98765-432109';
break;
case 'product-ean' :
return '987-65432-109-8';
break;
if (typeof mode !== 'string') {
return texts['default'];
}
// contact
case 'name' :
return 'Marianne Mustermann';
break;
case 'name-rev' :
return 'Mustermann, Marianne';
break;
case 'prename' :
return 'Marianne';
break;
case 'lastname' :
return 'Mustermann';
break;
case 'street' :
return 'Musterstraße';
break;
case 'housenumber' :
return '12a';
break;
case 'streetnr' :
return 'Musterstraße 12a';
break;
case 'zipcode' :
return '12345';
break;
case 'city' :
return 'Musterstadt';
break;
case 'zipcity' :
return '12345 Musterstadt';
break;
case 'cityzip' :
return 'Musterstadt, 12345';
break;
case 'country' :
return 'Deutschland';
break;
case 'iso' :
return 'DE';
break;
case 'phone' :
return '+49 1234 5678-9012';
break;
case 'email' :
return 'contact@example.com';
break;
case 'url' :
return 'http://example.com';
break;
case 'social' :
return '@twitter_user';
break;
// date/time
case 'time' :
return '13:54h';
break;
case 'date' :
return '12.06.2017';
break;
case 'date-long' :
return '12. Juni 2017';
break;
// text
case 'word' :
return 'Loremipsum';
break;
case 'word-dashed' :
return 'Lorem-ipsum';
break;
case 'words' :
return 'Lorem ipsum dolor sit amet';
break;
case 'normal' :
return 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.';
break;
case 'long' :
return 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.';
break;
case 'xlong' :
return 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet,';
break;
case 'short' :
default :
return 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.';
break;
if (typeof texts[mode] === 'undefined') {
return mode
}
return String( texts[mode] );
});
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