perlpunk / HTML-Template-Compiled

perl templating module with similar API as HTML::Template
6 stars 3 forks source link

Regexes in expression #2

Open ghost opened 10 years ago

ghost commented 10 years ago

I would like to have a feature for Regexes in expressions.

Like this:

<?IF expr="variable =~ /^blah(blubb)?/" ?>
<?/IF?>

or with like as equvalent for =~

<?IF expr="variable like /^blah(blubb)?/" ?>
<?/IF?>

The same with negated Regex match:

<?IF expr="variable unlike /^blah(blubb)?/" ?>
<?/IF?>

<?IF expr="variable !~ /^blah(blubb)?/" ?>
<?/IF?>

An other related nice feature would be getting the matched Regex subpatterns like this:

<?IF expr="variable =~ /^blah(blubb)?/" ?>
Match of pattern 1 is: <?= variable.1 ?>
<?/IF?>

or that:

<?IF expr="variable =~ /^blah(blubb)?/" ?>
Match of pattern 1 is: <?= variable.~1~ ?>
<?/IF?>

Or anything other syntax for the subpattern.
Depends on your idea of implementation.

//EDIT: My wish was inspired syntax of Blosxom's interpolate_fancy

Thanks a lot for the module! Mostly used in webdevelopment by me.

The module should get a golden Camel Award. ;)

ghost commented 8 years ago

@perlpunk Any efforts to integrate this enhancement to HTC?

perlpunk commented 8 years ago

@GwenDragon I commented on the pull request; it's not a trivial thing unfortunately. I can try to push my local branch where I have been working on this, so you can have a look maybe?

ghost commented 8 years ago

Thanks for reply. I will wait until you have time and can add the feature.

perlpunk commented 8 years ago

I pushed the branch anyway. I think I got pretty far, but wasn't sure if I tested all cases...