Example #1
0
    def render(self, posts_per_page=25):
        pages_count = (len(self.rendered_items) + posts_per_page - 1) // posts_per_page
        page_names = ["%d.html" % i for i in range(pages_count)]

        nav_section = T.nav(
            *[T.a(str(i), href=page_names[i], target=_PAGE_FRAME) for i in range(pages_count)]
        )

        index = T.html(
            T.head(
                T.meta(charset='utf-8'),
                stylesheet(_STYLE_CSS),
                stylesheet(_NAVBAR_CSS),
                T.script(src=_JQUERY_URL),
                inline_script_from(get_resource(Path(_SELECTED_JS)))
            ),
            T.body(
                nav_section,
                T.iframe(name=_PAGE_FRAME, src=page_names[0] if pages_count > 0 else 'none', width='100%', height='100%', style='border:none')
            )
        )
        self.pages['index.html'] = index

        for page_index in range(pages_count):
            page_items = self.rendered_items[page_index * posts_per_page: (page_index + 1) * posts_per_page]
            chunk_html = T.html(
                T.head(stylesheet('page.css')),
                T.body(
                    T.div(*page_items, id=ID_CONTAINER)
                )
            )
            self.pages[page_names[page_index]] = chunk_html
Example #2
0
def generate_html_report(html, recipients, message):

    current_time = time.strftime('%d/%m/%Y')
    if not message:
        message = f"Daily test results for {current_time}"
        subject = f"Execution Results {current_time}"
    else:
        subject = message
    with dominate.document(title='Test Report') as doc:
        tags.html(tags.h2("Greetings,"))
        tags.html(tags.h3(f"{message} (attached)"))
    doc = str(doc)
    send_mail(send_to=recipients, subject=subject, message=doc, payload=html)
    return html
Example #3
0
def home():
    return t.html(
        [
            t.head(
                [
                    cccp.REQUIRED,
                    cccp.BOOTSTRAP,
                    cccp.CreateReplaceHtmlFunc(),
                    cccp.CreateAppendHtmlFunc(),
                    cccp.CreatePrependHtmlFunc(),
                ]
            ),
            t.body(
                [
                    t.h1("Hello, CCCP!"),
                    t.div(id="pageContent"),
                    t.button(
                        "go to blog",
                        onClick=cccp.replaceHtml(
                            "http://127.0.0.1:9999/page/1", "pageContent"
                        ),
                    ),
                ]
            ),
        ]
    ).render()
Example #4
0
 def test_font_styles(self):
     c = Converter('Man', file='font_styles.man')
     c.translate()
     text = c.html.render()
     text = c.change_special_symbols(text)
     doc = tags.html(lang='en')
     doc = add_head(doc)
     doc_body = doc.add(tags.body())
     lines = [
         tags.b('one'), '\ntwo',
         tags.b('three'),
         tags.b('four'),
         tags.i('five'),
         tags.b('six'), '\nseven eight',
         tags.b('nine'), '\nten eleven twelve',
         tags.i('13'),
         tags.b('14'),
         tags.i('15'),
         tags.i('file'), '\n.',
         tags.small('bbbbb'),
         tags.small('aaaaaa dfghjhg'),
         tags.b('--posix'),
         tags.i('file1 file2')
     ]
     with doc_body:
         paragraph = tags.p()
         for line in lines:
             paragraph += line
     self.assertEqual(doc.render(), text)
Example #5
0
 def test_other(self):
     c = Converter('Man', file='diff.man')
     c.translate()
     text = c.html.render()
     text = c.change_special_symbols(text)
     doc = tags.html(lang='en')
     doc = add_head(doc)
     doc_body = tags.body()
     row = tags.div(cls='row')
     row = add_row(row, 'GCC(1)', '', 'GCC(1)')
     doc_body.add(row)
     with doc_body:
         paragraph = tags.p()
         paragraph.add(tags.br())
         paragraph.add('\n\\f(CW        c  c-header  cpp-output\\fP')
         paragraph.add(tags.br())
         paragraph.add(tags.br())
         def_list = tags.dl()
         def_termin = tags.dt()
         def_termin.add('\n')
         def_termin.add('\\fB-x none\\fR')
         def_def = tags.dd(cls='indent')
         def_def.add('\nstandard_output.')
         def_list.add(def_termin)
         def_list.add(def_def)
     row = tags.div(cls='row')
     row = add_row(row, '', '2018-07-20', 'GCC(1)')
     doc_body.add(row)
     doc.add(doc_body)
     doc = c.change_special_symbols(doc.render())
     self.assertEqual(doc, text)
