Beispiel #1
0
 def __init__(self, other=None):
     super().__init__()
     self.other = other
     self.header = tags.thead()
     self.body = tags.tbody(border='1px solid black')
     self.tag = tags.table(border='1 px solid black')[self.header, self.body]
     self.functions = [self.setStyle]
Beispiel #2
0
def genHelp_(lang, q, outfile):
    print "Attempting to generate", outfile, "... ",
    help, examples = q.getSchemeHelp()

    def exLister(context, data):
        for input, output, note in data:
            context.tag[T.tr[T.td(class_="input")[input.encode('utf-8')],
                             T.td(class_="output")[output.encode('utf-8')],
                             T.td(class_="note")[note.encode('utf-8')]]]
        return context.tag

    def processEx(e):
        if len(e) < 1:
            return

        return "Examples", T.ul[map(lambda x: T.li[x.encode('utf-8')], e)]

    def processTR(l):
        if len(l) < 1:
            return

        return T.tr[map(
            lambda x: T.td[x[0].encode('utf-8'), T.em[x[1].encode('utf-8')]],
            l)]

    def processTable(t):
        if len(t) < 1:
            return

        # If list of lists
        if type(t[0]) == type([]):
            return T.table(cellspacing="3",
                           cellpadding="4")[map(lambda x: processTR(x), t)]
        else:
            return T.table(cellspacing="3", cellpadding="4")[processTR(t)]

    def helpLister(context, data):
        ret = []
        for label, noteex, eachList in help:
            ret.append(T.h4[label.encode('utf-8')])

            for i in noteex:
                if type(i) == type("") or type(i) is unicode:
                    ret.append(T.p(class_="note")[i.encode('utf-8')])
                else:
                    ret.append(processEx(i))

            ret.append(processTable(eachList))

        return ret

    t = T.div(
        id="help"
    )[T.p(
        class_="heading"
    )["QuillPad allows users to type freely without having to follow any strict typing rules. While QuillPad predicts most words correctly, there may be a few cases where the desired word may not appear in the predicted options. Such words can be composed by entering the words in an ITRANS like scheme."],
      T.p(style="font-size: 12px")
      ["The following examples demonstrate how to write words using the ITRANS like scheme"],
      T.table(cellspacing="3", cellpadding="4")[
          T.thead[T.th["Input"], T.th["Output"], T.th],
          T.tbody(render=exLister, data=examples)], T.h3["Scheme Tables"],
      T.div(render=helpLister, data=help)]

    ts = open('help_template.html').read()
    f = open(outfile, "w")
    lang = lang[0].upper() + lang[1:]
    f.write(
        string.Template(ts).substitute(lang=lang,
                                       content=prettyXHTML(
                                           nevow.flat.flatten(t))))
    f.close()
    print "done"
Beispiel #3
0
 def __init__(self, other=None):
     self.other = other
     self.header = tags.thead()
     self.body = tags.tbody()
     self.tag = tags.table()[self.header, self.body]
     self.functions = []
