Skip to content

Add method to delete pages of the document by index - #1092

Merged
pointlessone merged 2 commits into
prawnpdf:masterfrom
davidsilveira:add_delete_last_page_method
Dec 14, 2018
Merged

Add method to delete pages of the document by index#1092
pointlessone merged 2 commits into
prawnpdf:masterfrom
davidsilveira:add_delete_last_page_method

Conversation

@davidsilveira

Copy link
Copy Markdown
Contributor

Comment thread lib/prawn/document.rb
Comment thread lib/prawn/document.rb Outdated
@davidsilveira
davidsilveira force-pushed the add_delete_last_page_method branch from 19d64b2 to 0340db6 Compare November 30, 2018 12:39
@sobrinho

Copy link
Copy Markdown

As we discussed, try to abstract to delete_page(index) to be able to delete any page instead of only the latest.

@pointlessone

Copy link
Copy Markdown
Member

I wonder what is the use case for this feature.

@sobrinho

Copy link
Copy Markdown

See #958.

@pointlessone

Copy link
Copy Markdown
Member

@sobrinho Thank you.

I'm not convinced that use case warrants an addition to the library.

@sobrinho

Copy link
Copy Markdown

@pointlessone this is a pattern that repeats over and over again in all projects that I work.

It's okay if you think that doesn't belong to the core but would be a good helper for us!

@pointlessone

Copy link
Copy Markdown
Member

If you want each thing on its own page why don't you start a new page before rendering a thing?

@sobrinho

Copy link
Copy Markdown

Because you can't start a new page in the first iteration, otherwise the blank page would be first one instead of the latest.

In that case, the code is like that:

things.each do |thing|
  if things.first != thiing
    document.start_new_page
  end

  render
end

@pointlessone

Copy link
Copy Markdown
Member

I see but I'm still hesitant since there's a straight-forward workaround and the code is not complex or obscure.

@sobrinho

Copy link
Copy Markdown

Your call!

Maybe there is other use cases, ours is just this one.

@johnnyshields

Copy link
Copy Markdown
Contributor

Deleting a page at an index is valid request. Ideally it should support negative indexes (-1 == last page).

The use case given is rather weak/inelegant however.

@davidsilveira
davidsilveira force-pushed the add_delete_last_page_method branch from 0340db6 to e7a948f Compare December 13, 2018 12:20
@davidsilveira davidsilveira changed the title Add method to delete the last page of the document Add method to delete pages of the document by index Dec 13, 2018
@davidsilveira
davidsilveira force-pushed the add_delete_last_page_method branch from e7a948f to 862346a Compare December 13, 2018 13:04
@davidsilveira

Copy link
Copy Markdown
Contributor Author

@sobrinho @johnnyshields I've updated this PR.
Now everyone can delete a page using an index value.
This method supports negative index, so if you want to delete the last page you just need to type -1.

@sobrinho

Copy link
Copy Markdown

Awesome!

sobrinho
sobrinho previously approved these changes Dec 13, 2018
@pointlessone

Copy link
Copy Markdown
Member

@davidsilveira Please make Rubocop happy. Otherwise it's good.

@pointlessone pointlessone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your contribution.

@pointlessone
pointlessone merged commit ea75d2a into prawnpdf:master Dec 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants