Ejemplo n.º 1
0
 def test_name_and_src_w_frag_template(self):
     name = "named"
     src = "template.html#label"
     t = Template(DEFAULT_DIR, name, src)
     data = dict(title="A Title", param="A Param")
     r = "<h1>A Title</h1><p>some A Param text</p>"
     self.assertEqual(r, t.evoque(**data))
    def appendUtterances(self, utterances):
        """
        Adds utterances

        ...

        Parameters
        ----------
        utterances :
        """
        t = Template(os.path.abspath("html"), "PoioIlUtterances.html")
        text = t.evoque(vars(), quoting="str")
        self.append(text)
Ejemplo n.º 3
0
 def test_non_empty_default_collection(self):
     name = 'template.html'
     t = Template(DEFAULT_DIR, name)
     self.failUnless(isinstance(t.collection.domain, Domain))
     self.failUnless(t.collection.domain.collections[""] is t.collection)
     self.failUnless(t is t.collection.get_template(name))
     self.failUnless(t is t.collection.domain.get_template(name, 
             collection=t.collection))
     self.assertRaises((ValueError,), Template, t.collection.domain, name)
Ejemplo n.º 4
0
 def test_direct_implied_domain_collection(self):
     collection_name = "mycollection"
     tc = Collection(None, collection_name, DEFAULT_DIR)
     td = tc.domain
     name = 'template.html'
     t = Template(tc.domain, name)
     self.failUnless(tc is t.collection)
     self.failUnless(tc is td.get_collection())
     self.assertEqual(tc.name, collection_name)
Ejemplo n.º 5
0
 def get_template(self,
                  name="",
                  src=None,
                  raw=None,
                  data=None,
                  quoting=None,
                  input_encoding=None,
                  filters=None):
     """ () -> Template : get / load (if file-based) a template 
     """
     try:
         t = self.cache.get(name)
         if t.is_modified_since():
             t.refresh()
     except KeyError:
         t = Template(self.domain, name, src, self, raw, data, False,
                      quoting, input_encoding, filters)
         self.cache.set(name, t)
     return t
Ejemplo n.º 6
0
 def set_template(self,
                  name,
                  src,
                  raw=None,
                  data=None,
                  from_string=True,
                  quoting=None,
                  input_encoding=None,
                  filters=None):
     """ () -> None : typically used to set a template from a string 
     """
     try:
         t = self.cache.get(name)
         raise ValueError("Collection [%s] already has a template named "
                          "[%s]" % (self.name, name))
     except KeyError:
         t = Template(self.domain, name, src, self, raw, data, from_string,
                      quoting, input_encoding, filters)
         self.cache.set(name, t)
Ejemplo n.º 7
0
 def test_empty_default_template(self):
     name = ""
     src = "template.html"
     t = Template(DEFAULT_DIR, name, src)
     self.failUnless(t is t.collection.get_template())
Ejemplo n.º 8
0
 def test_evoque_nested_direct(self):
     name = "template.html#label"
     t = Template(DEFAULT_DIR, name)
     r = "<h1>A Title</h1><p>some A Param text</p>"
     self.assertEqual(r, t.evoque(title="A Title", param="A Param"))
Ejemplo n.º 9
0
 def test_from_string(self):
     src = "<h1>${title}</h1><p>some ${param} text</p>"
     data = dict(title="A Title", param="A Param")
     r = "<h1>A Title</h1><p>some A Param text</p>"
     t = Template(DEFAULT_DIR, "fromstr", src=src, from_string=True)
     self.assertEqual(r, t.evoque(**data))
    def appendUtterance(self, id,  utterance, ilElements, translations):
        """
        Adds a utterance

        ...

        Parameters
        ----------
        id :
        utterance :
        ilElements :
        translations :
        """
        t = Template(os.path.abspath("html"), "PoioIlUtterance.html")
        countwords = len(ilElements)
        text = t.evoque(vars(), quoting="str")
        self.append(text)

        return
    
        c = self.textCursor()
        c.movePosition(QtGui.QTextCursor.End)
        
        # create table
        table = c.insertTable(4, countwords*2+1)
        table.mergeCells(0, 1, 1, countwords*2)
        format = table.format()
        format.setBorder(0)
        table.setFormat(format)
        
        # add utterace
        utteranceCell = table.cellAt(0, 0)
        utteranceCell.firstCursorPosition().insertText(id)
        format = utteranceCell.format()
        format.setFontCapitalization(QtGui.QFont.SmallCaps)
        format.setFontWeight(QtGui.QFont.Bold)
        format.setAnchorNames([id])
        utteranceCell.setFormat(format)
        
        utteranceCell = table.cellAt(0, 1)
        utteranceCell.firstCursorPosition().insertText(utterance)
        format = utteranceCell.format()
        format.setFontWeight(QtGui.QFont.Bold)
        format.setAnchorNames([id])
        utteranceCell.setFormat(format)
        
        elementCell = table.cellAt(1, 0)
        elementCell.firstCursorPosition().insertText("words")
        format = elementCell.format()
        format.setFontCapitalization(QtGui.QFont.SmallCaps)
        elementCell.setFormat(format)
        elementCell = table.cellAt(2, 0)
        elementCell.firstCursorPosition().insertText("morphemes")
        format = elementCell.format()
        format.setFontCapitalization(QtGui.QFont.SmallCaps)
        elementCell.setFormat(format)
        elementCell = table.cellAt(3, 0)
        elementCell.firstCursorPosition().insertText("glosses")
        format = elementCell.format()
        format.setFontCapitalization(QtGui.QFont.SmallCaps)
        elementCell.setFormat(format)
        
        for i in range(countwords):
            # add word
            elementCell = table.cellAt(1, i*2+1)
            format = elementCell.format()
            format.setAnchorNames([ilElements[i][0]])
            elementCell.setFormat(format)
            
            elementCell = table.cellAt(1, i*2+2)
            elementCell.firstCursorPosition().insertText(ilElements[i][1])
            if ilElements[i][4]:
                format = elementCell.format()
                format.setForeground(QGui.QBrush(0,1,0))
                elementCell.setFormat(format)
        
            # add morphemes
            elementCell = table.cellAt(2, i*2+1)
            format = elementCell.format()
            format.setAnchorNames([ilElements[i][0]])
            elementCell.setFormat(format)
            
            elementCell = table.cellAt(2, i*2+2)
            elementCell.firstCursorPosition().insertText(ilElements[i][2])
            if ilElements[i][4]:
                format = elementCell.format()
                format.setForeground(QGui.QBrush(0,1,0))
                elementCell.setFormat(format)

            # add glosses
            elementCell = table.cellAt(3, i*2+1)
            format = elementCell.format()
            format.setAnchorNames([ilElements[i][0]])
            elementCell.setFormat(format)
            
            elementCell = table.cellAt(3, i*2+2)
            elementCell.firstCursorPosition().insertText(ilElements[i][3])
            if ilElements[i][4]:
                format = elementCell.format()
                format.setForeground(QGui.QBrush(0,1,0))
                elementCell.setFormat(format)
Ejemplo n.º 11
0
def evoque_test(N):
	from evoque.template import Template
	t = Template(os.path.sep.join([os.getcwd(), "."]), "bench_evoque.html", quoting="str")
	for _ in range(N):
		(t.evoque({ 'items': items, 'name': "Evoque" }))