vimgen : vim inline generator / template expander
script karma |
Rating 69/18,
Downloaded by 1384 |
Comments, bugs, improvements
|
Vim wiki
|
created by |
Bastian Mathes |
|
script type |
utility |
|
description |
Vimgen is a simple template system that works inside a VIM buffer. The
input is a region of text. Everything until the first empty line in this
region is considered the data section, everything below the first empty line
is the template section. See included help file.
The data section of the input (everything until the first empty line) has to
be a valid VIM dictionary. Newlines ("\n") but no empty lines can be inserted for
better readability (they are ignored). The data section is evaluated using VIM's
eval function, hence it can include VIM functions, e.g. from the included range_date.vim.
The template section of the input (everything below the first empty line) is the
desired output (including newlines etc.) that has to be enriched/multiplied by the
data using vimgen tags.
There are only three types of tags:
«-var»...«-»
this tags loop over the variable 'var' which has to be
a list. Inside the loop «var» references the element of
the current iteration
«!var»...«-»
used inside a loop over 'var'. The test/tags that are surrounded
by this tag are ignored in the first iteration of the loop. This
is useful for enumerations (see |vimgen-examples|)
«var»
this tag is replaced with the variable 'var', where 'var'
either has only one value or the tag is surrounded by
a loop iterating over 'var'. In case of nested dictionaries,
a dot notation is used, e.g. a.b.c
Example of a template for a partitioned oracle table:
{'date':Range_month("200712","200803"), 'code':[['foo','0OF'',''OFF2'],['bar','RAB']]}
CREATE TABLE test_table
(date_id DATE NOT NULL, id1 NUMBER, id2 NUMBER)
PARTITION BY RANGE (date_id) SUBPARTITION BY LIST (id1)
(
«-date»«!date»,
«!»PARTITION testpart_«date» VALUES LESS THAN (TO_DATE('«date»01', 'YYYYMMDD'))
(
«-code»«!code»,
«!»SUBPARTITION testpart_«date»_«code[0]» VALUES ('«code[1]»')«-»
)«-»
);
Output:
CREATE TABLE test_table
(date_id DATE NOT NULL, id1 NUMBER, id2 NUMBER)
PARTITION BY RANGE (date_id) SUBPARTITION BY LIST (id1)
(
PARTITION testpart_200712 VALUES LESS THAN (TO_DATE('20071201', 'YYYYMMDD'))
(
SUBPARTITION testpart_200712_foo VALUES ('0OF','OFF2'),
SUBPARTITION testpart_200712_bar VALUES ('RAB')
),
PARTITION testpart_200801 VALUES LESS THAN (TO_DATE('20080101', 'YYYYMMDD'))
(
SUBPARTITION testpart_200801_foo VALUES ('0OF','OFF2'),
SUBPARTITION testpart_200801_bar VALUES ('RAB')
),
PARTITION testpart_200802 VALUES LESS THAN (TO_DATE('20080201', 'YYYYMMDD'))
(
SUBPARTITION testpart_200802_foo VALUES ('0OF','OFF2'),
SUBPARTITION testpart_200802_bar VALUES ('RAB')
),
PARTITION testpart_200803 VALUES LESS THAN (TO_DATE('20080301', 'YYYYMMDD'))
(
SUBPARTITION testpart_200803_foo VALUES ('0OF','OFF2'),
SUBPARTITION testpart_200803_bar VALUES ('RAB')
)
); |
|
install details |
This is a vimball, just edit vimgen.vba and source everything
:so % |
|
script versions (upload new version)
Click on the package to download.
ip used for rating: 3.144.229.52
|