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
Add support for layout in handlebars #136
Conversation
index.js
Outdated
|
||
if (layoutFileName) { | ||
try { | ||
readFileSync(join(templatesDir, getPage(layoutFileName, 'hbs'))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just a check on access?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. If an user passes a layout but the layout is not readable, this would return an error to them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind using https://nodejs.org/api/fs.html#fs_fs_accesssync_path_mode instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem.
@@ -398,6 +409,30 @@ function fastifyView (fastify, opts, next) { | |||
} else { | |||
next() | |||
} | |||
|
|||
function withLayout (render) { | |||
if (layoutFileName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this option going to affect other engines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently it would only affect handlebars
. This is because some engines already support their own layouts (e.g: pug
).
It is also possible to add support to other engines that don't already support layouts by applying them the withLayout
decorator (see here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would you mind throwing if layout
is present and the engine is not 'handlebars'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. Please see my new commits.
…ngine other than handlebars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@smartiniOnGitHub would you mind to take a look? |
@mcollina sure, I'll provide a feedbask ASAP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, changes looks good, but in your fork I don't see last changes from original repo (11 October), could you realign your fork to have them ? Sorry for the request ... so I can retry even the execution of examples there.
No problem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good now: just done some tests even on example custom commands and all works, great job !!
Relates to #112
A few notes regarding this PR:
layout
support. I'm not sure what are the views on functional programming for this project, so please let me know if you'd prefer a different implementation.Checklist
npm run test
andnpm run benchmark