commit 6b35c9509bfb77d34306a02a973e8bc850e3c0ec Author: Thomas Schwery Date: Sun May 29 12:42:17 2016 +0200 Recette build system diff --git a/build.js b/build.js new file mode 100644 index 0000000..01508ed --- /dev/null +++ b/build.js @@ -0,0 +1,146 @@ +var metalsmith = require('metalsmith') +var layouts = require('metalsmith-layouts') +var markdown = require('metalsmith-markdown') +var collections = require('metalsmith-collections') +var pagination = require('metalsmith-pagination') +var paths = require('metalsmith-paths') +var filemetadata = require('metalsmith-filemetadata') +var matters = require('metalsmith-matters') + +var fs = require('fs'); +var moment = require('moment'); + +var handlebars = require('handlebars'); +var hlayouts = require('handlebars-layouts'); + +handlebars.registerHelper(hlayouts(handlebars)); +handlebars.registerPartial('base', fs.readFileSync('templates/base.hbs', 'utf8')); + +handlebars.registerHelper('formatDate', function(date) { + return moment(new Date(date)).format('MMMM D, YYYY HH:mm:ss'); +}); + +handlebars.registerHelper('formatTimestamp', function(date) { + return moment(date, 'X').format('MMMM D, YYYY HH:mm:ss'); +}); + +function compareWith(v1, v2, operator) { + var itm = false; + + switch (operator) { + case '==': + itm = (v1 == v2); + break; + case '!=': + itm = (v1 != v2); + break; + case '===': + itm = (v1 === v2); + break; + case '<': + itm = (v1 < v2); + break; + case '<=': + itm = (v1 <= v2); + break; + case '>': + itm = (v1 > v2); + break; + case '>=': + itm = (v1 >= v2); + break; + } + return itm; +} + +handlebars.registerHelper('eachCond', function(context, member, operator, cond, options) { + var tot = ''; + for (var i = 0; i < context.length; i++) { + var itm = false; + var v1 = context[i][member]; + + + if (compareWith(v1, cond, operator)) { + tot += options.fn(context[i]); + } + } + return tot; +}); + +handlebars.registerHelper('ifCond', function (v1, operator, v2, options) { + if (compareWith(v1, v2, operator)) { + return options.fn(this); + } else { + return options.inverse(this); + } +}); + +metalsmith(__dirname) + .source('recettes') + .metadata(require('./config/metadata')) + .frontmatter(false) + .use(matters()) + .use(filemetadata(require('./config/filemetadata'))) + .use(collections(require('./config/collections'))) + .use(markdown(require('./config/markdown'))) + .use(pagination(require('./config/pagination'))) + .use(paths(require('./config/paths'))) + .use(layouts(require('./config/layouts'))) + .use(copyVendor()) + .destination('build') + .build(function (err) { + if (err) { + throw err + } + }) + +function debugCollection() { + return function(files, metalsmith, done) { + console.log(files); + for (var i in files) { + console.log(i + ' -> ' + ' (' + files[i].collection + ')'); + console.log(files[i]); + } + return done(); + } +} + +function debugMeta(metaname) { + return function(files, metalsmith, done) { + if (metaname !== undefined) { + console.log(metalsmith.metadata()[metaname]); + } else { + console.log(metalsmith.metadata()); + } + return done(); + } +} + +function debugPagination() { + return function(files, metalsmith, done) { + + for (var i in files) { + var f = files[i]; + if (f !== undefined && f.path != undefined) { + console.log(f.path); + } + } + + return done(); + } +} + + +function copyVendor() { + + return function(files, metalsmith, done){ + + var bufferMoment = fs.readFileSync('styles/customHighlight.css'); + files['styles/customHighlight.css'] = { + contents: bufferMoment + }; + + return done(); + }; +} + diff --git a/config/collections.js b/config/collections.js new file mode 100644 index 0000000..710c391 --- /dev/null +++ b/config/collections.js @@ -0,0 +1,6 @@ +module.exports = { + recettes: { + pattern: '*/*.md', + sortBy: 'title' + } +} diff --git a/config/css.js b/config/css.js new file mode 100644 index 0000000..246d32f --- /dev/null +++ b/config/css.js @@ -0,0 +1,6 @@ +module.exports = { + files: '**/*.css', + cleanCSS: { + rebase: true + } +} diff --git a/config/filemetadata.js b/config/filemetadata.js new file mode 100644 index 0000000..af80538 --- /dev/null +++ b/config/filemetadata.js @@ -0,0 +1,9 @@ +module.exports = [ + { + pattern: '*/*.md', + metadata: { + layout: 'recette.hbs', + type: 'recette' + } + } +] diff --git a/config/js.js b/config/js.js new file mode 100644 index 0000000..46c2df2 --- /dev/null +++ b/config/js.js @@ -0,0 +1,3 @@ +module.exports = { + preserveComments: 'some' +} diff --git a/config/layouts.js b/config/layouts.js new file mode 100644 index 0000000..5ae1360 --- /dev/null +++ b/config/layouts.js @@ -0,0 +1,5 @@ +module.exports = { + engine: 'handlebars', + default: 'test.hbs', + directory: 'templates' +} diff --git a/config/markdown.js b/config/markdown.js new file mode 100644 index 0000000..de5df5e --- /dev/null +++ b/config/markdown.js @@ -0,0 +1,32 @@ +var highlightjs = require('highlight.js'); + +highlightjs.registerLanguage('procedurelog', function(hljs) { + + return { + case_insensitive: false, + keywords: { + keyword: 'return', + literal: 'true false null undefined NaN Infinity', + built_in: 'macroBreak callTask executeAction createNewPage', + assertSuccess: 'SUCCESS', + assertFail: 'FAIL', + info: 'PROCEDURE ENDPROCEDURE SCRIPT INIT', + action: 'ACTION ASSERT' + }, + contains: [ + hljs.APOS_STRING_MODE, + hljs.QUOTE_STRING_MODE + ] + }; +}); + +var highlighter = function (code) { + var hl = highlightjs.highlightAuto(code, ['procedurelog', 'xml']); + return hl.value; +} + +module.exports = { + gfm: true, + tables: true, + highlight: highlighter +} diff --git a/config/metadata.js b/config/metadata.js new file mode 100644 index 0000000..5ff1171 --- /dev/null +++ b/config/metadata.js @@ -0,0 +1,6 @@ +module.exports = { + site: { + title: 'SNV4-cclient tests', + url: 'none' + } +} diff --git a/config/pagination.js b/config/pagination.js new file mode 100644 index 0000000..813395d --- /dev/null +++ b/config/pagination.js @@ -0,0 +1,8 @@ +module.exports = { + 'collections.recettes': { + perPage: 15, + first: 'index.html', + layout: 'index.hbs', + path: 'page/:num/index.html' + } +} diff --git a/config/paths.js b/config/paths.js new file mode 100644 index 0000000..bd294c7 --- /dev/null +++ b/config/paths.js @@ -0,0 +1,3 @@ +module.exports = { + +} diff --git a/config/redirect.js b/config/redirect.js new file mode 100644 index 0000000..7acaac2 --- /dev/null +++ b/config/redirect.js @@ -0,0 +1,3 @@ +module.exports = { + +} diff --git a/config/vendor.js b/config/vendor.js new file mode 100644 index 0000000..a40314b --- /dev/null +++ b/config/vendor.js @@ -0,0 +1,4 @@ +module.exports = { + src: 'vendor', + dest: 'vendor' +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..0dd0dac --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "snv4-testresults", + "version": "0.1.0", + "private": true, + "dependencies": { + "bower": "^1.5.2", + "handlebars": "^3.0.3", + "handlebars-layouts": "^3.1.0", + "highlight.js": "^9.4.0", + "metalsmith": "^1.0.1", + "metalsmith-collections": "^0.7.0", + "metalsmith-collections-paginate": "^2.0.1", + "metalsmith-filemetadata": "^1.0.0", + "metalsmith-layouts": "^1.6.5", + "metalsmith-markdown": "^0.2.1", + "metalsmith-matters": "^1.2.0", + "metalsmith-paginate": "^0.3.0", + "metalsmith-pagination": "^1.0.0", + "metalsmith-paths": "^2.1.2", + "metalsmith-permalinks": "^0.4.0", + "moment": "^2.6.0", + "serve": "^1.4.0" + }, + "scripts": { + "serve": "serve build -p ${PORT:-3000}", + "build": "node build.js" + }, + "license": "MIT" +} diff --git a/styles/customHighlight.css b/styles/customHighlight.css new file mode 100644 index 0000000..df8e002 --- /dev/null +++ b/styles/customHighlight.css @@ -0,0 +1,35 @@ +.step { + margin-top: 10px; + margin-bottom: 30px; + position: relative; +} + +.ingredients { + display: inline-block; + list-style-type: none; + max-width: 240px; +} + +.instructions { + display: inline-block; + position: absolute; + left: 250px; + bottom: 10px; +} + +.ing-name { + font-weight: bold; +} + +.recipe-image { + text-align: center; +} + +.content-title { + text-align: left; + border-bottom: solid 1px; +} + +.header { + text-align: right; +} diff --git a/templates/base.hbs b/templates/base.hbs new file mode 100644 index 0000000..76fdf2a --- /dev/null +++ b/templates/base.hbs @@ -0,0 +1,39 @@ + + + + + + + + + + + + + {{#block "title"}} {{/block}} + + + +
+
+ {{#block "content"}} {{/block}} +
+
+ + + diff --git a/templates/index.hbs b/templates/index.hbs new file mode 100644 index 0000000..2e65438 --- /dev/null +++ b/templates/index.hbs @@ -0,0 +1,35 @@ +{{#extend "base"}} + +{{#content "title"}} + Recettes +{{/ content}} + +{{#content "navitems"}} + {{#if pagination.previous }} +
  • + + Newer  
  • + {{/ if}} + {{#if pagination.next }} +
  • + +   Older
  • + {{/ if}} +{{/content}} + +{{#content "content"}} + {{#each pagination.files}} +
    +
    +

    + {{ data.title }} +

    +
    +
    + {{{ data.description }}} +
    +
    + {{/ each}} +{{/ content}} + +{{/ extend}} diff --git a/templates/recette.hbs b/templates/recette.hbs new file mode 100644 index 0000000..538be86 --- /dev/null +++ b/templates/recette.hbs @@ -0,0 +1,72 @@ +{{#extend "base"}} + +{{#content "title"}} + Recettes • {{ data.title }} +{{/ content}} + +{{#content "navitems"}} + {{#if next }} +
  • {{formatTimestamp next.date }} {{ next.procedure }}
  • + {{/if }} +
  • Up
  • + {{#if previous }} +
  • {{formatTimestamp previous.date }} {{ previous.procedure }}
  • + {{/if }} +{{/content}} + +{{#content "content"}} +
    +

    + Recette {{ data.title }} +

    + +
    +
    + {{#each data.steps }} +
    +
      + {{#each ingredients}} +
    • + {{ quantity }} {{ unit }} + {{ name }} + {{#if comment }}{{ comment }}{{/if }} +
    • + {{/each}} +
    +
    + {{ instructions }} +
    +
    + {{/each }} + {{#if data.image }} +
    + +
    + {{/if }} + + {{{ contents }}} +
    + + +

    Commentaires

    +
    + + +
    +{{/ content}} + +{{/ extend}}