Download!

0.2.0

Introduction

skema is a command line utility for expanding templates. It can be used in a number of ways. Examples include:

Of course, there’s nothing in skema that you can’t find in your favourite text editor’s templating facility; skema just makes it easier if you happen to like the command line.

skema uses the ERB templating library included with ruby, but you don’t need to know ruby or ERB to use it. See the ‘Creating templates’ section below for more details on how to add your own templates.

Installing

sudo gem install skema
skema -i skemaconfig . filename:.skemarc

and answer the questions.

Tutorial

skema comes with a couple of predefined templates. For example, the ‘gpl’ template adds a copyright statement at the beginning of a C++ file. To try it out, pick a source file test.cpp and run:

$ skema gpl test.cpp
-> ./test.cpp
Now take a look at test.cpp and you’ll notice that a nice GPL header with your name and email has been added. But what if you want to use a different name and/or email for the license? No problem, just set some arguments on the command line:
$ skema gpl test.cpp "name:John Doe" email:john.doe@example.com

The ‘gpl’ template, however, is somewhat peculiar in that it acts on a single, already existing file. Most of the times, you want to expand a template on a new directory, populating it with files. Let’s take the kapp template, that expands to an empty KDE4 application:

$ skema kapp myapp
ERROR: Missing argument title

What happened? Well, skema complains because it requires an argument and it has no way to infer it without asking.

$ skema kapp myapp title:MyApp
ERROR: Missing argument name

Now the name is missing:

$ skema kapp myapp title:MyApp name:myapp
-> CMakeLists.txt
-> main.cpp
-> ./myappui.rc

Ok. It worked! Note that skema has an interactive mode, useful when you don’t know (or don’t remember) the required args:

$ skema -i kapp myapp
email [p.capriotti@gmail.com]:
version [0.1]:
title: MyApp
name: myapp
author [Paolo Capriotti]:
-> CMakeLists.txt
-> main.cpp
-> ./myappui.rc

Just press enter at the prompt when you want to use the default.

Creating templates

Let’s create a class template, that expands to a C++ class file.

  1. Create a class directory in $HOME/.skema
  2. Inside the class directory, create a file called class.rb with something like:
    template :class => nil
  3. Create a ‘templates’ directory inside ‘class’
  4. Create a file called ‘h’ with the following content:
    <%= filename @class.downcase + ".cpp" %>
    #ifndef <%= @class.upcase %>_H
    #define <%= @class.upcase %>_H
    
    class <%= @class %> {
    public:
      <%= @class %>();
      virtual ~<%= @class %>();
    };
    
    #endif
    
  5. Create a file called cpp. Content left as an exercise :)
  6. Try out your new template with
    $ skema class . class:Test
    
    you should then get two files: test.h and test.cpp.

How to submit patches

Fork my repository at github.

License

This code is free to use under the terms of the MIT license.

Contact

Please send comments, complaints, new templates, bug reports and feature requests to Paolo Capriotti. skema does not have a bug tracker, yet, sorry.

Paolo Capriotti, 27th March 2008
Theme extended from Paul Battley