/demo/src/view.ads

http://github.com/ThomasLocke/yolk · Ada · 86 lines · 42 code · 12 blank · 32 comment · 0 complexity · 77e14cdcdb259815e26961cbbe28eae8 MD5 · raw file

  1. -------------------------------------------------------------------------------
  2. -- --
  3. -- Copyright (C) 2010-, Thomas ¸cke --
  4. -- --
  5. -- This is free software; you can redistribute it and/or modify it --
  6. -- under terms of the GNU General Public License as published by the --
  7. -- Free Software Foundation; either version 3, or (at your option) any --
  8. -- later version. This library is distributed in the hope that it will be --
  9. -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
  10. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
  11. -- You should have received a copy of the GNU General Public License and --
  12. -- a copy of the GCC Runtime Library Exception along with this program; --
  13. -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
  14. -- <http://www.gnu.org/licenses/>. --
  15. -- --
  16. -------------------------------------------------------------------------------
  17. -- The main view file. Resources shared between view.* packages are declared
  18. -- here.
  19. with Ada.Strings.Unbounded;
  20. with AWS.MIME;
  21. with AWS.Status;
  22. with AWS.Response;
  23. with AWS.Templates;
  24. with GNATCOLL.SQL.Exec;
  25. with GNATCOLL.SQL.Postgres;
  26. with GNATCOLL.SQL.Sqlite;
  27. with My_Configuration;
  28. with Yolk.Cache.Discrete_Keys;
  29. package View is
  30. use Ada.Strings.Unbounded;
  31. use AWS.MIME;
  32. use Yolk;
  33. package My renames My_Configuration;
  34. -- Easier to write, easier to read.
  35. PostgreSQL_Description : GNATCOLL.SQL.Exec.Database_Description :=
  36. GNATCOLL.SQL.Postgres.Setup
  37. (Database => My.Config.Get (My.DB_Name),
  38. User => My.Config.Get (My.DB_User),
  39. Host => My.Config.Get (My.DB_Host),
  40. Password => My.Config.Get (My.DB_Password),
  41. SSL => GNATCOLL.SQL.Postgres.Disable);
  42. -- A GNATColl PostgreSQL database description object.
  43. SQLite_Description : GNATCOLL.SQL.Exec.Database_Description :=
  44. GNATCOLL.SQL.Sqlite.Setup
  45. (Database => My.Config.Get (My.SQLite_Database));
  46. -- A GNATColl SQLite database description object.
  47. type Cache_Keys is (Feed_Data);
  48. package Cache is new Yolk.Cache.Discrete_Keys
  49. (Key_Type => Cache_Keys,
  50. Element_Type => Unbounded_String,
  51. Max_Element_Age => 10.0);
  52. -- Some pages are expensive to build, so we cache them. Here we test the
  53. -- Discrete_Keys cache.
  54. function Build_Response
  55. (Status_Data : in AWS.Status.Data;
  56. Content : in String;
  57. MIME_Type : in String := Text_HTML)
  58. return AWS.Response.Data;
  59. -- Build the resource response.
  60. -- This is a convenience function that gets rid of a few with clauses in
  61. -- the files for the View child packages.
  62. function Build_Response
  63. (Status_Data : in AWS.Status.Data;
  64. Template_File : in String;
  65. Translations : in AWS.Templates.Translate_Set;
  66. MIME_Type : in String := Text_HTML)
  67. return AWS.Response.Data;
  68. -- Build the resource response.
  69. -- This is a convenience function that gets rid of a few with clauses in
  70. -- the files for the View child packages.
  71. -- This one is just a wrapper for the first Build_Response function. With
  72. -- this one you can add the template file and translate set directly,
  73. -- instead of having to parse those in the view.* child package.
  74. end View;