demo1.lpr 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. { Demo for mustache engine with JSON context
  2. Copyright (C) 2021 michael Van Canneyt [email protected]
  3. This source is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
  4. published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  5. This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  6. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  7. A copy of the GNU General Public License is available on the World Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can
  8. also obtain it by writing to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.
  9. }
  10. program demo1;
  11. // jsonparser includes the json parser.
  12. uses jsonparser, fpmustache;
  13. Const
  14. JSON = '{ "products" : [ {"name" : "BMW" }, {"name" : "Mercedes"}, { "name" : "Audi" }] }';
  15. // Mock markdown table
  16. Template =
  17. '| name |'+sLineBreak+
  18. '|------|'+sLineBreak+
  19. '{{#products}}| {{name}} |'+sLineBreak+
  20. '{{/products}}';
  21. Var
  22. M : TMustache;
  23. begin
  24. M:=TMustache.Create(Nil);
  25. try
  26. // Json support enabled by default
  27. Writeln(M.Render(Template,JSON));
  28. finally
  29. M.Free;
  30. end;
  31. end.