Beispiel #4
0
class HTMLTableFragment(HTMLDataRenderer):
	"""A nevow renderer for result tables.
	"""
	rowsPerDivision = 25

	def _getRowFormatter(self):
		"""returns a callable returning a rendered row in HTML (as used for the
		stan xml tag).
		"""
		source = [
			"def formatRow(row, rowAttrs=''):",
			"  res = ['<tr%s>'%rowAttrs]",]
		for index, (name, _, wantsRow) in enumerate(self.formatterSeq):
			if wantsRow:
				source.append("  val = formatters[%d](row)"%index)
			else:
				source.append("  val = formatters[%d](row[%s])"%(index, repr(name)))
			source.extend([
#				"  import code;code.interact(local=locals())",
				"  if val is None:",
				"    val = 'N/A'",
				"  if isinstance(val, basestring):",
				"    serFct = escapeForHTML",
				"  else:",
				"    serFct = flatten",
				"  res.append('<td>%s</td>'%serFct(val))",])
		source.extend([
			"  res.append('</tr>')",
			"  return ''.join(res)"])

		return utils.compileFunction("\n".join(source), "formatRow", {
				"formatters": [p[1] for p in self.formatterSeq],
				"escapeForHTML": common.escapeForHTML,
				"flatten": flat.flatten})

	def render_rowSet(self, ctx, items):
		# slow, use render_tableBody
		return ctx.tag(render=rend.mapping)[self.defaultTds]

	def render_tableBody(self, ctx, data):
		"""returns HTML-rendered table rows in chunks of rowsPerDivision.

		We don't use stan here since we can concat all those tr/td much faster
		ourselves.
		"""
		rowAttrsIterator = itertools.cycle([' class="data"', ' class="data even"'])
		formatRow = self._getRowFormatter()
		rendered = []
		yield T.xml("<tbody>")
		for row in self.table:
			rendered.append(formatRow(row, rowAttrsIterator.next()))
			if len(rendered)>=self.rowsPerDivision:
				yield T.xml("\n".join(rendered))
				yield self.headCellsStan
				rendered = []
		yield T.xml("\n".join(rendered)+"\n</tbody>")

	docFactory = loaders.stan(T.div(class_="tablewrap")[
		T.div(render=T.directive("meta"), class_="warning")["_warning"],
		T.table(class_="results") [
				T.thead(render=T.directive("headCells")),
				T.tbody(render=T.directive("tableBody"))],
			T.invisible(render=T.directive("footnotes")),
		]
	)
def genHelp_(lang, q, outfile):
    print "Attempting to generate", outfile, "... ",
    help,examples = q.getSchemeHelp()

    def exLister(context, data):
        for input, output, note in data:
            context.tag [ T.tr [
                T.td (class_ = "input") [input.encode('utf-8')],
                T.td (class_ = "output") [output.encode('utf-8')],
                T.td (class_ = "note") [note.encode('utf-8')]
                ]
            ]
        return context.tag

    def processEx(e):
        if len(e) < 1:
            return

        return "Examples", T.ul [ 
                map(lambda x: T.li [x.encode('utf-8')], e) ]

    def processTR(l):
        if len(l) < 1:
            return

        return T.tr [ 
                map(lambda x: T.td [ 
                    x[0].encode('utf-8'), T.em [ x[1].encode('utf-8') ] 
                    ], l) ]

    def processTable(t):
        if len(t) < 1:
            return

        # If list of lists
        if type(t[0]) == type([]):
            return T.table(cellspacing="3", cellpadding="4") [ map(lambda x: processTR(x), t) ]
        else:
            return T.table(cellspacing="3", cellpadding="4") [ processTR(t) ]

    def helpLister(context, data):
        ret = []
        for label, noteex, eachList in help:
            ret.append(T.h4 [ label.encode('utf-8')] )

            for i in noteex:
                if type(i) == type("") or type(i) is unicode:
                    ret.append(T.p(class_="note") [ i.encode('utf-8') ])
                else:
                    ret.append(processEx(i))

            ret.append(processTable(eachList))

        return ret

    t = T.div (id="help") [ 
            T.p (class_ = "heading") [ "QuillPad allows users to type freely without having to follow any strict typing rules. While QuillPad predicts most words correctly, there may be a few cases where the desired word may not appear in the predicted options. Such words can be composed by entering the words in an ITRANS like scheme." ],
            T.p (style = "font-size: 12px") [ "The following examples demonstrate how to write words using the ITRANS like scheme" ],
            T.table (cellspacing="3", cellpadding="4") [
                T.thead [ T.th ["Input"], T.th ["Output"], T.th ],
                T.tbody(render=exLister, data=examples)
                ],
            T.h3 ["Scheme Tables"],
            T.div(render=helpLister, data=help)
            ]

    ts = open('help_template.html').read()
    f = open(outfile, "w")
    lang = lang[0].upper() + lang[1:]
    f.write(string.Template(ts).substitute(lang = lang, content = prettyXHTML(nevow.flat.flatten(t))))
    f.close()
    print "done"