-
Notifications
You must be signed in to change notification settings - Fork 130
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
merged field within the conditional is not rendering #141
Comments
Hi @lkfken my first assumption would be that |
Thank you for your response. I did try it by removing the surrounding "ifs" and it (dtrrd.premium) was render just fine. Thus I ruled out this "gotcha" possibility. Just one question, given a similar block/paragraph, does it work on your side? If so, could you tell me about your environment? Information such as version of Ruby/JRuby, Word, OS version? thank you |
Ah I think I just noticed the issue, it's the syntax in if block. The predicate part is wrong I think. Try doing this instead:
We test conditionals pretty exhaustively in https://github.com/senny/sablon/blob/master/test/fixtures/conditionals_template.docx so you might give that a look over as well. |
@stadelmanma thank you for the advice. I think I just narrow down the problem. require 'sablon'
class Dtrrd
def lis?
true
end
def premium
'$42'
end
def no_lis?
!lis?
end
def lisl
'100'
end
def lisc
'2'
end
end
context = {dtrrd: Dtrrd.new}
filename = "./#{Time.now.strftime('%Y%m%d_%H%M%S')}_sample.docx"
template = Sablon.template('sample1.docx')
template.render_to_file(filename, context) sample1.docx
I used the above code (sample.rb) and generate 2 files. Here is the sequence of this process.
I am going to run some more tests on this. But based on this result, it's rather discouraging to me because it would mean it's a matter of "luck" to get the perfect template...I am not sure if it is even possible! (try so many times but they are just mutually exclusive, never both "work"/"don't work") |
I run the same code using Ruby 2.6 (not JRuby 9.2.7) and everything is rendered correctly. |
Templates are a pain to maintain depending on their complexity but there shouldn't be any "randomness" to them working. Unless MS Word is doing less than ideal things with your merge fields. We don't test against JRuby and I wouldn't expect that to be the problem since Sablon is pretty high level, maybe JRuby's version of nokogiri is doing something unexpected (it uses native extensions)? If I have time I'll run the test suite against JRuby and see what happens. |
@lkfken I just installed jruby 9.1.7 into my development environment and the test suite threw multiple failures (39 failures, 2 errors) so it's safe to say at this point in time we don't support jruby. I don't know what the issue is but I suspect that the problem lies in the EDIT: The main part issue with tests failing is that the Java version of nokogiri is injecting |
«dtrrd.no_lis?:if»
What are my costs on this plan?
The Monthly premium for your plan is «=dtrrd.premium»
«dtrrd.no_lis?:endIf»
when dtrrd.no_lis? is true, it will print the paragraph; however, the field dtrrd.premium remained unchanged (not rendered).
I try it without the conditional and it's working fine.
Please help. Thank you.
The text was updated successfully, but these errors were encountered: