Re: [PHPTAL] use of 'structure' with custom PHPTAL modifier

2013-09-09 Thread Kornel Lesiński
On Tue, 03 Sep 2013 22:27:56 +0100, Chris Young chris.wisef...@gmail.com  
wrote:



*Invalid TALES path: 'structure /some/path', expected 'structure
/some/path' to be variable name*
Is there something simple I'm missing? I understand I *could* do:

span tal:content=structure abbrev: /some/path /

and change the function accordingly, which isn't really that bad, but I'm
curious as to if my original idea should work?


Bas is right, phptal_tales expects paths, but not the structure keyword.

What you get from phptal_tales is unescaped data - equivalent of  
structure already. It's just that complete result of all modifiers is  
going to be escaped afterwards.


I see what you're trying to do, and some ability do disable escaping from  
within modifiers would be useful, but unfortunately there's no API for it  
currently.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


[PHPTAL] Code Generator refactoring

2013-01-08 Thread Kornel Lesiński


A while ago I thought about creating PHP *optimizer*. The goal is to make  
PHPTAL-generated code as efficient as hand-written code, e.g. merge  
adjacent strings and echo statements (implemented) and avoid pushState()  
calls or maintenance of repeat/xx/key variables when those features are  
not used (not implemented yet).


To achieve this I've refactored PHPTAL's code generator to create sort-of  
Abstract Syntax Tree/intermediate representation mix. Generated code uses  
classes such as PHPTAL_Expr_Echo and PHPTAL_Expr_If, and these can be  
inspected, modified, optimized, etc.


I've released work-in-progress code:

https://github.com/pornel/PHPTAL/tree/AST


Is anybody in the mood for writing an optimizing PHP compiler? :)

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] XML Namespace and xmlns declaration removed from emitted DOM

2012-06-12 Thread Kornel Lesiński
On Tue, 12 Jun 2012 21:50:15 +0100, Hisateru Tanaka  
tanakahisat...@gmail.com wrote:



In another branch I started to let PHPTAL allow using with illegal
namespace. See:
https://github.com/pornel/PHPTAL/compare/html5_with_ns#L4R97


Thanks for fixing empty elements and HTML5 attributes!

I think the namespace fix needs to handle some more cases:

xhtml:p xhtml=http://www.w3.org/1999/xhtml;/xhtml:p

must be output in HTML5 mode as:

p/p

since that's a proper XHTML input from XML/DOM perspective. That's why the  
code was ignoring prefixes.



I wouldn't mind if:

foo:p xhtml=http://example.com/foons;/foo:p

was output as:

foo:p/foo:p

although it saddens me that's needed only for Google's invalid markup and  
now-deprecated FBML.



I'm not so sure about xmlns attributes. The http://www.w3.org/1999/xhtml;  
declaration is certainly not needed in HTML5. I think it may be better to  
omit other xmlns attributes too to avoid giving false impression that  
HTML5 has namespaces. It only has tags with invalid : character in them  
and ignores xmlns attributes for compatibility with polyglot XHTML  
documents (but HTML5 mode is inappropriate for polyglot documents).


Even in HTML5 output mode PHPTAL still is supposed to parse input as XML.  
As long as TAL claims to be XML-based language I think it should follow  
XML rule and require namespace declarations.


Ignoring of namespace declarations would be appropriate if PHPTAL had  
HTML5 *input* mode (parse HTML5 and output it as either HTML5 or XHTML).


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] PHP5.4 compatibility

2012-06-06 Thread Kornel Lesiński

On Tue, 05 Jun 2012 15:26:03 -0500, Hash mr.h...@gmail.com wrote:

Hello there, i was wondering what plans you have for compatibility with  
PHP5.4 since htmlspecialchars() and htmlentities() have changed  
significantly. Some of my applications use non-UTF8 character sets and  
currently they are broken under 5.4 because the encoding needs to be  
specified. Furthermore those functions add support for XHTML/XML/HTML5  
entities and more which could be quite helpful to all users.


What problems did you run into?

AFAIK PHPTAL doesn't use htmlentities at all, and htmlspecialchars is  
unaffected by charset declaration for ASCII-based encodings (PHPTAL does  
not support non-ASCII-based encodings).


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Bug when popping context

2012-05-09 Thread Kornel Lesiński
On Wed, 09 May 2012 13:32:28 +0100, Pierre-Olivier Vares  
p...@fingerprint.fr wrote:


I dropped this piece of code - I never use tal:define and  
metal:fill-slot in the same time. But has anybody an idea of a proper  
solution, correcting the 2 bugs ?


Yeah, it's a tricky piece of code. I've been going back and forth on this  
for a while.


I wonder whether stack of contexts for macros should be handled separately  
(pushSlotContext() rather than pushContext())...


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] How about Composer?

2012-04-10 Thread Kornel Lesiński
On Tue, 10 Apr 2012 12:36:09 +0100, Hisateru Tanaka  
tanakahisat...@gmail.com wrote:



I started to use a package manager called Composer but PHPTAL was not
found at the default repository of it. Would you like to register
PHPTAL to http://packagist.org/ ?


Sure. As I understand that requires addition of composer.json to the  
archive. Could you make a pull request on GitHub with this?


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


[PHPTAL] Re: PHPTAL and PHP5.3 Namespace

2012-03-28 Thread Kornel Lesiński
On Wed, 28 Mar 2012 10:57:49 +0100, Mario Schroeder  
m...@marioschroeder.com wrote:


the Support for PHP5.3 Namespaces is even planned. Can you tell at what  
point this will be available?


I've had an experimental namespaced version, but decided not to switch.

1. PHPTAL has prefixed classes already, so it doesn't conflict with  
anything. There is no necessity.


2. Users are not expected to use many classes other than simply PHPTAL  
class, so aliasing does not really shorten any PHPTAL-using code.


3. Keeping backwards compatibility with pre-NS code is not trivial.

4. In general I'm dissatisfied with PHP namespace implementation:

http://pornel.net/phpns

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] ZTal 1.3.0

2012-03-27 Thread Kornel Lesiński
On Tue, 27 Mar 2012 16:06:11 +0100, Robert Goldsmith  
rgoldsm...@names.co.uk wrote:



Just to let everyone know, ZTal 1.3.0 is now available.

Other than a few bug fixes, we've added:
* Support for the file upload element in ZTal form
* Context for ZTal form error messages (so you can use a different error  
translation for the same error on different elements on the form)

* Support for loading templates from within a Phar

Regarding the last item, we've used a Resolver class which anyone can  
make use of within a standard PHPTAL setup and there is nothing  
particularly ZTal about it :)


Thank you!

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] ZTal 1.3.0

2012-03-27 Thread Kornel Lesiński
On Tue, 27 Mar 2012 19:58:42 +0100, Marco Pivetta ocram...@gmail.com  
wrote:



Cool stuff, but I already moved to ZF2 here...


You're definitely an early adopter!

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Escape PHP tags '? ?' on HTML Comments !-- //--

2012-02-01 Thread Kornel Lesiński
On Wed, 01 Feb 2012 18:10:30 -, Nestor A Diaz nes...@tiendalinux.com  
wrote:



Hello, i am not sure if this is the supposed behaviour, but suppose i
have the following code inside a template.

!--
?xml version=1.0 encoding=utf-8?
//--

It will render as is, so having a problem regarding the generated PHP
code because the ? ?

*Parse error*: syntax error, unexpected T_STRING in ...


PHPTAL allows PHP blocks in comments too (perhaps it shouldn't...) and you  
have short_open_tag enabled in php.ini, which makes all ? ? blocks, even  
?xml ? interpreted as PHP code.


If you're not using ? blocks for PHP code (and always use ?php ) then  
you can disable short_open_tag setting.


Otherwise you need to change ?xml to something else or output it using  
?php echo '?xml'; ?


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Documentation needs updating about tal:on-error

2011-12-05 Thread Kornel Lesiński

On Sun, 04 Dec 2011 18:06:08 -, romtek rom...@gmail.com wrote:


From the current description, it's not clear that if a specified macro

isn't found, an exception could be suppressed too. I had to find this out
by running an experiment. So, I think the documentation should be  
updated.


Thanks for suggestion, I've rewritten that bit.

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Re: Cleaning cache files

2011-10-07 Thread Kornel Lesiński

On Fri, 07 Oct 2011 16:25:22 +0100, Bas Kooij kooy...@hotmail.com wrote:


Whoops, I just checked and it seems I left forceReparse on true
after all on the production site. Could that be the reason I got
so many cache files?


No, unless contents or modification time of templates changed very  
frequently.


If you've unexpectedly created a lot of cached content, then perhaps cache  
key contain values that change too frequently? (e.g. mistakenly use  
current time rather than modification time).


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Cleaning cache files

2011-10-06 Thread Kornel Lesiński

On Mon, 26 Sep 2011 15:06:12 +0100, Bas Kooij kooy...@hotmail.com wrote:


I make use of tal:cache attributes for an e-commerce
website. The cache expression for a block element
containing product info looks like this:

30d per php:product.GetProductId() . languageCode . productsLastUpdate

Obviously, if language or productId changes I want to
keep the cache files. But, if the variable productsLastUpdate
changes all cached files for this block become obsolete.
Is there any way to delete the files that were cached using this
identifier? Or do I just have to wait 30 days for the cache to
be cleared automatically.


I'd usually just recommend to leave them there, but as you report that you  
reach limits of glob(), then clearly this isn't a good solution for you.


Since PHPTAL names cached files after md5() of cache key, there is no easy  
way to delete only specific obsolete files.


You might have more luck with method Marco linked to — find command can  
deal with lots of files and you can run cleanup as often as you need.


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] tal:condition question

2011-09-23 Thread Kornel Lesiński

On Fri, 23 Sep 2011 19:16:11 +0100, Teis Lindemark m...@teilin.net wrote:

I have a list in my application where the first column should be one  
icon if the id of the offer is in an array or another icon otherwise.  
The array that have some icons looks something like this: $tmp[id] = 1  
or 0.


If id is 1, I should have one icon and another if 0. I added the array  
to template like this: $template-tmp = $tmp; and then I tried to do  
this:
td tal:condition=tmp/${offers/idiffer}/td Where offers/idoffer  
is the list that is repeated in the table, so each row have one idoffer.


If tmp has items for all IDs, then it should work fine (I presume  
idiffer misspelling is only in the e-mail).


Otherwise you can test for existence with:

tal:condition=exists:tmp/${offers/idoffer}


If you want to toggle between two icons:

td tal:condition=tmp/${offers/idoffer}/td
td tal:condition=not:tmp/${offers/idoffer}/td


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Escaping ${} and $

2011-09-02 Thread Kornel Lesiński
On Fri, 02 Sep 2011 09:59:51 +0100, Tarjei Huse tar...@scanmine.com  
wrote:


Hi, I'm trying to include a JQuery template containing ${} into a  
PHPTal template. Is there a way to say do not use phptal within this  
block or just escape the $ signs?


Yes, $${} will be printed as ${} in generated HTML.



Thanks, please consider the attached patch to the manual.


Excellent! Thanks!

http://phptal.org/manual/en/split/variableRefs.html

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Escaping ${} and $

2011-09-01 Thread Kornel Lesiński

On 1 wrz 2011, at 14:56, Tarjei Huse tar...@scanmine.com wrote:


Hi, I'm trying to include a JQuery template containing ${} into a PHPTal
template. Is there a way to say do not use phptal within this block or
just escape the $ signs?


Yes, $${} will be printed as ${} in generated HTML.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Any updates to translation tools?

2011-08-23 Thread Kornel Lesiński
On Tue, 23 Aug 2011 06:15:57 +0100, Darrell Hamilton darre...@4over.com  
wrote:



Does anyone have any additional input on this point?  From what I've
gathered, pandoc is what you want if your converting between any number  
of markup languages.  It can convert to DocBook, RST, Markdown, and many

others.  Unfortunately, it does not take DocBook as an input format.


pandoc is difficult to install for me. Did you get it working?

DocBook - HTML - Markdown might work?


Based on the links provided by Christoph, there are some tools for
converting DocBook to RST, but they appear to be in their infancy.  I  
have not experimented with them yet.


As a broader question, is Markdown the preferred format?  Or is the  
format open to general discussion?  I do not have a preference at this  
time nor do I know enough of the pros/cons of each to say anything about  
which is the
better tool for the job, but it might be worth hearing from people who  
have more experience with them.


I have slight preference for Markdown, since it uses single backtick for  
inline code. reStructuredText is fine though.


The next step would be to look into tool that produces multipage  
documentation from the single source file. I don't know of any for  
Markdown, so if reStructuredText has good (post)processors, it might be  
better. Otherwise, I'll probably write something myself.


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Any updates to translation tools?

2011-08-19 Thread Kornel Lesiński
On Sat, 06 Aug 2011 17:07:05 +0100, Anton Andriyevskyy  
x.meg...@gmail.com wrote:


(sorry for late reply, I've originally sent that e-mail from wrong  
account!)



I still want to help and finish translation of phptal documentation to
russian language (previously started and done 40% of chapters or so).

I see php introduced very good online tool to do such things:
https://edit.php.net/

If it is opensourced, maybe you can setup it so we all can help to  
translate phptal documentation?


PHP's tool looks like a quite complex beast. I think DocBook is too
complex to maintain already, and instead of piling more tools to deal with
it, I'd rather get rid of DocBook and switch to something simpler, e.g.
Markdown.

To do this, I need:

* tool to convert DocBook to Markdown (or HTML to Markdown):
https://svn.motion-twin.com/phptal/trunk/doc/en/book.xml

* tool to generate multi-page HTML with code syntax highlights from
Markdown (existing scripts might be reusable:
https://svn.motion-twin.com/phptal/website/highlight.php)

Any volunteers?

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Browser Based TAL Inspection Tool

2011-08-19 Thread Kornel Lesiński
On Fri, 19 Aug 2011 07:08:22 +0100, Darrell Hamilton darre...@4over.com  
wrote:



Even with a tool like PHPTAL, the array templates for extremely dynamic
sites can become difficult to manage, from a designer's point of view.   
So, my thought was to use prefilters to modify the rendered markup,  
dumping
information about the original tal markup.  Then, adding a javascript  
based (greasemonkey maybe?) inspection tool that would reveal things  
such as what translation key generated this block of text or what  
macro did this block of html come from, giving designers, even  
developers, the ability to simply look at the site and click on the  
region they want to modify and be told

exactly where to find it's source.


That's a cool idea!

I think it could be easily implemented by modifying PHPTAL to leave TAL
attributes in the generated markup.


In Element.php in separateAttributes()

} else if ($this-xmlns-isHandledNamespace($attr-getNamespaceURI())) {
$talAttributes[$attr-getQualifiedName()] = $attr;
$attr-hide();
}

if you remove $attr-hide(), then PHPTAL attributes will remain in the  
document.




Anyway, the i18n attributes were easy to deal with using a prefilter;
however, I came to find by the time the prefilters are triggered, all  
macros have been evaluated and placed inline, making it impossible to  
determine

what macro each block of markup belongs to.


No, macros are not inlined at compile time. Macro definitions are changed  
into functions: metal:define-macro creates function definition,  
metal:use-macro is a function call. If macro is in another template, then  
that template is loaded at run time as a separate file in a new PHPTAL  
object.


Anyway, prefilters are given access to template as-is, before PHPTAL  
starts messing with it.



--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Google +1 Button

2011-07-23 Thread Kornel Lesiński
On Sat, 23 Jul 2011 13:00:05 +0100, Kris Quigley kris.quig...@gmail.com  
wrote:



Trying to add a Google +1 button to my site, but getting this error :

*There is no namespace declared for prefix of element  g:plusone *

Any help would be greatly appreciated!


Google uses invalid HTML/ill-formed XML.

Correct usage of prefixed names in XML requires that every prefix is  
declared with xmlns, e.g.:


g:plusone xmlns:g=http://plus.google.com/;/g:plusone

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] tal:attributes and checkboxes

2011-07-15 Thread Kornel Lesiński


Now I was thinking to use tal:attributes=checked x something like that  
to be sure that it the item is checked after the checking submit the  
form.


Is this totally wrong way to get my idea to work?


Sounds OK. PHPTAL understands boolean attributes like checked and  
selected, so if you get x to be truthy/falsy, it will work.


Reading session directly in the template is probably a stretch, but you  
could do something like:


$phptal-favorite_checked = $_SESSION[...];

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] PHPTAL interpreter takes too long to recover from encountering an unterminated HTML element

2011-07-15 Thread Kornel Lesiński

On Thu, 14 Jul 2011 17:17:27 +0100, romtek rom...@gmail.com wrote:


If my template code contains an unterminated HTML element (e.g. img
src=stuff.jpg, br, etc.), PHP interpreter takes minutes to process a
request and display an error message. And while doing that, it consumes  
lots of CPU and RAM. Could this be improved?


That definitely shouldn't happen — PHPTAL throws exception as soon as it  
finds an error and that takes milliseconds.


Do you have your own exception handler? If PHP terminates on max execution  
time, where does it stop?


A related request: considering that the web technology has shifted away  
from XHTML, it would be cool if PHPTAL wasn't as strict on XML  
requirements as it is now. E.g. it would be very convenient if some HTML  
elements, such as img, br, hr, didn't need to be terminated.


There's HTML5 output option already. Input parsers are be replaceable. You  
can write HTML one if you want :)


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] i18n:domain Attribute

2011-06-28 Thread Kornel Lesiński
On Tue, 28 Jun 2011 17:49:04 +0100, Darrell Hamilton darre...@4over.com  
wrote:



There seems to be a lacking of any documentation for the i18n:domain
attribute.  In the current documentation, it is only mentioned as an
aside in the PHPTAL_TranslationService section of the PHP Integration
Chapter.


From the doc comments in it's implementation:


 * The i18n:domain attribute is used to specify the domain to be used
to get
 * the translation. If not specified, the translation services will
use a
 * default domain. The value of the attribute is used directly; it is
not
 * a TALES expression.


Indeed. It's a wrapper for bindtextdomain(), which is a bit mysterious in  
PHP documentation as well:


http://php.net/bindtextdomain

In practice it sets filename of .po/.mo file (domain foo would read  
translations from foo.mo).


If you're implementing your own translation service, you can use it for  
whatever you want.


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] [PATCH] Shouldn't skip over __get() just because __isset() was defined…

2011-06-28 Thread Kornel Lesiński
On Tue, 28 Jun 2011 18:44:49 +0100, Terin Stock terinjo...@gmail.com  
wrote:


isset() isn't defined for lazy-loading properties, they're either set or  
not set.


IMHO lazy-loading is an implementation detail that should not be visible  
to isset().


The state you have is property is there and it has a value, but the value  
is still in the database, but your __isset() says property is not there  
or has no value, which is a different thing.


Not not currently set, but could be in the future. Therefore, is it  
correct or incorrect to define it one way or another in our  
application's objects?


If you're saying that property is not set (yet), then PHPTAL will not use  
it (yet). I don't think it's safe for PHPTAL to assume that every unset  
property will appear when __get() is used.


In the current implementation, PHPTAL makes an active attempt at  
stopping me from having __isset defined in a way logical for the rest of  
my application.


It may be convenient for your application, but I don't think that's good  
solution for all applications that use PHPTAL. I believe consistency with  
isset() and ability to avoid double-checking with __get() is more  
important.


I think your application should use different method for exposing  
lazy-loading state (e.g. isLoaded($property)) and use __isset() for  
reporting existence of properties whether they're loaded or not.


My patch fixes that, and doesn't change anything if you have decided to  
implement __isset the other way.


Thank you for your patch. It's not fun to reject patches, I'm sorry for  
that.


You're of course free to use modified version of PHPTAL if you wish.

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] [PATCH] Shouldn't skip over __get() just because __isset() was defined…

2011-06-27 Thread Kornel Lesiński
On Sun, 26 Jun 2011 23:36:28 +0100, Terin Stock terinjo...@gmail.com  
wrote:


 I've been working with PHPTAL for quite some time, and have always been  
annoyed that from within the template an object's __get method was being  
ignored. I think I've tracked down the bug (in version 1.2.2, though it  
still present in trunk).


The scenario: an object, exampleObject, implements __isset, but returns  
false (exampleVariable is not set). exampleObject also implements __get,  
and returns something that isn't NULL.



In PHP it's *not possible* for isset() to return false on something that  
exists and has non-NULL value. I think __isset() and __get() emulate  
behavior of isset() and $obj-property, so if you have something  
equivalent to:


if ( ! isset($obj-prop)) echo $obj-prop;

I think it's illogical or buggy. You're saying it's not set, but then you  
expect it to be set anyway.



If you have lazily-loaded properties, then you should simply return *true*  
from __isset() for such properties.


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Lets boost PHPTAL support in PHPSTORM!

2011-06-27 Thread Kornel Lesiński
On Mon, 27 Jun 2011 11:03:48 +0100, Anton Andriyevskyy  
x.meg...@gmail.com wrote:



For everyone who loves PHPTAL, please spend 2 minutes and vote for PHPTAL
support in PhpStorm IDE.

Here is the link:

http://youtrack.jetbrains.net/issue/WI-2593?projectKey=WI


Voted :)

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] setting slots in any context

2011-06-21 Thread Kornel Lesiński
On Mon, 20 Jun 2011 09:57:34 +0100, Per Bernhardt p...@webfactory.de  
wrote:


I think this is broken. Of course, it is not possible to come up with an  
example that does make advantage of this behavior.


Could somebody explain what the comment works around a bug with  
tal:define means?


This is workaround for issue tested in  
MetalSlotTest::testPreservesContext().


The problem is that tal:define creates new context for its variables,  
which causes slots to be filled in a wrong context.


I've changed (in SVN) the workaround to fill only one level up instead of  
on top level.


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Extending namespace

2011-06-11 Thread Kornel Lesiński
On Fri, 10 Jun 2011 05:01:08 +0100, Hisateru Tanaka  
tanakahisat...@gmail.com wrote:



I'm trying to extend namespace of PHPTAL to use in my framework.
3 new attributes would introduced.

  pal:content-nl2br
  pal:replace-nl2br
  pal:attr

They might be things which some users wanted...

Test code is here:
https://gist.github.com/1016531
Someone tell me which this implementation is even good or not.


Yes, it's good.


If developer team is planning to change class tree or public/protected
method, how can I keep compatibility safer?


I don't see anything you could improve for future-compatibility.

I do plan to rewrite code generation someday, but until then you're safe :)

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Usage of __toString magic method

2011-06-07 Thread Kornel Lesiński

On Mon, 06 Jun 2011 07:39:25 +0100, Manu Robledo moli...@mopot.de wrote:

It would be possible to call output() first and pass the results to  
PHPTAL, but this way also widgets, which are not visible in the current  
template (maybe because of some tal:condition would have to be rendered.


You could also use ${widget/output} instead of ${widget}.

Lack of exceptions in __toString() is an annoyance, but that's PHP's rule.  
Even if it's worked around in PHPTAL, will you want workaround everywhere?  
Will you change every echo and cast to an explicit call? Then you don't  
really use __toString — why implement it at all?


If anything, I'd rather add _phptal_toString() or such, that doesn't  
forbid exceptions by design. Otherwise you have magic method that you  
don't want called magically…


You are right. But same here: If the solution is that simple, why not  
build it in? Unfortunately there are still servers out there with such  
old php versions.


Let's give them another reason to update seriously outdated—and likely  
insecure—software.


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Implementing phptal modifiers as static methods in multiple classes

2011-06-05 Thread Kornel Lesiński
On Fri, 03 Jun 2011 08:12:19 +0100, Anton Andriyevskyy  
x.meg...@gmail.com wrote:


Currently in PHPTAL I don't think it's possible, but you could easily  
modify PHPTAL to do it.


See PHPTAL_TalesRegistry-findUnregisteredCallback — loop through your  
classes there.



Alternatively, you could register all prefixes, but only before template  
is compiled. To do it, extend PHPTAL class and:


function parse()
{
// register 300 prefixes here :)
return parent::parse();
}

This way you won't get performance hit at run time.

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Unit Tests

2011-06-02 Thread Kornel Lesiński
On Wed, 01 Jun 2011 11:47:31 +0100, Robert Goldsmith  
rgoldsm...@names.co.uk wrote:


Interesting question - anyone tried unit testing Tales? Any ideas how to  
do so?


What exactly do you want to test?

If you want to test your TALES expressions or modifiers, then you could  
use PHPTAL-setSource() to create small snippets of code and run them,  
check results:


	$this-assertEquals(HELLO,  
PHPTAL::create()-setSource(${toUpperCase:string:hello})-execute());


For its own purpose PHPTAL tests result returned by phptal_tales()  
directly, but that exposes more than 3rd party application would want to  
know about PHPTAL internals, so I don't recommend that.


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] i18n translate - Unable to find variable

2011-05-28 Thread Kornel Lesiński
On Sat, 28 May 2011 12:59:48 +0100, webNet web...@webnet.katowice.pl  
wrote:


I created our own class 'class implements ZendPhpTalCsvTranslate  
PHPTAL_TranslationService' drawing on PHPTAL_GetTextTranslator.


The problem is that when you call span i18n:translate=login or email  
Login / span


you receive an error message

'An error occurred
Exception information:

Message: Unable to find variable 'login or email' in current scope


i18n:translate takes expression, just like tal:content would (this is to  
allow translation of dynamically generated text).


Use:
span i18n:translate=string:login or email

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Evaluating tal:attributes Generated By PreFilters

2011-05-11 Thread Kornel Lesiński
On Wed, 11 May 2011 07:42:50 +0100, Darrell Noice darre...@4over.com  
wrote:



foreach(...) {
...
$new_attrs = array();
$new_attrs[] = new  
PHPTAL_Dom_Attr(variables,,implode(,,$vars),UTF-8);

$new_attrs[] = new PHPTAL_Dom_Attr(tal:attributes,,token
{$token},UTF-8);


PHPTAL's DOM uses XML namespaces. In this case you're creating attribute  
named tal:attributes in default namespace, but you need attribute named  
attributes in http://xml.zope.org/namespaces/tal; namespace.


That should work and setAttributeNS will be a little prettier than new  
DOM_Attr:


$wrapper = new PHPTAL_Dom_Element(translation,,array(),  
$child-getXmlnsState());
$wrapper-setAttributeNS('http://xml.zope.org/namespaces/tal',  
'attributes', token $token);


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] issue with variable defined in a full page macro

2011-05-07 Thread Kornel Lesiński


(oops, I've pressed send accidentally :)

Sooo, replace these:

html metal:use-macro=person.zpt/main
+
div metal:fill-slot=content_main

with:

html metal:use-macro=person.zpt/main tal:define=callback  
'display-list'

+
div metal:define-macro=display-list


Basically use another macro instead of a slot.


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] new tag

2011-04-23 Thread Kornel Lesiński

On Fri, 22 Apr 2011 22:26:03 +0100, hosema...@poczta.onet.pl wrote:


How to create new tag
Ex.
I would like to create tag that automaticly includes js and css to  
document files from predefined directory like:


tal:js src=jquery.js
tal:css src=style.css

How to extend tal tags?


TAL doesn't use tags :) Elements in tal namespace are not output.

You could create your own attribute, e.g.

script xmlns:yournamespace=… yournamespace:src=jquery.js/

The easier option is to use prefilter to change this attribute into  
standard TAL attribute (e.g. a macro call or tal:content).


The hard way is to implement it the same way tal:content does it: by  
creating your own namespace (PHPTAL_Dom_Defs-registerNamespace()) and  
implementing your custom attribute by extending PHPTAL_Php_Attribute  
class, that writes code in before/after methods. I don't recommend that,  
because it's not documented and requires familiarity with PHPTAL's  
internals.



And the easiest solution is to create TALES prefix:

script tal:content=include:jquery.js /

function phptal_tales_include($expr, $nothrow)
{
	return  
'file_get_contents(your_directory/.'.phptal_tale($expr,$nothrow).')';

}

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] PHPTAL and ZTal

2011-04-14 Thread Kornel Lesiński
On Thu, 14 Apr 2011 13:42:55 +0100, Robert Goldsmith  
rgoldsm...@names.co.uk wrote:


Regarding a repository of useful tales, I'd be keen to see a (maybe  
optional) download from the PHPTAL site with a collection of well  
written common tales both to help developers writing their own and to  
provide a lot of convenient functionality. The lack of some basic  
abilities will, I'm sure, be putting people off of PHPTAL unnecessarily  
:(


I'm happy to add such thing if you could suggest worthy TALES (e.g.  
compile a list on the wiki).


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] tal:equal ?!

2011-04-13 Thread Kornel Lesiński
On Wed, 13 Apr 2011 14:45:31 +0100, Ciprian Voicu pict...@autoportret.ro  
wrote:



I've encountered lots of times the need to compare one or more pairs of
values so I used php: modifier, but let's say would be more professional
using some internal tal way instead of php native comparison way.

eg:

div tal:condition=php: listing.status == 'ACTIVE'  listing.type ==
'PREMIER'print some good content here/div


You could have method like isActivePremier() [or whatever name better  
describes state you're checking for] and use it like this:


div tal:condition=listing/isActivePremier

If the condition is related to your business rules, then I think that's  
the most appropriate way to do it.


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] translate ...

2011-02-13 Thread Kornel Lesiński
On Sun, 13 Feb 2011 17:03:50 -, GRolf ger...@pictureparking.com  
wrote:


And another question relating the i18n:translate in templates: the  
regular gettext contains xgettext to extract all keys from a PHP source  
code so you don't forget to translate one... does something similar  
exist for PHPTal templates? I guess not officially, but maybe somebody  
has developed something like that already?


There is/was a tool for this, but I haven't tested it with latest version  
of PHPTAL:


https://svn.motion-twin.com/phptal/phptal_i18n/trunk/bin/phptal-i18n-extract.php

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] translate ...

2011-02-13 Thread Kornel Lesiński
On Sun, 13 Feb 2011 18:38:59 -, Christian Welzel gaw...@camlann.de  
wrote:



This one does not work anymore with 1.2.x...
Some time ago i patched the version from svn to get it working again
and at least for me it works again.
The files can be downloaded here:

http://typo3.camlann.de/phptal-i18n.tgz


I've committed it to the repository. Thanks!

--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Ztal 1.0.0

2010-12-18 Thread Kornel Lesiński
On Fri, 17 Dec 2010 16:06:33 -, Robert Goldsmith  
rgoldsm...@names.co.uk wrote:



I'm pleased to announce the 1.0.0 release of Ztal, available here:

http://opensource.names.co.uk/ztal/

Ztal is a 'glue' framework that integrates PHPTAL and all it's wonderful  
goodness into Zend Framework as a replacement for the Zend_View class  
and Zend_Form class.


Thanks very much for this! And congratulations — that is a really nice  
code!


--
regards, Kornel Lesiński

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Feature request: better integration with doctrine orm

2010-11-22 Thread Kornel Lesiński
On 22 Nov 2010, at 12:35, Ivo Võsa wrote:

 seams like today is feature request day :) so here goes mine.
 
 I'm using phptal with Doctrine ORM.
 Unfortunately Doctrine and phtpal have different understanding about what 
 exactly isset means.
 So every time i upgrade phptal i have to apply this little patch.

How does isset behave in Doctrine?

If $obj-foo exists, but is not loaded, does isset($obj-foo) return false?

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Feature request: better integration with doctrine orm

2010-11-22 Thread Kornel Lesiński
On 22 Nov 2010, at 13:01, Ivo Võsa wrote:

 seams like today is feature request day :) so here goes mine.
 
 I'm using phptal with Doctrine ORM.
 Unfortunately Doctrine and phtpal have different understanding about what 
 exactly isset means.
 So every time i upgrade phptal i have to apply this little patch.

 
 How does isset behave in Doctrine?
 
 If $obj-foo exists, but is not loaded, does isset($obj-foo) return false?
 
  
 yes it will return false,
 and if you try to access it, it is loaded from database


That breaks behavior expected of PHP properties. If $obj-foo is supposed to 
have non-NULL value, then isset($obj-foo) shouldn't be returning false.

I consider that a Doctrine bug (leaky abstraction) and suggest that you patch 
Doctrine's __isset() to return true if relation exists, even if it isn't loaded 
yet. 

I think that's a better solution — it will make Doctrine's abstraction more 
robust, and won't require PHPTAL to have workaround for other application's 
inconsistent behavior.

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Re: Feature request: Allow array as parameter of PHPTAL's set() method

2010-11-22 Thread Kornel Lesiński
On 22 Nov 2010, at 14:58, Tjerk Meesters wrote:
 
 My bad, I did read from the beginning but I think certain parts ended in a 
 void ;)
 
 Still, in my opinion any function that takes name/value pairs is a candidate 
 for array overloading. I sometimes wished php would do java'ish method 
 overloading ... is there another reason beyond the one-up complexity to pick 
 another name?

Error detection. New method could be setVariables(array $foo), and would 
complain when you fail to pass an array. Similarly, set() with two arguments 
requires both to be present, so you'll know when you forget one.

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Collecting translation messages from templates

2010-11-04 Thread Kornel Lesiński

On 04-11-2010 at 02:52:06 Per Bernhardt p...@webfactory.de wrote:

When using gettext within php, tools like poedit are able to parse the  
php source code to generate a list of all messages that have to be  
translated.

Is there anything similar for phptal and it's i18n features?


There is a tool for this in SVN:

https://svn.motion-twin.com/phptal/phptal_i18n/trunk/

but I haven't touched it for a while, so I'm not sure if it still works.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Custom modifiers - any callback function

2010-11-03 Thread Kornel Lesiński

On 03-11-2010 at 07:46:29 Anton Andriyevskyy x.meg...@gmail.com wrote:


http://phptal.org/manual/en/split/custom-modifiers.html

Hey, lets add to PHPTAL a way to use standard php callbacks to define  
custom modifiers.


Currently it is so:

phptal_tales_mymodifier

It would be nice to use something like this:

$phptalInstance-setModifier('modifierName', phpStandardCallback)

This will allow to better integrate PHPTAL into pure OOP frameworks like
Kohana, CI and others.


Is it only because functions are not OO, or do you actually need to define  
modifiers with same name, but different implementation, in different parts  
of same PHP program?



PHPTAL does have object-oriented method for defining custom modifiers:

PHPTAL_TalesRegistry::getInstance()-registerPrefix('modifierName',  
phpStandardCallback)


but it doesn't solve any problems over simple function definition, which  
is why I don't recommend it.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Custom modifiers - any callback function

2010-11-03 Thread Kornel Lesiński

On 03-11-2010 at 12:26:14 Anton Andriyevskyy x.meg...@gmail.com wrote:


Thanks for hinting to that method.

Actually it can be just right way to follow fully-OOP framework like  
Kohana.


Please don't do it. OOP just for sake of OOP is pointless.


but...
PHPTAL_TalesRegistry::getInstance()

as I understand it will affect ALL phptal object instances available in
runtime?
What about concrete phptal instance, is it possible to affect only one of
them somehow?


It's not possible. Singletons, despite OO, have all the downsides of  
global functions.


However, so far I haven't found this to be a problem in real-world  
applications, so fixing this is far down on my list. I'm happy to accept  
patches fixing this.


If you were to write setModifier() function, I suggest naming it  
setModifierCompiler() or similar. That should make it clearer to new users  
that modifiers generate PHP code, rather than returning value immediately.


Callback could take object that has -compileTalesExpresssion() rather  
than $nothrow argument like it does now. That would eliminate another  
global dependency on phptal_tales().


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


[PHPTAL] DocBook killer

2010-10-25 Thread Kornel Lesiński
Does anyone have reason for keeping documentation in DocBook format?

It's getting on my nerves — xmlto, tool used to generate PHPTAL documentation, 
is pain to install (triggers avalanche of dependencies), and DocBook markup is 
inflexible and verbose at the same time.

I'd prefer to write documentation in Markdown.

Are there any volounters convert DocBook to Markdown (should be possible 
semi-automatically) and write scripts that publish documentation from Markdown 
in format similar to what's currently on the website?

https://svn.motion-twin.com/phptal/trunk/doc/

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] DocBook killer

2010-10-25 Thread Kornel Lesiński
On 25 Oct 2010, at 11:47, Anton Andriyevskyy wrote:

 Kornel, I remember that I have not finished translation to Russian,
 the problem partially is because there are no useful tools for DocBook.
 
 Maybe with Markdown we will go faster?
 Or it's not related to site translation at all?

There are PHP/Perl/JS scripts for Markdown to HTML conversion, so editing 
should become much easier.

BTW: I wonder whether it's better to have one large file for entire 
documentation, or one file per chapter?

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] PHPTAL 1.2.2 Released

2010-10-25 Thread Kornel Lesiński
On 25-10-2010 at 17:21:03 Piotr Kroczyński piotr.kroczyn...@gmail.com  
wrote:


I was wondering if bug described by me in this message  
http://comments.gmane.org/gmane.comp.php.phptal.general/1447 was fixed?  
I've searched in changelogs  but found nothing about it.


No, this one is in trickiest part of PHPTAL, so I didn't want to add it in  
this release.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


[PHPTAL] PHPTAL 1.2.2 Released

2010-10-24 Thread Kornel Lesiński

I've finally managed to get PHPTAL 1.2.2 out of the door.

I've deliberately kept changes to minimum, so if you've been using beta, it's 
safe to upgrade.


The new cool toy in this release is HTML whitespace compressor. Just add this 
to your sites:

$phptal-addPreFilter(new PHPTAL_PreFilter_Compress());

and you'll get smaller HTML output. The prefilter will carefully remove all 
useless whitespace from the document and sort attributes to further improve 
gzip compression (you're gzipping all your pages, right?)

Since it's a prefilter (run once), it doesn't slow down page generation at all!

-- 
regards, Kornel




___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Re: Does PHPTAL supports or tolerate Microdata?

2010-10-14 Thread Kornel Lesiński

On 13-10-2010 at 18:00:12 micheal hosema...@poczta.onet.pl wrote:


Thanx. what about RDFa? Does PHPTAL tolerates it?


Yes. And SVG, MathML and all other XML vocabularies are supposed to work  
with PHPTAL. You have to remember to declare XML namespaces for your  
prefixes (as XML spec requires).


I am new to semantic web and I wondering which to choose microdata or  
RDFa?

Someone experience at that field?


Microformats and Microdata are easier to use.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Re: Does PHPTAL supports or tolerate Microdata?

2010-10-14 Thread Kornel Lesiński

 Microformats and Microdata are easier to use.
 
 Yea, but let's assume that for me the result,SEO is pri
 ority(not learning curve). 
 I've read that RDFa has more support and more options. Whouldn't it be more 
 SEO 
 efficient?


IMHO RDFa's advantages are still only in a semantic web fantasy world. In 
practice it all depends whether search engine supports particular format and 
vocabulary, and whether you can get the data marked up correctly. AFAIK Google 
supports all three formats equally. Yahoo used to support Microformats, but I 
haven't checked recently if that survived Bing takeover.

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] PreFilter - filterDOM

