Exemplo n.º 1
0
    def get_rendered_for_toc(self, path_override=None):
        """Returns an html 'ul' element, that represents the entire table of contents for this category.
        Parameters
        ---------
        path_override : str
          If not None, gets urls for this path. Intended for use by parent categories getting the toc of their children.
        """
        root_elm = E.UL(E.CLASS("toc_category"))
        # Children categories.
        nav = self.navigation
        for child in self.children:
            if path_override != None:
                child_path = get_url(path_override, child.file_path)
            else:
                child_path = get_url(self.file_path, child.file_path)

            child_elm = E.LI(
                E.A(child.name, href=child_path),
                child.get_rendered_for_toc(path_override=self.path)
            )
            root_elm.append(child_elm)
        # Assets.
        for asset in self.assets:
            asset_path = get_new_ext(asset.path, 'html')
            if path_override != None:
                asset_path = get_url(path_override, asset_path)
            else:
                asset_path = get_url(self.file_path, asset_path)
            asset_elm = E.LI(
                E.A(asset.title, href=asset_path)
            )
            root_elm.append(asset_elm)
        return root_elm
Exemplo n.º 2
0
    def ToString(self):
        result = E.DIV()
        result.attrib['class'] = 'center'

        ul = E.UL()
        result.append(ul)
        ul.attrib['class'] = 'mktree'
        ul.attrib['id'] = 'diffRoot'

        #  Insert xml declarations

        n = E.LI()
        n.attrib['whereLeft'] = "L0_0"
        n.attrib['whereRight'] = "R0_0"
        leftText = '<?xml version="{0}" encoding="{1}"?>'.format(
            self.xml.docinfo.xml_version, self.xml.docinfo.encoding)
        rightText = '<?xml version="{0}" encoding="{1}"?>'. \
            format(self.matchNode.xml.docinfo.xml_version,
                   self.matchNode.xml.docinfo.encoding)
        self.diffTextToHtml(leftText, rightText, n)
        ul.append(n)

        # Insert DTD declaration if one exists
        n = E.LI()
        if self.xml.docinfo.doctype or self.matchNode.xml.docinfo.doctype:
            self.diffTextToHtml(self.xml.docinfo.doctype,
                                self.matchNode.xml.docinfo.doctype, n)
            ul.append(n)

        # now put all of the children into HTML

        for child in self.children:
            child.ToHtml(ul)

        return self._serialize(result)
Exemplo n.º 3
0
def template(name, contents):

    cpu_class = 'active' if name == 'cpu' else ''
    wc_class = 'active' if name == 'wc' else ''
    help_class = 'active' if name == 'help' else ''

    return E.HTML(
        E.HEAD(
            E.LINK(rel='stylesheet',
                   type='text/css',
                   href='bootstrap/css/bootstrap.css'),
            E.LINK(rel='stylesheet', type='text/css', href='profile.css'),
            E.SCRIPT(src='bootstrap/js/bootstrap.min.js'),
            E.TITLE('RUM Job Profile')),
        E.BODY(
            E.DIV(E.DIV(E.DIV(E.A(E.SPAN(CLASS='icon-bar'),
                                  E.SPAN(CLASS='icon-bar'),
                                  E.SPAN(CLASS='icon-bar'),
                                  CLASS='btn btn-navbar'),
                              E.A('RUM Profile', CLASS='brand', href='#'),
                              E.DIV(E.UL(E.LI(E.A('CPU time', href='cpu.html'),
                                              CLASS=cpu_class),
                                         E.LI(E.A('Wallclock time',
                                                  href='wc.html'),
                                              CLASS=wc_class),
                                         E.LI(E.A('Help', href='help.html'),
                                              CLASS=help_class),
                                         CLASS='nav'),
                                    CLASS='nav-collapse collapse'),
                              CLASS='container'),
                        CLASS='navbar-inner'),
                  CLASS='navbar navbar-inverse navbar-fixed-top'), E.BR(),
            E.BR(), E.BR(), E.DIV(contents, CLASS='container')))
