I have a variable "myPackage" in my template. I would like to replace that with the directory of the template.
For example if I created a file at /project/include/com/kidbombay/Myfile.as I would like to replace all instances of myPackage in my template with "com.kidbombay"
Basically the steps are 1. Is the file located inside a "include" directory? If yes continue. 2. Parse all folders down from the include level. "include/com/client/project" would return "com/client/project" 3. Replace the slashes with dots. "com/client/project" becomes com.client.project. 4. Replaces all instances of myPackage in my template with "com.client.project"
How would I do this? I am not very familiar with perl.
Thanks!
On Feb 14, 2005, at 19:53, Ketan Anjaria wrote:
I have a variable "myPackage" in my template. I would like to replace that with the directory of the template. [...] Basically the steps are How would I do this? I am not very familiar with perl.
In the template command you can add this line among the variables that are setup (e.g. make it line 2):
TM_PACKAGE=`sed <<<$TM_NEW_FILE_DIRECTORY -n 's#.*include/(.*)#\1#p'|tr / .` \
It should do what you want, and then in your template use ${TM_PACKAGE} where you want the package name (or change the name of the variable).
If your new file doesn't have 'include' as an ancestor directory, the variable will be empty.