Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

script to port symfony helpers into Twig extensions

  • Loading branch information...
commit 388133b07acd9c52d53d7c1186782d7be5d95c25 1 parent 8d7119f
Videla Alvaro authored

Showing 1 changed file with 43 additions and 0 deletions. Show diff stats Hide diff stats

  1. +43 0 helpers.sh
43 helpers.sh
... ... @@ -0,0 +1,43 @@
  1 +#/bin/sh
  2 +
  3 +#./helpers.sh /path/to/syfmony/lib/helper/
  4 +
  5 +
  6 +mkdir -p ./lib/extensions/
  7 +
  8 +for file in ${1}*Helper.php; do
  9 +
  10 +BNAME=`basename $file`
  11 +CNAME=`echo $BNAME | sed 's/Helper.php//'`
  12 +
  13 +sed -E -n 's/^function ([^_][[:alnum:]_]+)\(.*$/\1/p' $file | awk -v classname=$CNAME '
  14 +
  15 +BEGIN {
  16 + print "<?php\n"
  17 + print "class " classname "_Twig_Extension extends Twig_Extension"
  18 + print "{"
  19 + print " public function getFilters()"
  20 + print " {"
  21 + print " return array("
  22 +}
  23 +
  24 +{ printf(" \"'%s'\" => array(\"'%s'\", false),\n", $0, $0); }
  25 +
  26 +END {
  27 + print " );"
  28 + print " }\n"
  29 + print " public function getName()"
  30 + print " {"
  31 + printf(" return \"%s\";\n", tolower(classname));
  32 +# print " return '" classname "';"
  33 + print " }"
  34 + print "}"
  35 +}
  36 +
  37 +' > "./lib/extensions/${CNAME}_Twig_Extension.class.php"
  38 +
  39 +done
  40 +
  41 +for extensionclass in ./lib/extensions/*class.php; do
  42 + php -l $extensionclass
  43 +done

0 comments on commit 388133b

Please sign in to comment.
Something went wrong with that request. Please try again.