Re: [PHPTAL] require_once vs autoloading

2010-06-02 Thread Kornel Lesiński

On 02-06-2010 at 10:33:00 Robert Goldsmith  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  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  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] require_once vs autoloading

2010-06-02 Thread Kornel Lesiński

On 02-06-2010 at 11:54:30 Tjerk Meesters  wrote:

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?


Wouldn't that cause issues when PHPTAL needs to load more classes
during the course of the script's execution?


Yes, but PHPTAL doesn't need to load more classes when PHPTAL.php is  
included. I could fall back to require_once if this is ever needed.


--
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  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] phptal.org vanished

2010-06-14 Thread Kornel Lesiński

On 13-06-2010 at 04:40:45  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] callback?

2010-06-18 Thread Kornel Lesiński

On 18-06-2010 at 14:46:13 GRolf  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:


tal:content="employee/getDepartment/name"/>



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


  tal:content="department/name"/>


-- 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  wrote:


taken the following macro and macro-usage:









metal:use-macro="ul">


${item}



I would expect the template to be rendered like this:

a
b
c


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":

${x}



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  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  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] Insert TAL variables into TAL variable

2010-06-29 Thread Kornel Lesiński

On 29-06-2010 at 16:41:15 Bas  wrote:



.




Now, how would I get the variable ${NAME} to be processed? What would be  
the right way to go about this?


The only way I can think of, is to insert the articles, execute the  
template and assign the output to PHPTAL again, parse again for the  
article variables and output to screen.


Anyone have a better idea?


First, keep in mind that TAL templates can execute arbitrary PHP code, so  
only allow templates to be edited by users you trust.



To execute additional TAL code, use should macros:



You can use ${} variables in macro name, and path to macro can be anything.

Now, if you want macro to load templates from database, rather from disk,  
write SourceResolver class that recognizes your macro paths and loads them:


class ArticleSource extends PHPTAL_SourceResolver
{
  function resolve($path)
  {
 if (looks_like_path_of_article($path)) {
return new PHPTAL_StringSource(get_article_from_database($path));
 }
  }
}

$phptal->addSourceResolver(new ArticleSource());


This will create fake filesystem from which PHPTAL will be able to load  
templates.


--
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 16:46:43 Bas  wrote:

I implemented the solution, but now the macro is cached and I don't know  
how to specify that it should not be cached.

I already added a tal:cache attribute to the define macro tag, like this:



But no matter what I put in the tal:cache attribute, I still get the  
same output as when I first executed the macro.
I am sure the content of the article changed, if I just echo the content  
in the resolve function I do see the modified content.


Does it work without tal:cache?

Is the problem in caching values of variables, or do you change source  
code of the template and it's not updated?


If unchanging source code is the problem, then when you create  
PHPTAL_StringSource _don't_ specify path parameter  (it's used for  
caching, without it md5 of template is used) or implement your own  
PHPTAL_Source class that has getLastModifiedTime() method.


--
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  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  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] Re: Insert TAL variables into TAL variable

2010-07-06 Thread Kornel Lesiński

On 30-06-2010 at 17:42:17 Bas  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] Accessing namespaces from templates

2010-07-08 Thread Kornel Lesiński

On 08-07-2010 at 13:50:27 Thomas D.  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.  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.
 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] How to use repeat as while

2010-07-29 Thread Kornel Lesiński

On 29-07-2010 at 16:09:52 Klederson Bueno  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] How to use repeat as while

2010-07-30 Thread Kornel Lesiński

On 29-07-2010 at 20:47:05 Klederson Bueno  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 write a sort link for table headers

2010-07-30 Thread Kornel Lesiński

On 30-07-2010 at 16:41:26 Richard Dyce  wrote:


At present, I'm using:


  tal:content="repeat/item/key" >field name




That looks ok.


where I've captured incoming values in the GET ...

$template->column   = array_key_exists('column', $_GET)) ?  
htmlspecialchars($_GET['column']) : '';  # grab the sort column


Slightly off-topic, but usually you shouldn't use htmlspecialchars() when  
setting values for PHPTAL. PHPTAL HTML-escapes all output by default.


However, when you build URLs in TAL, you might need to urlencode()  
arguments.


I need to decide how to signify that a table, already sorted by  
'column', should be reverse sorted by column. In the past I'd do this by  
using the case of 'column' - 'column' for ascending and 'COLUMN' for  
descending. Is there a way to do this without resorting to php? or is  
there a more idiomatic PHPTAL way of doing it?


One way is to handle such things outside PHPTAL, and just give it array of  
URLs for sorting.


If you want to compute those column names in TAL, you could write TALES  
modifier and use ${upper:criteria}, but I think there's nothing wrong with  
${php:strtoupper(criteria)}.


Personally I use "column" and "-column" for sorting.

--
regards, Kornel

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


Re: [PHPTAL] PHPTAL and form macros

2010-08-02 Thread Kornel Lesiński
On 02.08.2010, at 19:27, Richard Dyce wrote:
> 
> Just a pre-re-invent-the-wheel inquiry... Does anyone have an example of 
> macros for formatting form fields in phptal?
> 
> I have an older framework which create field objects based on the data and 
> type, and populates them from a simple array:
> 
> e.g.
> 
>  
>  $fields = array(
>'id'=> array('label'=>'',  'type'=>'hidden', 'value'=>2),
>'name' => array('label'=>'Name',  'type'=>'text',   'value'=>'John Smith'),
>'user'=> array('label'=>'Owner', 'type'=>'select', 
> 'valuelist'=>array(1,2,3), 'value'=>2)
>);
> 
> ?>
> 
> It seems daft me to duplicate the logic twice over, and it appears that 
> phptal might be able to handle it with some repeats and templating. But 
> before I tie myself in knots over this, has anyone already done it, or tried 
> it and found the gotcha ;-)
> 

If you already have framework that works, then most pragmatic solution would be 
to let it generate HTML, and then output it literally in PHPTAL:

${structure form_html}


I don't have any code to generate form from such structure, but it seems quite 
doable with TAL.

-- 
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  wrote:


My current templates looks like this:

FILE main.xhtml:





FILE home.xhtml:










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] Re: SourceResolver path in nested macro

2010-08-06 Thread Kornel Lesiński
On 6 Aug 2010, at 10:35, Bas Kooij wrote:

> Thanks for the reply,
> 
> So if I name the macro customMacro/customMacro the resolver would recognize 
> it? But that makes the second part irrelevant for CustomResolvers right?

Right. If you use path customMacro/customMacro then resolver will get 
"customMacro" as path to resolve. Macro syntax is path/macro, and resolver is 
only for resolving paths, not macros.

If you used macros "path/macro1", "path/macro2", "path/macro3" then your 
resolver would be called only once with path "path".

> Slightly off topic... 
> 
> I really love PHPTal, it has cut development time for implementing templates 
> in half. 
> The only time I get stuck is when I have to insert dynamic templates into my 
> PHPTal template files. This is quite a common occurrence when clients use a 
> content 
> management system to edit pages. I want them to be able to insert some sort 
> of 
> tags in the CMS, ie. [DATE], which I can then replace with PHPTal code, for 
> instance 
> . 

This is what prefilters are for:

class DateMagic extends PHPTAL_PreFilter 
{
  function filter($src) {return str_replace('[DATE]', '', $src);}
}

$phptal->addPreFilter(new DateMagic());



-- 
regards, Kornel


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


Re: [PHPTAL] Re: SourceResolver path in nested macro

2010-08-06 Thread Kornel Lesiński
On 6 Aug 2010, at 12:16, Bas Kooij wrote:

>> This is what prefilters are for:
>> 
>> class DateMagic extends PHPTAL_PreFilter 
>> {
>>  function filter($src) {return str_replace('[DATE]', ' tal:content="date | nothing" />', $src);}
>> }
>> 
>> $phptal->addPreFilter(new DateMagic());
>> 
> 
> I tried usign PreFilters, but that doesn't seem work for inserted content, 
> only for code which is hard coded in the template. So if I retrieve the html 
> with the [DATE] tag from a database, insert it into a variable in my TAL 
> template, the PreFilter never fires for the [DATE] tag. If I put the [DATE] 
> tag in the template file itself it does work.

That's correct. PreFilter is run only once before template is executed for the 
first time, and result of PreFilter is cached by PHPTAL for all later runs of 
that template.

In PreFilters you're not supposed to replace your tags with data, but replace 
your tags with PHPTAL tags that will output desired data.

For example if you wanted [DATE] to insert current date, use PreFilter with:

str_replace('[DATE]', '', $src)

and then only update date variable:

$phptal->date = date('Y-m-d H:i:s');

This will give you tempalte that has [DATE] in it's source, and gives current 
date, updated every time.

> I have a working solution now. I have this in the home.xhtml template:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> And I use the following SourceResolver:
> 
> class MySourceResolver implements PHPTAL_SourceResolver {
>public function resolve($path) {
>if($path == 'homeMacro') {
>$pageContent = [retrieve html with DATE tag from DB]
>$content = ' macro="customMacro">'.$pageContent.'';
>$content = str_replace('[DATE]', '19-02-1981', $content);
>return new PHPTAL_StringSource($content, 
> PHPTAL_StringSource::NO_PATH_PREFIX.md5($pageContent));
>}
>}
> }
> 
> Is this the easiest/only way to achieve what I want?

You've reinvented prefilter here. It happens to work because md5($pageContent) 
forces to reload whole template whenever date changes (that's quite 
inefficient).

Even if you wanted template recompiled like that, you could do it with 
prefilter:

class DateMagic extends PHPTAL_PreFilter 
{
  function filter($src) {return str_replace('[DATE]', '19-02-1981' , $src);}
  function getCacheId() {return '19-02-1981';} // 
http://phptal.org/manual/en/split/prefilters.html
}


Do you want to allow your clients to use all PHPTAL constructs, or only HTML 
with your tags?

If the latter, then you don't need any resolvers or filters:

$phptal->page_content = str_replace('[DATE]', '19-02-1981', 
retrieve_html_with_DATE_tag_from_DB());



-- 
regards, Kornel


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


Re: [PHPTAL] Re: SourceResolver path in nested macro

2010-08-06 Thread Kornel Lesiński

On 06-08-2010 at 13:03:20 Bas Kooij  wrote:


Sorry, I tried to simplify things by using a date tag, but this has just
caused confusion. I don't just need to replace a date tag, I need to  
replace a
tag named logos, which I'd like to replace with a macro containing TAL  
code to

insert a bunch of company logo's. I have now done it like this:

In home.xhtml





[HOME]




Then I use the following PreFilter:

class HomePreFilter extends PHPTAL_PreFilter {
function filter($src) {
$content = [retrieve home page from db]
$content = str_replace('[logos]', '', $content);
return str_replace('[HOME]', $content, $src);
}
}

Which works fine. Is this the best way?



For changing [logos] to   
it's perfect.


I'm a bit concerned about retrieving pages from DB directly in the  
prefilter. Keep in mind that prefilters are applied to all files, so it  
would be run on logos.xhtml as well.


You could replace [HOME] with call to macro that is loads homepage via  
resolver (prefilter will be applied to that resolved page too, so you can  
have [HOME] that loads homepage with [logos] in it).


As you've noticed, either way can be made to work, but in PHPTAL the  
concept is that:


 * Load, but don't replace in resolvers.
 * Replace, but don't load in prefilters.

--
regards, Kornel

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


Re: [PHPTAL] Re: SourceResolver path in nested macro

2010-08-06 Thread Kornel Lesiński

On 06-08-2010 at 14:13:19 Bas Kooij  wrote:

It seems a little complicated to have to output another macro to get it  
to work. Anyway, thanks for all your help, I've got it all to work the  
way it should. Still think it's pretty complicated stuff for an  
essentially simple operation, ie. parse some TAL variable twice.


Yes, it is somewhat complicated, because PHPTAL is a compiled language. To  
be really fast it has to avoid parsing as much as possible.


ps. Something very different: is there a reference available to the  
Translator inside the templates, or do I have to provide one myself? (I  
can start a new subject for the archives if you want)

Again, I appreciate your time, sorry for all the questions.


I'm not sure what you're asking about.

If you're writing your own translation service, then it might be easiest  
to take PHPTAL_GetTextTranslator and modify it.


--
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  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:
Kopiëren van een rapport

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  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] Doctype removed with HTML5 output

2010-09-09 Thread Kornel Lesiński

On 09-09-2010 at 17:43:23 Bas Kooij  wrote:

If I set the ouput mode to PHPTAL::HTML5 the doctype gets corrupted. I  
have the

doctype set to:




If I remember correctly, this DOCTYPE triggers quirksmode (emulation of  
IE5 CSS bugs) — you shouldn't use it.



which PHPTAL rewrites to:



If I set the ouptut mode to XHTML it leaves the doctype as it was.


That's intentional. PHPTAL does not support HTML4, and HTML5 forbids  
DOCTYPEs other than .


--
regards, Kornel

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


Re: [PHPTAL] Re: Doctype removed with HTML5 output

2010-09-10 Thread Kornel Lesiński
On 9 Sep 2010, at 22:24, Bas wrote:

> Ok, thanks. I use it for sending a newsletter, but I would 
> be better off using XHTML rendering mode then?

Either mode should "work" as far as HTML in email clients "works" (PHPTAL's 
XHTML mode is backwards-compatible with text/html parsing). 

In case of e-mails DOCTYPE unfortunately doesn't trigger standards/quirks mode 
reliably, e.g., latest Outlook will completely screw it up no matter which mode 
you choose :(

> I think this 
> doctype () is giving a lot of email clients 
> a lot of trouble, they seem not to recognize the doctype as HTML 
> and render in text mode instead.

That's strange. It shouldn't be needed, because multipart e-mails have 
Content-Type header that declares which part is HTML and which is text. Are you 
sure you have headers correct?

I've checked few e-mails in my inbox, and some don't even have DOCTYPE.

-- 
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  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] 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] Next stable release

2010-09-20 Thread Kornel Lesiński

On 18-09-2010 at 18:33:59 Per Bernhardt  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] A counterpart of true: modifier

2010-09-27 Thread Kornel Lesiński

On 26-09-2010 at 20:42:46 romtek  wrote:


Hi,

PHPTAL offers PHPTALES modifier true: (equivalent of !empty()). I find it
very useful. I would really like to have its opposite. Perhaps, false:.  
But

I think that not: should be an equivalent of empty(). This would allow us
not to have to check for a variable's existence prior to checking its  
value.


not:true: works

exists: exists :)


--
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-29 Thread Kornel Lesiński
On 27 Sep 2010, at 22:22, Piotr Kroczyński wrote:
> 
> After clone PHPTAL stripped doctype... Why ?

Thanks for the test case — it was very helpful.

Short story: it's a bug.

Long story:

PHPTAL stores template state in nested PHPTAL_Context objects (tal:define, 
tal:repeat, macro calls, etc. create nested contexts). 

Clone of PHPTAL creates nested context too, which keeps reference to previous 
context. This makes new PHPTAL object behave like macro running in the old one 
(in fact that's how macros are executed).

So the problem is that cloned PHPTAL tries to set DOCTYPE in outermost context, 
which happens to be still in the previous PHPTAL object.

I've added quick'n'dirty fix for it in SVN (by setting DOCTYPE in two places). 
Proper fix might need some refactoring to eliminate cloning of PHPTAL in macro 
calls :(

> When I change output mode to HTML5, PHPTAL generates broken html (no quotes 
> around attributes values, does not matter if after clone or before) and does 
> not change/validate doctype in layout.html. Is this normal?

Do you mean it's broken according to HTML5 specification, or broken because it 
doesn't look like XML? In HTML5 mode omitting of quotes is intentional and 
PHPTAL should omit them only in cases permitted in HTML5 text/html syntax.

PHPTAL also is supposed to force DOCTYPE to be the only one allowed in HTML5 
(so you could have well-formed XHTML/1 with named entities as input and HTML5 
as output). If it doesn't do that, then I'd like to see a test case for it.

-- 
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] Why PHPTAL stop rendering doctype after clone.

2010-09-30 Thread Kornel Lesiński
On 29-09-2010 at 21:28:52 Piotr Kroczyński   
wrote:


They say that values with space or special chars must be quotes around.  
They don't say that quotes should be ommited everywhere else. Just mine  
interpretation :)


Can you send me test case where PHPTAL omits quotes when it shouldn't?

--
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:
> 
> 
> 
> 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  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] callback?

2010-10-01 Thread Kornel Lesiński
On 1 Oct 2010, at 09:37, GRolf wrote:

> and how can I solve this if I want to use it in my tal:repeat?
> 
> 
> e.g. for a Client, who has (potentially) multiple "invoices"
> 
> 
> ${client/name}
> ${invoice} tal:condition="not:repeat/invoice/end">,
> 
> 
> 
> this works fine if I retrieve all invoices before, but can I do it without  
> looping through all clients in PHP first, if I'd have a function 
> getInvoices($client_id)... ? 

I'm not sure what you're asking about. If you don't want to loop clients and 
just display one, then:

${invoice},

If you want to loop IDs, not client objects, then give PHPTAL array of IDs.

-- 
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] Generating multiple values for the class attribute dynamically

2010-10-04 Thread Kornel Lesiński

On 2 Oct 2010, at 07:15, romtek wrote:

> Hi,
> 
> I sometimes need to use multiple values for the class attribute but can't 
> seem to find a way to do this in PHPTAL if those values are to be determined 
> at run-time. For example,
> 
> ...
> I also need to set an additional class value, say:
> "class php:item.is_inactive ? 'inactive' : null"
> 
> Would somebody please suggest a way to do this?

If you don't mind getting class=" " sometimes (harmless in HTML), then you can 
simply use:



-- 
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  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  you should write itemscope=""> (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] Multiple calls to use-macro and default slot

2010-10-12 Thread Kornel Lesiński
On 12 Oct 2010, at 11:08, Bicou wrote:

> When calling metal:use-macro multiple times, default slots don't get 
> reinitialized.

I've tested version in SVN and it passes test you've sent. Can you verify?

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

-- 
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  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] PreFilter - filterDOM

2010-10-15 Thread Kornel Lesiński
On 14 Oct 2010, at 19:13, Levi Stanley wrote:

> $node->setValueEscaped($url);

Unfortunately PHPTAL's DOM isn't quite like W3C DOM and doesn't support setting 
value on Elements. You'll need to create a text node in there:

> foreach($node->childNodes as $n) {
> $node->removeChild($n);
> }
> $node->appendChild(new PHPTAL_Dom_Text(htmlspecialchars($url),'UTF-8'));

I'd like to switch PHPTAL to real W3C DOM, but so far I haven't found a way to 
reliably manage namespace prefixes :(

-- 
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


[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   
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


Re: [PHPTAL] implode()

2010-10-29 Thread Kornel Lesiński

On 29-10-2010 at 08:23:42 GRolf  wrote:



I often find myself using tal:repeat to implode an array

in php
$myarr = array('one', 'two', 'three');

is easily converted to
one, two, three

with
implode(', ',$myarr);


But in PHPTal, this is quite cumbersome


${val}, 


Isn't there an easier solution?


You could write TALES modifier:

${val}${comma:val}

function phptal_tales_comma($expr,$nothrow)
{
	return '('.phptal_tale('not:repeat/'.$expr.'/end',$nothrow).'? : ", " :  
"")';

}

--
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  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', )

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',  
)


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  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


Re: [PHPTAL] Collecting translation messages from templates

2010-11-04 Thread Kornel Lesiński

On 04-11-2010 at 02:52:06 Per Bernhardt  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] runtime generated slot names

2010-11-08 Thread Kornel Lesiński

On 08-11-2010 at 11:53:55 Robert Goldsmith  wrote:


Hi all,

I'd like to create a macro with fillable slots but I'd like the names of  
these slots to be based on variable information passed to the macro. It  
appears at the moment that the content of a 'define-slot=""' is not  
processed like other content and is simply treated as a string. I'd  
prefer not to resort to macros because all the slots themselves are  
fully static - I just want to control which of these static slots are  
inserted at any time. I recognise that one possible suggested solution  
here might be a collection of conditionals to pick the slot but the  
macro I'm writing is in a library and the slot names are, therefore, not  
definable in advance. I hope this makes sense!


In essence, my fill-slot statements are statically named but my  
define-slot statements need to be able to take variable string content.


Anyone have any ideas?


It's easy to implement (see attached patch), but I'm wondering if you're  
not trying to do something that's unnecessarily complex, or could be done  
using existing PHPTAL features.


--
regards, Kornel

variable_slot_name.patch
Description: Binary data
___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] runtime generated slot names

2010-11-10 Thread Kornel Lesiński

On 08-11-2010 at 14:05:36 Robert Goldsmith  wrote:

The experience of the end user hides all of this and they would just do  
something like:


	


			This set of preferences control when and how we contact you when  
we need to. 






OK, that looks like a good use-case.


--
regards, Kornel

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


Re: [PHPTAL] Public repository for PHPTAL custom expression modifiers

2010-11-17 Thread Kornel Lesiński

On 16-11-2010 at 19:36:31 romtek  wrote:


Do you think it can spread people little more if you will make
public repository to store & share PHPTAL custom expression modifiers?



I like this idea.


I like it too. Would you implement it? Or maybe Wiki is enough?

--
regards, Kornel

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


Re: [PHPTAL] Public repository for PHPTAL custom expression modifiers

2010-11-17 Thread Kornel Lesiński
On 17 Nov 2010, at 10:59, Anton Andriyevskyy wrote:

> ... or maybe github?

How would that work?

Code hosted on github is a good idea, but I presume the repository needs to 
have some presence on phptal.org pages, so there's one obvious place to find 
them all.

-- 
regards, Kornel


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


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

2010-11-22 Thread Kornel Lesiński
>> $template = new PHPTAL($this->_viewDir . DS . $fileName);
>> $template->set($this->_viewVars);
> 
> Another thing that IMHO should be considered is that PHPTAL should
> implement ArrayAccess so you could do
> $template['menu'] = $menu;
> 
> Would a patch for this be accepted?

Sorry, no. That would duplicate $template->menu = $menu syntax, which works 
already.

I agree about setting all variables in one call, but I'd add separate method 
for it (setAll?)

-- 
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 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] Feature request: better integration with doctrine orm

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

> Kornel Lesiński wrote:
>> 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.
>>  
> Easier said than done.
> If users generaly have phonenumbers, it does not mean this concrete user has 
> phonenumber, can't be sure about it before call to database has been made.

I'm not sure what you mean. If you're trying to output property in PHPTAL, then 
it has to be read anyway.

Why is check for $obj->hasRelation() in PHPTAL ok, but not in Doctrine's 
__isset()?

-- 
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
>> I'm not sure what you mean. If you're trying to output property in PHPTAL, 
>> then it has to be read anyway.
>>  
> it won't get loaded if doctrine thinks it is allready loaded because __isset 
> told so.
> i think it will be to much work to patch doctrine - and yes Doctrine 2, which 
> is total rewrite, is coming out soon.
> so either way it will probably be unofficial patch

I've looked at Doctrine sources, and it seems to check $this->data[] and few 
other properties, but I haven't noticed isset($this->{$property}). If it 
realies on it somewhere, then it really deserved that rewrite ;)

-- 
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] Ztal 1.0.0

2010-12-18 Thread Kornel Lesiński
On Fri, 17 Dec 2010 16:06:33 -, Robert Goldsmith  
 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] "There is no namespace declared" error in v. 1.2.1

2011-01-13 Thread Kornel Lesiński
On Thu, 13 Jan 2011 10:22:52 -, Tjerk Meesters  
 wrote:



Here's the problem; it throw an error, saying that the myns namespace
is not defined ... is that expected?


Yes (if I understood correctly what you're trying to do).

PHPTAL checks correctness of namespace declarations from perspective of  
source files, not the output (it probably should check output too, but  
that's a harder problem).


So if a file, looked at in isolation (before macros are executed), doesn't  
have required xmlns, that's an error according to XML.



I have a mixed feelings about enforcing XML strictness. It's sometimes  
annoying, OTOH it's a bit dishonest to call TAL an XML language when it  
doesn't play by XML rules.


--
regards, Kornel Lesiński

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


Re: [PHPTAL] "There is no namespace declared" error in v. 1.2.1

2011-01-13 Thread Kornel Lesiński
On Fri, 14 Jan 2011 00:26:35 -, Tjerk Meesters  
 wrote:



What I would like, therefore, is either:
a) a way to define my own namespace programmatically before parsing  
starts

b) a way to relax the parser so that namespace checking is not enforced,
like how tal ns is also not enforced


If you want to have behaviour of TAL namespaces, then  
PHPTAL_Dom_Defs::registerNamespace() would do that, but that probably  
requires too much irrelevant code just to fake a declaration.


You could wrap the file in  in  
PHPTAL_PreFilter::filter() (it's run before the parser starts).


I'm also considering making parser configurable, so you could just replace  
PHPTAL's standard parser and use your own syntax (XML5, HTML, HAML or  
whatever you like). I'm not decided on details yet: how to select which  
parser is used, especially in macros (file extension, doctype, some config  
vars?). How to load it lazily (probably PluginLoader class should be  
finished for that, or maybe PHPTAL should just have callback function  
before reparse?).



c) only do namespace checks on the output


That's a tough one, as it could potentially depend on runtime behavior and  
prefixes across files, so don't hold your breath for it.


--
regards, Kornel Lesiński

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


Re: [PHPTAL] PHPTAL strange behaviour - bug or feature?

2011-01-25 Thread Kornel Lesiński

On Tue, 25 Jan 2011 08:41:09 -, Robert Partyka  wrote:

I'm playing a little with php: in PHPTAL and found strange behaviour  
today.


this works without problem:
tal:attributes="style php:tal_optIsSet(raport_values, 'rnNNg',
'visibility: visible', 'visibility: hidden')"

but this:
tal:attributes="style php:tal_optIsSet(raport_values, 'rnNNg',
'visibility: visible;', 'visibility: hidden;')"

create such error:

it looks like adding ";" to string making something really nasty with
TAL compilation. Or did I overlooked something in documentation?


; separates attributes in tal:attribute:

tal:attribute="href someurl; title sometext"

Use ;; if you want the ; character.

--
regards, Kornel Lesiński

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


Re: [PHPTAL] Wiki Down

2011-02-01 Thread Kornel Lesiński
On Mon, 31 Jan 2011 15:51:51 -, Miquel 'Fire' Burns  
 wrote:



It appears as though the wiki is down. I was just on the site trying
to see what changes I needed to allow upgrading to the newest version
for an app I made.


Ooops. It's now fixed. Sorry for the delay!

--
regards, porneL

___
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   
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   
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] spaces before and after translation keys

2011-02-14 Thread Kornel Lesiński
On Mon, 14 Feb 2011 10:03:52 -, Robert Goldsmith  
 wrote:


We've had an issue submitted for ZTal regarding trimming white space off  
the start and end of translation keys for i18n:translate. Looking at the  
code for the standard getText translator in PHPTAL the trimming of a  
translation key, along with some other operations, is in a separate  
function with a comment about legacy support. Any chance someone can  
clarify whether trimming of whitespace should or should not be applied  
to translation keys? We'd like to stay compatible with the PHPTAL 'way'  
in ZTal :)


TAL way is XML way, and XML way is to trim and normalize whitespace. I  
think trimming makes sense unless you're translating site from Pythonian ;)


--
regards, Kornel Lesiński

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


Re: [PHPTAL] macros with optional translation

2011-02-15 Thread Kornel Lesiński
On Tue, 15 Feb 2011 11:13:19 -, Robert Goldsmith  
 wrote:


Idea 1: Create a fake translation class that doesn't actually translate  
and which is registered if translation is disabled.
Idea 2: Use conditionals to check if translation is enabled and have  
translated and non-translated versions of all elements within the macro.


Obviously idea 1 is 'neater' for the templates but it prob. decreases  
performance a bit and I consider it a hack. Idea 2 is more 'pure' but  
would add a lot of bulk to the macro templates as well as more  
additional work.


What do people think?


Dummy translator is the way to go.

In terms of overhead, there's possible optimisation that could be added to  
PHPTAL: translate constant strings during compilation of template, and  
cache template per language.


--
regards, Kornel Lesiński

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


Re: [PHPTAL] Template Expressions and Functions

2011-03-25 Thread Kornel Lesiński
On Fri, 25 Mar 2011 07:34:51 -, Anton Andriyevskyy  
 wrote:


Great feedback!


*1. IF-THEN-ELSE*.


That's a tough one. I see two issues:

1. I can't figure out XML-friendly syntax that works well for if/else and  
especially if/else-if/else
2. There's beauty in TAL's purely functional design: elements are  
independent, state doesn't escape tree structure (except few edge cases I  
like to pretend don't exist :), and it can be generated in one pass (with  
no look-aheads).


e.g.:

…
...

would require keeping result of 'if' until 'else' is found, and result of  
'if' would escape its element. Also, probably any content between if and  
else would have to be forbidden (or would give unexpected result?)


This:


...


creates weird situation where all of  is discarded, *except* , and  
nesting of elements is different than what you get after execution (e.g.  
you might want if/else versions of 

Re: [PHPTAL] tal:equal ?!

2011-04-13 Thread Kornel Lesiński
On Wed, 13 Apr 2011 14:45:31 +0100, Ciprian Voicu   
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:

print some good content here


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




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] PHPTAL and ZTal

2011-04-14 Thread Kornel Lesiński
On Thu, 14 Apr 2011 13:42:55 +0100, Robert Goldsmith  
 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] new tag

2011-04-23 Thread Kornel Lesiński

On Fri, 22 Apr 2011 22:26:03 +0100,  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:





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.



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:



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] issue with variable defined in a full page macro

2011-05-07 Thread Kornel Lesiński
On Sat, 07 May 2011 14:19:26 +0100, Fernando Martins  
 wrote:


This is a real pity, because in the same way that people.zpt defines the  
common elements of a web site, so would do the global variable people,  
ie, keeping all the common data for all the pages. This limitation  
(bug?) forces to include a call to peopleGet in all php/zpt pages.


Slots "see" variables from context (file) they are run in, not from  
context where the macro is defined.


Instead of:



you could use:



and


--
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:


+


with:


+



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] issue with variable defined in a full page macro

2011-05-11 Thread Kornel Lesiński
On Sun, 08 May 2011 16:14:46 +0100, Fernando Martins  
 wrote:


I'm afraid I can't understand what you are trying to achieve there. What  
is the effect of the tal:define="callback 'display-list'" ?? what do the  
quotes do to display-list? and how would I use the callback? Sorry, very  
confused...


I've meant using callback (macro called from macro) instead of slots.

e.g. your code modified to use callbacks:



























I have a main page template person.zpt which defines the layout for all  
the pages of the web site. Every other page, say people.zpt,  
meeting.zpt, team.zpt merely fills in the slots. All I wanted was to  
avoid redefining common variables in all pages. Just factoring out the  
common data into the common template.


If you have certain variables on all pages, why not simply set them from  
PHP?


In PHPTAL slots are executed in context where fill-slot is used, not in  
context where define-slot is, so what you're trying to achieve is not  
possible with slots.


I wasn't aware that in Zope context is different. Can Zope's fill-slot use  
variables from both its context and the macro? If both macro and context  
of fill-slot have variable with same name, which one "wins"?


--
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   
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] PHPTAL and Google Website Optimizer

2011-05-27 Thread Kornel Lesiński
On Fri, 27 May 2011 22:09:37 +0100, Jason Pollentier  
 wrote:



I'm trying to get Google Website Optimizer working on my site using
PHPTAL, and I ran into a couple of big problems. I'm hoping somebody
else has already figured this out or can point out some solutions I'm
missing.

1) Google wants to verify that their code is installed correctly on my
page before I can continue with the setup. They're very particular, to
the point of complaining about the "// 

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   
wrote:


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


The problem is that when you call   
Login 


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:


--
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  
 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] Usage of __toString magic method

2011-06-05 Thread Kornel Lesiński

On Sun, 05 Jun 2011 15:58:06 +0100, Manu Robledo  wrote:

I came a cross some problems, which were caused by PHPTAS relying on the  
__toString() magic method, when converting objects to strings.


First problem: Exceptions can´t be thrown within __toString(), see:
<http://stackoverflow.com/questions/2429642/why-its-impossible-to-throw-exception-from-tostring>


That's the contract of __toString, so you shouldn't even try to throw  
exceptions from this method, even if you can get away with it sometimes.


Is there a strong use-case for throwing exceptions at point of conversion  
to string?


Second problem: __toString() is not correctly implemented in PHP <  
5.2.0, so that on a test server with an older PHP version, the output is  
just "Object".


5.2.0 has been released in 2006! I'd rather not support software even  
older than that.


Here is, how I extended the phptal_tostring() and phptal_escape()  
functions to implement this workaround (3 small changes):


http://pastie.org/2022716


Thanks. You bring very good point about implicit cast in implode(). I'll  
fix that one.


--
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  
 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] Usage of __toString magic method

2011-06-07 Thread Kornel Lesiński

On Mon, 06 Jun 2011 07:39:25 +0100, Manu Robledo  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] Extending namespace

2011-06-11 Thread Kornel Lesiński
On Fri, 10 Jun 2011 05:01:08 +0100, Hisateru Tanaka  
 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] "setting slots in any context"

2011-06-21 Thread Kornel Lesiński
On Mon, 20 Jun 2011 09:57:34 +0100, Per Bernhardt   
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] [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   
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  
 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] [PATCH] Shouldn't skip over __get() just because __isset() was defined…

2011-06-28 Thread Kornel Lesiński

On Tue, 28 Jun 2011 07:52:06 +0100, Ivo Võsa  wrote:

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.


But think other way. __isset() returns true and then after that __get()  
returns NULL. I think that it is even more illogical.


It's not consistent with behavior of isset() indeed (it's more like  
property_exists(), which may be useful to some), but if you don't want  
that case to happen, it's up to you to implement __isset() correctly so  
that it doesn't happen. PHPTAL doesn't stop you from doing that.


--
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   
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   
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] 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  wrote:


If my template code contains an unterminated HTML element (e.g. , , 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


  1   2   3   4   5   >