Exemplo n.º 1
0
    def transform(self, result, encoding):
        css = u''
        javascript = u''
        for parent in parents(self.published.context, iface=IFlowFolder):
            css = parent._v_css = getattr(  # noqa: P001
                parent,
                '_v_css',
                Scss().compile(parent.css or u''),
            )
            javascript =\
                (parent.javascript or u'').strip().replace(u'\r\n', u'\n')
            break

        root = result.tree.getroot()
        if css:
            head = root.find('head')
            # trick LXML to render styles with //<!CDATA[[
            style = builder.STYLE(u'\n/*', type='text/css')
            style.append(builder.S(CDATA(u'*/\n' + css + u'\n/*')))
            style.getchildren()[0].tail = u'*/\n'
            head.append(style)
            # head.append(builder.STYLE(
            #     css,
            #     type='text/css',
            # ))

        if javascript:
            body = root.find('body')
            # trick LXML to render script with //<!CDATA[[
            script = builder.SCRIPT(u'\n//', type='application/javascript')
            script.append(builder.S(CDATA(u'\n' + javascript + u'\n//')))
            script.getchildren()[0].tail = u'\n'
            body.append(script)

        return result
Exemplo n.º 2
0
def make_summary_doc(tests_w_results):
    tbody = B.TBODY(
        B.TR(B.TH('Test Name'), B.TH('Inserted (in # of blocks)'),
             B.TH('Deleted (in # of blocks)'), B.TH('Links'), B.TH('Notes')))
    for (test, result) in tests_w_results:
        row = make_summary_row(test, result)
        tbody.append(row)
    return B.HTML(
        B.HEAD(B.TITLE('Readability Test Summary'),
               B.STYLE(SUMMARY_CSS, type='text/css')), B.BODY(B.TABLE(tbody)))
Exemplo n.º 3
0
 def head(self):
     """The HEAD of the html document"""
     head = E.HEAD(
         E.META({
             'http-equiv': 'Content-Type',
             'content': 'text/html; charset=utf-8'
         }),
         E.TITLE('%s -- GCC Python Plugin' % self.data['filename']),
     )
     head.extend(
         E.STYLE(
             file_contents(css + '.css'), media='screen', type='text/css')
         for css in ('extlib/reset-20110126.min', 'pygments_c', 'style'))
     return head
Exemplo n.º 4
0
def main():
    cursor = db.connect(user="******").cursor()
    query = db.Query("document d", "d.id", "d.title", "d.xml").order(2)
    query.join("doc_type t", "t.id = d.doc_type")
    query.where("t.name = 'Filter'")
    filters = []
    for doc_id, doc_title, doc_xml in query.execute(cursor).fetchall():
        filters.append(Filter(doc_id, doc_title, doc_xml))
    tbody = builder.TBODY()
    caption = builder.CAPTION(TITLE)
    for name in sorted(Parameter.parameters, key=str.lower):
        parm = Parameter.parameters[name]
        parm.add_rows(tbody)
    page = builder.HTML(
        builder.HEAD(
            builder.TITLE(TITLE),
            builder.LINK(rel="stylesheet", href="/stylesheets/cdr.css"),
            builder.STYLE("th { text-align: right; vertical-align: top; }")),
        builder.BODY(builder.TABLE(caption, tbody), builder.CLASS("report")))
    print("Content-type: text/html\n")
    print(etree.tostring(page, pretty_print=True).decode("ascii"))
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 generate(self):
        Logger.info("Generating Chart by id {0}".format(self._cid))
        self._data = {"columns": []}

        if isinstance(self.chart_type, dict):
            self._data["types"] = {
                key: get_raw_type(value)
                for key, value in self.chart_type.items()
            }
            self.raw_type = "MultipleType_{0}".format("_".join(
                list(self._data["types"].values())))
        elif isinstance(self.chart_type, str):
            self._data["type"] = get_raw_type(self.chart_type)
            self.raw_type = "SingleType_{0}".format(self._data["type"])
        else:
            raise ChartTypeError("invalid type format: {0}".format(
                self.chart_type))

        if "x" in self.options.keys():
            self._data["x"] = self.options["x"]
            self.options.pop("x", None)

        try:
            if self.stack:
                self._data["groups"] = [self.dataframe.columns.tolist()]
        except:
            pass

        for col in self.dataframe.columns:
            self._data["columns"].append([col] +
                                         self.dataframe[col].values.tolist())

        self._root = lxhtml.DIV(lxhtml.DIV(id=self._id),
                                lxhtml.CLASS("billboard-{0}".format(
                                    self.raw_type)),
                                style="padding: 10px;")

        script_text = ""
        if self.include_res:
            self._root.append(
                lxhtml.SCRIPT(get_config("billboard-js"),
                              id="{0}-js".format(self._id)))
            self._root.append(
                lxhtml.STYLE(get_config("billboard-css"),
                             id="{0}-css".format(self._id)))

            script_text += """
if (document.getElementById("billboard-js") == null && document.getElementById("billboard-css") == null) {
    var billboard_js = document.createElement("script"), billboard_css = document.createElement("style");
    billboard_js.id = "billboard-js", billboard_css.id = "billboard-css";

    billboard_js.appendChild(document.createTextNode(document.getElementById("%(js_id)s").text));
    billboard_css.appendChild(document.createTextNode(document.getElementById("%(css_id)s").innerText));

    document.head.appendChild(billboard_js);
    document.head.appendChild(billboard_css);
}

document.getElementById("%(js_id)s").remove();
document.getElementById("%(css_id)s").remove();
""" % {
                "js_id": "{0}-js".format(self._id),
                "css_id": "{0}-css".format(self._id)
            }

        script_text += """
bb.generate({
    bindto: "#%s",
    data: %s,
    %s
});
""" % (self._id, self._data, ",\n".join([
            "'{0}': {1}".format(key, value)
            for key, value in self.options.items()
        ]))

        self._root.append(
            lxhtml.SCRIPT(script_text,
                          type="text/javascript",
                          id="{0}-script".format(self._id),
                          onload="eval(this.text);"))

        Logger.info("Generated Chart {0}".format(self.raw_type))
