z0mt3c / hapi-swaggered-ui

An easy swagger-ui drop-in plugin for hapi (to be used with hapi-swaggered).
39 stars 31 forks source link

specifying a custom template #135

Open punkish opened 5 years ago

punkish commented 5 years ago

I am experimenting with the latest version of hapi-swaggered + hapi-swaggered-ui. So far so good. However, I would like to use my own handlebars template for the docs as well as to match the look and feel of the rest of the project. I created my own docs.hbs content and layout following templates/indexhbs, but of course, I can't figure out how to tell the plugin to use them. Is there an option setting where I can specify a different template?

Plus, (and this is not a huge setback but), I'd like to specify .html as the extension for my templates. I already use the following invocation

server.views({
        engines: {
            html: require('handlebars')
        },
        relativeTo: __dirname,
        path: './views',
        layoutPath: './views/layouts',
        partialsPath: './views/partials',
        layout: 'main',
        isCached: false
    });

Of course, I can add hbs: require('handlebars') to the engines section above, and that seems to work, but it would be simpler if all my templates could have the same extension.

Update: So I was able to do this by adding the following five settings to the plugin options

const hapiSwaggeredUiOpts = {
    …
    relativeTo: __dirname,
    contentTemplate: 'docs',
    layoutTemplate: 'docs',
    templates: './views',
    layoutPath: './views/layouts',
    partialsPath: './views/partials',
    …
}

and creating my custom templates in the above specified directories. Of course, I had update lib/index.js to accommodate the above settings.

I am sure a zillion things can go wrong with what I did, but it seems to work for me without any problem.