lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 34c088c 073/156: Move footer contents into an


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 34c088c 073/156: Move footer contents into an external template too
Date: Tue, 30 Jan 2018 17:22:14 -0500 (EST)

branch: master
commit 34c088c29d6951b4df33ea1bf4132f720cd741fd
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>

    Move footer contents into an external template too
    
    This will allow customizing footer more easily.
---
 footer.mustache             |  36 +++++++++++++
 ledger_pdf_generator_wx.cpp | 123 +++++++++++++++++---------------------------
 2 files changed, 82 insertions(+), 77 deletions(-)

diff --git a/footer.mustache b/footer.mustache
new file mode 100644
index 0000000..d675000
--- /dev/null
+++ b/footer.mustache
@@ -0,0 +1,36 @@
+<font size="-2">
+
+<table width="100%" cellspacing="0" cellpadding="0">
+    <tr>
+        <td colspan="3">&nbsp;</td>
+    </tr>
+    <tr>
+        <td>Date Prepared: {{date_prepared}}</td>
+        <td align="center">{{footer_contents}}</td>
+        <td align="right">{{InsCoName}}</td>
+    </tr>
+    <tr>
+        <td>System Version: {{LmiVersion}}</td>
+        <td>&nbsp;</td>
+        <td align="right">
+        {{#IsInforce}}
+            {{#Composite}}
+                {{ImprimaturInforceComposite}}
+            {{/Composite}}
+            {{^Composite}}
+                {{ImprimaturInforce}}
+            {{/Composite}}
+        {{/IsInforce}}
+        {{^IsInforce}}
+            {{#Composite}}
+                {{ImprimaturPresaleComposite}}
+            {{/Composite}}
+            {{^Composite}}
+                {{ImprimaturPresale}}
+            {{/Composite}}
+        {{/IsInforce}}
+        </td>
+    </tr>
+</table>
+
+</font>
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 1a8974f..65db474 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -85,6 +85,27 @@ class html_interpolator
     {
     }
 
+    // This function is provided to be able to delegate to it in custom
+    // interpolation functions, but usually shouldn't be called directly, just
+    // use operator() below instead.
+    std::string interpolation_func
+        (std::string const& s
+        ,interpolate_lookup_kind kind
+        ) const
+    {
+        switch(kind)
+            {
+            case interpolate_lookup_kind::variable:
+            case interpolate_lookup_kind::section:
+                return expand_html(s).as_html();
+
+            case interpolate_lookup_kind::partial:
+                return load_partial_from_file(s);
+            }
+
+        throw std::runtime_error("invalid lookup kind");
+    }
+
     // A method which can be used to interpolate an HTML string containing
     // references to the variables defined for this illustration. The general
     // syntax is the same as in the global interpolate_string() function, i.e.
@@ -105,19 +126,9 @@ class html_interpolator
                 ,[this]
                     (std::string const& s
                     ,interpolate_lookup_kind kind
-                    ) -> std::string
+                    )
                     {
-                    switch(kind)
-                        {
-                        case interpolate_lookup_kind::variable:
-                        case interpolate_lookup_kind::section:
-                            return expand_html(s).as_html();
-
-                        case interpolate_lookup_kind::partial:
-                            return load_partial_from_file(s);
-                        }
-
-                    throw std::runtime_error("invalid lookup kind");
+                        return interpolation_func(s, kind);
                     }
                 )
             );
@@ -609,72 +620,30 @@ class page_with_footer : public page
 
     // This method uses get_footer_contents() and returns the HTML wrapping it
     // and other fixed information appearing in the footer.
-    html::text get_footer_html(html_interpolator const& interpolate_html) const
+    text get_footer_html(html_interpolator const& interpolate_html) const
     {
-        return
-            tag::font[attr::size("-2")]
-                (tag::table[attr::width("100%")]
-                          [attr::cellspacing("0")]
-                          [attr::cellpadding("0")]
-                    (tag::tr
-                        (tag::td[attr::colspan("3")]
-                            (text::nbsp())
-                        )
-                    )
-                    (tag::tr
-                        (tag::td
-                            (interpolate_html
-                                ("Date Prepared: {{date_prepared}}"
-                                )
-                            )
-                        )
-                        (tag::td[attr::align("center")]
-                            (text::from(get_footer_contents())
-                            )
-                        )
-                        (tag::td[attr::align("right")]
-                            (interpolate_html
-                                ("{{InsCoName}}"
-                                )
-                            )
-                        )
-                    )
-                    (tag::tr
-                        (tag::td
-                            (interpolate_html
-                                ("System Version: {{LmiVersion}}"
-                                )
-                            )
-                        )
-                        (tag::td
-                            (text::nbsp()
-                            )
-                        )
-                        (tag::td[attr::align("right")]
-                            (interpolate_html
-                                (R"(
-    {{#IsInforce}}
-        {{#Composite}}
-            {{ImprimaturInforceComposite}}
-        {{/Composite}}
-        {{^Composite}}
-            {{ImprimaturInforce}}
-        {{/Composite}}
-    {{/IsInforce}}
-    {{^IsInforce}}
-        {{#Composite}}
-            {{ImprimaturPresaleComposite}}
-        {{/Composite}}
-        {{^Composite}}
-            {{ImprimaturPresale}}
-        {{/Composite}}
-    {{/IsInforce}}
-    )"
-                                )
-                            )
-                        )
-                    )
-                );
+        auto const contents = get_footer_contents();
+
+        // Use our own interpolation function to handle the special
+        // "footer_contents" variable that is replaced with the actual
+        // (possibly dynamic) footer contents.
+        return text::from_html
+            (interpolate_string
+                ("{{>footer}}"
+                ,[contents, interpolate_html]
+                    (std::string const& s
+                    ,interpolate_lookup_kind kind
+                    ) -> std::string
+                    {
+                    if(s == "footer_contents")
+                        {
+                        return contents;
+                        }
+
+                    return interpolate_html.interpolation_func(s, kind);
+                    }
+                )
+            );
     }
 
     int footer_top_ = 0;



reply via email to

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