PageRenderTime 28ms CodeModel.GetById 19ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/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 Lø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
18--  The main view file. Resources shared between view.* packages are declared
19--  here.
20
21with Ada.Strings.Unbounded;
22with AWS.MIME;
23with AWS.Status;
24with AWS.Response;
25with AWS.Templates;
26with GNATCOLL.SQL.Exec;
27with GNATCOLL.SQL.Postgres;
28with GNATCOLL.SQL.Sqlite;
29with My_Configuration;
30with Yolk.Cache.Discrete_Keys;
31
32package View is
33
34   use Ada.Strings.Unbounded;
35   use AWS.MIME;
36   use Yolk;
37
38   package My renames My_Configuration;
39   --  Easier to write, easier to read.
40
41   PostgreSQL_Description : GNATCOLL.SQL.Exec.Database_Description :=
42                              GNATCOLL.SQL.Postgres.Setup
43                                (Database => My.Config.Get (My.DB_Name),
44                                 User     => My.Config.Get (My.DB_User),
45                                 Host     => My.Config.Get (My.DB_Host),
46                                 Password => My.Config.Get (My.DB_Password),
47                                 SSL      => GNATCOLL.SQL.Postgres.Disable);
48   --  A GNATColl PostgreSQL database description object.
49
50   SQLite_Description : GNATCOLL.SQL.Exec.Database_Description :=
51                          GNATCOLL.SQL.Sqlite.Setup
52                            (Database => My.Config.Get (My.SQLite_Database));
53   --  A GNATColl SQLite database description object.
54
55   type Cache_Keys is (Feed_Data);
56
57   package Cache is new Yolk.Cache.Discrete_Keys
58     (Key_Type        => Cache_Keys,
59      Element_Type    => Unbounded_String,
60      Max_Element_Age => 10.0);
61   --  Some pages are expensive to build, so we cache them. Here we test the
62   --  Discrete_Keys cache.
63
64   function Build_Response
65     (Status_Data : in AWS.Status.Data;
66      Content     : in String;
67      MIME_Type   : in String := Text_HTML)
68      return AWS.Response.Data;
69   --  Build the resource response.
70   --  This is a convenience function that gets rid of a few with clauses in
71   --  the files for the View child packages.
72
73   function Build_Response
74     (Status_Data   : in AWS.Status.Data;
75      Template_File : in String;
76      Translations  : in AWS.Templates.Translate_Set;
77      MIME_Type     : in String := Text_HTML)
78      return AWS.Response.Data;
79   --  Build the resource response.
80   --  This is a convenience function that gets rid of a few with clauses in
81   --  the files for the View child packages.
82   --  This one is just a wrapper for the first Build_Response function. With
83   --  this one you can add the template file and translate set directly,
84   --  instead of having to parse those in the view.* child package.
85
86end View;