Padre::Plugin::Shell::Template - Create new documents from templates.


Padre-Plugin-Template documentation  | view source Contained in the Padre-Plugin-Template distribution.

Index


NAME

Top

Padre::Plugin::Shell::Template - Create new documents from templates.

DESCRIPTION

Top

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

Top

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

Top

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

Top

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 and sh available then the template is wrapped in a cat block and executed using sh.

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 both cat and sh, specify cp [% 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 and sh then the new document is created from the template as is.

ISSUES

Top

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

Top

Gregory Siems <gsiems@gmail.com>

COPYRIGHT AND LICENSE

Top


Padre-Plugin-Template documentation  | view source Contained in the Padre-Plugin-Template distribution.