Example #6
0
def cv():
    base = Path('cv')
    with (base / 'content' / 'data.toml').open() as toml, \
         (base / 'style' / 'index.css').open() as css:
        data = loads(toml.read())
        with html(lang='en') as document:
            with head():
                meta(charset='utf-8')
                meta(name='description',
                     content=f'{SHARED.info.person_name} (engineer|designer)')
                meta(name='keywords', content=','.join(SHARED.meta.keywords))
                meta(name='author', content=f'{SHARED.info.person_name}')
                title(SHARED.info.person_name)
                style(raw(css.read()))
            with body():
                with table(id='content') as content:
                    with tr():
                        with td(id='image', colspan=4):
                            img(src='img/header.png', alt='...')
                            div('Curriculum Vitae')
                for row in chain(
                        Basic(data['basic']).as_rows(),
                        Skills(data['skills']).as_rows(),
                        Experience(data['experience']).as_rows(),
                        Education(data['education']).as_rows()):
                    content.add(row)

    copyright = comment(f'Copyright (C) 2015 - {datetime.now().year} '
                        f'{SHARED.info.person_name}. '
                        'All rights reserved.')
    return f'<!DOCTYPE html>{copyright}{document.render(pretty=False)}'
Example #7
0
def site():
    base = Path('website')
    with (base/'content'/'index.toml').open() as toml, \
         (base/'style'/'index.css').open() as css:
        data = loads(toml.read())

        with html(lang='en') as document:

            with head():
                meta(charset='utf-8')
                meta(name='description',
                     content=f'{SHARED.info.person_name} (engineer|designer)')
                meta(name='keywords', content=','.join(SHARED.meta.keywords))
                meta(name='author', content=f'{SHARED.info.person_name}')
                title(SHARED.info.person_name)
                link(rel='shortcut icon',
                     type='image/x-icon',
                     href='favicon.ico')
                link(rel='icon', type='image/x-icon', href='favicon.ico')
                style(raw(css.read()))
                script(src='website/js/anim.js')
                script(src='website/js/index.js')

            with body():
                _block('engineer', data['engineer'])
                _block('designer', data['designer'])
                with div(id='handler'):
                    div(raw('&laquo;&raquo;'))
                script('main();', type='text/javascript')

    copyright = comment(f'Copyright (C) 2015 - {datetime.now().year} '
                        f'{SHARED.info.person_name}. '
                        'All rights reserved.')
    return f'<!DOCTYPE html>{copyright}{document.render(pretty=False)}'
Example #8
0
 def test_many_argument_strings(self):
     c = Converter('Man', file='links.man')
     c.translate()
     text = c.html.render()
     text = c.change_special_symbols(text)
     doc = tags.html(lang='en')
     doc = add_head(doc)
     doc_body = tags.body()
     row = tags.div(cls='row')
     row = add_row(row, 'GREP(1)', 'User Commands', 'GREP(1)')
     doc_body.add(row)
     with doc_body:
         paragraph = tags.p()
         paragraph += (tags.a('the bug-reporting address',
                              href='mailto:[email protected]'))
         paragraph += tags.br()
         paragraph += (tags.a(
             'email archive',
             href='http://lists.gnu.org/mailman/listinfo/bug-grep'))
         paragraph += tags.br()
         paragraph += tags.br()
     row = tags.div(cls='row')
     row = add_row(row, 'GNU grep 3.1', '2017-06-21', 'GREP(1)')
     doc_body.add(row)
     doc.add(doc_body)
     self.assertEqual(doc.render(), text)
def render_html_table(rows):
    h = html()
    with h.add(body()).add(div(id='content')):
        with table().add(tbody()):
            for row in rows:
                l = tr()
                for cell in row:
                    l.add(td(cell))
    return h.render()
Example #10
0
def create_mainpage_html(local, url_list, path, web_title):
    _html = dmtags.html(style="background-color:#fcfbeb;")
    _head, _body = _html.add(dmtags.head(dmtags.title(web_title)),
                             dmtags.body(cls="main_page"))
    with _head:
        dmtags.comment("The page is genarated on {} by Ein".format(
            time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
        dmtags.meta(charset="utf-8",
                    name="viewport",
                    content="width=device-width, initial-scale=1")
        dmtags.link(
            href="https://fonts.googleapis.com/css?family=Noto+Sans+JP:500",
            rel="stylesheet")
        dmtags.link(
            href=
            "https://cdnjs.cloudflare.com/ajax/libs/milligram/1.3.0/milligram.min.css",
            rel="stylesheet")
        dmtags.link(href="https://rawcdn.githack.com/c892836a/python_for_fun/"
                    "b2fa53022b0ae5a26d6f140c38b860a210c21040/css/custom.css",
                    rel="stylesheet")
        dmtags.link(
            href="https://lh3.googleusercontent.com/S__tM5EYqZDFLuv1uPG" +
            "mlZTTLLyNAbUvljzDH8-S0Pxq2nA9fnFF3SwU0w0wF8PlMu_hv3WhLMdlFodKbQ=s0",
            rel="shortcut icon",
            type="image/vnd.microsoft.icon")
    main_div = _body.add(
        dmtags.div(
            style=
            "text-align:center; font-family: 'Noto Sans JP', sans-serif; font-size:36px;"
        ))

    with main_div:
        _p1 = dmtags.p(style="color:#470000;")
        for url in url_list:
            _p2 = dmtags.p(style="font-size:20px;")
            with _p2:
                dmtags.a(url[0], href="{}".format(url[1]))
        with _p1:
            text("{}".format(web_title))

    # create html file
    if local:
        os.chdir(path)
        os.chdir(os.pardir)
        with open("{}.html".format(web_title), "w", encoding='utf8') as f:
            f.write("<!DOCTYPE html>\n")
            f.write(_html.render())

    else:
        with open("{}\\{}.html".format(path, web_title), "w",
                  encoding='utf8') as f:
            f.write("<!DOCTYPE html>\n")
            f.write(_html.render())
Example #11
0
def index():
    css, grid = create_matrix()
    return cccp.render(
        t.html([
            t.head([
                cccp.raw("""    <!-- Required meta tags -->
                                <meta charset="utf-8">
                                <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
                            """),
                cccp.REQUIRED,
                css,
            ]),
            t.body(t.div(grid, cls="content-container")),
        ]))
Example #12
0
def create_table(table_rows, *content):
    html_table = table(cellspacing="0",
                       cellpadding="5",
                       width="100%",
                       margin="0 auto",
                       border="1",
                       style="white-space:nowrap;")
    with html_table.add(thead()).add(tr()):
        for val in [
                "name", "purchase_price", "purchase_level", "min_price",
                "min_level", "min_profit", "min_percent", "relevant_price",
                "relevant_level", "relevant_profit", "relevant_percent"
        ]:
            th(val)
    with html_table:
        tbody(table_rows)
    return html(body(table(tr(td(html_table, *content)))))
Example #13
0
 def __init__(self, _title, file=None, data=None):
     self.file = file
     self.data = data
     self.html = tags.html(lang='en')
     self.head = self.html.add(tags.head())
     self.head.add(tags.meta(charset='utf-8'))
     self.head.add(tags.title(_title))
     self.head.add(tags.link(rel='stylesheet', href='styles.css'))
     self.body = self.html.add(tags.body())
     self.paragraph = None
     self.div_header = None
     self.div_subheader = None
     self.date = None
     self.program = None
     self.name_page = None
     self.iterator = None
     self.indent = 0
     self.rs = None
Example #14
0
 def test_file_structure(self):
     c = Converter('Man', file='structured_file.man')
     c.translate()
     text = c.html.render()
     text = c.change_special_symbols(text)
     doc = tags.html(lang='en')
     doc = add_head(doc)
     doc_body = tags.body()
     row = tags.div(cls='row')
     row = add_row(row, 'BASH(1)', '', 'BASH(1)')
     doc_body.add(row)
     with doc_body:
         tags.h2('NAME')
         content = tags.div(cls='content')
         paragraph = tags.p()
         paragraph += '\ngrep, egrep, fgrep, rgrep'
         content.add(paragraph)
         content.add(tags.h4('Simple Commands'))
         content2 = tags.div(cls='content')
         content2.add(tags.br())
         paragraph = tags.p()
         paragraph += '\nA \\fIsimple command\\fP'
         content2.add(paragraph)
         def_list = tags.dl()
         def_termin = tags.dt()
         def_termin.add('\nInterpret')
         def_list.add(def_termin)
         def_list.add(tags.dd(cls='indent'))
         content2.add(def_list)
         def_list = tags.dl()
         def_termin = tags.dt(cls='short')
         def_termin.add((tags.b('%%')))
         def_list.add(def_termin)
         def_def = tags.dd(cls='indent')
         def_def.add('\nA literal')
         def_list.add(def_def)
         content2.add(def_list)
         content.add(content2)
     row = tags.div(cls='row')
     row = add_row(row, 'GNU Bash 4.4', '2016-08-26', 'BASH(1)')
     doc_body.add(row)
     doc.add(doc_body)
     doc = c.change_special_symbols(doc.render())
     self.assertEqual(doc, text)
Example #15
0
def html_report(figs,
                text=None,
                name='report',
                directory=None,
                dpi=75,
                fig_dir='figs'):
    """Produce an HTML report containing figs and text."""
    #
    # if dominate not installed, dive out here
    if not dominate:
        return

    if directory is None:
        directory = name
    try:
        os.mkdir(directory)
    except FileExistsError as e:
        print(e)

    try:
        os.mkdir(os.path.join(directory, fig_dir))
    except FileExistsError as e:
        print(e)

    h = html()
    with h.add(body()).add(div(id='content')):
        h1(f'Performance Plots: {name}')
        if text:
            pre(text)
        with table().add(tbody()):
            for j, row in enumerate(figs):
                r = tr()
                for i, item in enumerate(row):
                    url = os.path.join(fig_dir, f"{name}-fig-{j}_{i}.png")
                    item.savefig(os.path.join(directory, url),
                                 dpi=dpi,
                                 bbox_inches='tight')
                    r += td(img(src=url))

    with open(os.path.join(directory, name + '.html'), 'w') as f:
        print(h, file=f)
    return h
Example #16
0
def create_html_news(path, News):
    if os.path.isdir(path) is False:
        raise RssException("Error. It isn't a folder")

    path = os.path.join(path, "News.html")

    news_html = html()
    news_html.add(head(meta(charset='utf-8')))
    news_body = news_html.add(body())
    with news_body:
        for item_news in News:
            news_body = news_body.add(div())
            news_body += h1(item_news.title)
            news_body += p(b("Date: "), a(item_news.date))

            text = item_news.news

            # remove links in the text and add pictures
            if len(item_news.links) > 0:
                start = text.find(']', 0, len(text))
                text = text[start + 1:]

                this_dir = os.path.abspath(os.path.dirname(__file__))
                sys.path.append(this_dir)
                news_body += img(src=f"file:///{this_dir}/images/{correct_title(item_news.title)}.jpg")
            else:
                # if there are no pictures, just remove the links
                start = text.find(']', 0, len(text))
                text = text[start + 1:]

            news_body += p(text.encode("utf-8").decode("utf-8"), br(), br())

    try:
        with open(path, 'w', encoding='utf-8') as rss_html:
            rss_html.write(str(news_html))
    except FileNotFoundError:
        raise RssException('Error. No such folder\n')
    print("file News.html created")
Example #17
0
def create_singlepage_html(local, is_mainpage, web_title, web_title_next,
                           web_title_pre, file_array, path):
    parent_web_title = ""
    if is_mainpage:
        os.chdir(path)
        os.chdir(os.pardir)
        parent_web_title = str(os.getcwd())[str(os.getcwd()).rindex("\\") + 1:]
    if local:
        web_title_next = special_character_encode(web_title_next)
        web_title_pre = special_character_encode(web_title_pre)
    _html = dmtags.html(style="background-color:black;")
    _head, _body = _html.add(dmtags.head(dmtags.title(web_title)),
                             dmtags.body())
    with _head:
        dmtags.comment("The page is genarated on {} by Ein".format(
            time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
        dmtags.meta(charset="utf-8",
                    name="viewport",
                    content="width=device-width, initial-scale=1")
        dmtags.link(
            href="https://fonts.googleapis.com/css?family=Noto+Sans+JP:500",
            rel="stylesheet")
        dmtags.link(
            href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.6/"
            "jquery.fancybox.min.css",
            rel="stylesheet")
        dmtags.link(
            href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-rc.25/css/"
            "uikit.min.css",
            rel="stylesheet")
        dmtags.link(href="https://rawcdn.githack.com/c892836a/python_for_fun/"
                    "b2fa53022b0ae5a26d6f140c38b860a210c21040/css/custom.css",
                    rel="stylesheet")
        dmtags.link(
            href="https://lh3.googleusercontent.com/S__tM5EYqZDFLuv1uPG" +
            "mlZTTLLyNAbUvljzDH8-S0Pxq2nA9fnFF3SwU0w0wF8PlMu_hv3WhLMdlFodKbQ=s0",
            rel="shortcut icon",
            type="image/vnd.microsoft.icon")
        dmtags.script(
            src=
            "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js")
        dmtags.script(
            src=
            "https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.6/jquery.fancybox.min.js"
        )

    main_div = _body.add(
        dmtags.div(
            style=
            "text-align:center; font-family: 'Noto Sans JP', sans-serif; font-size:32px;"
        ))
    with main_div:
        _p1 = dmtags.p(style="color:#C2FFFC;padding-top: 20px;")
        if web_title_next == "" and web_title_pre == "":
            _button_top_div = dmtags.div(style="display: none;")
        else:
            _button_top_div = dmtags.div(style="padding-bottom: 30px;")
        if local:
            for pic in file_array:
                _a1 = dmtags.a(datafancybox="gallery",
                               href='./{}/{}'.format(
                                   urllib.parse.quote(web_title),
                                   urllib.parse.quote(pic)))
                with _a1:
                    dmtags.img(width="1200px",
                               src='./{}/{}'.format(
                                   urllib.parse.quote(web_title),
                                   urllib.parse.quote(pic)))
        else:
            web_title_temp = restrict_foldername(web_title)
            for pic in file_array:
                _a1 = dmtags.a(datafancybox="gallery",
                               href='./{}/{}'.format(
                                   urllib.parse.quote(web_title_temp),
                                   urllib.parse.quote(pic)))
                with _a1:
                    dmtags.img(width="1200px",
                               src='./{}/{}'.format(
                                   urllib.parse.quote(web_title_temp),
                                   urllib.parse.quote(pic)))
        with _p1:
            text("{} ({}P)".format(web_title, str(len(file_array))))
        _button_bottom_div = dmtags.div(
            style="padding-top: 20px; padding-bottom: 40px;")
        with _button_top_div:
            if web_title_pre != "":
                dmtags.a("Prev",
                         cls="uk-button uk-button-secondary n-bt",
                         href="./{}.html".format(web_title_pre))
            else:
                dmtags.a("Prev",
                         cls="uk-button uk-button-secondary h-bt",
                         href="./{}.html".format(web_title_pre))
            if is_mainpage:
                dmtags.a("Index",
                         cls="uk-button uk-button-secondary n-bt",
                         href="../{}.html".format(parent_web_title))
            if web_title_next != "":
                dmtags.a("Next",
                         cls="uk-button uk-button-secondary n-bt",
                         href="./{}.html".format(web_title_next))
            else:
                dmtags.a("Next",
                         cls="uk-button uk-button-secondary h-bt",
                         href="./{}.html".format(web_title_next))

        with _button_bottom_div:
            if web_title_pre != "":
                dmtags.a("Prev",
                         cls="uk-button uk-button-primary n-bt",
                         href="./{}.html".format(web_title_pre))
            else:
                dmtags.a("Prev",
                         cls="uk-button uk-button-primary h-bt",
                         href="./{}.html".format(web_title_pre))
            if is_mainpage:
                dmtags.a("Index",
                         cls="uk-button uk-button-primary n-bt",
                         href="../{}.html".format(parent_web_title))
            if web_title_next != "":
                dmtags.a("Next",
                         cls="uk-button uk-button-primary n-bt",
                         href="./{}.html".format(web_title_next))
            else:
                dmtags.a("Next",
                         cls="uk-button uk-button-primary h-bt",
                         href="./{}.html".format(web_title_next))

    # create html file
    with open("{}.html".format(special_character_encode(path)),
              "w",
              encoding='utf8') as f:
        f.write("<!DOCTYPE html>\n")
        f.write(_html.render().replace("datafancybox", "data-fancybox"))
Example #18
0
pages_dir = "test_pages"

try:
    os.mkdir(pages_dir)
except:
    pass

n = 20

pages = []
for i in range(1, n + 1):
    pages.append("{}.html".format(i))

for j in range(1, n + 1):
    page = tags.html()

    page_title = tags.title("Page " + str(j))
    page_head = tags.head(page_title)

    page_body = tags.body()
    for k in range(1, random.randint(1, n)):
        image = tags.img(src=("image_source" + str(k)))
        page_body.add(image)

    ul_links = tags.ul()
    for r in range(1, random.randint(1, n)):
        li_link = tags.li()
        page_to_link = pages[random.randint(0, n - 1)]
        link = li_link.add(
            tags.a("This is a link to {}".format(page_to_link),
Example #19
0
def process():
    #   doc = dominate.document(DOCNAME)

    h = html(name=DOCNAME)

    with h:

        #           _head = head()

        _head = head()
        with _head:
            s = style()
            s.add("\nh3, h4 {text-align:center;}")
            s.add("\nth {background-color:yellow;}")
            s.add("\ntr, td, th {text-align:center;}")
            s.add("\ntd.left {text-align:left;}")
            s.add("\n")

        b = body()

        b.add(h3(DOCNAME))
        b.add(h4(asctime()))
        b.add(hr())

        t = table(border="1", cellpadding="3", cellspacing="3")
        b.add(t)

        r = tr()
        t.add(r)

        r.add(th("Code"))
        r.add(th("Waypoint"))
        r.add(th("Image"))
        r.add(th("Note"))

        f = open(FILENAME, "r")

        for index, line in enumerate(f.readlines()):
            if index == 0:
                continue

            code, waypoint_name, url = line.split('\t')

            r = tr()
            t.add(r)

            r.add(td(code))
            r.add(td(a(waypoint_name, href=url)))

            if code in IMAGES:
                link = IMAGES[code]
                if isinstance(link, type([])):
                    images = table()
                    for link in link:
                        r2 = tr()
                        r2.add(td(a(link, href=link)))
                        images.add(r2)
                else:
                    images = a(link, href=link)
            else:
                images = ""
            r.add(td(images))

            if code in NOTES:
                note = NOTES[code]
            else:
                note = "TBD"
            r.add(td(note, cls="left"))

    outfile = open(OUTFILE, "wb")
    print >> outfile, h
    outfile.close()
    print "Output is in %s" % OUTFILE