Using pasteScript with complex data

7 views
Skip to first unread message

cyril giraudon

unread,
Mar 9, 2009, 12:02:35 PM3/9/09
to Paste Users
Hello,

I'd like to you PasteScript for a project resquesting a template
engine. I think of PasteScript for two reasons :
- The ability to create "template driven" file systems
( +directory_name+/+synthax+ )
- The Cheetah integration.

However, Cheetah can handle very complex objects and can use objects's
attributes : $father.age for instance.

Is it possible to use PasteScript from python code with complex in
order to profit from the two worlds :
- Paste file templating system;
- Cheetah file templating system.

If not, is there any python product which can do that ?

Thanks a lot,

Cyril.

Ian Bicking

unread,
Mar 9, 2009, 1:28:14 PM3/9/09
to cyril giraudon, Paste Users
On Mon, Mar 9, 2009 at 11:02 AM, cyril giraudon
<cyril.g...@gmail.com> wrote:
>
> Hello,
>
> I'd like to you PasteScript for a project resquesting a template
> engine. I think of PasteScript for two reasons :
>  - The ability to create "template driven" file systems
> ( +directory_name+/+synthax+ )
>  - The Cheetah integration.
>
> However, Cheetah can handle very complex objects and can use objects's
> attributes : $father.age for instance.

Because of installation problems, Paste now uses Tempita instead of
Cheetah. Tempita is also able to run arbitrary Python, so you can
have arbitrarily complex substitution.

> Is it possible to use PasteScript from python code with complex in
> order to profit from the two worlds :
>  - Paste file templating system;
>  - Cheetah file templating system.
>
> If not, is there any python product which can do that ?

You mean, invoke what Paste Script does without using "paster create"?
Yes, probably you could simply use paste.script.copydir, which does
most of the work.

--
Ian Bicking | http://blog.ianbicking.org

cyril giraudon

unread,
Mar 9, 2009, 2:09:48 PM3/9/09
to Paste Users
Thanks Ian for your answer,

But imagine a python Person class :

class Person(object):
def __init__(self, name, father):
self.name = name
# father is a person
self.father = father

dad = Person("joe", None)
son = Person("nick", dad)

and the fact that the var class in templates is very simple and is
composed only of strings.

Therefore, I don't see how to use Tempita python blocks or how to use
{{son.father.name}} structure in a Tempita template from a
paste.script.copydir invocation ? Parameters "var" must be strings.
From copydir, I'd like to use son as parameters.

Finaly, is there any restriction to use Tempita to generate python, C+
+, Java or SQL ?


Thanks a lot.

Cyril.


Ian Bicking

unread,
Mar 9, 2009, 2:34:43 PM3/9/09
to cyril giraudon, Paste Users
On Mon, Mar 9, 2009 at 1:09 PM, cyril giraudon <cyril.g...@gmail.com> wrote:
> Thanks Ian for your answer,
>
> But imagine a python Person class :
>
> class Person(object):
>  def __init__(self, name, father):
>    self.name = name
>    # father is a person
>    self.father = father
>
> dad = Person("joe", None)
> son = Person("nick", dad)
>
> and the fact that the var class in templates is very simple and is
> composed only of strings.

That's all that you can input from paster create. You can convert
those values or put in new values in your Template class. Look in
paste.script.templates.Template.check_vars -- override that method to
add or change values.

> Therefore, I don't see how to use Tempita python blocks or how to use
> {{son.father.name}} structure in a Tempita template from a
> paste.script.copydir invocation ? Parameters "var" must be strings.
> From copydir, I'd like to use son as parameters.
>
> Finaly, is there any restriction to use Tempita to generate python, C+
> +, Java or SQL ?

Nope, it just creates text files for any kind of source.

cyril giraudon

unread,
Mar 11, 2009, 5:13:35 AM3/11/09
to Paste Users
>
> That's all that you can input from paster create. You can convert
> those values or put in new values in your Template class. Look in
> paste.script.templates.Template.check_vars -- override that method to
> add or change values.
>
Ok, I will try the way.

Thanks again,

Cyril.
Reply all
Reply to author
Forward
0 new messages