.. _Other_services: ************** Other Services ************** .. _Tag_utils: Tag utils ========= .. index:: Tag utils .. highlight:: ada The child package `Utils`, see :ref:`Templates_Parser.Utils` contains a routine to encode a Tag variable into a string and the inverse routine that build a Tag given it's string representation. This is useful for example, in the context of AWS to store a Tag into a session variable. See the AWS project. .. _XML_representation: XML representation ================== .. index:: XML The child package `XML`, see :ref:`Templates_Parser.XML` contains routines to save a `Translation_Set` into an XML document or to create a `Translation_Set` by loading an XML document. The XML document must conform to a specific `DTD` (see the Ada spec file). .. _Templates2Ada: Templates2Ada ============= .. index:: templates2ada `templates2ada` is a tool that will generate a set of Ada packages from a templates file. These Ada packages can then be used in your application to avoid hard-coded strings, and help maintain the templates and the code synchronized. One of its goal is to ensure that you are only setting tags that actually exist in the template (and thus prevent, as much as possibly, typos in the name of tags); also, when combined with other tools, to help ensure that all tags needed by the template are properly set. Templates2ada also has special knowledge about HTTP constructs and will generate Ada constants for the HTTP parameters you might receive in return. Once more the goal is to help avoid typos in the Ada code. For instance, we will consider a simple template file, found in a local file :file:`resources/block1.thtml`. This template contains the following simple html code: .. code-block:: xml
} When you run :file:`templates2ada` (as described in the following subsection), the following Ada package will be generated. Note that this is only the default output of :file:`templates2ada`, which can be fully tailored to your needs:: package Templates.Block1 is pragma Style_Checks (Off); Template : constant string := "resources/block1.thtml"; Tag1 : constant String := "TAG1"; Tag2 : constant String := "TAG2"; package Http is Param1 : constant String := "PARAM1"; Param2 : constant String := "PARAM2"; end Http; end Templates.Block1; `templates2ada` knows about special constructs in the template file. Such templates are generally associated with html pages. It is possible to specify within the template itself what the url associated with the template is, so that it provides a convenient link between the two. Likewise, you can also define explicitly what the possible HTTP parameters are when loading that page. This is mostly useful when those parameters do not correspond to some form fields within the page itself. The syntax for these two is the following:: -- HTTP_URL(the_url): any comment you want -- HTTP_GET(param1_name): description of the parameter -- HTTP_GET(param2_name): description of the parameter and that results in the following constants in the generated Ada package:: package Templates.Block1 is URL : constant String := "the_url"; package Http is Param1_Name : constant String := "param1_name"; Param2_Name : constant String := "param2_name"; end Http; end Templates.Block1; The templates parser API lets you define your own custom filters. It is often useful for those filters to take parameters, just like the predefined filters do. However, it is also useful for these parameters to be able to check the value of other tags. One convention for doing this is to start the name of the parameter with "@". See for example the example in :ref:`User_defined_filters`. As a reminder, the template would look like: .. code-block:: xml