From faccee86845ccbe68e9d6239860eab037f865ae0 Mon Sep 17 00:00:00 2001 From: Jonathan Wolter Date: Mon, 27 Feb 2012 08:08:32 -0800 Subject: [PATCH] huge hack to make it work with a malformed template --- lib/docx_templater/template_processor.rb | 12 +++++- spec/template_processor_spec.rb | 55 ++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/lib/docx_templater/template_processor.rb b/lib/docx_templater/template_processor.rb index be19988..db93674 100644 --- a/lib/docx_templater/template_processor.rb +++ b/lib/docx_templater/template_processor.rb @@ -14,7 +14,17 @@ def render(document) document = enter_multiple_values(document, key) document.gsub!("#SUM:#{key.to_s.upcase}#", value.count.to_s) else - document.gsub!("$#{key.to_s.upcase}$", safe(value)) + # Massive hack + if key.to_s.downcase == 'connected_users_table' + xml = Nokogiri::XML(document) + t_node = xml.xpath("//w:t[contains(., 'CONNECTED_USERS_TABLE')]").first + new_node = xml.create_element("tbl") + new_node.inner_html = value + t_node.parent.parent.replace new_node + document = xml.to_s + else + document.gsub!("$#{key.to_s.upcase}$", safe(value)) + end end end document diff --git a/spec/template_processor_spec.rb b/spec/template_processor_spec.rb index 65dabfb..bf3c020 100644 --- a/spec/template_processor_spec.rb +++ b/spec/template_processor_spec.rb @@ -218,4 +218,59 @@ module TestData out.index("#{data[:roster].count} Students").should >= 0 out.index("#{data[:event_reports].count} Events").should >= 0 end + + + + it "massive hack" do + data.clear + data[:connected_users_table] = < + + + + + + + + + + + + + + + + + +EOF + xml = < + + + + + + + + + + + + + + + + + + + + + $CONNECTED_USERS_TABLE$ + + + + +EOF + parser.render(xml).to_s.index('CONNECTED_USERS_TABLE').should be_nil + end end