[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 61fae89 091/156: Reimplement the contract num
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 61fae89 091/156: Reimplement the contract numbers fragment as an external template |
Date: |
Tue, 30 Jan 2018 17:22:19 -0500 (EST) |
branch: master
commit 61fae892154bef6c6cba9b22a22029b5aa325f10
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>
Reimplement the contract numbers fragment as an external template
This replaces the approach of the previous commit, which generated the
entire fragment in the code, by moving the fragment definition to an
external template and just defining the necessary variables for it in
the code.
This approach is more verbose and arguably less clear, but it keeps the
separation between data and presentation intact.
---
contract_numbers.mustache | 25 +++++++++++++++++++++
header.mustache | 2 +-
ledger_pdf_generator_wx.cpp | 54 ++++++++++-----------------------------------
3 files changed, 38 insertions(+), 43 deletions(-)
diff --git a/contract_numbers.mustache b/contract_numbers.mustache
new file mode 100644
index 0000000..f855118
--- /dev/null
+++ b/contract_numbers.mustache
@@ -0,0 +1,25 @@
+{{#HasMasterContract}}
+ Master contract:
+ {{#HasPolicyNumber}}
+ {{^Composite}}
+ {{MasterContractNumberAbbrev15}}
+ {{/Composite}}
+ {{#Composite}}
+ {{MasterContractNumberAbbrev30}}
+ {{/Composite}}
+ {{/HasPolicyNumber}}
+ {{^HasPolicyNumber}}
+ {{MasterContractNumberAbbrev30}}
+ {{/HasPolicyNumber}}
+{{/HasMasterContract}}
+{{#HasPolicyNumber}}
+ {{^Composite}}
+ Contract number:
+ {{#HasMasterContract}}
+ {{ContractNumberAbbrev15}}
+ {{/HasMasterContract}}
+ {{^HasMasterContract}}
+ {{ContractNumberAbbrev30}}
+ {{/HasMasterContract}}
+ {{/Composite}}
+{{/HasPolicyNumber}}
diff --git a/header.mustache b/header.mustache
index 50c967d..0021e39 100644
--- a/header.mustache
+++ b/header.mustache
@@ -54,7 +54,7 @@
{{^Composite}}
Initial Death Benefit Option: {{InitDBOpt}}<br>
{{/Composite}}
- {{ContractNumbers}}
+ {{>contract_numbers}}
</td>
<td width="40%">
Initial {{#HasTerm}}Total{{/HasTerm}}
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index abfee9f..84577a8 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -746,51 +746,21 @@ class pdf_illustration : protected html_interpolator
auto const& invar = ledger_.GetLedgerInvariant();
- // Build the combined string containing the master and individual
- // contract numbers, omitting each of them if it's not specified and
- // also truncating them to either 15 characters if both are present or
- // 30 if only one of them is.
+ // Define the variables needed by contract_numbers template.
add_variable
- ("ContractNumbers"
- ,[this,invar]() -> std::string
- {
- std::ostringstream oss;
-
- bool const use_master_number
- = !invar.MasterContractNumber.empty();
-
- bool const use_policy_number
- = !invar.ContractNumber.empty()
- && !ledger_.is_composite()
- ;
-
- size_t const full_abbrev_length = 30;
-
- if(use_master_number)
- {
- oss << "Master contract: "
- << abbreviate_if_necessary
- (invar.MasterContractNumber
- ,use_policy_number
- ? full_abbrev_length / 2
- : full_abbrev_length
- );
- }
- if(use_policy_number)
- {
- oss << "Contract number: "
- << abbreviate_if_necessary
- (invar.ContractNumber
- ,use_master_number
- ? full_abbrev_length / 2
- : full_abbrev_length
- );
- }
-
- return oss.str();
- }()
+ ("HasMasterContract"
+ ,!invar.MasterContractNumber.empty()
+ );
+ add_variable
+ ("HasPolicyNumber"
+ ,!invar.ContractNumber.empty()
);
+ size_t const full_abbrev_length = 30;
+ add_abbreviated_variable("MasterContractNumber", full_abbrev_length);
+ add_abbreviated_variable("MasterContractNumber", full_abbrev_length /
2);
+ add_abbreviated_variable("ContractNumber", full_abbrev_length);
+ add_abbreviated_variable("ContractNumber", full_abbrev_length / 2);
}
// Use non-default font sizes to make it simpler to replicate the existing
- [lmi-commits] [lmi] master f8853b9 090/156: Add "contract numbers" fragment to the header, (continued)
- [lmi-commits] [lmi] master f8853b9 090/156: Add "contract numbers" fragment to the header, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 61430d2 092/156: Move some variable definitions to the base illustration class, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 7ccd207 087/156: Rename "footer_contents" to more precise "page_number", Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 3a64b87 094/156: Correct misleading comment for page class dtor, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 4e76bba 098/156: Add support for comments to the string interpolation function, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master b5fe850 102/156: Add NASD basic illustration page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 4250de9 104/156: Add first variant of NASD supplemental page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 7a1e1e8 025/156: Include the missing <cstring> header, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 8bfb896 109/156: Add NASD illustration first explanatory notes page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master ea20a31 095/156: Make pdf_illustration dtor virtual, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 61fae89 091/156: Reimplement the contract numbers fragment as an external template,
Greg Chicares <=
- [lmi-commits] [lmi] master 0c55621 085/156: Replace trivial PDF page classes with single standard_page one, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master ea2564b 099/156: Split the NASD header template in the upper and lower parts, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master c1bf4a8 032/156: Adjust position of the right hand side of the header manually, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 89b4674 120/156: Add automatic support for multiline super-headers, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 0f885a2 116/156: Define CorpNameAbbrev60 and Insured1Abbrev30 in common code, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 08559c3 121/156: Factor out base_suffix() and ir_suffix() functions, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 36c84ce 123/156: Add another individual private placement illustration page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 0ecc8ec 036/156: Add support for partials to our ad hoc Mustache parser, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 6f09722 107/156: Add missing words to the narrative summary continuation page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 6510601 150/156: Rename a mute variable to avoid gcc -Wshadow warning, Greg Chicares, 2018/01/30