Code template Apache Velocity - iterating over an array

Hi,

I hope you are well.

I was wondering how to access simple operations like iterations from within a code template.

I am trying to create a template for typescript testing using the apache velocity documentation.


// tslint:disable:no-expression-statement
import { test } from 'ava';
import {} from './${NAME}';

#foreach( $export in $exports )
test('$export', t => {
t.is($export(''), true);
t.is($export(''), false);
});
#end

 

Thanks for any pointers you might offer.

1 comment

It can look as follows:

#set($exports = $input.split(" "))
#set(${export} = "")

// tslint:disable:no-expression-statement
import { test } from 'ava';
import {} from './${NAME}';
#foreach( ${export} in $exports )
    test('${export}', t => {
    t.is(${export}(''), true);
    t.is(${export}(''), false);
});
    
#end

 

Enter the input values separated by space:

it will generate

 

// tslint:disable:no-expression-statement
import {test} from 'ava';
import {} from './test';

test('foo', t => {
t.is(foo(''), true);
t.is(foo(''), false);
});

test('bar', t => {
t.is(bar(''), true);
t.is(bar(''), false);
});

test('baz', t => {
t.is(baz(''), true);
t.is(baz(''), false);
});
1

Please sign in to leave a comment.