Re: Does Cheetah count line numbers its written?
Nate Reid <[email protected]> Wed, 9 Mar 2011 11:23:04 -0800
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <[email protected]> |
--===============0464152485589673211== Content-Type: multipart/alternative; boundary="_9fbdc3ce-b7a6-4aa6-bcb0-259dabe036b2_" --_9fbdc3ce-b7a6-4aa6-bcb0-259dabe036b2_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks James=2C I'll give this a try and thanks for taking the time to writ= e this up. Cheers -Nate Date: Wed=2C 9 Mar 2011 01:03:20 -0500 Subject: Re: [Cheetahtemplate-discuss] Does Cheetah count line numbers its = written? From: [email protected] To: [email protected] CC: [email protected] This is a bit ugly but it may work for you: #!/usr/bin/env python import Cheetah.Compiler import Cheetah.Template class MyAutoMethodCompiler(Cheetah.Compiler.AutoMethodCompiler): def addPlaceholder(self=2C expr=2C filterArgs=2C rawPlaceholder=2C cacheTokenParts=2C lineCol=2C silentMode=3DFalse): if rawPlaceholder =3D=3D u'$LINE': self.addFilteredChunk(repr(unicode(lineCol[0]))=2C filterArgs=2C rawPlaceholder=2C lineCol=3DlineCol) else: super(MyAutoMethodCompiler=2C self).addPlaceholder( expr=2C filterArgs=2C rawPlaceholder=2C cacheTokenParts=2C lineCol=2C silentMode=3DsilentMode) class MyAutoClassCompiler(Cheetah.Compiler.AutoClassCompiler): methodCompilerClass =3D MyAutoMethodCompiler class MyCompiler(Cheetah.Compiler.Compiler): classCompilerClass =3D MyAutoClassCompiler tclass =3D Cheetah.Template.Template.compile('''\ This is line $LINE Hello=2C $name! And this is line $LINE'''=2C compilerClass=3DMyCompiler) print tclass(searchList=3D[{"name": "Nate"}]) --=20 James Abbatiello On Tue=2C Mar 8=2C 2011 at 1:45 PM=2C Nate Reid <[email protected]> wrote= : I'm writing a source generator using Cheetah templates for C++ and would li= ke to add #line directives into the generated source. Without delving deep= into the Cheetah source code=2C I was wondering if anyone on the list knew= if Cheetah keeps track of how many lines are written so I can easily query= the current line number in the template and use that in the template outpu= t itself for inserting #line directives into the generated source code. Thanks! -Nate =20 ---------------------------------------------------------------------------= --- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity=2C details its effect on application quality=2C and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d _______________________________________________ Cheetahtemplate-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss = --_9fbdc3ce-b7a6-4aa6-bcb0-259dabe036b2_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <html> <head> <style><!-- .hmmessage P { margin:0px=3B padding:0px } body.hmmessage { font-size: 10pt=3B font-family:Tahoma } --></style> </head> <body class=3D'hmmessage'> Thanks James=2C I'll give this a try and thanks for taking the time to writ= e this up.<br>Cheers<br>-Nate<br><br><hr id=3D"stopSpelling">Date: Wed=2C 9= Mar 2011 01:03:20 -0500<br>Subject: Re: [Cheetahtemplate-discuss] Does Che= etah count line numbers its written?<br>From: [email protected]<br>To: gnatt= [email protected]<br>CC: [email protected]<br><br>= This is a bit ugly but it may work for you:<br><br>#!/usr/bin/env python<br= >import Cheetah.Compiler<br>import Cheetah.Template<br><br>class MyAutoMeth= odCompiler(Cheetah.Compiler.AutoMethodCompiler):<br> =3B =3B = =3B def addPlaceholder(self=2C expr=2C filterArgs=2C rawPlaceholder=2C<br>  =3B =3B =3B =3B =3B =3B =3B =3B =3B&nb= sp=3B =3B =3B =3B =3B =3B =3B =3B =3B = =3B =3B =3B =3B cacheTokenParts=2C lineCol=2C<br> =3B = =3B =3B =3B =3B =3B =3B =3B =3B =3B =3B=  =3B =3B =3B =3B =3B =3B =3B =3B =3B&nb= sp=3B =3B silentMode=3DFalse):<br> =3B =3B =3B =3B = =3B =3B =3B if rawPlaceholder =3D=3D u'$LINE':<br> =3B =3B&= nbsp=3B =3B =3B =3B =3B =3B =3B =3B =3B sel= f.addFilteredChunk(repr(unicode(lineCol[0]))=2C<br> =3B =3B =3B=  =3B =3B =3B =3B =3B =3B =3B =3B =3B&nb= sp=3B =3B =3B =3B =3B =3B =3B =3B =3B = =3B =3B =3B =3B =3B =3B =3B =3B =3B =3B=  =3B =3B filterArgs=2C<br>  =3B =3B =3B =3B =3B =3B =3B =3B =3B&nb= sp=3B =3B =3B =3B =3B =3B =3B =3B =3B = =3B =3B =3B =3B =3B =3B =3B =3B =3B =3B=  =3B =3B =3B =3B =3B rawPlaceholder=2C<br> =3B = =3B =3B =3B =3B =3B =3B =3B =3B =3B =3B=  =3B =3B =3B =3B =3B =3B =3B =3B =3B&nb= sp=3B =3B =3B =3B =3B =3B =3B =3B =3B = =3B =3B =3B =3B lineCol=3DlineCol)<br> =3B =3B =3B&= nbsp=3B =3B =3B =3B else:<br> =3B =3B =3B =3B&n= bsp=3B =3B =3B =3B =3B =3B =3B super(MyAutoMethodCo= mpiler=2C self).addPlaceholder(<br> =3B =3B =3B =3B =3B=  =3B =3B =3B =3B =3B =3B =3B =3B =3B&nb= sp=3B expr=2C filterArgs=2C rawPlaceholder=2C<br>  =3B =3B =3B =3B =3B =3B =3B =3B =3B&nb= sp=3B =3B =3B =3B =3B =3B cacheTokenParts=2C lineCol=2C= <br> =3B =3B =3B =3B =3B =3B =3B =3B = =3B =3B =3B =3B =3B =3B =3B silentMode=3DsilentMode= )<br><br><br>class MyAutoClassCompiler(Cheetah.Compiler.AutoClassCompiler):= <br> =3B =3B =3B methodCompilerClass =3D MyAutoMethodCompiler<b= r><br><br>class MyCompiler(Cheetah.Compiler.Compiler):<br>  =3B =3B =3B classCompilerClass =3D MyAutoClassCompiler<br><br>= <br>tclass =3D Cheetah.Template.Template.compile('''\<br>This is line $LINE= <br>Hello=2C $name!<br>And this is line $LINE'''=2C compilerClass=3DMyCompi= ler)<br> print tclass(searchList=3D[{"name": "Nate"}])<br><br><br>-- <br>James Abbat= iello<br><br><br><div class=3D"ecxgmail_quote">On Tue=2C Mar 8=2C 2011 at 1= :45 PM=2C Nate Reid <span dir=3D"ltr"><=3B<a href=3D"mailto:gnatty7@hotma= il.com">[email protected]</a>>=3B</span> wrote:<br> <blockquote class=3D"ecxgmail_quote" style=3D"border-left: 1px solid rgb(20= 4=2C 204=2C 204)=3B padding-left: 1ex=3B"> <div> I'm writing a source generator using Cheetah templates for C++ and would li= ke to add #line directives into the generated source. =3B Without delvi= ng deep into the Cheetah source code=2C I was wondering if anyone on the li= st knew if Cheetah keeps track of how many lines are written so I can easil= y query the current line number in the template and use that in the templat= e output itself for inserting #line directives into the generated source co= de.<br> Thanks!<br>-Nate<br> </div> <br>-----------------------------------------------------------------------= -------<br> What You Don't Know About Data Connectivity CAN Hurt You<br> This paper provides an overview of data connectivity=2C details<br> its effect on application quality=2C and explores various alternative<br> solutions. <a href=3D"http://p.sf.net/sfu/progress-d2d" target=3D"_blank">h= ttp://p.sf.net/sfu/progress-d2d</a><br>____________________________________= ___________<br> Cheetahtemplate-discuss mailing list<br> <a href=3D"mailto:[email protected]">Cheetahtem= [email protected]</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-dis= cuss" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/cheeta= htemplate-discuss</a><br> <br></blockquote></div><br> </body> </html>= --_9fbdc3ce-b7a6-4aa6-bcb0-259dabe036b2_-- --===============0464152485589673211== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d --===============0464152485589673211== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Cheetahtemplate-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss --===============0464152485589673211==--