Exemplo n.º 7
0
def full_html_from_doc(doc):
    article_element = fragment_fromstring(doc.summary().html)
    html_element = B.HTML(
        B.HEAD(B.TITLE(doc.title()), B.STYLE(DISPLAY_CSS, type='text/css')),
        B.BODY(B.H1(doc.title(), {'class': 'articleTitle'}), article_element))
    return tostring(html_element)
Exemplo n.º 8
0
def add_css(doc):
    style = B.STYLE(READABILITY_CSS, type='text/css')
    head = B.HEAD(style, content='text/html; charset=utf-8')
    doc.insert(0, head)
Exemplo n.º 9
0
    "Databases": "Databases (Custom)",
    "Design": "Design (Custom)",
    "General": "General (Custom)",
    "Integration": "Integration (Custom)",
    "Misc1": "Misc 1 (Custom)",
    "Misc2": "Misc 2 (Custom)",
    "Revisions": "Revisions (Custom)",
    "Shapes": "Shapes (Custom)",
    "Structure": "Structure (Custom)"
}
css = """\
img { border: 1px black solid }
* { font-family: Arial; }
"""
paths = glob.glob("d:/Inetpub/wwwroot/images/xmetal/*.jpg")
content = B.CENTER(B.H1("XMetaL CDR Icons"))
for path in sorted(paths):
    if "xmetal_cdr" not in path and "Standard" not in path:
        name = path.replace("\\", "/").split("/")[-1][:-4]
        content.append(B.H2(names.get(name, name)))
        content.append(B.IMG(src="/images/xmetal/%s.jpg" % name))
page = B.HTML(
    B.HEAD(
        B.TITLE("XMetaL CDR Icons"),
        B.STYLE(css)
    ),
    B.BODY(content)
)
xml = etree.tostring(page, pretty_print=True, encoding="unicode")
print(f"Content-type: text/html\n\n{xml}")
Exemplo n.º 10
0
CHECK = "\u2713"
COLORS = {"-": "LightGoldenrodYellow", "+": "Khakhi", "?": "LightSkyBlue"}
RULES = {
    "*": "font-family: Arial, sans-serif;",
    "h1": "color: maroon; font-size: 22pt;",
    "h2": "font-size: 20pt; color: green;",
    "h3": "background-color: green; color: white; padding: 5px;",
    "p.ok": "font-size: 16pt; padding-left: 30px;",
    "pre.fixed, pre.fixed span": "font-family: monospace; font-size: 9pt;",
    "input.path": "width: 500px;",
}
RULES = "\n".join([f"{sel} {{ {rules} }}" for (sel, rules) in RULES.items()])
HEAD = builder.HEAD(
    builder.META(charset="utf-8"),
    builder.TITLE(TITLE),
    builder.STYLE(RULES),
)


def compare_table(body, name, old, new):
    items = []
    ot = old.tables[name]
    nt = new.tables[name]
    if set(ot.cols) != set(nt.cols):
        ul = builder.UL()
        item = builder.LI("TABLE STRUCTURE MISMATCH", ul)
        ul.append(builder.LI(f"old: {ot.cols:!r}"))
        ul.append(builder.LI(f"new: {nt.cols:!r}"))
        items.append(item)
    if ot.names:
        for key in sorted(ot.names):