Exemplo n.º 4
0
    def visit_Component(self, node):
        inst = getattr(self, 'inst', None)
        if inst:
            title = 'Instance {} of {} Register Map'.format(inst, node.name)
        else:
            title = 'Base {} Register Map'.format(node.name)
        self.title = title

        # Create the main content by sweeping the tree.
        bc = E.DIV(id='breadcrumbs')
        try:
            if self.breadcrumbs is not None:
                bc.append(self.breadcrumbs)
        except AttributeError:
            pass

        ww = node.width // 8
        an = ((node.size - 1).bit_length() + 3) // 4
        with self.tempvars(wordwidth=ww, address_nibbles=an, hlev=2):
            nodes = ([E.H1(title, id='title'), bc] +
                     [E.P(d) for d in node.description] +
                     [c
                      for c in self.visitchildren(node)] + [self.footer(node)])
            contentnode = E.DIV(*nodes, id='content')

        # Add a table of contents sidebar.  We'll assume that everything that
        # wants to be in the TOC is already a heading and just work from there.
        h2list = E.UL()
        for elem in contentnode.iter('h2', 'h3'):
            id = escape(elem.text)
            elem.attrib['id'] = id
            if elem.tag == 'h2':
                h2node = E.LI(E.A(elem.text, href='#' + id))
                h2list.append(h2node)
                h3list = None
            else:
                if h3list is None:
                    h3list = E.UL()
                    h2list.append(h3list)
                h3list.append(E.LI(E.A(elem.text, href='#' + id)))

        # Put it all together.
        return E.HTML(
            E.HEAD(
                E.TITLE(title),
                E.LINK(rel='stylesheet',
                       type='text/css',
                       href=htmlpathjoin(self.styledir, 'reg.css'))),
            E.BODY(
                E.DIV(E.DIV(E.P(E.A(title, href='#title')),
                            h2list,
                            id='sidebar'),
                      contentnode,
                      id='wrapper')),
        )
Exemplo n.º 5
0
    def test_save(self):
        Company = self.env['res.company']
        View = self.env['ir.ui.view']

        # create a view with an xmlid, like the file import would
        with self.env.norecompute():
            self.view_id = View.create({
                'name': "Test View",
                'type': 'qweb',
                'arch': ET.tostring(self.arch, encoding='utf-8').decode('utf-8')
            })
        imd = self.env['ir.model.data'].create({
            'module': 'website',
            'name': 'test_view',
            'model': 'ir.ui.view',
            'res_id': self.view_id,
        })

        # the xml_id of the view should not be flagged as 'noupdate'
        self.assertEqual(self.view_id.model_data_id, imd)
        self.assertFalse(imd.noupdate)

        replacement = ET.tostring(h.DIV(
            h.H3("Column 2"),
            h.UL(
                h.LI("wob wob wob"),
                h.LI(h.SPAN("Acme Corporation", attrs(model='res.company', id=1, field='name', expression="bob", type='char'))),
                h.LI(h.SPAN("+12 3456789", attrs(model='res.company', id=1, field='phone', expression="edmund", type='char'))),
            )
        ), encoding='utf-8')
        self.view_id.save(value=replacement, xpath='/div/div[2]')

        # the xml_id of the view should be flagged as 'noupdate'
        self.assertTrue(imd.noupdate)

        company = Company.browse(1)
        self.assertEqual(company.name, "Acme Corporation")
        self.assertEqual(company.phone, "+12 3456789")
        self.eq(
            ET.fromstring(self.view_id.arch.encode('utf-8')),
            h.DIV(
                h.DIV(
                    h.H3("Column 1"),
                    h.UL(
                        h.LI("Item 1"),
                        h.LI("Item 2"),
                        h.LI("Item 3"))),
                h.DIV(
                    h.H3("Column 2"),
                    h.UL(
                        h.LI("wob wob wob"),
                        h.LI(h.SPAN({'t-field': "bob"})),
                        h.LI(h.SPAN({'t-field': "edmund"}))
                    ))
            )
        )
