Skip to content

Commit

Permalink
v7.16.0 — Using f-templates-loader to load shared templates into do…
Browse files Browse the repository at this point in the history
…cs. (#120)

* v7.16.0 — Using `f-templates-loader` to load shared templates into docs.

* v7.16.0 — Updated changelog date.
  • Loading branch information
DamianMullins authored Apr 9, 2018
1 parent e4a01c8 commit a6da6a7
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 13 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ const ConfigOptions = () => {
dataDir: 'data',
outputAssets: false,
remoteBase: '',
helpers: {}
helpers: {},
excludeTemplateDirs: ['resources']
},

fonts: {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> (http://www.damianmullins.com)",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
20 changes: 19 additions & 1 deletion tasks-dev/assemble.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
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');

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]);
Expand All @@ -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))
Expand Down
36 changes: 27 additions & 9 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ describe('environment config', () => {
});
});


describe('css config', () => {
it('`scssDir` should be set', () => {
expect(config.css.scssDir).toBe('scss');
Expand Down Expand Up @@ -273,7 +272,6 @@ describe('javascript config', () => {
});
});


describe('`logger` config', () => {
it('should exist', () => {
expect(config.logger).toBeDefined();
Expand Down Expand Up @@ -378,7 +376,6 @@ describe('imported assets config', () => {

});


describe('service worker config', () => {
it('`isEnabled` should be false', () => {
expect(config.sw.isEnabled).toBe(false);
Expand Down Expand Up @@ -501,7 +498,6 @@ describe('service worker config', () => {
});
});


describe('copy config', () => {
it('copy js config should be set', () => {
expect(config.copy.js).toEqual({});
Expand Down Expand Up @@ -588,7 +584,6 @@ describe('copy config', () => {
});
});


describe('documentation config', () => {
it('`rootDir` should be set', () => {
expect(config.docs.rootDir).toBe('./docs');
Expand Down Expand Up @@ -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);
});
});

Expand All @@ -734,7 +754,6 @@ describe('fonts config', () => {
});
});


describe('browserSync config', () => {
it('`files` should be set', () => {
expect(config.browserSync.files).toEqual([]);
Expand Down Expand Up @@ -782,7 +801,6 @@ describe('browserSync config', () => {
});
});


describe('miscellaneous config', () => {
it('`showFileSize` should be true', () => {
expect(config.misc.showFileSize).toBe(true);
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
glob "^7.1.2"
mkdirp "^0.5.1"

"@justeat/[email protected]":
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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a6da6a7

Please sign in to comment.