-
Notifications
You must be signed in to change notification settings - Fork 536
Added pagination start page #227
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,6 +144,7 @@ function getContent (page) { | |
| // Creates page section | ||
| // -------------------- | ||
| function createSection (section, content, options) { | ||
| var opts = options | ||
| options = options[section] || {} | ||
| var c = content[section] || {} | ||
| var o = options.contents | ||
|
|
@@ -153,11 +154,19 @@ function createSection (section, content, options) { | |
| height: options.height, | ||
| contents: phantom.callback(function (pageNum, numPages) { | ||
| var html = o[pageNum] || c[pageNum] | ||
|
|
||
| var pageNumFinal = pageNum, numPagesFinal = numPages; | ||
| if(opts.paginationStartPage && opts.paginationStartPage > 1) { | ||
| var pageOffset = opts.paginationStartPage - 1; | ||
| pageNumFinal = (pageNumFinal - pageOffset > 0 ? pageNumFinal - pageOffset : ''); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's strange that you have an empty string as fallback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. The empty string is to actualy print out a blank for cover pages and such There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it would look nicer if we have that fallback in the replace method. |
||
| numPagesFinal -= pageOffset; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to never use e.g. var paginationStartPage = (opts.paginationStartPage > 1) ? opts.paginationStartPage : 1
var pageNumFinal = (pageNum - pageOffset > 0) ? pageNumFinal - pageOffset : ''
var numPagesFinal = numPages - (paginationStartPage - 1)There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, will make those changes. |
||
| } | ||
|
|
||
| if (pageNum === 1 && !html) html = o.first || c.first | ||
| if (pageNum === numPages && !html) html = o.last || c.last | ||
| return (html || o.default || c.default || '') | ||
| .replace(/{{page}}/g, pageNum) | ||
| .replace(/{{pages}}/g, numPages) + content.styles | ||
| .replace(/{{page}}/g, pageNumFinal) | ||
| .replace(/{{pages}}/g, numPagesFinal) + content.styles | ||
| }) | ||
| } | ||
| } | ||
|
|
||
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.
Please split up multiple assignments onto multiple lines.
This didn't throw an error in the linting script because only
bin/index.jswas tested.I've created a pr here that fixes the config https://github.com/marcbachmann/node-html-pdf/pull/230/files
Can you please rebase and apply those changes.