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

Michael Van Canneyt michael at freepascal.org
Fri Aug 22 13:40:34 CEST 2008



On Fri, 22 Aug 2008, Tom Verhoeff wrote:

> On Fri, Aug 22, 2008 at 09:25:23AM +0200, Michael Van Canneyt wrote:
> > > 
> > >  7. It is not clear to me what the requirements are for naming files
> > >     in the template, and how these names get changed when the template
> > > is instantiated.  Should I put files like project.ini, project.lpi,
> > > project.pas, unit1.pas in the template directory, and will
> > > project.{lpi,pas} be renamed depending on the name chosen by
> > > the user when instantiating the template?  That is, are there
> > > more substitutions than just for the occurrences of $(varname)
> > > in non-Exluded files, viz. file name changes?
> > 
> > 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.

Michael.



More information about the Lazarus mailing list