Permalink
Browse files

script to port symfony helpers into Twig extensions

  • Loading branch information...
1 parent 8d7119f commit 388133b07acd9c52d53d7c1186782d7be5d95c25 Videla Alvaro committed Oct 12, 2009
Showing with 43 additions and 0 deletions.
  1. +43 −0 helpers.sh
View
@@ -0,0 +1,43 @@
+#/bin/sh
+
+#./helpers.sh /path/to/syfmony/lib/helper/
+
+
+mkdir -p ./lib/extensions/
+
+for file in ${1}*Helper.php; do
+
+BNAME=`basename $file`
+CNAME=`echo $BNAME | sed 's/Helper.php//'`
+
+sed -E -n 's/^function ([^_][[:alnum:]_]+)\(.*$/\1/p' $file | awk -v classname=$CNAME '
+
+BEGIN {
+ print "<?php\n"
+ print "class " classname "_Twig_Extension extends Twig_Extension"
+ print "{"
+ print " public function getFilters()"
+ print " {"
+ print " return array("
+}
+
+{ printf(" \"'%s'\" => array(\"'%s'\", false),\n", $0, $0); }
+
+END {
+ print " );"
+ print " }\n"
+ print " public function getName()"
+ print " {"
+ printf(" return \"%s\";\n", tolower(classname));
+# print " return '" classname "';"
+ print " }"
+ print "}"
+}
+
+' > "./lib/extensions/${CNAME}_Twig_Extension.class.php"
+
+done
+
+for extensionclass in ./lib/extensions/*class.php; do
+ php -l $extensionclass
+done

0 comments on commit 388133b

Please sign in to comment.