senny / sablon

Ruby Document Template Processor based on docx templates and Mail Merge fields.
MIT License
446 stars 128 forks source link

Make it possible for an if statement to include method parameters #135

Closed ulrik closed 5 years ago

ulrik commented 5 years ago

I need to be able to make the if statement compare the given value with a string.

I would therefore purpose a syntax like this

«smoking:if(== "Often")»
«smoking:elseIf(=="Rare")»
«smoking:else»
«smoking:endIf»

I guess the line in lib/sablon/operations.rb value = value.public_send(predicate) if predicate could be generalized to let public_send take more arguments, but I can't see how it could be done...

stadelmanma commented 5 years ago

This has been proposed before but we want to avoid making the actual word document templates more complex, see #73.

This can be done via a custom field handler, and I actually have it implemented as a test case here https://github.com/senny/sablon/blob/master/test/custom_field_handler_test.rb#67.

Let me know if you have any other questions!