Re: cheetah and jquery

[email protected]
Newsgroups gmane.comp.python.cheetah
Message-ID <[email protected]>
Thanks mike
Emacs mode for cheetah

Add this to your ~/.emacs

(define-derived-mode cheetah-mode html-mode "Cheetah"
  (make-face 'cheetah-variable-face)
  (font-lock-add-keywords
   nil
   '(
     ("\(#\(from\|else\|try\|pass\|silent\|except\|include\|set\|import\|for\|if\|end\)+\)\&gt;"
1 font-lock-type-face)
     ("\(#\(from\|for\|end\)\).*\&lt;\(for\|import\|if\|try\|in\)\&gt;"
3 font-lock-type-face)
     ("\(\$\(?:\sw\|}\|{\|\s_\)+\)" 1 font-lock-variable-name-face))
   )
  (font-lock-mode 1)
  )
(setq auto-mode-alist (cons '( "\.tmpl'" . cheetah-mode ) auto-mode-alist ))




On 4/26/09, Michael Higgins <[email protected]> wrote:
>
> I'm not sure if it's relevant for the whole list.  I use js2-mode under
> emacs for Javascript.  For Cheetah, I put emacs into whatever mode is
> closest to the kind of code I'm generating: usually html-mode.
>
> Mike
>
> On Apr 26, 2009, at 3:28 PM, [email protected] wrote:
>
> Mike
>> What editor do you use for cheetah?
>> and what editor do you use for javascript
>> thanks
>> http://youfindr.com/s?src=definition&q=javascript%20ide
>>
>>
>> On 4/25/09, Michael Higgins <[email protected]> wrote: Personally,
>> I'd recommend against doing a lot of Javascript code generation inside a
>> Cheetah template.  Instead, keep your Javascript in separate files.  There
>> are a couple of reasons for this:
>>
>> * Editing convenience.  You can use an editor mode optimized for
>> Javascript to edit your Javascript, and optimized for Cheetah or HTML or
>> Python to edit your other code.  Also, it's easier to write unit tests and
>> to use tools like JSLint if things are separated out.
>>
>> * Avoids code generation bugs.  When you use a templating system to
>> generate source code, debugging the generated source code can be difficult
>> because bugs can live both in the template that generated the source code,
>> and the source code itself.  The simplest example of such bugs is quoting
>> problems: you try to say something like:
>>
>> var foo = "$myVar";
>>
>> and things seem to work fine, until $myVar evaluates to something like:
>>
>> He said "hello, world!"
>>
>> and then the generated code reads
>>
>> var foo = "He said "hello world!"";
>>
>> which is not valid Javascript!
>>
>> * Encourages modularity.  It's a lot easier to think about your Javascript
>> objects if you keep them structurally split out from your Cheetah and Python
>> objects.
>>
>> * Encourages secure code practices.  If you're generating Javascript in a
>> template, you're going to be tempted to just shove values from a database or
>> from user input right into the code.  This can be unsafe if you're not
>> careful --- a clever user could inject Javascript code into your system if
>> you don't do the right clean-up.  Separating things out a bit more makes it
>> clearer where and when that kind of clean-up needs to happen.
>>
>> * And, yeah, it avoids the $ collision problem.  (Which happens with a ton
>> of Javascript toolkits, not just JQuery.)
>>
>> Obviously, you will need to do a little Javascript in the template, but
>> this can usually be minimized to a couple of functions or initialization
>> routines that simply call out to the real code.
>>
>> So, to actually answer your question, there are two ways I typically pass
>> values for variables.  One is to use AJAX, so the value is sent as XML or
>> JSON after the page is loaded.  The other is to create a hidden form element
>> and store the value as URL-encoded JSON in the value of the form, which the
>> Javascript can then fetch and decode when the page is loaded.
>>
>> I find that doing it that way keeps my interfaces clearer, makes it more
>> obvious where values need to be cleaned up, and makes it easier to edit the
>> code.
>>
>> I'm sure other people have other "best practices" as well.
>>
>> Mike Higgins
>> CTO, Rhiza Labs
>>
>> P.S.  This is not to say that template-driven program code generation is a
>> bad thing: used well, it's extremely powerful.  But I don't think it's the
>> right approach for everyday chores.
>>
>>
>> On Apr 25, 2009, at 6:36 AM, [email protected] wrote:
>>
>> Cheetah doesnt play well along with jquery
>> as Jquery uses $ to find variables or ids
>> But since cheetah doesnt find the variables in the search list it throws
>> an error
>>
>> But since we need to fill some javascript with variables from cheetah we
>> cannot do
>>
>> #raw
>> Jquery code
>> #end raw
>>
>> How do you guys deal with this situation
>> thanks
>>
>> --
>> Bidegg worlds best auction site
>> http://bidegg.com
>>
>> ------------------------------------------------------------------------------
>> Crystal Reports &#45; New Free Runtime and 30 Day Trial
>> Check out the new simplified licensign option that enables unlimited
>> royalty&#45;free distribution of the report engine for externally facing
>> server and web deployment.
>>
>> http://p.sf.net/sfu/businessobjects_______________________________________________
>> Cheetahtemplate-discuss mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
>>
>>
>>
>>
>> --
>> Bidegg worlds best auction site
>> http://bidegg.com
>>
>
>


-- 
Bidegg worlds best auction site
http://bidegg.com

------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects

_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.