Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fields for example #97

Merged
merged 1 commit into from Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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