本文整理汇总了Python中tractags.api.TagEngine.name_details方法的典型用法代码示例。如果您正苦于以下问题:Python TagEngine.name_details方法的具体用法?Python TagEngine.name_details怎么用?Python TagEngine.name_details使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tractags.api.TagEngine
的用法示例。
在下文中一共展示了TagEngine.name_details方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _page_titles
# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import name_details [as 别名]
def _page_titles(self, pages):
""" Extract page titles, if possible. """
titles = {}
tagspace = TagEngine(self.env).tagspace.wiki
for pagename in pages:
href, link, title = tagspace.name_details(pagename)
titles[pagename] = title
return titles
示例2: render_listtagged
# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import name_details [as 别名]
def render_listtagged(self, req, *tags, **kwargs):
""" List tagged objects. Optionally accepts a list of tags to match
against. The special tag '''. (dot)''' inserts the current Wiki page name.
`[[ListTagged(<tag>, ...)]]`
||'''Argument'''||'''Description'''||
||`tagspace=<tagspace>`||Specify the tagspace the macro should operate on.||
||`tagspaces=(<tagspace>,...)`||Specify a set of tagspaces the macro should operate on.||
||`operation=intersection|union`||The set operation to perform on the discovered objects.||
||`showheadings=true|false`||List objects under the tagspace they occur in.||
"""
if 'tagspace' in kwargs:
tagspaces = [kwargs.get('tagspace', None)]
else:
tagspaces = kwargs.get('tagspaces', '') or \
list(TagEngine(self.env).tagspaces)
showheadings = kwargs.get('showheadings', 'false')
operation = kwargs.get('operation', 'intersection')
if operation not in ('union', 'intersection'):
raise TracError("Invalid tag set operation '%s'" % operation)
engine = TagEngine(self.env)
page_name = req.hdf.get('wiki.page_name')
if page_name:
tags = [tag == '.' and page_name or tag for tag in tags]
taginfo = {}
out = StringIO()
out.write('<ul class="listtagged">')
# Cull empty names
tagged_names = [(tagspace, names) for tagspace, names in
engine.get_tagged_names(tags=tags, tagspaces=tagspaces,
operation=operation, detailed=True).iteritems()
if names]
for tagspace, tagspace_names in sorted(tagged_names):
if showheadings == 'true':
out.write('<lh>%s tags</lh>' % tagspace)
for name, tags in sorted(tagspace_names.iteritems()):
if tagspace == 'wiki' and unicode(name).startswith('tags/'): continue
tags = sorted(tags)
taginfo = self._tag_details(taginfo, tags)
href, link, title = engine.name_details(tagspace, name)
htitle = wiki_to_oneliner(title, self.env)
name_tags = ['<a href="%s" title="%s">%s</a>'
% (taginfo[tag][0], taginfo[tag][1], tag)
for tag in tags]
if not name_tags:
name_tags = ''
else:
name_tags = ' (' + ', '.join(sorted(name_tags)) + ')'
out.write('<li>%s %s%s</li>\n' %
(link, htitle, name_tags))
out.write('</ul>')
return out.getvalue()
示例3: getDetails
# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import name_details [as 别名]
def getDetails(self, req, hack):
""" Fetch hack details. Returns dict with name, dependencies and
description. """
from tractags.api import TagEngine
wikitags = TagEngine(self.env).tagspace.wiki
tags = wikitags.get_tags(hack)
types = self.getTypes()
hacks = wikitags.get_tagged_names(types)
dependencies = hacks.intersection(tags)
href, htmllink, description = wikitags.name_details(hack)
return {"name": hack, "dependencies": tuple(dependencies), "description": description}
示例4: render_listtagged
# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import name_details [as 别名]
def render_listtagged(self, req, *tags, **kwargs):
""" List tagged objects. Takes a list of tags to match against.
The special tag '.' inserts the current Wiki page name.
Optional keyword arguments are tagspace=wiki,
tagspaces=(wiki, title, ...) and showheadings=true.
By default displays the intersection of objects matching each tag.
By passing operation=union this can be modified to display
the union of objects matching each tag.
"""
if 'tagspace' in kwargs:
tagspaces = [kwargs.get('tagspace', None)]
else:
tagspaces = kwargs.get('tagspaces', '') or \
list(TagEngine(self.env).tagspaces)
showheadings = kwargs.get('showheadings', 'false')
operation = kwargs.get('operation', 'intersection')
if operation not in ('union', 'intersection'):
raise TracError("Invalid tag set operation '%s'" % operation)
engine = TagEngine(self.env)
page_name = req.hdf.get('wiki.page_name')
if page_name:
tags = [tag == '.' and page_name or tag for tag in tags]
taginfo = {}
out = StringIO()
out.write('<ul class="listtagged">')
for tagspace, tagspace_names in sorted(engine.get_tagged_names(tags=tags, tagspaces=tagspaces, operation=operation, detailed=True).iteritems()):
if showheadings == 'true':
out.write('<lh>%s tags</lh>' % tagspace)
for name, tags in sorted(tagspace_names.iteritems()):
if tagspace == 'wiki' and unicode(name).startswith('tags/'): continue
tags = sorted(tags)
taginfo = self._tag_details(taginfo, tags)
href, link, title = engine.name_details(tagspace, name)
htitle = wiki_to_oneliner(title, self.env)
name_tags = ['<a href="%s" title="%s">%s</a>'
% (taginfo[tag][0], taginfo[tag][1], tag)
for tag in tags]
if not name_tags:
name_tags = ''
else:
name_tags = ' (' + ', '.join(sorted(name_tags)) + ')'
out.write('<li>%s %s%s</li>\n' %
(link, htitle, name_tags))
out.write('</ul>')
return out.getvalue()