本文整理汇总了Python中Nouvelle.tag函数的典型用法代码示例。如果您正苦于以下问题:Python tag函数的具体用法?Python tag怎么用?Python tag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tag函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_intervals
def render_intervals(self, context):
return [[
tag('a', _name=anchor, id=anchor)[
tag('h2')[ name ],
],
tag('div', _class='sensorInterval')[ ' ', self.renderInterval(length, context) ],
] for name, length, anchor in self.intervals]
示例2: renderEntry
def renderEntry(self, entry):
return [
tag('hr'),
tag('a', href="feeds.py/entry?id=%s" % entry.guid)[ entry.title ],
tag('br'),
tag('i')[ entry.feed.name ], " (", formatDate(entry.date), ") ",
]
示例3: unknownElement
def unknownElement(self, element):
# Format the element name and attributes
elementName = tag("span", _class="xml-element-name")[element.nodeName]
elementContent = [elementName]
for attr in element.attributes.values():
elementContent.extend(
[
" ",
tag("span", _class="xml-attribute-name")[attr.name],
'="',
tag("span", _class="xml-attribute-value")[attr.value],
'"',
]
)
# Now the contents...
if element.hasChildNodes():
completeElement = [
"<",
elementContent,
">",
tag("blockquote", _class="xml-element-content")[[self.parse(e) for e in element.childNodes],],
"</",
elementName,
">",
]
else:
completeElement = ["<", elementContent, "/>"]
return tag("div", _class="xml-element")[completeElement]
示例4: _render_rows
def _render_rows(self, metadata, context, result):
url, description, photo_results, owner_results = metadata
rows = []
if url:
rows.append(tag("a", href=url)[url])
if photo_results and photo_results[0][0]:
path, width, height = photo_results[0]
rows.append(Template.Photo("/images/db/" + path, width=width, height=height))
if description:
rows.append(description)
# XXX: This is kind of a hack, but it should improve usability
# between the old and new sites. Show 'edit' links if
# this is something users can edit (projects or authors)
# and if it isn't claimed exclusively already.
if (
not owner_results
and len(self.target.pathSegments) >= 2
and self.target.pathSegments[0] in ("project", "author")
):
rows.append(
tag(
"a",
href="/account/%ss/add/%s/" % (self.target.pathSegments[0], "/".join(self.target.pathSegments[1:])),
)["Edit..."]
)
result.callback(rows)
示例5: formatLine
def formatLine(self, line):
"""Format one line from the IRC log, returning a (timestamp, nick, content) tuple"""
timestamp, message = line.split(" ", 1)
timestamp = self.formatTimestamp(int(timestamp[1:]))
nick = ()
# Strip colors
message = re.sub("(\x03..|\x0F|\x02)", "", message)
if message[0] == '<':
# Normal conversation
sender, content = message[1:].split("> ", 1)
nick = [" <", self.formatNick(sender), "> "]
elif message[0] == '-':
# A system message of some sort
content = tag('span', _class="serverMessage")[ message[1:].split("- ", 1)[1] ]
elif message[0] == '[':
# A CTCP message
sender, ctcp = message[1:].split("] ", 1)
msgType, content = ctcp.split(" ", 1)
if msgType == "ACTION":
content = [self.formatNick(sender), " ", content]
else:
content = ["CTCP ", msgType, " ", content]
else:
content = message
return [tag('td', _class="timestamp")[ timestamp ],
tag('td', _class="nick")[ nick ],
tag('td', _class="content")[ content ]]
示例6: SubscriptionLink
def SubscriptionLink(url, content, icon="/images/rss.png", iconSize=(36,14)):
"""An anchor tag that can be used to link to RSS feeds.
"""
return tag('a', href = url)[
tag('img', src=icon, _class="left-icon", alt="RSS",
width=iconSize[0], height=iconSize[1]),
content,
]
示例7: renderMetadataItem
def renderMetadataItem(self, name, value, mimeType, context):
"""Render a single metadata item. If the content is short and in
a text format, we include it directly. Otherwise, just link to it.
XXX: These links don't really make sense any more, since the metadata
format changed.
"""
valueTag = tag('value', _type=mimeType)[ str(value) ]
return tag('item', _name=name)[ valueTag ]
示例8: _render_photo
def _render_photo(self, query_results, context, result):
if query_results and query_results[0][0]:
result.callback(tag('image')[
tag('url')[ '/images/db/' + query_results[0][0] ],
tag('title')[ place('title') ],
tag('link')[ place('link') ],
])
else:
result.callback([])
示例9: render_content
def render_content(self, context):
e = self.entries[context['args']['id']]
return [
tag('b')[ place('title') ],
tag('br'),
tag('i')[ e.feed.name ], " (", formatDate(e.date), ") ",
tag('hr'),
tag('p')[ e.content ],
]
示例10: renderTemperature
def renderTemperature(latest, _class='temperatures'):
degC = latest.get('average')
if degC is None:
return "No data"
degF = units.degCtoF(degC)
return tag('div', _class=_class)[
tag('span', _class='mainTemperature')[ "%.01f" % degF, xml("°"), "F" ],
tag('span', _class='temperatureSeparator')[ " / " ],
tag('span', _class='altTemperature')[ "%.01f" % degC, xml("°"), "C" ],
]
示例11: format
def format(self, f):
"""Read an IRC log from the given file-like object, returning
the corresponding formatted Nouvelle tree.
"""
return tag('table')[[
tag('tr')[
self.formatLine(line),
]
for line in f.xreadlines()
]]
示例12: renderBargraph
def renderBargraph(alpha, numBars=16):
alpha = max(0, min(1, alpha))
filledBars = int(alpha * numBars + 0.5)
bars = []
for i in xrange(numBars):
if i < filledBars:
bars.append(tag('span', _class="filledBar")[ " " ])
else:
bars.append(tag('span', _class="emptyBar")[ " " ])
return tag('span', _class="bargraph")[ bars ]
示例13: MessageHeaders
def MessageHeaders(d):
"""A factory for displaying message headers from a dictionary-like object.
If order is important (it probably is) use twisted.python.util.OrderedDict.
"""
return tag('table', _class="messageHeaders")[[
tag('tr')[
tag('td', _class='name')[ name, ":" ],
tag('td', _class='value')[ value ],
]
for name, value in d.iteritems()
]]
示例14: SectionGrid
def SectionGrid(*rows):
"""Create a grid of sections, for layouts showing a lot of small boxes
in a regular pattern.
"""
return tag('table', _class="sectionGrid")[[
tag('tr', _class="sectionGrid")[[
tag('td', _class="sectionGrid")[
cell
] for cell in row
]] for row in rows
]]
示例15: render_tabs
def render_tabs(self, context):
"""The page's tabs show all named components"""
tabs = []
for component in context['request'].site.components:
if component.name:
tabs.append(tag('li')[
xml('» '),
tag('a', href=component.url)[ component.name ],
])
return tag('ul', _class='heading')[ tabs ]