routeFileMaker function
Implementation
PartFile routeFileMaker(
ServerParentRoute route,
String Function(Spec) format,
) {
final closure = Method(
(p) => p
..name = route.handlerName
..returns = refer((Route).name)
..requiredParameters.addAll([
Parameter(
(b) => b
..name = route.className.toCamelCase()
..type = refer(route.className),
),
Parameter(
(b) => b
..name = 'di'
..type = refer((DI).name),
),
])
..body = Block.of([
refer((Route).name)
.newInstance([
literalString(route.routePath),
], {
...createRouteArgs(
route: route,
classVarName: route.classVarName,
),
if (route.routes.isNotEmpty)
'routes': literalList([
for (final child in route.routes)
createChildRoute(child, route),
]),
})
.returned
.statement,
]),
);
return PartFile(
path: ['routes', '__${route.fileName}'],
content: format(closure),
);
}