Vimplate is a project mainly written in Vim Script, it's free.
template system for vim (example for C++, Perl, LaTeX and make)
This is a mirror of http://www.vim.org/scripts/script.php?script_id=1311
Vimplate provides an extensible and powerful template processing system. It is based on Perl and Template-Toolkit. You can create templates for program code, makefiles, letters, html pages, latex etc. As example vimplate contains templates for C++, LaTeX, Perl and Makefile. With vimplate you can write templates which interact with the user. For themes are the functions choice() and input(). You can choose different locale for the function date() and locale(). You can write your own perl code directly in the templates.
In case you find my template useful, or have suggestions for improvements, please let me know.
If you write a new template, and would like me to add it to the vimplate package please send it to: [email protected]
Usage:
:Vimplate [options]
choice whit
Subroutines vimplate-subroutines
locale() for locale please see: man locale [% loc=locale() %] get the current locale and write it to the variable loc [% locale('C') %] set global the current locale to C [% locale('de_DE') %] set global the current locale to de_DE date() for date please see: man date [% date('%c') %] print the current date with the current locale setting [% date('de_DE', '%c') %] print the current date with the locale de_DE input() [% var=input() %] read input from user and write it to the variable var choice() [% day=choice('day:', 'Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa') %] let the user choice between different values and write it to the variable day
please try :Vimplate Test
Example vimplate-example
a LaTeX Template: http://typedef.ch/vimplate/example/LaTeX.tt.html the generated LaTeX File: http://typedef.ch/vimplate/example/Example.tex.html a Makefile Template for LaTeX: http://typedef.ch/vimplate/example/Makefile-LaTeX.tt.html the generated Makefile: http://typedef.ch/vimplate/example/Makefile.html c++ Templates: http://typedef.ch/vimplate/example/hpp-default.tt.html http://typedef.ch/vimplate/example/cpp-default.tt.html the generated class: http://typedef.ch/vimplate/example/Example.hpp.html http://typedef.ch/vimplate/example/Example.cpp.html the generated class with doxygen: http://typedef.ch/vimplate/example/ExampleDoxy.hpp.html http://typedef.ch/vimplate/example/ExampleDoxy.cpp.html a perl Template: http://typedef.ch/vimplate/example/perl.tt.html the genereated program: http://typedef.ch/vimplate/example/Example.pl.html the genereated program with Log4Perl: http://typedef.ch/vimplate/example/ExampleLog.pl.html
Example: the template letter.tt:
[%
sex=choice('sex: ', 'female', 'male')
name=input('name: ')
location=input('your location: ')
-%]
[% ucfirst(location) %], [% date('C', '%b %d, %Y') %]
Dear [% IF sex=='female'; 'Ms'; ELSE; 'Mr'; END %] [% ucfirst(name) %]
...
Sincerely
[% user.firstname %] [% user.lastname %]
________________________________________________________
run vim: :Vimplate letter sex: 0) female 1) male 0 name: Meier your location: Olten
your input was:
:Vimplate letter
this will produce this letter:
Olten, Jul 11, 2005
Dear Ms Meier
...
Sincerely
Urs Stotz
________________________________________________________
Example: the template hpp-default.tt:
[% classname=input('Class name: ')
doxygen=choice('with Doxygen comments: ', 'no', 'yes')
-%]
#ifndef [% uc(classname) %]_HPP
#define [% uc(classname) %]_HPP
[% IF doxygen=='yes' -%]
/**
* @brief [% classname %] ... short description ...
* @author [% user.firstname %] [% user.lastname %] <[% user.mail %]>
* @date [% date('%Y-%m-%d') %]
* ... description ...
*/
[% END -%]
class [% classname %]
{
public:
[% IF doxygen=='yes' -%]
/**
* Default constructor
*/
[% END -%]
[% classname %]();
[% IF doxygen=='yes' -%]
/**
* Copy constructor
* @param other reference on object to copy
*/
[% END -%]
[% classname %](const [% classname %]& other);
[% IF doxygen=='yes' -%]
/**
* Assignment operator
* @param other reference on object to copy
* @return reference on initialisated object
*/
[% END -%]
[% classname %]& operator=(const [% classname %]& other);
[% IF doxygen=='yes' -%]
/**
* Destructor
*/
[% END -%]
virtual ~[% classname %]();
private:
[% IF doxygen=='yes' -%]
/**
* Base initialisation should be called
* at beginning of each constructor
*/
[% END -%]
void init();
[% IF doxygen=='yes' -%]
/**
* Method to copy each member (deep copy)
* @param other reference on object to copy
*/
[% END -%]
void init(const [% classname %]& other);
};
#endif /* #ifndef [% uc(classname) %]_HPP */
________________________________________________________
run vim: :Vimplate hpp-default Class name: Parent with Doxygen comments: 0) no 1) yes 1
your input was:
:Vimplate hpp-default
this will produce this c++ include file:
#ifndef PARENT_HPP
#define PARENT_HPP
/**
* @brief Parent ... short description ...
* @author Urs Stotz <[email protected]>
* @date 2005-07-18
* ... description ...
*/
class Parent
{
public:
/**
* Default constructor
*/
Parent();
/**
* Copy constructor
* @param other reference on object to copy
*/
Parent(const Parent& other);
/**
* Assignment operator
* @param other reference on object to copy
* @return reference on initialisated object
*/
Parent& operator=(const Parent& other);
/**
* Destructor
*/
virtual ~Parent();
private:
/**
* Base initialisation should be called
* at beginning of each constructor
*/
void init();
/**
* Method to copy each member (deep copy)
* @param other reference on object to copy
*/
void init(const Parent& other);
};
#endif /* #ifndef PARENT_HPP */
________________________________________________________
Documentation:
Todo:
License: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
A copy of the GNU GPL is available as /usr/share/common-licenses/GPL-2 on Debian systems, or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html You can also obtain it by writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
Copyright: Copyright (c) 2005, Urs Stotz [email protected]
Version: vimplate 0.2.3