NAME
Padre::Plugin::Shell::Template - Create new documents from templates.
DESCRIPTION
Create new documents from a list of user defined templates. Optionally, the template may be processed with an external command prior to creating the new document.
CONFIGURATION
Template definitions are kept in a YAML formatted configuration file in the user's Padre configuration directory (~/.padre
).
Each template is labeled with the name that is to be displayed in the template menu. In addition to the name there are four attributes for each template definition:
- command (optional) -
-
The command to process the template through prior to creating a new document.
- description (optional) -
-
A description of the template. This is not [currently] used by the plugin and is intended for the benefit of the individual maintaining the template configuration.
- mimetype (optional) -
-
The mimetype of the created document. If no mimetype is specified the Padre will be attempt to guess the mimetype.
- source_file (required) -
-
The full path and name of the template file.
ENVIRONMENT VARIABLES
To provide additional information for the templates, various environment variables are set prior to processing the template. These environment variables are covered in the Padre::Plugin::Shell::Base documentation.
METHODS
plugin_menu
Generates and returns a menu of the defined templates.
example_config
Returns an example configuration. This is the initial configuration that gets created the first time that this plugin is used.
new_from_template ($template_name)
Searches the template configuration for a template definition that matches the supplied $template_name. If a matching template is found then one of three actions is performed.
- Use command -
-
If a command is supplied as part of the template configuration then the template is processed through that command and the output is used to create the new document.
There are two rather important placeholders in the command string
[% IN %]
and[% OUT %]
for the input and output filenames used in running the command. When the command is run, the[% IN %]
placeholder is replaced with the template filename and the[% OUT %]
placeholder is replaced by the name temporary file that the command is to write to. - Use the shell -
-
If no command is supplied and the system has both
cat
andsh
available then the template is wrapped in acat
block and executed usingsh
.By using this approach it is possible to include environment variables and other commands within the template. For example, the combination of
$USER
and`date +%F`
could be used to insert the current user and date into the documentation section of a new script.As a result of this approach, any dollar signs (
$
) that are to be preserved in the template need to be escaped as do any back ticks (`
). To avoid this behavior on systems with bothcat
andsh
, specifycp [% IN %] [% OUT %]
as the command to execute as this will simply copy the template to a temporary file before creating the new document. - Use nothing -
-
If no command is specified and the system does not have
cat
andsh
then the new document is created from the template as is.
ISSUES
When adding entries to the configuration file it appears to be necessary to have an empty line at the end of the file in order for the configuration to properly load. No properly loaded configuration results in no menu for the plug-in.
AUTHOR
Gregory Siems <gsiems@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2009 by Gregory Siems
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.