Exemplo n.º 6
0
def _update_commands(toolshed, doc_ul, doc):
    from lxml.html import builder as E
    missing = {}
    for bi in toolshed.bundle_info(None):
        for cmd in bi.commands:
            words = cmd.name.split(maxsplit=2)
            name = words[0]
            if name in doc or name in missing:
                continue
            synopsis = cmd.synopsis
            if len(words) > 1:
                # synopsis not appropriate for multiword commands
                synopsis = bi.synopsis
            href = bi.get_path(os.path.join("docs", "user", "commands", "%s.html" % name))
            if href:
                missing[name] = ("commands/%s.html" % name, synopsis)
    names = list(doc)
    missing_names = list(missing)
    missing_names.sort(key=str.casefold)
    all_names = names + missing_names
    all_names.sort(key=str.casefold)
    for name in missing_names:
        i = all_names.index(name)
        href, synopsis = missing[name]
        if synopsis:
            synopsis = " \N{En dash} " + synopsis
        doc_ul.insert(
            i, E.LI(E.A(E.B(name), href=href), synopsis))
Exemplo n.º 7
0
def diff(base, new):
    u"""
    Return an Element that renders the version differences between the amis `base` and `new`.

    Arguments:
        base, new (dicts): Descriptions of a deployed AMI. Any keys that start with
            'version:' should have values that are a repo and a sha, separated by a space.
            They must also have the keys 'environment', 'deployment', 'play', and 'ami_id'.
    """
    diff_items = []
    for delta in sorted(set(version_deltas(base, new))):
        version = delta.new or delta.base
        repo = GITHUB_PREFIX.sub(u'', version.repo)
        diff_items.append(
            E.LI(
                E.A(
                    u"{}: {}...{}".format(repo, delta.base.sha, delta.new.sha),
                    href=u"{}/compare/{}...{}".format(version.repo, delta.base.
                                                      sha, delta.new.sha),
                ) if delta.base.sha != delta.new.sha else E.A(
                    u"{}: {} (no change)".format(repo, delta.base.sha),
                    href=u"{}/commit/{}".format(repo, delta.base.sha),
                )))
    return SECTION(
        E.
        H3(u"Comparing {base.environment}-{base.deployment}-{base.play}: {base.ami_id} to {new.ami_id}"
           .format(
               base=base,
               new=new,
           )), E.UL(*diff_items, style=u"list-style-type: square"))
Exemplo n.º 8
0
    def body(self):
        """The BODY of the html document"""
        reports = E.OL(id='reports')
        code = self.code()

        for i, (state_html, state_problem) in enumerate(self.states(), 1):
            reports.append(
                E.LI(
                    E.ATTR(id="state{0}".format(i)),
                    E.E.header(
                        E.DIV(
                            E.CLASS('error'),
                            state_problem,
                        ),
                        E.DIV(
                            E.CLASS('report-count'),
                            E.H3('Report'),
                            str(i),
                        ),
                    ),
                    E.DIV(
                        E.CLASS('body'),
                        E.DIV(
                            E.CLASS('source'),
                            deepcopy(code),
                        ),
                        state_html,
                    ),
                ), )

        return E.BODY(
            self.header(),
            reports,
            self.footer(),
        )
Exemplo n.º 9
0
    def ToHtml(self, parent):

        node = E.LI()
        parent.append(node)
        if self.deleted:
            n = E.SPAN()
            n.attrib["class"] = 'left'
            node.attrib["whereLeft"] = SourceFiles.LineFormat(self.xml, False)
            self.fixPreserveSpace(n, self.toText())
            node.append(n)
        elif self.inserted:
            n = E.SPAN()
            n.attrib['class'] = 'right'
            node.attrib["whereRight"] = SourceFiles.LineFormat(self.xml, True)
            self.fixPreserveSpace(n, self.toText())
            node.append(n)
        elif self.matchNode is None:
            n = E.SPAN()
            n.attrib['class'] = 'error'
            self.fixPreserveSpace(n, self.toText())
            node.append(n)
        else:
            self.diffTextToHtml(self.toText(), self.matchNode.toText(), node)
            node.attrib["whereLeft"] = SourceFiles.LineFormat(self.xml, False)
            node.attrib["whereRight"] = SourceFiles.LineFormat(
                self.matchNode.xml, True)
