Factor out buildDirective template.