Пример #1
0
    def create_pagelink_list(self, pagenames, ordered=False, display="FullPath"):
        """ Creates an ET with a list of pagelinks from a list of pagenames.

            Parameters:

              pagenames: a list of pages, each being like a flask request.path[1:]

              ordered: Should the list be ordered or unordered list (<ol> or <ul>)?

                  Options:
                      False : Display list as an unordered list.  (default)
                      True  : Display list as an ordered list.

              display: How should the link be displayed?

                  Options:
                      FullPath  : The full page path (default)
                      ChildPath : The last component of the FullPath, including the '/'
                      ChildName : ChildPath, but minus the leading '/'
                      UnCameled : ChildName, but with a space ' ' character between
                                  blocks of lowercase characters or numbers and an
                                  uppercase character.
                      skiptag   : skip items with this tag
                      ItemTitle : Use the title from the first header in the linked page *not implemented
            """

        page_list = moin_page.list(attrib={moin_page.item_label_generate: ordered and 'ordered' or 'unordered'})
        for pagename in pagenames:
            # This link can never reach pagelinks
            url = str(iri.Iri(scheme='wiki', authority='', path='/' + pagename))

            if display == "FullPath":
                linkname = pagename
            elif display == "ChildPath":
                index = pagename.rfind('/')
                linkname = pagename[index:]
            elif display == "ChildName":
                index = pagename.rfind('/')
                linkname = pagename[(index + 1):]
            elif display == "UnCameled":
                index = pagename.rfind('/')
                tempname = re.sub("([a-z0-9])([A-Z])", r"\g<1> \g<2>", pagename[(index + 1):])  # space before a cap char
                linkname = re.sub("([a-zA-Z])([0-9])", r"\g<1> \g<2>", tempname)
            elif display == "ItemTitle":
                raise NotImplementedError(_('"ItemTitle" is not implemented yet.'))
            else:
                raise KeyError(_('Unrecognized display value "%s".' % display))

            pagelink = moin_page.a(attrib={xlink.href: url}, children=[linkname])
            item_body = moin_page.list_item_body(children=[pagelink])
            item = moin_page.list_item(children=[item_body])
            page_list.append(item)
        return page_list
Пример #2
0
 def create_number_pagelink_list(self, num_pagenames, ordered=False):
     """ creates an ET with a list of pagelinks from a list of pagenames """
     num_page_list = moin_page.list(attrib={moin_page.item_label_generate: ordered and 'ordered' or 'unordered'})
     for num, pagename in num_pagenames:
         num_code = moin_page.code(children=["{0:6d} ".format(num)])
         # This link can never reach pagelinks
         url = str(iri.Iri(scheme='wiki', authority='', path='/' + pagename))
         pagelink = moin_page.a(attrib={xlink.href: url}, children=[pagename])
         item_body = moin_page.list_item_body(children=[num_code, pagelink])
         item = moin_page.list_item(children=[item_body])
         num_page_list.append(item)
     return num_page_list
Пример #3
0
    def recurse(self, elem, page):
        new_page_href = elem.get(moin_page.page_href)
        if new_page_href:
            page = iri.Iri(new_page_href)

        if elem.tag in (moin_page.part, moin_page.inline_part):
            yield elem, page

        for child in elem:
            if isinstance(child, ET.Node):
                for i in self.recurse(child, page):
                    yield i
Пример #4
0
 def create_pagelink_list(self, pagenames, ordered=False):
     """ creates an ET with a list of pagelinks from a list of pagenames """
     page_list = moin_page.list(attrib={
         moin_page.item_label_generate:
         ordered and 'ordered' or 'unordered'
     })
     for pagename in pagenames:
         # This link can never reach pagelinks
         url = unicode(
             iri.Iri(scheme=u'wiki', authority=u'', path=u'/' + pagename))
         pagelink = moin_page.a(attrib={xlink.href: url},
                                children=[pagename])
         item_body = moin_page.list_item_body(children=[pagelink])
         item = moin_page.list_item(children=[item_body])
         page_list.append(item)
     return page_list
Пример #5
0
    def _Include_repl(self, args, text, context_block):
        """
        Return a moin_page node representing an include macro that will be processed
        further in /converters/include.py.

        The transclusion {{jpeg.jpg}} and the macro <<Include(jpeg.jpg)>> will have
        identical output.

        If context_block is true, the macro expansion will be enclosed in a DIV-tag, else the
        macro output will be enclosed in a SPAN-tag. converters/include.py will resolve
        HTML 5 validation issues should the macro output block tags within an inline context.
        """
        def error_message(msg):
            txt = moin_page.p(children=(text, ))
            msg = moin_page.p(children=(msg, ))
            msg.set(moin_page.class_, 'moin-error')
            div = moin_page.div(children=(txt, msg))
            return div

        if args:
            args = parse_arguments(args, parse_re=include_re)
        else:
            return error_message(
                _("Include Macro above has invalid format, missing item name"))
        pagename = args[0]
        heading = None
        level = None
        try:
            heading = args[1]
            level = int(args[2])
        except (IndexError, ValueError):
            pass
        sort = 'sort' in args and args['sort']
        if sort and sort not in ('ascending', 'descending'):
            return error_message(
                _("Include Macro above has invalid format, expected sort=ascending or descending"
                  ))
        # TODO: We need corresponding code in include.py to process items, skipitems, titlesonly, and editlink
        items = 'items' in args and int(args['items'])
        skipitems = 'skipitems' in args and int(args['skipitems'])
        titlesonly = 'titlesonly' in args
        editlink = 'editlink' in args

        attrib = {}
        xpointer = []
        xpointer_moin = []

        def add_moin_xpointer(function, args):
            args = str(args).replace('^',
                                     '^^').replace('(',
                                                   '^(').replace(')', '^)')
            xpointer_moin.append(function + '(' + args + ')')

        moin_args = []

        if pagename.startswith('^'):
            add_moin_xpointer('pages', pagename)
            if sort:
                add_moin_xpointer('sort', sort)
            if items:
                add_moin_xpointer('items', items)
            if skipitems:
                add_moin_xpointer('skipitems', skipitems)
        else:
            link = iri.Iri(scheme='wiki.local', path=pagename)
            attrib[xinclude.href] = link

        if heading is not None:
            add_moin_xpointer('heading', heading)
        if level:
            add_moin_xpointer('level', str(level))
        if titlesonly:
            add_moin_xpointer('titlesonly', '')
        if editlink:
            add_moin_xpointer('editlink', '')

        if xpointer_moin:
            xpointer.append('page:include({0})'.format(
                ' '.join(xpointer_moin)))

        if xpointer:
            # TODO: Namespace?
            ns = 'xmlns(page={0}) '.format(moin_page)

            attrib[xinclude.xpointer] = ns + ' '.join(xpointer)

        span_wrap = xinclude.include(attrib=attrib)
        if not context_block:
            return span_wrap
        attrib = {moin_page.class_: 'moin-p'}
        return moin_page.div(attrib=attrib, children=[span_wrap])