Exemplo n.º 10
0
 def ToHtml(self, parent):
     node = E.LI()
     parent.append(node)
     myLine = "<--" + self.xml.text.replace(' ', nbsp) + "-->"
     while myLine[0] == '\n':
         myLine = myLine[1:]
     while myLine[-1] == '\n':
         myLine = myLine[:-1]
     if self.inserted:
         n = E.SPAN()
         n.attrib['class'] = 'artwork right'
         node.attrib["whereRight"] = SourceFiles.LineFormat(self.xml, True)
         self.fixPreserveSpace(n, myLine)
         node.append(n)
     elif self.deleted:
         n = E.SPAN()
         n.attrib['class'] = 'artwork left'
         node.attrib["whereLeft"] = SourceFiles.LineFormat(self.xml, False)
         self.fixPreserveSpace(n, myLine)
         node.append(n)
     elif self.matchNode is None:
         n = E.SPAN()
         n.attrib['class'] = 'artwork error'
         self.fixPreserveSpace(n, myLine)
         node.append(n)
     else:
         node.attrib["whereLeft"] = SourceFiles.LineFormat(self.xml, False)
         node.attrib["whereRight"] = SourceFiles.LineFormat(
             self.matchNode.xml, True)
         left = myLine
         right = "<--" + self.matchNode.xml.text.replace(' ', nbsp) + "-->"
         self.diffTextToHtml(left, right, node)
Exemplo n.º 11
0
def render_change_as_html(
    change: Dict[str, Any],
    filepath: str,
    current_depth: int,
    max_depth: int,
    compressed: Optional[bool] = False,
) -> Optional[Any]:
    """
    Returns nested part of report in compressed or uncompressed format.
    """
    if current_depth >= max_depth:
        return None

    link = change.get("link")
    if link is None:
        link = filepath

    if compressed:
        change_elements = change_representation_compressed(
            change, link, filepath, current_depth, max_depth)
    else:
        change_elements = change_representation_full(change, link, filepath,
                                                     current_depth, max_depth)

    return E.LI(*change_elements)
Exemplo n.º 12
0
 def ToHtml(self, parent):
     node = E.LI()
     parent.append(node)
     if self.deleted:
         n = E.SPAN()
         n.attrib["class"] = 'left'
         node.attrib['whereLeft'] = SourceFiles.LineFormat(self.xml, False)
         n.text = self.xml.text
         node.append(n)
     elif self.inserted:
         n = E.SPAN()
         n.attrib["class"] = 'right'
         node.attrib['whereRight'] = SourceFiles.LineFormat(self.xml, True)
         n.text = self.xml.text
         node.append(n)
     elif self.matchNode is None:
         n = E.SPAN()
         n.attrib["class"] = 'error'
         n.text = self.xml.text
         node.append(n)
     else:
         node.attrib['whereLeft'] = SourceFiles.LineFormat(self.xml, False)
         node.attrib['whereRight'] = SourceFiles.LineFormat(
             self.matchNode.xml, True)
         if self.xml.text == self.matchNode.xml.text:
             node.text = self.xml.text
         else:
             self.diffTextToHtml(self.xml.text, self.matchNode.xml.text,
                                 node)
Exemplo n.º 13
0
    def test_save(self):
        Company = self.env['res.company']

        # create an xmlid for the view
        imd = self.env['ir.model.data'].create({
            'module': 'website',
            'name': 'test_view',
            'model': self.view_id._name,
            'res_id': self.view_id.id,
        })
        self.assertEqual(self.view_id.model_data_id, imd)
        self.assertFalse(imd.noupdate)

        replacement = ET.tostring(h.DIV(
            h.H3("Column 2"),
            h.UL(
                h.LI("wob wob wob"),
                h.LI(
                    h.SPAN(
                        "Acme Corporation",
                        attrs(model='res.company',
                              id=1,
                              field='name',
                              expression="bob",
                              type='char'))),
                h.LI(
                    h.SPAN(
                        "+12 3456789",
                        attrs(model='res.company',
                              id=1,
                              field='phone',
                              expression="edmund",
                              type='char'))),
            )),
                                  encoding='unicode')
        self.view_id.save(value=replacement, xpath='/div/div[2]')

        # the xml_id of the view should be flagged as 'noupdate'
        self.assertTrue(imd.noupdate)

        company = Company.browse(1)
        self.assertEqual(company.name, "Acme Corporation")
        self.assertEqual(company.phone, "+12 3456789")
        self.eq(
            ET.fromstring(self.view_id.arch),
            h.DIV(
                h.DIV(h.H3("Column 1"),
                      h.UL(h.LI("Item 1"), h.LI("Item 2"), h.LI("Item 3"))),
                h.DIV(
                    h.H3("Column 2"),
                    h.UL(h.LI("wob wob wob"), h.LI(h.SPAN({'t-field': "bob"})),
                         h.LI(h.SPAN({'t-field': "edmund"}))))))
