Created
September 15, 2013 06:09
-
-
Save ThomasLocke/6568402 to your computer and use it in GitHub Desktop.
Using the Ada Web Server (AWS), part 2 - snippet 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with AWS.Messages; | |
| with AWS.Templates; | |
| package body Hello_World is | |
| -- Stuff... | |
| ------------------------ | |
| -- Generate_Content -- | |
| ------------------------ | |
| function Generate_Content | |
| (Request : in AWS.Status.Data) | |
| return AWS.Response.Data | |
| is | |
| use AWS.Templates; | |
| type Natural_List is array (0 .. 9) of Natural; | |
| Fibs : Natural_List; | |
| Browser : constant String := AWS.Status.User_Agent (Request); | |
| Fibonacci : Vector_Tag; | |
| Position : Vector_Tag; | |
| Translations : Translate_Set; | |
| begin | |
| Insert (Translations, Assoc ("BROWSER", Browser)); | |
| for i in Fibs'Range loop | |
| case i is | |
| when 0 => Fibs (i) := 0; | |
| when 1 => Fibs (i) := 1; | |
| when others => Fibs (i) := Fibs (i - 1) + Fibs (i - 2); | |
| end case; | |
| Append (Position, i); | |
| Append (Fibonacci, Fibs (i)); | |
| end loop; | |
| Insert (Translations, Assoc ("POSITION", Position)); | |
| Insert (Translations, Assoc ("FIBONACCI", Fibonacci)); | |
| return AWS.Response.Build | |
| (Content_Type => AWS.MIME.Text_HTML, | |
| Message_Body => Parse (Filename => "templates/hello_world.tmpl", | |
| Translations => Translations, | |
| Cached => True), | |
| Status_Code => AWS.Messages.S200); | |
| end Generate_Content; | |
| end Hello_World; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment