[Lazarus] How to add your own 'New Project' template?

Tom Verhoeff T.Verhoeff at tue.nl
Fri Aug 22 19:09:28 CEST 2008


On Fri, Aug 22, 2008 at 01:40:34PM +0200, Michael Van Canneyt wrote:
> > > 
> > > No. Any substitution must be marked as such. There are no 'special'
> > > cases, but if you want to send some patches to handle this, let me know.
> > 
> > What you mention concerns substitutions _inside_ the (text) files.  What I
> > was aiming at is substitutions of the _names_ of files being copied.
> > Assuming we have in project.ini:
> > 
> > [Project]
> > Name=Special
> > Author=Tom
> > Description=A special FreePascal program.
> > Recurse=0
> > Exclude=.lrs
> > 
> > [Variables]
> > special=Example
> > 
> > Using the template below on the left creating a new project with
> > project name 'my_new_proj' in directory 'My New Project', you get 
> > the instance on the right:
> > 
> > Template dir	Transformation	Instantiated dir
> > ------------	--------------	----------------
> > project.ini	not copied
> > project.lpi	substituted	my_new_proj.lpi
> > project.lpr	substituted	my_new_proj.lpr
> > main.pas	substituted	main.pas
> > main.dfm	substituted	main.dfm
> > main.lrs	copied as is	main.lrs
> > aux.pas		substituted	aux.pas
> > 
> > where 'substituted' means that in the contents of the file,
> > the following substitutions are carried through while copying:
> > 
> > $(ProjName)	->	my_new_proj
> > $(ProjDir)	->	My New Project
> > $(special)	->	Example
> > 
> > In the README for components/projecttemplates is says:
> > 
> > 	During the copy, the package will scan the file/directory names and the 
> > 	contents of the files for variable substitution: $(VARNAME) will be 
> > 	replaced by the value of a variable $(VARNAME).
> > 
> > This suggests that substitutions are also done for file names (as
> > well as the file contents).  But how should one name the files,
> > to get their names substituted?  Should they rather be called
> > 
> > $(ProjName).lpi
> > $(ProjName).lpr
> > 
> > This is rather awkward for a file name.  Please confirm.
> 
> I admit it is rather awkward, but it is currently so :-)
> 
> Maybe we should introduce a variable 'ProjectFileName' in project.ini, 
> which tells the templating engine which file is the project file.
> While copying files, it checks for variations of this filename 
> (stripping extension), and if it matches, the ProjName is substituted.
> 
> What do you think ? It should be very easy to add; 15 minutes tops.

I think that foremost it should be clear to the user what the
rules of the game are.  I begin to understand it.  Thanks.

The way it is now is quite flexible, but a bit awkward when
it comes to file name substitution.  For file names, the most
important case is the name of the main program (.lpi, .lpr).

Since project.ini seems to be treated specially anyway (it is
not copied), it makes sense to treat project.* also specially
and substitute $(ProjName) for 'project'.  I will then add an
example...

(I'll start a new thread on renaming files within a project,
after creation.)

	Tom
-- 
E-MAIL: T.Verhoeff @ TUE.NL     | Dept. of Math. & Comp. Science
PHONE:  +31 40 247 41 25        | Technische Universiteit Eindhoven
FAX:    +31 40 247 54 04        | PO Box 513, NL-5600 MB Eindhoven
http://www.win.tue.nl/~wstomv/  | The Netherlands



More information about the Lazarus mailing list