Exemplo n.º 14
0
 def parse(self, block):
     """"""
     list = self.list_type()
     for inner_block in re.split(self.list_pattern, block)[1:]:
         item = E.LI()
         self.parser.process_blocks(item, clean_indent(inner_block))
         list.append(item)
     return list
Exemplo n.º 15
0
def compare_tables(body, old, new):
    body.append(builder.H2("Table Comparisons"))
    for name in sorted(old.tables):
        body.append(builder.H3(name))
        if name in new.tables:
            compare_table(body, name, old, new)
        else:
            body.append(builder.UL(builder.LI(builder.B("TABLE LOST"))))
Exemplo n.º 16
0
    def states(self):
        """Return an ordered-list of states, for each report."""
        for report in self.data['reports']:
            annotations = E.OL({'class': 'states'})

            prevline = None
            lineno_to_index = {}
            index = -1
            for state in report['states']:
                if not state['location'] or not state['message']:
                    continue

                line = state['location'][0]['line']
                state = E.P(state['message'])

                # We try to combine with the previous state.
                if line != prevline:
                    child = E.LI({'data-line': str(line)})
                    annotations.append(child)
                    index += 1

                child.append(state)

                lineno_to_index[line] = (index, child)
                prevline = line

            for note in report['notes']:
                line = note['location'][0]['line']
                note = E.P({'class': 'note'}, note['message'])

                # Put this note on the last matching state, if possible
                for ann in reversed(tuple(annotations)):
                    annline = int(ann.attrib['data-line'])
                    if line == annline:
                        ann.append(note)
                        break
                    elif line > annline:
                        ann.addnext(
                            E.LI({'data-line': str(line)}, note)
                        )
                        break
                else:
                    annotations.insert(0, E.LI({'data-line': str(line)}, note))

            yield annotations, report['message']
Exemplo n.º 17
0
    def test_field_tail(self):
        replacement = ET.tostring(h.LI(
            h.SPAN(
                "+12 3456789",
                attrs(model='res.company',
                      id=1,
                      type='char',
                      field='phone',
                      expression="edmund")), "whop whop"),
                                  encoding="utf-8")
        self.view_id.save(value=replacement, xpath='/div/div[2]/ul/li[3]')

        self.eq(
            ET.fromstring(self.view_id.arch.encode('utf-8')),
            h.DIV(
                h.DIV(h.H3("Column 1"),
                      h.UL(h.LI("Item 1"), h.LI("Item 2"), h.LI("Item 3"))),
                h.DIV(
                    h.H3("Column 2"),
                    h.UL(
                        h.LI("Item 1"),
                        h.LI(
                            h.SPAN(
                                "My Company",
                                attrs(model='res.company',
                                      id=1,
                                      field='name',
                                      type='char'))),
                        h.LI(h.SPAN({'t-field': "edmund"}), "whop whop"),
                    ))))
Exemplo n.º 18
0
def build_locale_content():
    main = template_keys['mirror.locale.main']
    content = E.DIV(E.P("Browse in ", _locale_link(main), ", or:"))
    ul = E.UL()
    for locale in locales:
        ul.append(E.LI(_locale_link(locale)))
    content.append(ul)
    template_keys['mirror.locale.content'] = html.tostring(content).decode(
        'utf-8')
Exemplo n.º 19
0
def transform_demo(div):
    div.append(E.BUTTON('Run demo'))

    demo_dir = op.join(FILEBASE, div.get('demo'))
    div.set('demo', demo_dir)

    files = (f for f in os.listdir(demo_dir) if not f.startswith('.'))
    ul = E.UL(*(E.LI(E.A(f, href=op.join(demo_dir, f))) for f in files))
    div.append(ul)
