Re: [Templates] setting input checked

2014-12-07 Thread Kiss Gabor (Bitman)
 Yea, I had already tried the single  and it does not work.

Unfortunately there are no arithmetic and bitwise operators in TT.
But in theory the problem can be solved with comparisons only. :-)

Let's assume that flags can be at most 255. Then this logical expression
is equal to flags0x08:

   flags = 248 ||
flags  240  flags = 232 ||
flags  224  flags = 216 ||
flags  208  flags = 200 ||
flags  192  flags = 184 ||
flags  176  flags = 168 ||
flags  160  flags = 152 ||
flags  144  flags = 136 ||
flags  128  flags = 120 ||
flags  112  flags = 104 ||
flags   96  flags =  88 ||
flags   80  flags =  72 ||
flags   64  flags =  56 ||
flags   48  flags =  40 ||
flags   32  flags =  24 ||
flags   16  flags =   8

Gabor

___
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates


[Templates] How to write a macro that changes a scalar variable

2014-10-21 Thread Kiss Gabor (Bitman)
Dear folks,

How could I define a macro that modifies a scalar variable
got in param list?

This obviously does not work:

/tmp$ cat macrotest
[% MACRO seven(param) BLOCK %]
 [% SET param = '7' %]
! var inside = [% var %] param inside = [% param %]
[% END %]
! starting...
[% SET var = 3 %]
! var before = [% var %]
[% seven(var) %]
! var after = [% var %] (wanted 7 here)
/tmp$ tpage macrotest 

! starting...

! var before = 3

 
! var inside = 3 param inside = 7

! var after = 3 (wanted 7 here)
/tmp$ 


I do understand what happens but I have no idea how to modify
the code. Actually I would need a macro that acts like a subroutine
and returns a scalar value but I guess this is not possible.
Therefore I tried to modify named parameters but they seems to be
localised too.

Any hint? (Except usage of Perl subroutines.)

Thanks

Gabor

___
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates


Re: [Templates] How to write a macro that changes a scalar variable

2014-10-21 Thread Kiss Gabor (Bitman)
 You can return a scalar (but not an array or hash ref) in
 the macro's output, and capture it in a variable using SET.
 
 
 $ tpage
 [% MACRO seven BLOCK; 7; END %]
 ! starting...
 [% SET var = 3 %]
 ! var before = [% var %]
 [% SET var = seven() %]
 ! var after = [% var %] (wanted 7 here)
 [%%]
 
 ! starting...
 
 ! var before = 3
 
 ! var after = 7 (wanted 7 here)

Cl! :-)
Many thanks.

Gabor

___
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates


Re: [Templates] Can a template tell if it has been PROCESSed or INCLUDEd?

2014-09-25 Thread Kiss Gabor (Bitman)
 Any suggestions?

Just define a global variable in the outermost file:
[% SET processed = 1 %]
In the included file you will see this scalar unintialized.

(This version is not perfect because cannot detect INCLUDE+PROCESS
chains. but you can develop is necessary. :-)

Gabor

___
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates


Re: [Templates] Can a template tell if it has been PROCESSed or INCLUDEd?

2014-09-25 Thread Kiss Gabor (Bitman)
 This won't work.  That variable will be there in an INCLUDE as well,
 because, The 'INCLUDE' directive localises (i.e. copies) all variables
 before processing the template.[1]  It doesn't give you a clean slate.

E...
You are right. I don't know how I thought. :-(

Gabor

___
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates


[Templates] Part of output into variable

2014-09-24 Thread Kiss Gabor (Bitman)
Dear folks,

Is it possible to catch output of a BLOCK and to assign
it to a scalar variable for later use?
(And the same but without writing Perl code? :-)
Any hints will be appreciated.

Gabor

___
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates


Re: [Templates] Part of output into variable

2014-09-24 Thread Kiss Gabor (Bitman)
 Is it possible to catch output of a BLOCK and to assign
 it to a scalar variable for later use?
 (And the same but without writing Perl code? :-)

Oh! I got it.
After google-ing an hour or so:

http://template-toolkit.org/docs/manual/Directives.html#section_BLOCK
 You can use an anonymous BLOCK to capture the output of a template fragment.

Sorry for the line noise.

Gabor

___
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates


Re: [Templates] Why doesn't this work: INSERT in PROCESS block.

2014-01-28 Thread Kiss Gabor (Bitman)
 [% PROCESS header.inc
 Title = Instant Trees -- Just add water
 Desc = Sherwood's Forests advice on getting your own forest quickly.
 [% INSERT last-modified-gmt.inc %]
 %]
 
 When I run ttree it fusses:
 
  ! file error - parse error - Solutions/Instant_Forest.tt2 line 1-5:
 unexpected token (%)
   [% PROCESS header.inc
 Title = Instant Trees -- Just add water
 Desc = Sherwood's Forests advice on getting your own forest quickly.
 Last_Major_Modification = Tue 28 Jan 2014 20:23:42 MST
 [% INSERT last-modified-gmt.inc %]

I guess nesting is not allowed. The inner %] closed the outer [%.
Outer %] caused syntax error in parser.
Try to omit inner [% %].

Gabor

___
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates


Re: [Templates] Newbie question: include all files

2013-06-05 Thread Kiss Gabor (Bitman)
  After one and half document reading and web search I can't figure
  out how to include all files from a directory relative to the
  main template.
 
 This may help you find the current directory for the current template
 that you are in:
 

 http://mail.template-toolkit.org/pipermail/templates/2007-December/009881.html

Dear Larry,

Thanks for your answer.

Unfortunately template.name gives a path not absolute
but relative to the one of members of INCLUDE_PATH.

Meanwhile the [% USE dir = Directory(...) %] construction
works as usual open() system call. It requires absolute
path or relative to the current working directory.

The problems are:
- CWD may vary and there is no way to figure out runtime.
- No way to determine what are members of INCLUDE_PATH
  and which one contains the root template.

At least according to my knowledge. :-)
(Of course adding PERL code can solve anything. I wonder
is there any way to avoid this.)

Gabor
-- 
E-mail = m-mail * c-mail ^ 2

___
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates


[Templates] Newbie question: include all files

2013-06-04 Thread Kiss Gabor (Bitman)
Dear folks,

After one and half document reading and web search I can't figure
out how to include all files from a directory relative to the
main template.

Directory structure is like

/usr/local/lib/templates/foo/version1/-+-main.tt
   |
   +-features/-+-bar
   |
   +-baz

Template processor is called with INCLUDE_PATH=/usr/local/lib/templates,
and the template to process is called as foo/version1/main.tt.
I should find a way to include all files under features
directory but their number and name is not known in advance.

With hardcoded absolute paths in main.tt I could do it:

[% USE dir = Directory('/usr/local/lib/templates/foo/version1/features') %]
[% FOREACH file = dir.files %]
[% PROCESS /usr/local/lib/templates/foo/version1/features/$file.name %]
[% END %]

But this is not acceptable. Include path most relative to the directory
containing main.tt not depending on its absolute location.

Any hint will be appreciated. (As well as strictly checked. :)

Gabor

___
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates


Re: [Templates] Some virtual methods do not work

2013-04-09 Thread Kiss Gabor (Bitman)
 What version of TT are you using? What does the VMethods manual page say
 on your machine? trim only became a VMethod in the latest release, for
 example. Before that it is [only] a filter.

Oh! What a lamer am I! :-)

It is installed from libtemplate-perl 2.22-0.1 Debian package.
However Template(3pm) says
Template Toolkit version 2.20_1, released April 2009.

Sorry for the line noise.

Gabor

___
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates