generator_plugin.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. #
  3. # Shell script that creates a new transformation plug-in (both main and
  4. # abstract class) using a template.
  5. #
  6. # The 'description' parameter will add a new entry in the language file.
  7. # Watch out for special escaping.
  8. #
  9. # $1: MIMEType
  10. # $2: MIMESubtype
  11. # $3: Transformation Name
  12. # $4: (optional) Description
  13. echo $#
  14. if [ $# -ne 3 -a $# -ne 4 ]; then
  15. echo -e "Usage: ./generator_plugin.sh MIMEType MIMESubtype TransformationName [Description]\n"
  16. exit 65
  17. fi
  18. # make sure that the MIME Type, MIME Subtype and Transformation names
  19. # are in the correct format
  20. # make all names lowercase
  21. MT="`echo $1 | tr [:upper:] [:lower:]`"
  22. MS="`echo $2 | tr [:upper:] [:lower:]`"
  23. TN="`echo $3 | tr [:upper:] [:lower:]`"
  24. # make first letter uppercase
  25. MT="${MT^}"
  26. MS="${MS^}"
  27. TN="${TN^}"
  28. # make the first letter after each underscore uppercase
  29. MT="`echo $MT`"
  30. MT="`echo $MT | sed -e 's/_./\U&\E/g'`"
  31. MS="`echo $MS`"
  32. MS="`echo $MS | sed -e 's/_./\U&\E/g'`"
  33. TN="`echo $TN`"
  34. TN="`echo $TN | sed -e 's/_./\U&\E/g'`"
  35. # define the name of the main class file and of its template
  36. ClassFile=$MT\_$MS\_$TN.class.php
  37. Template=TEMPLATE
  38. # define the name of the abstract class file and its template
  39. AbstractClassFile=abstract/"$TN"TransformationsPlugin.class.php
  40. AbstractTemplate=TEMPLATE_ABSTRACT
  41. # replace template names with argument names
  42. sed "s/\[MIMEType]/$MT/; s/\[MIMESubtype\]/$MS/; s/\[TransformationName\]/$TN/;" < $Template > $ClassFile
  43. echo "Created $ClassFile"
  44. GenerateAbstractClass=1
  45. if [ -n $4 ]; then
  46. if [ "$4" == "--generate_only_main_class" ]; then
  47. if [ -e $AbstractClassFile ]; then
  48. GenerateAbstractClass=0
  49. fi
  50. fi
  51. fi
  52. if [ $GenerateAbstractClass -eq 1 ]; then
  53. # replace template names with argument names
  54. sed "s/\[TransformationName\]/$TN/; s/Description of the transformation./$4/;" < $AbstractTemplate > $AbstractClassFile
  55. echo "Created $AbstractClassFile"
  56. fi
  57. echo ""