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

merged field within the conditional is not rendering #141

Open
lkfken opened this issue Oct 11, 2019 · 7 comments
Open

merged field within the conditional is not rendering #141

lkfken opened this issue Oct 11, 2019 · 7 comments
Labels
jruby Issues that only affect jruby

Comments

@lkfken
Copy link

lkfken commented Oct 11, 2019

«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.

@stadelmanma
Copy link
Collaborator

stadelmanma commented Oct 12, 2019

Hi @lkfken my first assumption would be that «=dtrrd.premium» doesn't match the expected merge field format. Did you add the equals sign after the fact? A common "gotcha" is that editing the text displayed does not edit the actual merge field tag, you'll need to right click and toggle the tag info to edit it directly.

@lkfken
Copy link
Author

lkfken commented Oct 16, 2019

Hi @lkfken my first assumption would be that «=dtrrd.premium» doesn't match the expected merge field format. Did you add the equals sign after the fact? A common "gotcha" is that editing the text displayed does not edit the actual merge field tag, you'll need to right click and toggle the tag info to edit it directly.

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

@stadelmanma
Copy link
Collaborator

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:

«dtrrd:if(no_lis?)»
What are my costs on this plan?
The Monthly premium for your plan is «=dtrrd.premium»
«dtrrd:endIf»

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.

@lkfken
Copy link
Author

lkfken commented Oct 18, 2019

@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

«dtrrd:if(lis?)»
Your subsidy codes are
«=dtrrd.lisl»	«=dtrrd.lisc»
«dtrrd:endIf»
«dtrrd:if(no_lis?)»
What are my costs on this plan?
The monthly premium for your plan is «=dtrrd.premium».
«dtrrd:else»
What are my costs since I qualify for Extra Help?
With subsidy, the monthly premium for your plan is «=dtrrd.premium».
«dtrrd:endIf»

I used the above code (sample.rb) and generate 2 files. Here is the sequence of this process.

  1. run sample.rb
  2. 20191018_141919_sample.docx generated. The first "if" block rendered correctly, but not the 2nd "if" block
Your subsidy codes are
100	2
What are my costs since I qualify for Extra Help?
With subsidy, the monthly premium for your plan is «=dtrrd.premium».
  1. open sample1.docx, WITHOUT REALLY CHANGING THE FILE (something like add a space and delete it again). Then save the file
  2. run sample.rb
  3. 20191018_142013_sample.docx generated. Interestingly, the first "if" block did not render correctly, but the 2nd "if" block did.
Your subsidy codes are
«=dtrrd.lisl»	«=dtrrd.lisc»
What are my costs since I qualify for Extra Help?
With subsidy, the monthly premium for your plan is $42.

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")

@lkfken
Copy link
Author

lkfken commented Oct 21, 2019

I run the same code using Ruby 2.6 (not JRuby 9.2.7) and everything is rendered correctly.

@stadelmanma
Copy link
Collaborator

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.

@stadelmanma
Copy link
Collaborator

stadelmanma commented Nov 6, 2019

@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 nokogiri gem since Sablon works at a pretty high level otherwise.

EDIT: The main part issue with tests failing is that the Java version of nokogiri is injecting xmlns:w tags in a huge fraction of the nodes for seemingly no reason because the C version does not do that.

@stadelmanma stadelmanma added the jruby Issues that only affect jruby label Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jruby Issues that only affect jruby
Projects
None yet
Development

No branches or pull requests

2 participants