in reply to Re^4: Here documents in blocks
in thread Here documents in blocks

some require pluralisation whilst other don't.

Have you seen Lingua::EN::Inflexion? It allows you to construct a generic pattern (a template of sorts) to handle various cases like this.

If there is a way to simplify it which can be quickly implemented then I would certainly change my approach.

It can be quickly implemented, if not quickly learnt. Because these are modules with which I am familiar I would use Template for the templating system with the Template::Plugin::Lingua::EN::Inflexion plugin which would allow for a simple loop to produce the table contents and proper pluralisation of the prose. TIMTOWTDI, of course.

#!/usr/bin/env perl use strict; use warnings; use Template; # Set up your data my $data = { table => [ { head => 'Bookings this month', val => 132, }, { head => 'Previous 30 days', val => 99, }, { head => 'Forthcoming 30 days', val => 150, }, { head => 'Forthcoming 60 days', val => 189, }, ], event_count => 1, call_list => 5 }; # Set up your template (easiest/commonest in an external datastore (fi +le # or DB) my $template = <<EOT; <div style="float:right"> <p class="sectionHead"><b>FHL Properties:</b></p> <table> [% FOR k IN table %] <tr> <th class="itemHead">[% k.head %]:</th> <td>[% k.val %] </td> </tr> [% END %] </table> </div> <hr style="clear:both"> [% USE infl = Lingua.EN.Inflexion; FILTER inflect; -%] <p class="sectionHead"><b>Progress in Property Event:</b></p> <p class="itemHeadLarge"><#:[% event_count %]> <N:person> <V:has> regi +stered their interest.</p> <hr> <p class="sectionHead"><b>Customer Contentment Call List:</b></p> <p class="itemHeadLarge"><#d:[% call_list %]> There <V:is> [% call_lis +t %] <N:person> who <V:is> on the Call List.</p> <hr> [% END %] EOT # Run it Template->new->process (\$template, $data); exit;

🦛

Replies are listed 'Best First'.
Templating system choice
by Bod (Parson) on Dec 21, 2020 at 10:39 UTC
    It can be quickly implemented, if not quickly learnt. Because these are modules with which I am familiar I would use Template for the templating system

    Thanks hippo. Last evening my bedtime reading was Template along with Template::Manual and Templete::Tutorial. Nothing like a bit of light bedtime reading!

    I'm convinced!!!

    There is an immediate use I see for this solving a problem that is going to need addressing next year - allowing non-techie team members to create company branded emails without having to manipulate HTML.

    But...it strikes me that there are a number of Perl templating systems. hippo (and others), if you were starting again today, would you use Template or might you be looking at others?

      There is indeed a range of templating modules and this is a good thing because one size does not necessarily fit all. I am happy with Template and would choose it again if starting from scratch because it has everything I need with very few downsides. It has a steeper learning curve that many of the alternatives, but the docs are good and a novice can still construct fairly simple but effective templates using it. It is well maintained, suitable for any output format (HTML, CSV, XML, JSON, plain text, LaTeX source, SVG, you name it), comes with command-line utilities (ttree, tpage) and is widely used.


      🦛

        Thanks hippo. It does seem to me that, whilst Template is powerful and does many things, the documentation is quite clear. Having read the tutorial last evening, I am quite sure I could make it do something useful today.

        Unlike Mojolicious, Template seems more general purpose and not specifically intended for web deployment.

        Template is also already installed on my shared hosting :)

        I am happy with Template and would choose it again if starting from scratch because it has everything I need with very few downsides

        This evening I've made a start with Template and it was easier to get something working than I expected. It all just seems to fit together nicely.

        Thanks hippo and everyone else who directed me down the templating path.

Re^6: Here documents in blocks
by Bod (Parson) on Dec 20, 2020 at 23:25 UTC
    Have you seen Lingua::EN::Inflexion?

    No I haven't...well - I have now :) Thanks

    Coincidentally, I have been looking at Lingua::EN::Fathom recently for a different project.