Exemplo n.º 1
0
    def preface_html(
        self, novel: Novel, urls: List[NovelUrl], metadata: List[MetaData]
    ) -> epub.EpubHtml:
        synopsis_section = E.DIV(
            E.H4("Synopsis"),
            E.DIV(
                *[E.P(para) for para in novel.synopsis.splitlines()],
                style="padding: 0 1rem",
            ),
        )

        meta_by_name: Dict[str, List[MetaData]] = {}
        for item in metadata:
            meta_by_name.setdefault(item.name, []).append(item)

        metadata_sections = []
        for name, items in meta_by_name.items():
            item_strings = [metadata_helper.display_value(item) for item in items]

            section = E.DIV(
                E.H4(name.capitalize()),
                E.DIV(
                    ", ".join(item_strings),
                    style="padding: 0 1rem",
                ),
            )

            metadata_sections.append(section)

        html = E.DIV(
            E.H1(novel.title, style="margin-bottom: 0;"),
            E.DIV(f"by: {novel.author}"),
            synopsis_section,
            *metadata_sections,
            E.DIV(
                E.H4("Sources"),
                E.DIV(
                    *[E.A(n_url.url, href=n_url.url) for n_url in urls],
                    style="padding: 0 1rem",
                ),
            ),
        )

        return epub.EpubHtml(
            title="Preface",
            file_name="preface.xhtml",
            content=lxml.html.tostring(html),
            lang=novel.lang,
        )
Exemplo n.º 2
0
def html_file_section_handler_vanilla(item: Dict[str, Any]) -> Any:
    filepath = item["file"]
    file_url = item.get("file_url", filepath)
    change_elements = [
        render_change_as_html(change, filepath, 0, 2)
        for change in item["changes"]
    ]
    file_elements = [
        E.H4(E.A(filepath, href=file_url)),
        E.B("Changes:"),
        E.UL(*change_elements),
    ]
    return E.DIV(*file_elements)
Exemplo n.º 3
0
def html_page_return(board, thread, default_style):
    html = E.HTML(
        E.HEAD(
            E.META(**{'http-equiv':"Default-Style", 'content':default_style, 'id':'stylemetatag'}),
            E.TITLE("/"+board+"/ - №"+str(thread)), #title
            E.SCRIPT(type = 'text/javascript', src = '/mainscript.js'), #js
            *initiate.style_cache
            ),
        E.BODY(
            E.P(E.CLASS("board"), board, id = 'board'),
            E.P(E.CLASS("thread"), str(thread), id = 'thread'),
            E.TABLE(
                E.CLASS("maintable"),
                E.THEAD(E.TR(E.TD(
                    E.TABLE(E.TR(E.TD(E.CLASS('left'), copy.copy(initiate.board_cache_navigation)),
                                 E.TD(E.CLASS('right'), utilfunctions.generate_right_up_corner_menu()),
                                 ),
                            id='headblock'),
                    E.HR(E.CLASS("delimeter")),
                    )), id = 'header'),
                E.TBODY(E.TR(E.TD(
                    E.H2(E.CLASS("boardname"),
                         E.A('/' + board + '/ - '+ initiate.board_cache[board].name, href = '/' + board),
                         ),
                    E.HR(E.CLASS("delimeter")),
                    initiate.board_cache[board].post_form, #need to make it depending on post_form_type
                    E.SCRIPT('function open_form() {document.getElementById("postform").style.display = "block"; document.getElementById("closeform").style.display = "block"; document.getElementById("threadcreate").style.display = "none";}'),
                    E.SCRIPT('function close_form() {document.getElementById("postform").style.display = "none"; document.getElementById("closeform").style.display = "none"; document.getElementById("threadcreate").style.display = "block";}'),
                    E.H3(E.A('Ответить в тред', href = "javascript:open_form();"), id = 'threadcreate'),
                    E.H4(E.A('Скрыть форму', href = "javascript:close_form();"), id = 'closeform'),
                    E.HR(E.CLASS("delimeter")),
                    EM('main', '', id = 'mainframe'),
                    E.DIV('', id = 'optionsdiv'),
                    )), id = 'mainpart'),
                E.TFOOT(E.TR(E.TD(
                       E.DIV(
                           E.HR(E.CLASS("delimeter"), id = 'end')
                           ),
                       initiate.board_cache_navigation,
                       E.DIV('powered by ',
                             E.A('Farlight Imageboard Engine',
                                 href='https://github.com/Alpherie/farlight_board_engine',
                                 target='_blank',
                                 ),
                             id='credentials'),
                    )), id = 'footer'),#we make it a footer
                ),
            onload = 'threadfunc()'
            )
        )
    return lxml.html.tostring(html)