Exemplo n.º 20
0
    def ToHtml(self, parent):
        root2 = E.LI()
        parent.append(root2)
        root = E.SPAN()
        root2.append(root)
        if self.inserted:
            root.attrib['class'] = 'right'
            root.attrib["whereRight"] = SourceFiles.LineFormat(self.xml, True)
        elif self.deleted:
            root.attrib['class'] = 'left'
            root.attrib["whereLeft"] = SourceFiles.LineFormat(self.xml, False)
        elif self.matchNode is None:
            root.attrib['class'] = 'error'
        else:
            root.attrib["whereLeft"] = SourceFiles.LineFormat(self.xml, False)
            root.attrib["whereRight"] = SourceFiles.LineFormat(
                self.matchNode.xml, True)
            if self.xml.target == self.matchNode.xml.target:
                if self.xml.text == self.matchNode.xml.text:
                    pass
                else:
                    root.text = "<?{0} ".format(self.xml.target)
                    s = E.SPAN()
                    s.attrib['class'] = 'left'
                    s.text = self.xml.text
                    root.append(s)
                    s = E.SPAN()
                    s.attrib['class'] = 'right'
                    s.text = self.matchNode.xml.text
                    root.append(s)
                    s.tail = "?>"
                    return
            else:
                root.text = "<?"
                s = E.SPAN()
                s.attrib['class'] = 'left'
                s.text = self.xml.target
                root.append(s)
                s = E.SPAN()
                s.attrib['class'] = 'right'
                s.text = self.matchNode.xml.target
                root.append(s)
                s.tail = ' '
                s = E.SPAN()
                s.attrib['class'] = 'left'
                s.text = self.xml.text
                root.append(s)
                s = E.SPAN()
                s.attrib['class'] = 'right'
                s.text = self.matchNode.xml.text
                root.append(s)
                s.tail = "?>"
                return

        root.text = "<?{0} {1}?>".format(self.xml.target, self.xml.text)
Exemplo n.º 21
0
    def test_save(self):
        Company = self.registry('res.company')
        View = self.registry('ir.ui.view')

        replacement = ET.tostring(h.DIV(
            h.H3("Column 2"),
            h.UL(
                h.LI("wob wob wob"),
                h.LI(
                    h.SPAN(
                        "Acme Corporation",
                        attrs(model='res.company',
                              id=1,
                              field='name',
                              expression="bob",
                              type='char'))),
                h.LI(
                    h.SPAN(
                        "+12 3456789",
                        attrs(model='res.company',
                              id=1,
                              field='phone',
                              expression="edmund",
                              type='char'))),
            )),
                                  encoding='utf-8')
        View.save(self.cr,
                  self.uid,
                  res_id=self.view_id,
                  value=replacement,
                  xpath='/div/div[2]')

        company = Company.browse(self.cr, self.uid, 1)
        self.assertEqual(company.name, "Acme Corporation")
        self.assertEqual(company.phone, "+12 3456789")
        self.eq(
            ET.fromstring(
                View.browse(self.cr, self.uid,
                            self.view_id).arch.encode('utf-8')),
            h.DIV(
                h.DIV(h.H3("Column 1"),
                      h.UL(h.LI("Item 1"), h.LI("Item 2"), h.LI("Item 3"))),
                h.DIV(
                    h.H3("Column 2"),
                    h.UL(h.LI("wob wob wob"), h.LI(h.SPAN({'t-field': "bob"})),
                         h.LI(h.SPAN({'t-field': "edmund"}))))))
Exemplo n.º 22
0
 def setUp(self):
     super(TestViewSaving, self).setUp()
     self.arch = h.DIV(
         h.DIV(h.H3("Column 1"),
               h.UL(h.LI("Item 1"), h.LI("Item 2"), h.LI("Item 3"))),
         h.DIV(
             h.H3("Column 2"),
             h.UL(
                 h.LI("Item 1"),
                 h.LI(
                     h.SPAN(
                         "My Company",
                         attrs(model='res.company',
                               id=1,
                               field='name',
                               type='char'))),
                 h.LI(
                     h.SPAN(
                         "+00 00 000 00 0 000",
                         attrs(model='res.company',
                               id=1,
                               field='phone',
                               type='char'))))))
     self.view_id = self.registry('ir.ui.view').create(
         self.cr, self.uid, {
             'name': "Test View",
             'type': 'qweb',
             'arch': ET.tostring(self.arch,
                                 encoding='utf-8').decode('utf-8')
         })
Exemplo n.º 23
0
    def test_fixup_arch(self):
        replacement = h.H1("I am the greatest title alive!")

        result = self.registry('ir.ui.view').replace_arch_section(
            self.cr, self.uid, self.view_id, '/div/div[1]/h3', replacement)

        self.eq(
            result,
            h.DIV(
                h.DIV(h.H3("I am the greatest title alive!"),
                      h.UL(h.LI("Item 1"), h.LI("Item 2"), h.LI("Item 3"))),
                h.DIV(
                    h.H3("Column 2"),
                    h.UL(
                        h.LI("Item 1"),
                        h.LI(
                            h.SPAN(
                                "My Company",
                                attrs(model='res.company',
                                      id=1,
                                      field='name',
                                      type='char'))),
                        h.LI(
                            h.SPAN(
                                "+00 00 000 00 0 000",
                                attrs(model='res.company',
                                      id=1,
                                      field='phone',
                                      type='char')))))))
Exemplo n.º 24
0
def compare_docs(body, old, new, verbose):
    body.append(builder.H2("Document Comparisons"))
    for name in sorted(old.docs):
        body.append(builder.H3(f"{name} Docs"))
        new_docs = new.docs[name]
        if not new_docs.docs:
            body.append(builder.UL(builder.LI(builder.B(LOST))))
        else:
            old_docs = old.docs[name]
            items = []
            for key in old_docs.docs:
                old_id, old_title, old_xml = old_docs.docs[key]
                if key not in new_docs.docs:
                    items.append(builder.I(builder.LI(old_title)))
                else:
                    diffs = diff_xml(old_xml, new_docs.docs[key][2], verbose)
                    if diffs is not None:
                        title = builder.B(old_title)
                        items.append(builder.LI(title, diffs))
            if not items:
                body.append(builder.P(CHECK, OK))
            else:
                body.append(builder.UL(*items))
Exemplo n.º 25
0
 def tocify(_toc, curr):
     section = E.OL()
     i = 0
     for level, text, id in _toc:
         i += 1
         if level == top_heading_level:
             continue
         if level < curr:
             return section
         if level == curr:
             section.append(
                 E.LI(E.A(text, href="#" + id),
                      tocify(_toc[i:], curr + 1)))
     return section
Exemplo n.º 26
0
def _update_tools(toolshed, doc_ul, doc):
    from lxml.html import builder as E
    missing = {}
    for bi in toolshed.bundle_info(None):
        for t in bi.tools:
            name = t.name
            if name in doc:
                continue
            href = None
            tools_dir = bi.get_path(os.path.join("docs", "user", "tools"))
            if tools_dir is not None:
                n1 = name.replace(' ', '_')
                n2 = name.replace(' ', '')
                names = [n1, n2, n1.casefold(), n2.casefold()]
                for n in names:
                    html = "%s.html" % n
                    if os.path.exists(os.path.join(tools_dir, html)):
                        href = "tools/%s" % html
                        break
            missing[name] = (href, t.synopsis)
    names = list(doc)
    missing_names = list(missing)
    missing_names.sort(key=str.casefold)
    all_names = names + missing_names
    all_names.sort(key=str.casefold)
    for name in missing_names:
        i = all_names.index(name)
        href, synopsis = missing[name]
        if synopsis:
            synopsis = " \N{En dash} " + synopsis
        if href is None:
            e = E.LI(E.B(name), synopsis)
        else:
            e = E.LI(E.A(E.B(name), href=href), synopsis)
        e.tail = '\n'
        doc_ul.insert(i, e)
Exemplo n.º 27
0
 def _format_amis(self):
     u"""
     Return an Element that contains formatted description of the deployed AMIs.
     """
     return SECTION(
         E.H2(u"Final AMIs"),
         E.UL(
             *[
                 E.LI(u"{ami.environment}-{ami.deployment}-{ami.play}: {ami.ami_id}".format(ami=ami))
                 for _, ami in self.ami_pairs
                 if ami is not None
             ],
             style=u"list-style-type: square"
         ),
     )
