本文整理汇总了Python中dominate.tags.a方法的典型用法代码示例。如果您正苦于以下问题:Python tags.a方法的具体用法?Python tags.a怎么用?Python tags.a使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dominate.tags
的用法示例。
在下文中一共展示了tags.a方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def __init__(self, web_dir, title, refresh=0):
"""Initialize the HTML classes
Parameters:
web_dir (str) -- a directory that stores the webpage. HTML file will be created at <web_dir>/index.html; images will be saved at <web_dir/images/
title (str) -- the webpage name
refresh (int) -- how often the website refresh itself; if 0; no refreshing
"""
self.title = title
self.web_dir = web_dir
self.img_dir = os.path.join(self.web_dir, 'images')
if not os.path.exists(self.web_dir):
os.makedirs(self.web_dir)
if not os.path.exists(self.img_dir):
os.makedirs(self.img_dir)
self.doc = dominate.document(title=title)
if refresh > 0:
with self.doc.head:
meta(http_equiv="refresh", content=str(refresh))
示例2: add_images
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def add_images(self, ims, txts, links, width=400):
"""add images to the HTML file
Parameters:
ims (str list) -- a list of image paths
txts (str list) -- a list of image names shown on the website
links (str list) -- a list of hyperref links; when you click an image, it will redirect you to a new page
"""
self.t = table(border=1, style="table-layout: fixed;") # Insert a table
self.doc.add(self.t)
with self.t:
with tr():
for im, txt, link in zip(ims, txts, links):
with td(style="word-wrap: break-word;", halign="center", valign="top"):
with p():
with a(href=os.path.join('images', link)):
img(style="width:%dpx" % width, src=os.path.join('images', im))
br()
p(txt)
示例3: visit_Subgroup
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def visit_Subgroup(self, node):
if not self._in_dropdown:
li = tags.li(_class='dropdown')
if node.active:
li['class'] = 'active'
a = li.add(tags.a(node.title, href='#', _class='dropdown-toggle'))
a['data-toggle'] = 'dropdown'
a['role'] = 'button'
a['aria-haspopup'] = 'true'
a['aria-expanded'] = 'false'
a.add(tags.span(_class='caret'))
ul = li.add(tags.ul(_class='dropdown-menu'))
self._in_dropdown = True
for item in node.items:
ul.add(self.visit(item))
self._in_dropdown = False
return li
else:
raise RuntimeError('Cannot render nested Subgroups')
示例4: add_images
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def add_images(self, ims, txts, links, K, width=400):
"""add images to the HTML file
Parameters:
ims (str list) -- a list of image paths
txts (str list) -- a list of image names shown on the website
links (str list) -- a list of hyperref links; when you click an image, it will redirect you to a new page
"""
self.t = table(border=1, style="table-layout: fixed;") # Insert a table
self.doc.add(self.t)
with self.t:
with tr():
for im, txt, link in zip(ims, txts, links):
with td(style="word-wrap: break-word;", halign="center", valign="top"):
with p():
with a(href=os.path.join('images', link)):
if txt == 'refs':
img(style="width:%dpx" % K*width, src=os.path.join('images', im))
else:
img(style="width:%dpx" % width, src=os.path.join('images', im))
br()
if txt == 'refs':
p(txt+':K='+str(K))
else:
p(txt)
示例5: add_header
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def add_header(self, text):
"""Insert a header to the HTML file
Parameters:
text (str) -- the header text
"""
with self.doc:
h3(text)
示例6: visit_Link
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def visit_Link(self, node):
item = tags.li()
item.add(tags.a(node.text, href=node.get_url()))
return item
示例7: visit_View
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def visit_View(self, node):
item = tags.li()
item.add(tags.a(node.text, href=node.get_url(), title=node.text))
if node.active:
item['class'] = 'active'
return item
示例8: add_table
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def add_table(table):
with dtags.table().add(dtags.tbody()):
for row in table:
with dtags.tr():
for col_idx, col_val in enumerate(row[1:]):
if col_idx == 0:
dtags.td().add(dtags.a("{}".format(col_val), href=row[0]))
else:
if isinstance(col_val, float):
col_val = "{0:.5f}".format(col_val)
dtags.td().add("{}".format(col_val))
示例9: add_pagetitle
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def add_pagetitle(self, text):
""" Insert a title in the first line
Parametres:
text (str): -- the page title text
"""
with self.doc:
h1(text)
示例10: add_caption
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def add_caption(self, text):
""" Insert a caption under the first line
Parametres:
text (str): -- the caption text
"""
with self.doc:
h2(text)
示例11: make_nav
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def make_nav(session):
""" Creates the navigation using flask-nav.
"""
pages = (session
.query(Page)
.filter(Page.hidden == 0)
.order_by(Page.orders)
.all())
parts = []
groups = {}
for page in pages:
dest = '/' + page.link if page.uri is None else page.uri
# add all pages with the same nav_group into a Subgroup.
if page.nav_group:
if page.nav_group not in groups:
groups[page.nav_group] = Subgroup(page.nav_group)
parts.append(groups[page.nav_group])
groups[page.nav_group].items.append(Link(page.name, dest))
else:
parts.append(Link(page.name, dest))
title = 'pygame'
endpoint = 'news.index'
# in tests, news.index might not exist. So we don't link there if not.
try:
url_for(endpoint)
nav_bar = Navbar(View(title, endpoint))
except (BuildError, RuntimeError):
nav_bar = Navbar(title)
nav_bar.items.extend(parts)
return nav_bar
示例12: add_nav
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def add_nav(app):
""" called by pygameweb.app.add_views_front
"""
nav = Nav()
@nav.navigation()
def mynavbar():
""" Every time a page is loaded we create the navigation.
We cache the navbar in the templates.
"""
return make_nav(current_session)
nav.init_app(app)
示例13: visit_object
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def visit_object(self, node):
"""Fallback rendering for objects.
If the current application is in debug-mode
(``flask.current_app.debug`` is ``True``), an ``<!-- HTML comment
-->`` will be rendered, indicating which class is missing a visitation
function.
Outside of debug-mode, returns an empty string.
"""
if current_app.debug:
return tags.comment('no implementation in {} to render {}'.format(
self.__class__.__name__,
node.__class__.__name__, ))
return ''
示例14: visit_Link
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def visit_Link(self, node):
return tags.a(node.text, href=node.get_url())
示例15: visit_View
# 需要导入模块: from dominate import tags [as 别名]
# 或者: from dominate.tags import a [as 别名]
def visit_View(self, node):
kwargs = {}
if node.active:
kwargs['_class'] = 'active'
return tags.a(node.text,
href=node.get_url(),
title=node.text,
**kwargs)