Exemplo n.º 4
0
    def write_heading(self,
                      text,
                      bullet=None,
                      autoAnchor=None,
                      anchor=None,
                      level=1):
        # Use a hierarchy of header tags if docmapping set
        h = E.H1()
        if self.pis['docmapping'] == 'yes':
            if level == 2:
                h = E.H2()
            elif level == 3:
                h = E.H3()
            elif level >= 4:
                h = E.H4()
        if autoAnchor:
            h.attrib['id'] = autoAnchor
        if bullet:
            # Use separate elements for bullet and text
            a_bullet = E.A(bullet)
            a_bullet.tail = ' '
            if autoAnchor:
                a_bullet.attrib['href'] = '#' + autoAnchor
            h.append(a_bullet)
            if anchor:
                # Use an anchor link for heading
                a_text = E.A(
                    text.strip(),
                    href='#' + anchor,
                )
                a_text.attrib["id"] = anchor
                h.append(a_text)
            else:
                # Plain text
                a_bullet.tail += text
        else:
            # Only use one <a> pointing to autoAnchor
            a = E.A(text)
            if autoAnchor:
                a.attrib['href'] = '#' + autoAnchor
            h.append(a)

        # Add to body buffer
        self.buf.append(self._serialize(h))
def create_table():
    """HTML generation by lxml.html tree."""

    divisions = ['All', 'E', 'CMS', 'T', 'A', 'AE', 'PPD', 'AD/APC',
                 'TD', 'CD', 'ND', 'LBN', 'Other']
    pubtypes = ['All', 'PUB', 'THESIS', 'CONF', 'TM', 'FN', 'SLIDES', 'POSTER']
    dates = [YEAR_2, YEAR_1, YEAR, MONTH_2, MONTH_1, MONTH]
    years = [YEAR_2, YEAR_1, YEAR]
    months = [MONTH_2, MONTH_1, MONTH]

    # This is a doctype work around for a lxml.etree bug
    doctype_wa = etree.parse(StringIO('''<!DOCTYPE html>\n<html>\n</html>'''))
    head_tag = E.HEAD(
        E.META({'charset': 'utf-8'}),
        E.TITLE("FERMILAB RESEARCH AT A GLANCE"),
        E.STYLE(
            {'type': 'text/css'},
            "td {text-align: right;}",
            " td.l {text-align: left;padding: 7px;}",
            " a.t {display: block;}"
        )
    )
    body = E.BODY(E.P(
        E.A("Fermilab Technical Publications",
            href="http://ccd.fnal.gov/techpubs/fermilab_spires.html")
    ))
    tag_h3 = E.H3("FERMILAB RESEARCH AT A GLANCE")
    tag_p = E.P("Glossary at end.")
    tag_p_and_i = E.P(E.I("Updated: " + DATE_TIME_STAMP))

    body.append(tag_h3)
    body.append(tag_p)
    body.append(tag_p_and_i)
    table = E.TABLE()

    tag_tr_td = E.TR(E.TD, E.TD("Date"))
    for division in divisions:
        if division == 'A':
            division = 'AT'
        tag_tr_td.append(E.TD(division))
    table.append(tag_tr_td)

    pub_table_row = E.TR()
    for pubtype in pubtypes:
        pub_table_row.append(E.TD(pubtype))
        pub_type_datelist = E.TD()
        year_list = E.UL()
        month_list = E.UL()
        for year in years:
            year_list.append(E.LI(year))
        for month in months:
            month_list.append(E.LI(month))
        pub_type_datelist.append(year_list)
        pub_type_datelist.append(month_list)
        pub_type_datelist.append(E.UL())
        pub_table_row.append(pub_type_datelist)
        pub_type_datelist = E.TD()

        for division in divisions:
            tdg = E.TD()
            list_of_searches = E.UL()
            for date in dates:
                if division == 'All':
                    division = ''
                if pubtype == 'All':
                    pubtype = ''
                search = 'find r fermilab ' + pubtype
                if division == 'Other':
                    for good_division in divisions[1:len(divisions)-1]:
                        if good_division == 'AD/APC':
                            search += ' not  (r AD or APC)'
                        else:
                            search += ' not r ' + good_division
                elif division == 'AD/APC':
                    search = 'find r fermilab ' + pubtype + \
                             ' and (r AD or APC)'
                else:
                    search += ' ' + division
                search += ' and de ' + date
                search = re.sub(r'\s+', ' ', search)
                result = perform_request_search(p=search, cc="Fermilab")
                result = len(result)
                if result == 0:
                    hit_number = E.LI()
                else:
                    link = search.replace(' ', '+')
                    link = 'https://inspirehep.net/search?cc=Fermilab&p=' + link
                    link += '&rg=100&sf=earliestdate'
                    hit_number = E.LI(E.A({'class': 't'}, str(result),
                                          href=link))
                list_of_searches.append(hit_number)
                if date == YEAR or date == MONTH:
                    tdg.append(list_of_searches)
                    list_of_searches = E.UL()

            pub_table_row.append(tdg)

        table.append(pub_table_row)
        pub_table_row = E.TR()
    glos = E.H4('Glossary')
    table2 = E.TABLE()
    glos_tr_td = E.TR(
        E.TD({'class': 'l'}, "E: Experimental papers"),
        E.TD({'class': 'l'}, "PPD: Particle Physics Division papers")
    )
    table2.append(glos_tr_td)
    glos_tr_td = E.TR(E.TD({'class': 'l'}, "T: Particle Physics Division \
Theoretical Physics Department papers"),
                      E.TD({'class': 'l'}, "AD/APC: Accelerator Division \
and Accelerator Physics Center papers"))
    table2.append(glos_tr_td)
    glos_tr_td = E.TR(E.TD({'class': 'l'}, "AT: Fermilab Center for Particle \
Astrophysics theoretical papers"),
                      E.TD({'class': 'l'}, "TD: Technical Division papers"))
    table2.append(glos_tr_td)
    glos_tr_td = E.TR(E.TD({'class': 'l'}, "AE: Fermilab Center for Particle \
Astrophysics experimental papers"),
                      E.TD({'class': 'l'}, "CD: Computing Sector papers"))
    table2.append(glos_tr_td)
    glos_tr_td = E.TR(E.TD({'class': 'l'}, "ND: Neutrino Division papers"),
                      E.TD({'class': 'l'}, "LBN: Long Baseline Neutrino \
Sector papers"))
    table2.append(glos_tr_td)
    glos_tr_td = E.TR(E.TD({'class': 'l'}, " "), E.TD({'class': 'l'}, " "))
    table2.append(glos_tr_td)
    glos_tr_td = E.TR(E.TD({'class': 'l'}, " "), E.TD({'class': 'l'}, " "))
    table2.append(glos_tr_td)
    glos_tr_td = E.TR(E.TD({'class': 'l'}, " "), E.TD({'class': 'l'}, " "))
    table2.append(glos_tr_td)
    glos_tr_td = E.TR(E.TD({'class': 'l'}, "PUB: Paper intended for \
publication in a journal"),
                      E.TD({'class': 'l'}, "FN: Physics note - short paper not \
fitting the other categories"))
    table2.append(glos_tr_td)
    glos_tr_td = E.TR(E.TD({'class': 'l'}, "CONF: Paper written as part of a \
conference"),
                      E.TD({'class': 'l'}, "SLIDES: Slides presented at a \
conference or lecture"))
    table2.append(glos_tr_td)
    glos_tr_td = E.TR(E.TD({'class': 'l'}, "THESIS: Ph.D. thesis based on \
work done at Fermilab"),
                      E.TD({'class': 'l'}, "POSTER: Poster presented at a \
conference"))
    table2.append(glos_tr_td)
    glos_tr_td = E.TR(E.TD({'class': 'l'}, "TM: Technical memo"),
                      E.TD({'class': 'l'}, ""))
    table2.append(glos_tr_td)

    body.append(table)
    body.append(glos)
    body.append(table2)
    doctype_wa.getroot().append(head_tag)
    doctype_wa.getroot().append(body)
    out = lxml.html.tostring(doctype_wa, encoding='UTF-8', pretty_print=True,
                             method='html').rstrip('\n')
    return out