Exemplo n.º 28
0
    def visit_MemoryMap(self, node):
        """Create an HTML file for a MemoryMap."""
        self.title = title = node.name + ' Peripheral Map'
        an = ((node.size - 1).bit_length() + 3) // 4

        # Sweep the document tree to build up the main content
        with self.tempvars(wordwidth=1,
                           address_nibbles=an,
                           base=node.base,
                           subdir=node.name + '_instances',
                           hlev=2):
            children = list(self.visitchildren(node))
            table = E.TABLE(
                E.TR(E.TH('Peripheral'), E.TH('Base Address'), E.TH('Size'),
                     E.TH('Description'), *children), CLASS('component_list'))
            nodes = ([E.H1(title, id='title')] +
                     [E.P(d) for d in node.description] +
                     [E.HR(), table, self.footer(node)])
            contentnode = E.DIV(*nodes, id='content')

        # Add a table of contents sidebar for each table row.
        instlist = E.UL()
        for elem in contentnode.xpath("//td[contains(@class, 'peripheral')]"):
            text = tostring(elem, method="text", encoding="unicode")
            id = escape(text)
            elem.attrib['id'] = id
            node = E.LI(E.A(text, href='#' + id))
            instlist.append(node)

        # And put it all together.
        return E.HTML(
            E.HEAD(
                E.TITLE(title),
                E.LINK(rel='stylesheet',
                       type='text/css',
                       href=htmlpathjoin(self.styledir, 'reg.css'))),
            E.BODY(
                E.DIV(E.DIV(E.P(E.A(title, href='#title')),
                            instlist,
                            id='sidebar'),
                      contentnode,
                      id='wrapper')),
        )
Exemplo n.º 29
0
    def _create_toc(self):
        # Add link for toc itself
        link = E.LINK(href='#rfc.toc')
        link.attrib["rel"] = 'Contents'
        self.buffers['toc_head_links'].append(self._serialize(link))
        tocdepth = self.pis['tocdepth']
        try:
            tocdepth = int(tocdepth)
        except ValueError:
            xml2rfc.log.warn('Invalid tocdepth specified, must be integer:', \
                             tocdepth)
            tocdepth = 3
        curdepth = 1
        for item in self._getTocIndex():
            if item.level <= tocdepth:
                # set UL level
                if item.level > curdepth:
                    self.buffers['toc_rows'].append('<ul>')
                for i in range(item.level, curdepth):
                    self.buffers['toc_rows'].append('</ul>')
                curdepth = item.level

                # Create link for head
                link = E.LINK(href='#' + item.autoAnchor)
                link.attrib['rel'] = 'copyright' in item.autoAnchor and \
                                     'Copyright' or 'Chapter'
                if item.title and item.counter:
                    link.attrib[
                        'title'] = item.counter + ' ' + item.title.strip()
                self.buffers['toc_head_links'].append(self._serialize(link))
                # Create actual toc list item
                a = E.A(item.title.strip(), href='#' + item.autoAnchor)
                counter_text = item.counter and item.counter + '.   ' or ''
                # Prepend appendix at first level
                if item.level == 1 and item.appendix:
                    counter_text = "Appendix " + counter_text
                li = E.LI(counter_text)
                li.append(a)
                self.buffers['toc_rows'].append(self._serialize(li))
        for i in range(1, curdepth):
            self.buffers['toc_rows'].append('</ul>')
Exemplo n.º 30
0
    def __bullets_points(self, iter_elem):
        ul = builder.UL()

        i = 0
        for elem in iter_elem:
            elem = " ".join(elem)
            if self.capitalize_bullets:
                elem = "".join([elem[0].upper(), elem[1:]])

            if i == len(iter_elem) - 1:
                elem += str(self.end_of_last_bullet)
            else:
                elem += str(self.end_of_bullet)

            if "<" in elem and ">" in elem:
                elem = html.fromstring(elem)

            ul.append(builder.LI(elem))
            i += 1

        return html.tostring(ul, encoding="utf-8").decode("utf-8")