lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 41de2e2 140/156: Add helper expand_template()


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 41de2e2 140/156: Add helper expand_template() method
Date: Tue, 30 Jan 2018 17:22:33 -0500 (EST)

branch: master
commit 41de2e21ed4b851d459bae5c69bc89904aef0962
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>

    Add helper expand_template() method
    
    No real changes, just simplify the code a little by providing a method
    for interpolating the contents of an external template removing the need
    to manually create "{{>template_name}}" strings and interpolating them.
---
 ledger_pdf_generator_wx.cpp | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index ef1bd4b..c9e017e 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -232,6 +232,15 @@ class html_interpolator
         return evaluator_(name, index);
     }
 
+    // Interpolate the contents of the given external template.
+    //
+    // This is exactly the same as interpolating "{{>template_name}}" string
+    // but a bit more convenient to use and simpler to read.
+    text expand_template(std::string const& template_name) const
+    {
+        return (*this)("{{>" + template_name + "}}");
+    }
+
   private:
     // The expansion function used with interpolate_string().
     text expand_html(std::string const& s) const
@@ -687,7 +696,7 @@ class page
             (writer.get_horz_margin()
             ,writer.get_vert_margin()
             ,writer.get_page_width()
-            ,interpolate_html("{{>" + template_name + "}}")
+            ,interpolate_html.expand_template(template_name)
             );
     }
 
@@ -846,7 +855,7 @@ class pdf_illustration : protected html_interpolator
 
         add_variable
             ("HasComplianceTrackingNumber"
-            ,(*this)("{{>compliance_tracking_number}}")
+            ,expand_template("compliance_tracking_number")
                 .as_html().find_first_not_of(" \n")
                 != std::string::npos
             );
@@ -989,7 +998,7 @@ class page_with_footer : public page
                 (frame_horz_margin
                 ,0
                 ,frame_width
-                ,interpolate_html("{{>" + upper_template + "}}")
+                ,interpolate_html.expand_template(upper_template)
                 ,e_output_measure_only
                 );
 
@@ -1024,7 +1033,7 @@ class page_with_footer : public page
                 (frame_horz_margin
                 ,y
                 ,frame_width
-                ,interpolate_html("{{>" + upper_template + "}}")
+                ,interpolate_html.expand_template(upper_template)
                 );
             }
 
@@ -1649,7 +1658,9 @@ class page_with_tabular_report
             (writer.get_horz_margin()
             ,pos_y
             ,writer.get_page_width()
-            ,interpolate_html("{{>" + get_fixed_page_contents_template_name() 
+ "}}")
+            ,interpolate_html.expand_template
+                (get_fixed_page_contents_template_name()
+                )
             ,output_mode
             );
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]