Skip to content

Commit

Permalink
Update fields for example (#97)
Browse files Browse the repository at this point in the history
- update helper to find fields from apps/${name}/fields.js if fields not set on route
- amend readme for changes to fields
- amend example, remove fields and view false override
  • Loading branch information
JoeChapman committed Jan 4, 2017
1 parent 59afabb commit 219785d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -156,15 +156,14 @@ HOF-bootstrap accepts the following options so a developer can customise element

### Options

- `views`: Location of the base views relative to the root of your project.
- `views`: Location of the common views relative to the root of your project.
- Will not error if it can't find any views in the root of your project.
- Looks for views - optionally set in your [route options](#route-options).
- Always loads views from [hof-template-partials.views](https://github.com/UKHomeOfficeForms/hof-template-partials/tree/master/views).
- Views extend like so, where route-views are the most specific: `hot-template-partials -> your-common-views -> your-route-views`

- `fields`: Location of the common fields relative to the root of your project. Defaults to `__dirname + '/fields'`.
- Will not error if it can't find any views in the root of your project.

- Views extend like so, where route-views are the most specific: `hof-template-partials -> your-common-views -> your-route-views`.
- `fields`: Location of the common fields relative to the root of your project.
- Does not error if not set, as long as `fields` are set for the route.
- [Route level `fields`](#route-options) will override common `fields`.
- `translations`: Location of the common translations relative to the root of your project. Defaults to `./translations`.
- `middleware`: An optional array of middleware functions to add to the application middleware pipeline.
- `baseController`: The base controller for all routes and steps. Defaults to [HOF-controllers.base](https://github.com/UKHomeOfficeForms/hof-controllers/blob/master/lib/base-controller.js).
Expand Down Expand Up @@ -242,6 +241,7 @@ const myRoutes = [{
- `name`: Passed to the form Wizard.
- `baseUrl`: Base url from which all steps are relative. Defaults to `/`. If provided will be used to locate views, fields and translations for a form journey.
- `fields`: Location of the routes' fields, relative to the root of your project. Will take precedence over fields specified at the base level.
- If route `fields` is not explicitly set, will try to load them from the project using the route `name` assuming the fields file is located in `apps/${name}/fields`.
- `views`: Location of the routes' views relative to the root of your project. Will take precedence over views specified at the base level and from [hof-template-partials.views](https://github.com/UKHomeOfficeForms/hof-template-partials/tree/master/views).

**NOTE**: The `fields` defined in a `route` is the path to the folder, relative to the root, where the `fields` are is located.
Expand Down
2 changes: 0 additions & 2 deletions example/index.js
Expand Up @@ -3,8 +3,6 @@
const bootstrap = require('hof-bootstrap');

bootstrap({
views: false,
fields: false,
translations: './apps/example-app/translations',
routes: [
require('./apps/example-app')
Expand Down
11 changes: 9 additions & 2 deletions lib/helpers.js
Expand Up @@ -5,11 +5,19 @@ const path = require('path');

module.exports = class Helpers {

static getRouteFields(config) {
let routeFields = config.route.fields && path.resolve(config.caller, config.route.fields);
if (!routeFields) {
routeFields = config.route.name && path.resolve(config.caller, `apps/${config.route.name}/fields.js`);
}
return routeFields;
}

static getPaths(config) {
return {
fields: {
base: config.fields && path.resolve(config.caller, config.fields),
route: config.route.fields && path.resolve(config.caller, config.route.fields)
route: this.getRouteFields(config)
},
views: {
base: config.views && path.resolve(config.caller, config.views),
Expand All @@ -30,7 +38,6 @@ module.exports = class Helpers {
throw new Error(`Cannot find fields at ${pathFields.base}`);
}
}

if (pathFields.route) {
try {
routeFields = require(pathFields.route);
Expand Down

0 comments on commit 219785d

Please sign in to comment.