<?lsmb#   This is a comment block; it's ignored by the template engine.

   Version:  1.2
   Date:     2025-05-02
   File:     display_report.csv
   Set:      demo

Template version numbers are explicitly not aligned across templates or
releases. No explicit versioning was applied before 2021-01-04.

Version   Changes
1.1       Merged 'dynatable.csv' into this template
1.2       Fix missing newlines after each row


-?>
<?lsmb-

BLOCK do_quote ;
  IF VALUE.to_output.defined();
    value = VALUE.to_output();
  ELSE;
    value = VALUE;
  END;

  IF value.match('[^0-9.+-]'); # any non-digit means run escaping
     '"'; value.replace('"', '""'); '"'; # " balance the double quotes
  ELSE;
     value;
  END;
END;

BLOCK dynatable;
    SKIP_TYPES = ['hidden', 'radio', 'checkbox'];

    FOREACH COL IN columns;
        IF SKIP_TYPES.grep(COL.type).empty();
            UNLESS loop.first();
               ',';
            END;
            INCLUDE do_quote VALUE = COL.name;
        END;
    END;
    "\n";

    FOREACH ROW IN tbody.rows;
        FOREACH COL IN columns;
            COL_ID = COL.col_id;
            IF SKIP_TYPES.grep(COL.type).empty();
                UNLESS loop.first();
                   ',';
                END;
                INCLUDE do_quote VALUE = ROW.$COL_ID;
            END;
        END;
        "\n";
    END;
END;


PROCESS dynatable tbody = {rows = rows };
?>