2010-10-14 Thread Kornel Lesiński
On 14 Oct 2010, at 17:08, Levi Stanley wrote:
 
 I am migrating over to using PreFilter and using the DOM to manipulate
 the html document.  However, am trying to figure out the usefulness of
 the method, filterDOM().  I have my DOM, and I am walking threw it and
 making my changes, however, after I am finished the page still renders
 the same, am I missing something?


It might be the cache. Try PHTPAL-setForceReparse(true) during development.

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Does PHPTAL supports or tolerate Microdata?

2010-10-11 Thread Kornel Lesiński

On 08-10-2010 at 21:06:54 hosema...@poczta.onet.pl wrote:

I am planning to integrate some semanticweb technology. Does PHPTAL  
supports or tolerate Microdata?


http://www.google.com/support/webmasters/bin/answer.py?answer=146862


It tolerates it.

Note that Google's examples use HTML syntax, but PHPTAL templates are  
based on X(HT)ML. Instead of p itemscope you should write p  
itemscope=/p (both syntaxes are correct in Microdata).


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Re: AW: Logical operators in PHPTAL

2010-10-04 Thread Kornel Lesiński
On 1 Oct 2010, at 18:46, Moritz Baumann wrote:

 I think the next step would be to work out syntax exactly:
 
 http://phptal.org/wiki/doku.php/improvedtales 
 
 Hm, that page mentions a lot more than just logical operators. I guess that’s
 what the negative feedback was about, not logical operators inside 
 tal:condition.
 
 The main difference between PHPTAl and other template engines is that the 
 syntax
 is quite simple and that the templates look clean. IMHO, function calls and 
 an
 equivalent to the ?: operator would add unnecessary complexity to PHPTAL and
 spoil exactly what makes PHPTAL unique and great. Support for logical 
 operators
 inside tal:condition, on the other hand, would make the php: modifier more or
 less unnecessary.


I look at this differently: these are things I need, whether their syntax is 
nice or not, so I'd prefer to make their syntax nicer.

Perhaps arguments to functions is a step too far (and authors should be 
required to write expression modifiers for these), but setting of class name 
based on condition is a very common pattern and ternary operator is an awful 
way to do it.

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] optional attribute, based on another condition

2010-09-30 Thread Kornel Lesiński
On 30 Sep 2010, at 10:01, Ionut Matei wrote:

 Hello,
 
 I want the 'href' attribute to be skipped if $item['route'] is empty:
 
 a tal:content=php:tm._(item['title']) tal:attributes=href
 php:ro.gen(item['route'])/
 
 the manual says attributes can be skipped with  | nothing, but this
 is based on the attribute's value.


With php: modifier NULL also works:

tal:attribute=href php:item['route'] ? ro.gen(item['route']) : NULL

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Why PHPTAL stop rendering doctype after clone.

2010-09-30 Thread Kornel Lesiński

 So when using HTML5 mode in PHPTAL I need to wrap all values in quotes but in 
 output I get them without quotes. Isn't it additional work for parser to 
 remove quotes even when they are permitted in HTML5?

PHPTAL has HTML5 *output* mode. Input is always XML (I haven't gotten around to 
writing HTML5 parser yet).

PHPTAL doesn't output markup you write. It reads markup into abstract tree 
(DOM) and then from that syntax-less tree generates PHP code that generates new 
markup. 

Input is completely separated from output. This is similar to the way browsers 
process markup (e.g., code in innerHTML doesn't retain any syntactical details 
from your page source).

In current implementation decision to generate quotes is taken at compile time, 
so there's absolutely no penalty at run time. It might even be microscopically 
faster, as template code ends up few bytes shorter :)

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: AW: [PHPTAL] Logical operators in PHPTAL

2010-09-30 Thread Kornel Lesiński

On 30-09-2010 at 15:45:46 Per Bernhardt p...@webfactory.de wrote:


I would love to see this feature, too!
Was it no positive feedback or no feedback at all?


http://lists.motion-twin.com/pipermail/phptal/2009-November/001967.html


Do you think it is hard to implement?


It requires writing a mini compiler with parser that supports operator  
priorities. Maybe a bit more complex parser if it were to support php:  
modifier well.


I've got basic parser already.


Does it break backwards compatibility?


It would break compatibility with TALES paths that use spaces, but I  
presume those are very rare, and could be worked around by using  
/foo/${string: part with spaces }/bar.



I would be willing to help with the implementation...


Great!

I think the next step would be to work out syntax exactly:

http://phptal.org/wiki/doku.php/improvedtales

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Why PHPTAL stop rendering doctype after clone.

2010-09-30 Thread Kornel Lesiński

On 30 Sep 2010, at 18:28, Piotr Kroczyński wrote:

 Ok thank you for reply. I have just one more question. In which revision is 
 that diry quick fix that you wrote earlier to make PHPTAL write doctype after 
 clone? I just added this to svn:externals in place of 1.2.1:

r993

 phptal -r 939 https://svn.motion-twin.com/phptal/trunk/classes/ to svn 
 externals

Wrong revision number.

 But problem is still there. Can you tell me where and what to add to fix this 
 bug ?

The fix is in PHPTAL_Context::setDocType(). Sets it in current context, rather 
than topmost context. I'm not sure if that is sufficient in all cases, but 
passes test case you've sent me (which I've added to tests in r991).

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Logical operators in PHPTAL

2010-09-29 Thread Kornel Lesiński
On 29 Sep 2010, at 06:33, romtek wrote:
 
 I'd like to be able to use a bit more simple logic in my templates. Being 
 able to use AND, OR, and NOT would be good. E.g. 
 tal:condition=event/featured AND event/upcoming, tal:condition=NOT 
 event/featured AND event/upcoming
 
 I remember there was an activity to extend the library to make PHPTAL more 
 expressive. What's happened to that?

I've asked about this on the mailinglist and didn't get positive feedback, so 
the feature got shelved.

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Next stable release

2010-09-20 Thread Kornel Lesiński

On 18-09-2010 at 18:33:59 Per Bernhardt p...@webfactory.de wrote:


is there a planed date for the next stable release of phptal?
Because of some important bugfixes (e.g. slot inheritance), we use the  
current beta in our production environment.
Now we have to launch a project at our customers site and he is a bit  
nervous because of the beta status...


It's been quite stable, so I'll call it a release in a couple of weeks.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] PHPTAL and JQUERY tmpl

2010-09-17 Thread Kornel Lesiński
On 17 Sep 2010, at 18:46, hosema...@poczta.onet.pl wrote:

 Maybe it is time to lobby for PHPTAL syntax for JQUERY tmpl? 
 John Resig (author of Jquery) are planning to integrate some template 
 functionality inside JQuery core.
 http://forum.jquery.com/topic/jquery-templates-proposal#1473700751961
 More on tmpl:
 http://github.com/jquery/jquery-tmpl
 http://github.com/nje/jquery-tmpl

Oh yes, please do! They seem to be going for awful {{if}} {{/if}} syntax: 
http://forum.jquery.com/topic/templating-syntax

-- 
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Translate field

2010-09-15 Thread Kornel Lesiński

On 15-09-2010 at 13:04:09 GRolf ger...@pictureparking.com wrote:

I have records in a table that have a status field, which contains a  
status in 'code' (i.e. NEW, PENDING, APPROVED, ...).


There is no conversion table for the moment

When outputting this, I'd like to convert this status code to some more  
human-readable form ('Awaits approval', ...). I have a vague memory of a  
suggestion to use i18n: to solve this. But I don't want to make it to  
complicated. All I need to translate is this one particular field, I'm  
not planning on installing gettext etc. If there is no easy solution,  
I'd rather run through my results in PHP first to convert them to the  
required output...


Any help?


i18n would be overkill for this.


$phptal-statuses = array('NEW'='New status',…);

tal:content=statuses/${status}

or

tal:content=php:nice_status_name(status)


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Hello, and PHPTAL probelm with UTF-8

2010-08-31 Thread Kornel Lesiński

On 31-08-2010 at 10:54:11 Robert Partyka bob...@wdg.pl wrote:


I notice today strange problem with PHPTAL, when I start to use
nederlands national characters in template.
I get such error:

Exception thrown while processing template

From /var/www/test-nt/deny/files/index-main.html around line 34
exception 'PHPTAL_ParserException' with message 'Tag closure mismatch,  
expected  /div  (opened in line 34) but found  /iv ' in  
/var/www/test-nt/deny/files/index-main.html:34

