Skip to content
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

raise an exception when align value is not a Symbol #1057

Merged
merged 1 commit into from
May 30, 2018
Merged

raise an exception when align value is not a Symbol #1057

merged 1 commit into from
May 30, 2018

Conversation

lucianosousa
Copy link
Contributor

No description provided.

@pointlessone
Copy link
Member

@lucianosousa Hi! Thank you for your interest in giving back to community!

Could you please give a bit of context for this PR?

@lucianosousa
Copy link
Contributor Author

@pointlessone sure man.
I was trying to align here with align: 'center' and the pdf render just broke.
Some rails methods accept both kinds of argument types, eg: https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validations.rb#L256
we can do the same here, don't you think?

@pointlessone
Copy link
Member

Prawn is not a part of the Ruby on Rails framework. We do not quite share an outlook on API design with Rails.

I agree that it's suboptimal to break document rendering. But I think a proper solution here to let the user know what's wrong instead of extending the API. We generally do not accept strings where only a limited number of named options can be accepted and I don't want to diverge from that in this case.

What do you think of an alternative solution? Add an else to that case that will raise an ArgumentError with a descriptive message.

@lucianosousa
Copy link
Contributor Author

@pointlessone cool. better raise an exception then ;)

@pointlessone
Copy link
Member

@lucianosousa Would you like to change the code in this PR or l it to someone else?

@lucianosousa lucianosousa changed the title accepts string as align argument raise an exception when align value is not a Symbol Mar 23, 2018
@lucianosousa
Copy link
Contributor Author

@pointlessone sorry the delay. it's here! ;)

@pointlessone
Copy link
Member

@lucianosousa I would very much prefer if the exception was risen in every unrecognized case not only when it's not a symbol.

@lucianosousa
Copy link
Contributor Author

sorry being late. updated

@pointlessone
Copy link
Member

NP. Thank you for keeping working on this.

Could you please put the raise into else branch of the case statement to save us extra check?

@@ -267,6 +267,9 @@ def draw_fragment(
else
@at[0] + @width - line_width
end
else
raise ArgumentError, 'align value needs to have a valid value: left, right, center or justify as symbol' unless
Copy link
Member

Choose a reason for hiding this comment

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

  • The unless part is not needed any more. It's covered by the preceding case branches.
  • You also can write valid values in Ruby syntax (e.g. :left). I believe developers would pick that up.
  • I'm not a native speaker myself but overall wording is a bit awkward to me. What do you think of the following: align must be one of :left, :right, :center or :justify

@lucianosousa
Copy link
Contributor Author

done @pointlessone sorry being late

Copy link
Member

@pointlessone pointlessone left a comment

Choose a reason for hiding this comment

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

Well done!

Copy link
Member

@pointlessone pointlessone left a comment

Choose a reason for hiding this comment

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

Could you please fix code style to make RuboCop happy?

@lucianosousa
Copy link
Contributor Author

@pointlessone I guess we need merge #1060 first here

@pointlessone
Copy link
Member

pointlessone commented Apr 30, 2018

Not sure. That one improves document consistency but I never saw a difference between 2.2 and 2.3+.

I'll leave it up to you. Wait for #1060 if you think it will fix the failure or you can dig and see if it's something worth checking before #1060.

@lucianosousa
Copy link
Contributor Author

@pointlessone just merged and passes! :D ready for u

@pointlessone
Copy link
Member

@lucianosousa Could you please clean up the history a bit?

@lucianosousa
Copy link
Contributor Author

@pointlessone done

@pointlessone pointlessone merged commit 2cdd2e7 into prawnpdf:master May 30, 2018
@pointlessone
Copy link
Member

Thank you for your contribution.

@lucianosousa lucianosousa deleted the document-align-improvement branch May 31, 2018 02:51
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.

None yet

2 participants