示例#1
0
 def url(self):
     directive = removeSecurityProxy(self.context)
     subDirective = None
     # Sub-directives are not directly documented, so use parent
     parent = getParent(directive)
     if not (IRootDirective.providedBy(parent) or
             IRootDirective.providedBy(directive)):
         subDirective = directive
         directive = parent
     ns, name = directive.name
     # Sometimes ns is `None`, especially in the slug files, where no
     # namespaces are used.
     ns = quoteNS(ns or 'ALL')
     zcml = getUtility(IDocumentationModule, 'ZCML')
     if name not in zcml[ns]:
         ns = 'ALL'
     link = '%s/ZCML/%s/%s/index.html' % (
         findAPIDocumentationRootURL(self.context, self.request), ns, name)
     if subDirective:
         link += '#' + subDirective.name[1]
     return link
示例#2
0
    def attributes(self):
        context = removeSecurityProxy(self.context)
        attrs = [{'name': (ns and context.prefixes[ns]+':' or '') + name,
                  'value': value, 'url': None, 'values': []}
                 for (ns, name), value in context.attrs.items()]

        names = context.schema.names(True)
        rootURL = absoluteURL(findDocModule(self), self.request)
        for attr in attrs:
            name = (attr['name'] in names) and attr['name'] or attr['name']+'_'
            field = context.schema.get(name)

            if isinstance(field, (GlobalObject, GlobalInterface)):
                attr['url'] = self.objectURL(attr['value'], field, rootURL)

            elif isinstance(field, Tokens):
                field = field.value_type
                values = attr['value'].strip().split()
                if len(values) == 1:
                    attr['value'] = values[0]
                    attr['url'] = self.objectURL(values[0], field, rootURL)
                else:
                    for value in values:
                        if isinstance(field,
                                           (GlobalObject, GlobalInterface)):
                            url = self.objectURL(value, field, rootURL)
                        else:
                            break
                        attr['values'].append({'value': value, 'url': url})

        # Make sure that the attributes are in the same order they are defined
        # in the schema.
        fieldNames = getFieldNamesInOrder(context.schema)
        fieldNames = [name.endswith('_') and name[:-1] or name
                      for name in fieldNames]
        attrs.sort(lambda x, y: _compareAttrs(x, y, fieldNames))

        if not IRootDirective.providedBy(context):
            return attrs

        xmlns = []
        for uri, prefix in context.prefixes.items():
            name = prefix and ':'+prefix or ''
            xmlns.append({'name': 'xmlns'+name,
                          'value': uri,
                          'url': None,
                          'values': []})

        xmlns.sort(lambda x, y: cmp(x['name'], y['name']))
        return xmlns + attrs