Stack trace:
#0 /var/www/test-nt/deny/lib/PHPTAL/PHPTAL/Dom/SaxXmlParser.php(194):  
PHPTAL_Dom_DocumentBuilder-onElementClose('iv')
#1 /var/www/test-nt/deny/lib/PHPTAL/PHPTAL.php(1113):  
PHPTAL_Dom_SaxXmlParser-parseString(Object(PHPTAL_Dom_DocumentBuilder),  
'parse()

#3 /var/www/test-nt/deny/lib/PHPTAL/PHPTAL.php(651): PHPTAL-prepare()
#4 /var/www/test-nt/index.php(62): PHPTAL-execute()
#5 {main}


Line which make error looks like this:
div class=box_titleKopiëren van een rapport/div

so the close tag is correct. Whole error disaperar when I change ë
into e. Template file is UTF-8 (no BOM).


It does look like encoding-related issue, but I cannot reproduce it in  
current version of PHP:


https://svn.motion-twin.com/phptal/trunk/tests/UTF8Test.php

Perhaps specific bytes that cause the problem didn't survive copying via  
e-mail. Could you send me a file (preferably minimized test case) that  
causes the problem?


You could also check out copy from SVN  
(https://svn.motion-twin.com/phptal/trunk), install PHPUnit  
(https://svn.motion-twin.com/phptal/trunk/README) and run `phpunit` in  
root of the working copy. Does your copy pass the tests?


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Hello, and PHPTAL probelm with UTF-8

2010-08-31 Thread Kornel Lesiński

On 31-08-2010 at 16:06:29 Robert Partyka bob...@wdg.pl wrote:


 W dniu 2010-08-31 13:07, Robert Partyka pisze:

Now will need to find differences in conf

Ok... it looks like
mbstring.func_overload = 7

is destroying work of PHPTAL.


That's very destructive setting in general. I recommend against using it.


But... what if I need somewhere else UTF
functions for str_replace and preg_* ?


It doesn't work with preg. It only worked with ereg functions, which are  
deprecated.


Use /u modifier in preg (always works, regardless of mb*).

Single-byte string replacement functions are safe with UTF-8 (UTF-8 char  
is never substring of another UTF-8 char).


For strlen/substr/strtoupper, etc. use mb_-prefixed functions explicitly.  
Find'n'replace over your sourcecode should break less things than  
func_overload.



Is there way to force PHPTAL to work with mbstring ?


PHPTAL works fine with mbstring extension installed. The only problem is  
func_overload hack that changes semantics of string functions, but fails  
to change string subscript operator, causing bugs in correct PHP code.


You could edit Dom/SaxXmlParser.php and change all $str[xxx] to  
substr($str,xxx,1). I hope mb_substr has some clever optimisations,  
otherwise this could make parser very, very slow.


There might be other places suffering from func_overload hack, and it may  
be difficult to find them all, which is why I'd rather not support it.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] SourceResolver path in nested macro

2010-08-06 Thread Kornel Lesiński

On 05-08-2010 at 20:44:45 Bas Kooij kooy...@hotmail.com wrote:


My current templates looks like this:

FILE main.xhtml:

html metal:define-macro=main
tal:block metal:define-slot=page /
/html

FILE home.xhtml:

tal:block metal:use-macro=main.xhtml/main
tal:block metal:fill-slot=page

tal:block metal:use-macro=customMacro /

/tal:block
/tal:block


I have a custom SourceResolver like this:

class MySourceResolver implements PHPTAL_SourceResolver {
public function resolve($path) {
echo $path;
}
}

However, this SourceResolver only echo's the path 'home.xhtml', I never  
get the
vaule ´customMacro´. Am I doing something wrong here, or is this  
impossible or a

bug?

I tried the latest beta too btw, with the same results.


That's by design. Resolver just needs to find the file, and PHPTAL will  
then look for the macro in it.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] How to use repeat as while

2010-07-30 Thread Kornel Lesiński

On 29-07-2010 at 20:47:05 Klederson Bueno kleder...@klederson.com wrote:


Tks for everything, now up and running:

class BurnModelIterator implements Iterator
{
protected $obj, $current;

public function __construct(PhpBURN_Core $obj) {
$this-obj = $obj;


You shouldn't use $obj in PHP5. $this-obj = $obj; does the right thing.


function current() {
return $this-current = $this-obj;
}


This looks suspicious - current() shouldn't change anything, and only  
return currently loaded element.


If $obj is a weird object that changes its own identity on fetch(), then  
don't need to keep $this-current, and can simply return $this-obj.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] How to use repeat as while

2010-07-29 Thread Kornel Lesiński

On 29-07-2010 at 16:09:52 Klederson Bueno kleder...@klederson.com wrote:

I have this framework ( www.phpburn.com ) and while i do: $obj-fetch()  
it

returns true or false until while ends... however repeat works more as a
foreach and then i cant use this... how can i work with repeat working  
as a while ?


You can wrap it in an iterator:

class WhileIterator implements Iterator
{
protected $current, $obj;

function __construct($obj)
{
   $this-obj = $obj;
}

function next()
{
$this-current = $this-obj-fetch() ? you_get_next_object_here()  
: false;

}

function current()
{
return $this-current;
}

function key()
{
return 'implement if you care';
}

function valid()
{
return !!$this-current;
}

function rewind()
{
$this-next(); // loads first object
}
}


You can also make custom expression modifier:

function phptal_tales_while($expr, $nothrow)
{
return 'new WhileIterator('.phptal_tale($expr,$nothrow).')';
}

and then use tal:repeat=x while:obj

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Accessing namespaces from templates

2010-07-08 Thread Kornel Lesiński

On 08-07-2010 at 13:50:27 Thomas D. whist...@googlemail.com wrote:


which will end in a ...unexpected T_NS_SEPARATOR... error.

So how do we do that? Isn't that currently possible, because PHPTal  
hasn't got namespace support? Do we need to use the experimental PHPTal  
version

with explicit namespace support?


You don't need that experimental version. The problem is only in code  
parser for php: modifier, which has been extended to allow namespaces  
after 1.2.1 was released. So you version newer than 1.2.1 (try 1.2.2b or  
SVN).


The fix is trivial, so if you prefer sticking to stable version, you can  
modify PHPTAL_Php_Transformer::isVarNameChar() and add '\\' as allowed  
character there.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Re: Accessing namespaces from templates

2010-07-08 Thread Kornel Lesiński

On 08-07-2010 at 15:24:01 Thomas D. whist...@googlemail.com wrote:


I wrote:

I upgraded PHPTal to v1.2.2b3 and it's working right now.


Uhm, I got confused. I didn't saw that b4 is the current beta.
http://phptal.org/download.html is still listing b3 and the latest  
news, which contains a link to b4, is wrongly dated to *2009*-06-01, so  
I didn't read it ;-)


Now running with v1.2.2b4.


Ooops! That's what happens when I update site late at night ;)

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Re: Insert TAL variables into TAL variable

2010-07-06 Thread Kornel Lesiński

On 30-06-2010 at 17:42:17 Bas kooy...@hotmail.com wrote:

It doesn't work without the cache attribute, in fact that was the reason  
I tried using the cache attribute. I tried putting a span inside the  
tal:block with the define macro and set the cache on the span, but that  
didn't make a difference.


It looks like the caching occurs in the main template file. If I change  
the 'use macro' name to content2 I get the error message:


'PHPTAL_MacroMissingException' with message 'Macro 'content2' is not  
defined in article_69.


Even if I change the resolve function to output a macro called content2.



I've added test for it (in SVN tests/SourceTest.php) and it works for me.

I've found one gotcha - if you use PHPTAL_StringSource, then $realpath  
constructor argument should be either path of file on disk, or change  
whenever source changes.


This is a bit confusing, so I've made that argument optional (in SVN  
version) -- don't specify it, and caching will work.



Workaround for v1.2.1:

new PHPTAL_StringSource($source,  
PHPTAL_StringSource::NO_PATH_PREFIX.md5($source));


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Re: Insert TAL variables into TAL variable

2010-06-30 Thread Kornel Lesiński

On 30-06-2010 at 17:15:30 Bas kooy...@hotmail.com wrote:


Thanks for the quick reply. I didn't change the template code, only the
variables.


In this case I guess phptal:cache= is to blame. Does it work without it?

Try putting tal:block phptal:cache= on its own (either inside the  
macro, or outside element calling the macro) rather than on the same  
element that defines macro.



One more thing:

tal:cache=100d per article/getDateContentModified /

This will make cache shared among all articles with same date. Try 100d  
per php:article.getID() . article.getDateContentModified().


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Variables not found while filling slot

2010-06-25 Thread Kornel Lesiński

On 24-06-2010 at 18:55:31 Per Bernhardt p...@webfactory.de wrote:


taken the following macro and macro-usage:

tal:block metal:define-macro=ul
ul
li tal:repeat=item items
tal:block metal:define-slot=li /
/li
/ul
/tal:block

tal:block tal:define=items php:array('a', 'b', 'c')  
metal:use-macro=ul

tal:block metal:fill-slot=li
${item}
/tal:block
/tal:block

I would expect the template to be rendered like this:
ul
lia/li
lib/li
lic/li
/ul

But with the current stable and beta what you get is a  
PHPTAL_VariableNotFoundException saying Unable to find variable 'item'  
in current scope.
More generally spoken: Variables defined within a macro definition  
cannot be accessed while using the macro and filling one of its slots.


Is this a bug, missing implementation or an unwanted feature?


That's just how it works. Slots work by assigning generated HTML to a  
hidden variable. They're executed immediately when fill-slot is called.



Technically the issue is which scope (variables) slot should see:

div tal:define=x '1' metal:fill-slot=slot${x}/div

div tal:define=x '2' metal:define-slot=slot!-- 1 or 2? --/div

For slots the answer is 1. Analogous code with macro callbacks would give  
2.



I've added explanation to the manual:
http://phptal.org/manual/en/split/metal-use-macro.html#macro-callback

See also:
http://www.mail-archive.com/phptal@lists.motion-twin.com/msg01331.html

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Slots - the second...

2010-06-25 Thread Kornel Lesiński

On 25-06-2010 at 09:57:12 Per Bernhardt p...@webfactory.de wrote:

Thanks. That's a great example. I've turned it into a test case - and it  
passes in the SVN version, but it may be just because the test is short.  
There's optimisation that turns large slot fills into callbacks to save  
memory and improve streamability of documents.


Try changing
PHPTAL_Php_Attribute_METAL_FillSlot::shouldUseCallback()
and see if that fixes the bug.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: AW: [PHPTAL] Slots - the second...

2010-06-25 Thread Kornel Lesiński

On 25-06-2010 at 11:57:12 Per Bernhardt p...@webfactory.de wrote:


For me it is exactly the other way around :)

When I return true in  
PHPTAL_Php_Attribute_METAL_FillSlot::shouldUseCallback(), my actual  
template works fine!

Returning false (and so disabling the optimisation) breaks the result.

It is the same with beta and the latest svn.

So maybe you should always use callbacks / optimisation?


There's a setup cost involved for callback, so it doesn't make sense for  
very short slots.


I'd rather fix code for both cases.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] callback?

2010-06-18 Thread Kornel Lesiński

On 18-06-2010 at 14:46:13 GRolf ger...@pictureparking.com wrote:

let's say I have a query that will fetch employees from a table. every  
row has a field department_id.


when looping through this array in my template, is there a way to call a  
callback function that will fetch the department's name from an other  
table?


PHPTAL automatically calls methods in TAL expressions. If you use ORM it  
should be quite simple, e.g. if you have Employee object that has  
getDepartment() method that returns Department object:


li tal:repeat=employee employees  
tal:content=employee/getDepartment/name/



Alternatively you can call PHP functions using php: prefix in expressions:

li tal:repeat=employee_row employees_array
  tal:block tal:define=department  
php:get_department_row(employee_row['department_id'])  
tal:content=department/name/


-- regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] phptal.org vanished

2010-06-14 Thread Kornel Lesiński

On 13-06-2010 at 04:40:45 s...@prrbl.org wrote:


Is this normal ? We can not reach phptal.org anymore.


Not normal, but it's fixed now. I've had to move to another DNS server,  
and I've messed up some config in the process.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


[PHPTAL] PHP5 DOM prefilters

2010-06-14 Thread Kornel Lesiński


I've realized that exposing PHPTAL's DOM in prefilters wasn't the best  
idea - it's too basic to be useful.


So I've added PHPTAL_PreFilter::filterElement() method, which receives  
PHP5's native DOMElement to work on. This allows you to use full DOM,  
XPath, XSLT etc. in prefilters.


Even if you use DOM-based prefilter, PHPTAL still uses its own parser, and  
there's a lot of magic going on behind the scenes making PHPTAL's parser  
build PHP5 DOM and then convert PHP5 DOM to PHPTAL DOM.



http://phptal.org/files/PHPTAL-1.2.2b3.tar.gz

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Spelling mistakes in the manual

2010-06-03 Thread Kornel Lesiński

On 30-05-2010 at 12:40:33 Alex a...@xplodinghead.org wrote:


I've found a few spelling mistakes in the manual. English is not my fist
language and I'm not sure if this is the right place to mention it but
here I am ;)


Thanks. They're fixed now.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] require_once vs autoloading

2010-06-02 Thread Kornel Lesiński

On 02-06-2010 at 05:10:07 Tjerk Meesters tjerk.meest...@gmail.com wrote:


I could be wrong here, but I think it's not so much any problem with
require_once as it is to reduce memory consumption while using the
library. This happens when developers only use 30% of the library and
yet the whole shebang is loaded on every request ;-)


Yes, that's the reason. Large parts of PHPTAL are used only at  
compile-time. There are optional parts like filters, translation services.  
There's bunch of Exception subclasses which usually are not used.


I'd like all PHPTAL features to just work after you include only  
PHPTAL.php, but OTOH I don't want to load classes that are not going to be  
used.



Let me know if you find any problems with autoload.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] require_once vs autoloading

2010-06-02 Thread Kornel Lesiński

On 02-06-2010 at 09:56:23 Robert Goldsmith rgoldsm...@names.co.uk wrote:

I think autoloading is a good idea but please keep in mind that the app  
the phptal is being used within may already have autoloading configured.  
a prime example would be Zend.


I've used spl_autoload_register(). Does it conflict with Zend?

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] require_once vs autoloading

2010-06-02 Thread Kornel Lesiński

On 02-06-2010 at 10:33:00 Robert Goldsmith rgoldsm...@names.co.uk wrote:


No idea :)

However, if you allowed for autoloading to be optional then if needed  
people could turn it off and replace it with an external system such as  
Zend's. Maybe moving the autoloader into its own file and telling people  
they need to require_once the file if they wish to use the phptal  
autoloader.


Why would someone choose to replace PHPTAL's autoload with something else?  
(I'm not implying it's perfect or such, just wondering what problem would  
such option solve).


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] require_once vs autoloading

2010-06-02 Thread Kornel Lesiński

On 02-06-2010 at 10:58:41 Tjerk Meesters tjerk.meest...@gmail.com wrote:

Zend uses spl_autoload_register() as well I believe, so that should be  
safe.


The main problem I can see is that if there's an existing __autoload()
function, spl_autoload_register() will replace it (as stated in the
manual). I don't think putting the autoloader in a separate file will
make a difference.

This will probably require a change in the major/minor revision
number, so that developers are aware that it may break their code.


That's a good point.

This might avoid the problem in basic case:

if (!spl_autoload_functions()  function_exists('__autoload')) {
spl_autoload_register('__autoload');
}

but I'm not sure if it's not too hacky.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] require_once vs autoloading

2010-06-02 Thread Kornel Lesiński

On 02-06-2010 at 11:10:43 Robert Goldsmith rgoldsm...@names.co.uk wrote:

Why would someone choose to replace PHPTAL's autoload with something  
else? (I'm not implying it's perfect or such, just wondering what  
problem would such option solve).


If people already have autoloader code and wish to use only one  
autoloader in their application or if they find the autoloader they are  
already using conflicts with the phptal one then it would be good to  
allow them to disable the phptal autoloader.


require_once PHPTAL.php;
spl_autoload_unregister(array('PHPTAL','autoload'));
// if needed: spl_autoload_register('__autoload');

Would that be OK?

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] meta tal:content=.../ not working - expected behaviour?

2010-05-05 Thread Kornel Lesiński

On 05-05-2010 at 10:20:28 Marco Pivetta ocram...@gmail.com wrote:


So I'm forced to set XML only, right?


By default PHPTAL works in XHTML mode, and in this mode meta (as well as  
br, link, etc.) gets special handling and is always empty.


If you're generating non-XHTML XML, then set PHPTAL to generate arbitrary  
XML: $phptal-setOutputMode(PHPTAL::XML);


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] metal slots and repeats in metal macros

2010-05-05 Thread Kornel Lesiński

On 05-05-2010 at 14:26:08 Robert Goldsmith rgoldsm...@names.co.uk wrote:

Just a quick one. Could someone tell me how to reference a variable  
defined within a metal macro from within a slot?


You can't. Slots aren't filled on demand, but in advance before the macro  
is called (slot in a loop would repeat the same content over and over).


In particular, I'd like to define a macro that generates a calendar grid  
of days and then use a slot to provide varying content to be rendered  
within the 'day' cells. I am trying to do this as a macro accepting an  
array and looping through the array content. This works fine but when I  
then try to split out the cell content into a slot, I receive errors  
that I can't access the current loop value (or, by my understanding, any  
other variables defined within the metal macro) from the slot.


A quick (very simplified) example...

The macro block (in macro.xhtml):
tal:block
table metal:define-macro=calendarMonthGrid
thead
tr

thmonday/ththtuesday/ththwednesday/thththursday/ththfriday/ththsaturday/ththsunday/th
/tr
/thead
tbody
tal:block tal:repeat=currentDay days
td
tal:block 
metal:define-slot=calendarDayContent /
/td
/tal:block
/tbody
/table
/tal:block


You could change:


tal:block 
metal:define-slot=calendarDayContent /


to:


tal:block 
metal:use-macro=${calendarDayMacro} /


And instead of filling slot, define macro for day:

span metal:define-macro=dayMacro  
tal:content=currentDay/someInterestingInfo /


tal:block tal:define=days monthDays; calendarDayMacro  
string:thisfile.xhtml/dayMacro  
metal:use-macro=macro.xhtml/calendarMonthGrid



--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Does stripComments() work?

2010-03-23 Thread Kornel Lesiński

On 22-03-2010 at 20:03:18 romtek rom...@gmail.com wrote:


Here's a message I get:

PHPTAL Exception: Could not load class PreFilter_StripComments for
prefilter 'strip_comments' in:
C:\Users\[name]\Documents\Dev\Web\Sites\project\3rdpartybackendlibs\phptal\PHPTAL\.
Load class before execution of the template or add path to plugin loader



I am resending this because it seems to have gotten lost or unnoticed.


I'm aware of this. It will be fixed in due course. In the meantime, you  
can work around that problem by including PreFilter_StripComments class  
yourself.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Duplcate/repeated macros

2010-03-07 Thread Kornel Lesiński
On 07.03.2010, at 15:44, Rowan @ Jetboy wrote:

 A very simple example. If I have a macro with a slot:
  
 div metal:define-macro=page
 div metal:define-slot=slot/div
 /div
  
 and another macro:
  
 div metal:define-macro=box
 div tal:content=heading/div
 /div
  
 I can fill 'slot' with multiple instances of 'box' like:
  
 div metal:use-macro=page
 div metal:fill-slot=slot
 div metal:use-macro=box/div
 div metal:use-macro=box/div
 /div
 /div
  
 As I'd expect, just using $template-heading = 'Heading name', echos 'Heading 
 name' to both boxes. What do I need to change so I can insert unique heading 
 content into each 'box' instance?

You can locally redefine variables using tal:define, like this:

div metal:fill-slot=slot
div tal:define=heading string:another value 
metal:use-macro=box/
div metal:use-macro=box/
/div

-- 
regards, Kornel




___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Conditional slot containing element/s

2010-03-07 Thread Kornel Lesiński

On 07.03.2010, at 18:42, Rowan @ Jetboy wrote:

 If I have a containing 'wrapper' element to a slot definition:
 
   div class=wrapper
   tal:block metal:define-slot=content /
   /div
 
 how can I show or hide 'wrapper' dependent on whether the slot's filled?
 
 Slot filled:
 
   div class=wrapper
   pcontent/p
   /div
 
 Slot unfilled:
 
   Nothing!
 
 
 I appreciate I can move the slot definition to the 'wrapper' element, but
 this would mean having to insert 'wrapper', in addition to the content,
 whenever I wanted to use the slot. Presumably there's a better way?

I'm afraid that ability to check slot is not exposed in TALES. 

You could set a variable in addition to slot:

div class=wrapper tal:omit-tag=true:hide-wrapper
tal:block metal:define-slot=content /
 

/div

or if the wrapper is complex, create another macro that fills slot with the 
wrapper.

-- 
regards, Kornel




___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] nested cache bug

2010-03-04 Thread Kornel Lesiński

On 04-03-2010 at 13:45:44 Ivo Võsa i...@insert.ee wrote:


Hello, with markup like this

div phptal:cache=1m per string: 1 1 div phptal:cache=1h per  
string: 2 2 /div /div


i'm getting following results:

request 1:
div 1 div 2 /div /div

request 2:
div 1 div 1 div 2 /div /div /div

request 3:
div 1 div 1 div 1 div 2 /div /div /div /div

and so forth.


Indeed. Thanks for good test-case. The bug is fixed in SVN.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


[PHPTAL] Experimental version with PHP 5.3 namespaces

2010-01-27 Thread Kornel Lesiński

Little background story:

PHPTAL has been accepted as PEAR package, but PEAR requires change of  
class names from PHPTAL_* to HTML_Template_PHPTAL_*, which would break all  
existing code for IMHO not a good enough reason.


Therefore I've decided that if I'm having to break existing code, at least  
I'll make it for a better reason: migration to PHP 5.3 namespaces and  
PEAR2 (don't worry, I'll maintain PHP 5.2/PEAR1 package for as long as  
it's needed).



Here's my first try:

http://phptal.org/files/PHPTAL-1.2.2-namespaced.tar.gz


*WARNING:* don't install this as a PEAR package! I haven't upgraded build  
system yet. Just unpack it somewhere and include using absolute path. It's  
not backwards compatible. Requires PHP 5.3 of course.



There are still some unresolved bugs, e.g. PluginLoader (that loads  
prefilters) isn't namespace-aware yet and will fail. I've had some  
problems with Phing and PHPUnit getting confused by namespaces.



Changes required in your code:

use pear2\HTML\Template\PHPTAL;

$tpl = new PHPTAL\PHPTAL();



Classes that were called PHPTAL_Foo_Bar_Baz are now PHPTAL\Foo\Bar\Baz  
(assuming you add 'use' statement as above to _every_ file that refers to  
them). Class PHPTAL became PHPTAL\PHPTAL. PHPTAL_VERSION is PHPTAL\VERSION.


I'm not sure what to do with phptal_tales() function and function  
modifiers. Currently they're in PHPTAL namespace (PHPTAL\phptal_tales()),  
but it might make sense to move them to global namespace, so that existing  
modifiers don't need any code changes.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] macros in external files

2010-01-15 Thread Kornel Lesiński

On 15-01-2010 at 16:07:45 Peter Niederlag pe...@niederlag.de wrote:


I want to explore the possibilities of macros. Using a
metal:define-macro INSIDE my template works as expected.

However I fail to use a macro defined in another file.

Trying to access the same macro from another template by
'metal:use-macro=file.xhtml/mymacro' unfortunatly fails. :-

It seems to me that the generated template tries to call a
'tpl_4b5072d9_functions__hdJL174SgV8j9WAXA4fLmw_mymacro()' but the
generated file has written this function into
'tpl_4b5072d9_functions__hdJL174SgV8j9WAXA4fLmw()'

Note that the '_maymacro' part is missing here.

Does anybody have an example on using macros in external files that is
working? Or could it be there is a bug?


The external file has to have element with appropriate metal:define-macro  
attribute.


In your case file.xhtml is expected to have foo  
metal:define-macro=mymacro.


You can't simply call entire file as macro.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Is this a typo?

2010-01-07 Thread Kornel Lesiński

On 07-01-2010 at 05:53:30 Wallace McGee wall...@petrosys.com.au wrote:


Hi guys,

I just got an error msg and saw this apparent typo:
_executeMacroOfTempalte

eg:
\Temp\tpl_4b457551_myobSummary_xhtml__NFgTOiFviwyk0yIkOTzxWg.php(251):  
PHPTAL-_executeMacroOfTempalte('../common/xhtml...', Object(PHPTAL))


It does not appear to be causing a problem as everything runs smoothly  
when I dont make mistakes and cause errors.. just thought I would let  
people know.


Yes, that's a typo. It's corrected in SVN.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] i18n plural forms

2010-01-07 Thread Kornel Lesiński

On 06-01-2010 at 21:13:55 Marcin Głowacki panglowa...@gmail.com wrote:


How to use gettext plural forms in PO file?

I've added suitable header (Plural-Forms: nplurals=2; plural=n != 1;\n  
- for english) and tried in different ways:


msgid picture
msgid_plural pictures
msgstr[0] picture
msgstr[1] pictures

or

msgid picture
msgid_plural ${n} pictures
msgstr[0] ${n} picture
msgstr[1] ${n} pictures

but nothing worked ;-/

phptal used:

tal:block i18n:translate=span i18n:name=n  
tal:replace=data/count/ pictures/tal:block


where data/count is 1, 2, 3, ...



Unfortunately it doesn't support it out of the box.


In GetTextTranslator class change:

$value = gettext($key);

to something like:

if (false === strpos('${number}', $key))
{
$value = gettext($key);
}
else
{
$value = ngettext($key, $key, $this-_vars['number']);
}


The problem is, as you see, that gettext requires use of a different  
function for plural form, and TAL syntax has no way to indicate when this  
is needed. I'm open to suggestions.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] while loop in PHPTAL

2009-12-31 Thread Kornel Lesiński

On 31-12-2009 at 04:44:34 romtek rom...@gmail.com wrote:


Thank you very much  for this sample! It's much more elegant, easier to
understand and maintain than what I've come up with. Things like this had
better be published in a special section of documentation. And I hope  
that
array_chunk() doesn't copy data needlessly. This method does introduce  
more

overhead.

Kornel, what would you do if data were a collection but not an array
(besides using something like what was suggested by Rasmus Schultz at
http://php.net/manual/en/function.array-chunk.php)?


If it's small enough to fit in memory, then probably conversion to array  
with iterator_to_array() will be fastest.


Otherwise you could write something like IteratorIterator  
http://www.php.net/IteratorIterator that ignores reset() and pretends it  
ends every n elements.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] while loop in PHPTAL

2009-12-30 Thread Kornel Lesiński

On 29-12-2009 at 22:06:13 romtek rom...@gmail.com wrote:


I was looking for a more elegant way to generate grids using PHPTAL that
what I've been using and stumbled upon this post:
http://lists.motion-twin.com/pipermail/phptal/2007-February/000730.html.  
In

it, Aaron McClimont has proposed adding a while loop (and also
dowhile)construct to PHPTAL. I think it's very valuable as it allows for
much more elegant code in certain situations. Has this been added to the
library? If not, could it be?


Are there any other uses for while?

Variable number of columns can be done more elegantly than by _copying   
pasting_ code, and it can even vary at run time:


tr tal:repeat=row php:array_chunk(data, number_of_columns)
  td tal:repeat=col row tal:content=col /
/tr


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Support for PHP 5.3 closures

2009-12-24 Thread Kornel Lesiński

On 23-12-2009 at 22:16:25 Iván Montes drsl...@pollinimini.net wrote:


Ok, I see. Certainly native properties access are faster than using the
magic __get() method, although I would guess that for the kind of
loops in templating logic, the difference would be totally negligible.


Yes, it probably would be negligible most of the time, but unfortunately  
lots of users are (unreasonably) afraid of template engine overhead and  
use synthetic benchmarks to compare template engines :(


It's also far-reaching change which couldn't be reversed without breaking  
people's templates, so I need to be careful not to complicate future  
development.



${closure}  - $this-closure
${call:closure} - $this-closure()
${closure/foo} - $this-closure()-foo
${call:closure/foo} - $this-closure()-foo()

So basically the call modifier just operates over the last segment of
the path. Previous segments being closures would be automatically
executed by Context::path().


I think technically that's workable solution. I'm a little concerned that  
it would be confusing to users - closures would sometimes work, and  
sometimes cause PHPTAL to die with error like Cannot convert Closure to  
string.



Also, what's your opinion about handling of __invoke() on objects that  
have public properties and methods? Should PHPTAL test presence of methods  
and properties first, or should it always invoke first?




By the way, reviewing the Context.php code I noticed the following lines:

public function __get($varname)
 {
 if (property_exists($this, $varname)) { // must use  
property_exists to avoid calling own __isset().
 return $this-$varname;// edge case with NULL  
will be weird

 }


Good point. I've removed that.

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] PHPTAL PEAR news

2009-12-21 Thread Kornel Lesiński

On 20-12-2009 at 23:46:11 Daniel Trebbien dtrebb...@gmail.com wrote:


Would you like bug reports to be posted to the new pear package site,
or do you want to continue receiving them through the mailing list?


I think PEAR bug tracker should work already, and I prefer that.

However, if you're not sure if something is a bug or a feature, then I  
don't mind if you post it to the mailinglist :)


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] PHP newline consumption

2009-12-10 Thread Kornel Lesiński

On 10-12-2009 at 03:18:56 romtek rom...@gmail.com wrote:


This would also be useful for generating plain text email.


People, please! Stop wasting your time with PHPTAL and plaintext! It's  
deliberately *not* supported.


http://phptal.org/wiki/doku.php/plaintext

--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Re: PHP newline consumption

2009-12-10 Thread Kornel Lesiński

On 09-12-2009 at 23:06:40 Richard Cernava cern...@gmail.com wrote:

I hate to bring this back up, but this does not seem to be fixed. I'm  
running PHPTal 1.2.2a1.


inside function prepare() I added the preg_replace underneath $result =
$this-parse(); to fix it for now.

$result = preg_replace('/\?\r?\n/', ?\r\n\r\n, $result);


Can you send me example template that exposes the problem?

I'd rather not fix it by find'n'replace, as it could change other XML  
processing instructions, markup in CDATA etc.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


  1   2   3   >