KDevelop4/Manual/Working with templates: Difference between revisions

From KDE UserBase Wiki
(Created page with "{{ Construction }} Some of KDevelop's code generation features use templates. These define the output structure, while you supply the needed parameters and data. Using templat...")
 
Line 12: Line 12:


A project template is a compressed archives with specific contents. Every template needs a description file with the same base name as the archive itself, and an extension ".kdevtemplate". Other files are treated as template contents and will be present in the generated project.  
A project template is a compressed archives with specific contents. Every template needs a description file with the same base name as the archive itself, and an extension ".kdevtemplate". Other files are treated as template contents and will be present in the generated project.  
The directory structure within the archive can be similar to this


{{Input|1=<nowiki>
{{Input|1=<nowiki>
my_template.tar.bz2
my_template.tar.bz2
|
|-- my_template.kdevtemplate
+
|-- src/
|  |-- CMakeLists.txt
|  |-- main.cpp
|  |-- %{APPNAMELC}.h
+-- %{APPNAMELC}.cpp
+-- CMakeLists.txt
</nowiki>}}
 
Let's say we create the project using the above template and application name <code>Example</code>. The resulting project tree will look like this


{{Output|1=<nowiki>
~/projects/Example
|-- src/
|  |-- CMakeLists.txt
|  |-- main.cpp
|  |-- example.h
|  +-- example.cpp
+-- CMakeLists.txt
</nowiki>}}
</nowiki>}}
The .kdevtemplate description file was removed, as it is used to describe the template, not the resulting project. Other files have been copied from the archive to the project folder. Variables in files names have been replaced with their values. Although not visible from the file structure, variables in the files' contents have been replaced as well.


==== Variables ====
==== Variables ====

Revision as of 13:47, 9 July 2012

Under Construction

This is a new page, currently under construction!


Some of KDevelop's code generation features use templates. These define the output structure, while you supply the needed parameters and data.

Using templates instead of fixed functionality allows greater flexibility and customizability. Templates can be chosen and modified to suite your particular needs, programming language and coding style. In the cases of project and class templates, they can be shared and downloaded, providing additional functionality to KDevelop without extra code.

Project Templates

Instructions for starting a new project are avaliable in the section Setting up a new project.

File structure

A project template is a compressed archives with specific contents. Every template needs a description file with the same base name as the archive itself, and an extension ".kdevtemplate". Other files are treated as template contents and will be present in the generated project.

The directory structure within the archive can be similar to this

my_template.tar.bz2
|-- my_template.kdevtemplate
|-- src/
|   |-- CMakeLists.txt
|   |-- main.cpp
|   |-- %{APPNAMELC}.h
|   +-- %{APPNAMELC}.cpp
+-- CMakeLists.txt

Let's say we create the project using the above template and application name Example. The resulting project tree will look like this

~/projects/Example
|-- src/
|   |-- CMakeLists.txt
|   |-- main.cpp
|   |-- example.h
|   +-- example.cpp
+-- CMakeLists.txt

The .kdevtemplate description file was removed, as it is used to describe the template, not the resulting project. Other files have been copied from the archive to the project folder. Variables in files names have been replaced with their values. Although not visible from the file structure, variables in the files' contents have been replaced as well.

Variables

Project templates in KDevelop, just like in KAppTemplate, use KMacroExpander to substitute variable placeholders with their real values. This means that when generating a project, strings of the form %{VARIABLE_NAME} will be replaced with the value of VARIABLE_NAME.

The recognised variables in KDevelop are

  • APPNAME
  • APPNAMELC
  • APPNAMEUC

Class Templates

Documentation Templates