Exemplo n.º 6
0
def process_robot_output(robot_output):
    root = etree.parse(robot_output).getroot()
    print("one time")
    for suite in root.xpath("//suite[@source]"):
        suite_id = suite.get("id", "")
        suite_container = E.DIV(E.CLASS("suite span12"), id=suite_id)
        suite_container.append(E.H3(E.CLASS("span12"), suite.get("name", "")))

        tests = suite.xpath(".//test")
        for i, test in enumerate(tests):
            test_id = "{0}".format(test.get("id", ""))

            test_container = E.DIV(E.CLASS("span6"))
            test_name = test.get("name", "")

            test_container.append(E.H4(test_name))

            doc = "".join([
                doc.text for doc in test.xpath("./doc") if doc.text is not None
            ])
            test_container.append(E.P(doc))

            status_tags = test.xpath("./status")
            status = ""
            if status_tags != []:
                status = status_tags[0].get("status")
                if status == "PASS":
                    btn_class = "btn-success"
                    text_class = "text-success"
                elif status == "FAIL":
                    btn_class = "btn-danger"
                    text_class = "text-error"

            btn_id = test_id + "-btn"
            test_container.append(
                E.BUTTON(status,
                         E.CLASS("btn " + btn_class),
                         type="button",
                         id=btn_id))

            btn = test_container.get_element_by_id(btn_id)
            btn.set("data-target", "#" + test_id)
            btn.set("data-toggle", "collapse")

            messages = E.DIV(E.CLASS("collapse " + text_class), id=test_id)
            for kw in test.xpath("./kw"):
                for msg in kw.xpath(".//msg"):
                    messages.append(format_msg(msg, status=status))
                if kw.get(
                        "name") == "Selenium2Library.Wait Until Page Contains":
                    text_check = [
                        "text" in doc.text for doc in kw.xpath(".//doc")
                    ]
                    if text_check:
                        text_match = " ".join(
                            [arg.text for arg in kw.xpath(".//arg")])
                    messages.append(
                        E.P("Checking the page contains: " + text_match))
            test_container.append(messages)

            # Two columns per row
            if i % 2 == 0 or i == len(tests):
                row = E.DIV(E.CLASS("row"), test_container)
                suite_container.append(row)
            else:
                row.append(test_container)

        content_area.append(E.DIV(E.CLASS("row"), suite_container))

    # ScrollSpy might be nice
    # report.body.set("data-spy","scroll")
    # report.body.set("data-target", ".suite")
    report.append(E.SCRIPT(src="http://code.jquery.com/jquery-1.9.1.min.js"))

    report.append(
        E.SCRIPT(
            src=
            "http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"  # noqa: E501
        ))