src/pyams_template/metadirectives.py
changeset 0 31ded33115d7
child 15 c3d0112a61f6
equal deleted inserted replaced
-1:000000000000 0:31ded33115d7
       
     1 #
       
     2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
       
     3 # All Rights Reserved.
       
     4 #
       
     5 # This software is subject to the provisions of the Zope Public License,
       
     6 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    10 # FOR A PARTICULAR PURPOSE.
       
    11 #
       
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 
       
    16 # import standard library
       
    17 
       
    18 # import interfaces
       
    19 from pyramid.interfaces import IRequest
       
    20 
       
    21 # import packages
       
    22 from zope.configuration.fields import Path, GlobalObject, GlobalInterface
       
    23 from zope.interface import Interface
       
    24 from zope.schema import TextLine, ASCIILine
       
    25 from pyams_template.interfaces import IContentTemplate, ILayoutTemplate
       
    26 
       
    27 
       
    28 class ITemplateDirective(Interface):
       
    29     """Parameters for the template directive."""
       
    30 
       
    31     template = Path(title='Layout template.',
       
    32                     description="Refers to a file containing a page template (should "
       
    33                                 "end in extension ``.pt`` or ``.html``).",
       
    34                     required=True)
       
    35 
       
    36     name = TextLine(title="The name of the template.",
       
    37                     description="The name is used to look up the template.",
       
    38                     default='',
       
    39                     required=False)
       
    40 
       
    41     macro = TextLine(title='Macro',
       
    42                      description="""
       
    43                          The macro to be used.
       
    44                          This allows us to define different macros in one template.
       
    45                          The template designer can now create a whole site, the
       
    46                          ViewTemplate can then extract the macros for single viewlets
       
    47                          or views.
       
    48                          If no macro is given the whole template is used for rendering.
       
    49                          """,
       
    50                      default='',
       
    51                      required=False)
       
    52 
       
    53     for_ = GlobalObject(title='View',
       
    54                         description='The view for which the template should be available',
       
    55                         default=Interface,
       
    56                         required=False)
       
    57 
       
    58     layer = GlobalObject(title='Layer',
       
    59                          description='The layer for which the template should be available',
       
    60                          required=False,
       
    61                          default=IRequest)
       
    62 
       
    63     context = GlobalObject(title='Context',
       
    64                            description='The context for which the template should be available',
       
    65                            required=False)
       
    66 
       
    67     provides = GlobalInterface(title="Interface the template provides",
       
    68                                description="This attribute specifies the interface the template "
       
    69                                            "instance will provide.",
       
    70                                default=IContentTemplate,
       
    71                                required=False)
       
    72 
       
    73     contentType = ASCIILine(title='Content Type',
       
    74                             description='The content type identifies the type of data.',
       
    75                             default='text/html',
       
    76                             required=False)
       
    77 
       
    78 
       
    79 class ILayoutTemplateDirective(ITemplateDirective):
       
    80     """Parameters for the layout template directive."""
       
    81 
       
    82     provides = GlobalInterface(title="Interface the template provides",
       
    83                                description="This attribute specifies the interface the template "
       
    84                                            "instance will provide.",
       
    85                                default=ILayoutTemplate,
       
    86                                required=False)