From a6da6a7463f5a7f8d5a3c3be42d49153af31fa31 Mon Sep 17 00:00:00 2001 From: Damian Mullins Date: Mon, 9 Apr 2018 09:29:53 +0100 Subject: [PATCH] =?UTF-8?q?v7.16.0=20=E2=80=94=20Using=20`f-templates-load?= =?UTF-8?q?er`=20to=20load=20shared=20templates=20into=20docs.=20(#120)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * v7.16.0 — Using `f-templates-loader` to load shared templates into docs. * v7.16.0 — Updated changelog date. --- CHANGELOG.md | 12 ++++++++++++ README.md | 11 ++++++++++- config.js | 3 ++- package.json | 4 +++- tasks-dev/assemble.js | 20 +++++++++++++++++++- test/config.test.js | 36 +++++++++++++++++++++++++++--------- yarn.lock | 10 ++++++++++ 7 files changed, 83 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfb79e3..ae49116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +v7.16.0 +------------------------------ +*April 9, 2018* + +### Added +- Added `f-templates-loader` module which handles locating and registering shared templates. +- Added `config.docs.excludeTemplateDirs` property to allow directories to be ignored when adding shared templates. + +### Updated +- `.gitignore` updated to exclude yalc config files + + v7.15.0 ------------------------------ *April 3, 2018* diff --git a/README.md b/README.md index f122e49..7d14f11 100644 --- a/README.md +++ b/README.md @@ -348,7 +348,8 @@ Here is the outline of the configuration options, descriptions of each are below dataDir, outputAssets, remoteBase, - helpers + helpers, + excludeTemplateDirs }, fonts: { fontsDir @@ -797,6 +798,14 @@ Will add a content hash to the JS and CSS filenames, generating a new filename i Will expose the helper `toLowercase` so that using `{{toLowercase name}}` within a handlebars template will convert the handlebars string `name` to lowercase. +- #### `excludeTemplateDirs` + + Type: `array` + + Default: `['resources']` + + Directory names which should be ignored when adding any shared templates to the documentation. By default the array contains known directory names which should be ignored. + ### `fonts` - #### `fontsDir` diff --git a/config.js b/config.js index e4d3cae..1174bcc 100644 --- a/config.js +++ b/config.js @@ -110,7 +110,8 @@ const ConfigOptions = () => { dataDir: 'data', outputAssets: false, remoteBase: '', - helpers: {} + helpers: {}, + excludeTemplateDirs: ['resources'] }, fonts: { diff --git a/package.json b/package.json index c67ec72..73a5273 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@justeat/gulp-build-fozzie", - "version": "7.15.0", + "version": "7.16.0", "description": "Gulp build tasks for use across Fozzie modules", "main": "index.js", "author": "Damian Mullins (http://www.damianmullins.com)", @@ -29,6 +29,7 @@ "dependencies": { "@justeat/eslint-config-fozzie": "^1.4.0", "@justeat/f-copy-assets": "^0.6.0", + "@justeat/f-templates-loader": "0.0.3", "@justeat/stylelint-config-fozzie": "^2.0.1", "assemble": "^0.24.3", "autoprefixer": "^8.2.0", @@ -69,6 +70,7 @@ "gulp-tap": "^1.0.1", "gulp-uglify": "^3.0.0", "gulp-util": "^3.0.8", + "handlebars-helper-i18n": "^0.1.0", "handlebars-helpers": "^0.10.0", "helper-markdown": "^1.0.0", "helper-md": "^0.2.2", diff --git a/tasks-dev/assemble.js b/tasks-dev/assemble.js index 4229c8d..03f166d 100644 --- a/tasks-dev/assemble.js +++ b/tasks-dev/assemble.js @@ -1,6 +1,10 @@ const gulp = require('gulp'); const assemble = require('assemble'); + const helpers = require('handlebars-helpers'); +const { getCompiledTemplate, getTemplateNames } = require('@justeat/f-templates-loader'); +const { i18n } = require('handlebars-helper-i18n'); + const plumber = require('gulp-plumber'); // const newer = require('gulp-newer'); const extname = require('gulp-extname'); @@ -8,14 +12,26 @@ const extname = require('gulp-extname'); const config = require('../config'); const pathBuilder = require('../pathBuilder'); - const app = assemble(); app.helper('is', helpers.comparison().is); +app.helper('i18n', i18n); app.helper('markdown', require('helper-markdown')); app.helper('md', require('helper-md')); +/** + * Looping through directories in './templates' and registering a helper for each module found + */ +const registerSharedTemplates = () => { + const templateNames = getTemplateNames(config.docs.excludeTemplateDirs); + + templateNames.forEach(templateName => { + app.helper(`f-${templateName}`, () => getCompiledTemplate(templateName)); + }); +}; + + // Loops through the helpers object and initialises handlebars helpers Object.keys(config.docs.helpers).forEach(helper => { app.helper(helper, config.docs.helpers[helper]); @@ -42,6 +58,8 @@ gulp.task('assemble', () => { jsFilename: config.js.distFile }); + registerSharedTemplates(); + return app.src(`${pathBuilder.docsTemplateDir}/pages/**/*.{md,hbs}`) // stops watch from breaking on error .pipe(plumber(config.gulp.onError)) diff --git a/test/config.test.js b/test/config.test.js index c1bab79..37a5172 100644 --- a/test/config.test.js +++ b/test/config.test.js @@ -91,7 +91,6 @@ describe('environment config', () => { }); }); - describe('css config', () => { it('`scssDir` should be set', () => { expect(config.css.scssDir).toBe('scss'); @@ -273,7 +272,6 @@ describe('javascript config', () => { }); }); - describe('`logger` config', () => { it('should exist', () => { expect(config.logger).toBeDefined(); @@ -378,7 +376,6 @@ describe('imported assets config', () => { }); - describe('service worker config', () => { it('`isEnabled` should be false', () => { expect(config.sw.isEnabled).toBe(false); @@ -501,7 +498,6 @@ describe('service worker config', () => { }); }); - describe('copy config', () => { it('copy js config should be set', () => { expect(config.copy.js).toEqual({}); @@ -588,7 +584,6 @@ describe('copy config', () => { }); }); - describe('documentation config', () => { it('`rootDir` should be set', () => { expect(config.docs.rootDir).toBe('./docs'); @@ -710,9 +705,34 @@ describe('documentation config', () => { expect(config.docs.remoteBase).toBe(remoteBase); }); + it('`helpers` should be set', () => { + expect(config.docs.helpers).toEqual({}); + }); + + it('`helpers` can be updated', () => { + // Arrange + const helpers = () => 'Hi'; + + // Act + config.update({ docs: { helpers } }); + + // Assert + expect(config.docs.helpers).toBe(helpers); + }); + + it('`excludeTemplateDirs` should be set', () => { + expect(config.docs.excludeTemplateDirs).toEqual(['resources']); + }); + + it('`excludeTemplateDirs` can be updated', () => { + // Arrange + const excludeTemplateDirs = ['ignore-me', 'and-me']; - it('`helpers` should be an object', () => { - expect(typeof config.docs.helpers).toBe('object'); + // Act + config.update({ docs: { excludeTemplateDirs } }); + + // Assert + expect(config.docs.excludeTemplateDirs).toBe(excludeTemplateDirs); }); }); @@ -734,7 +754,6 @@ describe('fonts config', () => { }); }); - describe('browserSync config', () => { it('`files` should be set', () => { expect(config.browserSync.files).toEqual([]); @@ -782,7 +801,6 @@ describe('browserSync config', () => { }); }); - describe('miscellaneous config', () => { it('`showFileSize` should be true', () => { expect(config.misc.showFileSize).toBe(true); diff --git a/yarn.lock b/yarn.lock index 0970cca..aa4644c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -46,6 +46,12 @@ glob "^7.1.2" mkdirp "^0.5.1" +"@justeat/f-templates-loader@0.0.3": + version "0.0.3" + resolved "https://registry.yarnpkg.com/@justeat/f-templates-loader/-/f-templates-loader-0.0.3.tgz#2fe83a3f4b0ea123f0550789e63fca3f3a5c55b5" + dependencies: + handlebars "^4.0.11" + "@justeat/stylelint-config-fozzie@^2.0.1": version "2.0.1" resolved "https://registry.yarnpkg.com/@justeat/stylelint-config-fozzie/-/stylelint-config-fozzie-2.0.1.tgz#7723b62a0e9b9d10519edcd8f05b995e85a0708e" @@ -5733,6 +5739,10 @@ handlebars-helper-create-frame@^0.1.0: create-frame "^1.0.0" isobject "^3.0.0" +handlebars-helper-i18n@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/handlebars-helper-i18n/-/handlebars-helper-i18n-0.1.0.tgz#6329b2c63264b2451eea5f9e26faf7b656af9ed5" + handlebars-helpers@^0.10.0: version "0.10.0" resolved "https://registry.yarnpkg.com/handlebars-helpers/-/handlebars-helpers-0.10.0.tgz#663d49e718928eafbead1473419ed7bc24bcd45a"