Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Feature: Allow set specific template #171

Merged

Conversation

luizdesign
Copy link
Contributor

Proposal to resolve issue #170

@luizdesign
Copy link
Contributor Author

Working to fix broken unit test

@codecov
Copy link

codecov bot commented Aug 22, 2017

Codecov Report

Merging #171 into master will decrease coverage by 0.48%.
The diff coverage is 94.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #171      +/-   ##
==========================================
- Coverage   96.59%   96.11%   -0.49%     
==========================================
  Files          13       13              
  Lines         529      540      +11     
  Branches       92       94       +2     
==========================================
+ Hits          511      519       +8     
- Misses         18       21       +3
Impacted Files Coverage Δ
lib/fetch-template.js 91.48% <94.11%> (-5.74%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8344613...0c8a6dc. Read the comment docs.

@codecov
Copy link

codecov bot commented Aug 22, 2017

Codecov Report

Merging #171 into master will decrease coverage by 1.45%.
The diff coverage is 65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #171      +/-   ##
==========================================
- Coverage   96.59%   95.14%   -1.46%     
==========================================
  Files          13       13              
  Lines         529      535       +6     
  Branches       92       94       +2     
==========================================
- Hits          511      509       -2     
- Misses         18       26       +8
Impacted Files Coverage Δ
lib/fetch-template.js 78.57% <65%> (-18.66%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8344613...a7c5a34. Read the comment docs.

@@ -0,0 +1,2039 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove the package-lock file? we use yarn.lock

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! (:

return parseTemplate(baseTemplate);
}
return getTemplatePath(request, templatesPath)
.then((templatePath) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you combine it by this way

getTemplatePath(request, templatesPath)
    .then(readFile)
    .then(baseTemplate)

looks cleaner IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! (:

@vigneshshanmugam
Copy link
Collaborator

Thanks a lot for working on this. If you are interested, feel free to use https://github.com/ljharb/util.promisify to promisify the functions. We thought of using that package anyways.

* @return {Promise} Template Path on success or TemplateError on fail
*/
const getTemplatePath = (request, templatesPath) => new Promise((resolve, reject) => {
fs.lstat(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're using node 8.x, you can use util.promisify to make this code simpler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the code style of 'readFile' function, however we can change the both functions to promisify sintaxe. What do you think? Or do we open a new issue to discuss about it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also do it in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok @vigneshshanmugam, I will open a issue about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mroderick
Copy link

If you are interested, feel free to use https://github.com/ljharb/util.promisify to promisify the functions. We thought of using that package anyways.

@vigneshshanmugam is util.promisify not available?

@vigneshshanmugam
Copy link
Collaborator

vigneshshanmugam commented Aug 23, 2017

@mroderick We still support node 6, so we can use that polyfill for node < 8

const templatePath = path.join(templatesPath, pathname) + '.html';

return readFile(templatePath)
return getTemplatePath(request, templatesPath)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two problems with this approach

  1. the url parsing happens twice with this approach. In getTemplatePath when its a directory and inside baseTemplateFn.
  2. You would also need to look at modify this logic
    const baseTemplatePath = path.join(templatesPath, templateName) + '.html';
    Will totally break if the templatesPath is a single file instead of dir.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I will check this points as soon as possible!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vigneshshanmugam I adjust the duplicated url parsing and refactoring the logic to factory the complete template path. Now I working for break the process in case of single file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

return parseTemplate(baseTemplate);
}
return getTemplatePath(templatesPath, pathname)
.then((templateStat) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a small change to keep the indentation depth minimal

.then({path} => readFile(path))
.then(baseTemplate => ....)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vigneshshanmugam I understand your point of view, however i use the templateStat object to break the template parse logic on resolve the readFile promise. In your logic this not working apparently:

.then(({path}) => readFile(path))
.then(baseTemplate => {
    // templateStat is not defined
})

We can pass the complete object to readFile, add the baseTemplate to object and resolve the promise with the object. What do you think about it?

Copy link
Collaborator

@vigneshshanmugam vigneshshanmugam Aug 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh thanks for pointing out. No this is fine then, We can do the cleanup as part of using util.promisify library changes.
lets get this merged :)

@vigneshshanmugam
Copy link
Collaborator

👍

@addityasingh
Copy link
Contributor

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants