use of io.micronaut.starter.template.RockerWritable in project micronaut-starter by micronaut-projects.
the class AwsLambda method apply.
@Override
public void apply(GeneratorContext generatorContext) {
Project project = generatorContext.getProject();
if (shouldGenerateSources(generatorContext)) {
addBook(generatorContext, project);
addBookSaved(generatorContext, project);
ApplicationType applicationType = generatorContext.getApplicationType();
if (applicationType == DEFAULT || applicationType == FUNCTION) {
if (applicationType == DEFAULT) {
addBookController(generatorContext, project);
addBookControllerTest(generatorContext, project);
} else {
addRequestHandler(generatorContext, project);
addTest(generatorContext, project);
}
DocumentationLink link = new DocumentationLink(LINK_TITLE, LINK_URL);
generatorContext.addHelpTemplate(new RockerWritable(readmeRockerModel(this, generatorContext, link)));
}
}
}
use of io.micronaut.starter.template.RockerWritable in project micronaut-starter by micronaut-projects.
the class ApplicationController method home.
/**
* Provides a description of the API.
* @param request The request
* @return A description of the API.
*/
@Get("/")
@Produces(MediaType.TEXT_PLAIN)
@ApiResponse(responseCode = "200", description = "A textual description of the API", content = @Content(mediaType = MediaType.TEXT_PLAIN))
HttpResponse<Writable> home(HttpRequest<?> request, @Parameter(hidden = true) RequestInfo info) {
Collection<MediaType> accept = request.accept();
URI redirectURI = configuration.getRedirectUri().orElse(null);
if (accept.contains(MediaType.TEXT_HTML_TYPE) && redirectURI != null) {
return HttpResponse.permanentRedirect(redirectURI);
} else {
return HttpResponse.ok(new Writable() {
@Override
public void writeTo(Writer out) {
// no-op
}
@Override
public void writeTo(OutputStream outputStream, @Nullable Charset charset) {
new RockerWritable(new starterApi().serverURL(info.getServerURL()).micronautVersion(VersionInfo.getMicronautVersion())).write(outputStream);
}
});
}
}
use of io.micronaut.starter.template.RockerWritable in project micronaut-starter by micronaut-projects.
the class AbstractFunctionFeature method applyFunction.
protected void applyFunction(GeneratorContext generatorContext, ApplicationType type) {
BuildTool buildTool = generatorContext.getBuildTool();
generatorContext.addHelpTemplate(new RockerWritable(readmeTemplate(generatorContext, generatorContext.getProject(), buildTool)));
if (type == ApplicationType.DEFAULT) {
final String className = StringUtils.capitalize(generatorContext.getProject().getPropertyName());
Project project = generatorContext.getProject().withClassName(className);
Language language = generatorContext.getLanguage();
String sourceFile = generatorContext.getSourcePath("/{packagePath}/" + className + "Controller");
switch(language) {
case GROOVY:
generatorContext.addTemplate("function", new RockerTemplate(sourceFile, groovyControllerTemplate(project)));
break;
case KOTLIN:
generatorContext.addTemplate("function", new RockerTemplate(sourceFile, kotlinControllerTemplate(project)));
break;
case JAVA:
default:
generatorContext.addTemplate("function", new RockerTemplate(sourceFile, javaControllerTemplate(project)));
break;
}
applyTestTemplate(generatorContext, project, className + getTestSuffix(type));
}
}
use of io.micronaut.starter.template.RockerWritable in project micronaut-starter by micronaut-projects.
the class Readme method apply.
@Override
public void apply(GeneratorContext generatorContext) {
List<Feature> featuresWithDocumentationLinks = generatorContext.getFeatures().getFeatures().stream().filter(feature -> feature.getMicronautDocumentation() != null || feature.getThirdPartyDocumentation() != null).collect(Collectors.toList());
List<Writable> helpTemplates = generatorContext.getHelpTemplates();
if (!helpTemplates.isEmpty() || !featuresWithDocumentationLinks.isEmpty()) {
generatorContext.addTemplate("readme", new Template() {
@Override
public String getPath() {
return "README.md";
}
@Override
public void write(OutputStream outputStream) throws IOException {
for (Writable writable : generatorContext.getHelpTemplates()) {
writable.write(outputStream);
}
for (Feature feature : featuresWithDocumentationLinks) {
Writable writable = new RockerWritable(readme.template(feature));
writable.write(outputStream);
}
}
});
}
}
Aggregations