CL-WHO-like HTML templating for other languages?

前端 未结 9 1085
别那么骄傲
别那么骄傲 2020-12-10 04:44

Common Lisp guys have their CL-WHO, which makes HTML templating integrated with the \"main\" language thus making the task easier. For those who don\'t know CL-WHO, it looks

9条回答
  •  余生分开走
    2020-12-10 05:12

    Perl's standard CGI module can do something similar:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use CGI qw/:standard/;
    
    print 
        start_html("An example"),
        h1(
            {
                -align => "left",
                -class => "headerinfo",
            },
            'this is an example'
        ),
        "The CGI module has functions that add HTML:",
        ul( map li($_),
            ("start_html",
            "h1, h2, h3, etc.",
            "ol, ul, li",
            "ol, ul, li",
            "table, tr, th, td")
        ),
        "and many more.",
        end_html();
    

    That produces:

    
    
    
    An example
    
    
    
    

    this is an example

    The CGI module has functions that add HTML:
    • start_html
    • h1, h2, h3, etc.
    • ol, ul, li
    • ol, ul, li
    • table, tr, th, td
    and many more.

    The li section could be rewritten like this

    print ol(map li($_), @list);
    

    if you had a list or an array.

提交回复
热议问题