You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, in Sablon::Statement::Insertion, when expr evaluates to nil (i.e. there is no entry in the context), it simply removes the field (basically, nil is the same as an empty string).
It would be nice if there were a way to specify that we want to abort with an exception if a value is not provided for a given field. This is important for documents like contracts, where there might be serious consequences if a value is not filled in.
The text was updated successfully, but these errors were encountered:
Hi @anamba, I completely understand your use case but I don't think this is something we will add to the main sablon gem. However, it can be easily done in your application's initiailization/config via a custom field handler and a slightly modified Insertion class.
This comment #108 (comment) has some useful background on either monkey patching Sablon::Statement::Insertion or implementing your own field handler class. See lib/sablon/processor/document/field_handlers.rb and lib/sablon/processor/document.rb for examples on how the "builtin" handlers are done.
Actually, on second thought I think my sleepy mind may have made too hasty a judgement. Sablon aims to keep templates simple because they can be a real pain in the neck to debug. That is why we tend to decline changes that move more logic into the template.
However, "required" fields may add a degree of robustness to a template that help prevent context changes in one part of the code (possibly a quite distant section of code) from breaking the final document.
Currently, in Sablon::Statement::Insertion, when expr evaluates to nil (i.e. there is no entry in the context), it simply removes the field (basically,
nil
is the same as an empty string).It would be nice if there were a way to specify that we want to abort with an exception if a value is not provided for a given field. This is important for documents like contracts, where there might be serious consequences if a value is not filled in.
The text was updated successfully, but these errors were encountered: