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
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('«»')) 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)}'
def add_head(doc): doc_head = doc.add(tags.head()) with doc_head: tags.meta(charset='utf-8') tags.title('Man') tags.link(rel='stylesheet', href='styles.css') return doc
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()
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)}'
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())
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")), ]))
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
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")
def head(self) -> html_tag: h = head() h.add(script(src="/giotto-statics/main.js", defer=True)) h.add(script(src="https://unpkg.com/[email protected]")) h.add(link(href="/giotto-statics/styles.css", rel="stylesheet")) return h
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
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), href="/{}".format(page_to_link))) ul_links.add(li_link) page_body.add(ul_links)
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"))