Search in sources :

Example 1 with RockerWritable

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)));
        }
    }
}
Also used : Project(io.micronaut.starter.application.Project) ApplicationType(io.micronaut.starter.application.ApplicationType) RockerWritable(io.micronaut.starter.template.RockerWritable) DocumentationLink(io.micronaut.starter.feature.function.DocumentationLink)

Example 2 with RockerWritable

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);
            }
        });
    }
}
Also used : RockerWritable(io.micronaut.starter.template.RockerWritable) io.micronaut.starter.template.api.starterApi(io.micronaut.starter.template.api.starterApi) OutputStream(java.io.OutputStream) MediaType(io.micronaut.http.MediaType) RockerWritable(io.micronaut.starter.template.RockerWritable) Writable(io.micronaut.core.io.Writable) Charset(java.nio.charset.Charset) URI(java.net.URI) Writer(java.io.Writer) Produces(io.micronaut.http.annotation.Produces) Get(io.micronaut.http.annotation.Get) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 3 with RockerWritable

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));
    }
}
Also used : RockerTemplate(io.micronaut.starter.template.RockerTemplate) Project(io.micronaut.starter.application.Project) RockerWritable(io.micronaut.starter.template.RockerWritable) Language(io.micronaut.starter.options.Language) BuildTool(io.micronaut.starter.options.BuildTool)

Example 4 with RockerWritable

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);
                }
            }
        });
    }
}
Also used : OutputStream(java.io.OutputStream) Options(io.micronaut.starter.options.Options) Writable(io.micronaut.starter.template.Writable) ApplicationType(io.micronaut.starter.application.ApplicationType) Feature(io.micronaut.starter.feature.Feature) Set(java.util.Set) IOException(java.io.IOException) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) Template(io.micronaut.starter.template.Template) List(java.util.List) DefaultFeature(io.micronaut.starter.feature.DefaultFeature) NonNull(edu.umd.cs.findbugs.annotations.NonNull) GeneratorContext(io.micronaut.starter.application.generator.GeneratorContext) RockerWritable(io.micronaut.starter.template.RockerWritable) io.micronaut.starter.feature.other.template.readme(io.micronaut.starter.feature.other.template.readme) FeaturePhase(io.micronaut.starter.feature.FeaturePhase) RockerWritable(io.micronaut.starter.template.RockerWritable) OutputStream(java.io.OutputStream) Writable(io.micronaut.starter.template.Writable) RockerWritable(io.micronaut.starter.template.RockerWritable) IOException(java.io.IOException) Feature(io.micronaut.starter.feature.Feature) DefaultFeature(io.micronaut.starter.feature.DefaultFeature) Template(io.micronaut.starter.template.Template)

Aggregations

RockerWritable (io.micronaut.starter.template.RockerWritable)4 ApplicationType (io.micronaut.starter.application.ApplicationType)2 Project (io.micronaut.starter.application.Project)2 OutputStream (java.io.OutputStream)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Writable (io.micronaut.core.io.Writable)1 MediaType (io.micronaut.http.MediaType)1 Get (io.micronaut.http.annotation.Get)1 Produces (io.micronaut.http.annotation.Produces)1 GeneratorContext (io.micronaut.starter.application.generator.GeneratorContext)1 DefaultFeature (io.micronaut.starter.feature.DefaultFeature)1 Feature (io.micronaut.starter.feature.Feature)1 FeaturePhase (io.micronaut.starter.feature.FeaturePhase)1 DocumentationLink (io.micronaut.starter.feature.function.DocumentationLink)1 io.micronaut.starter.feature.other.template.readme (io.micronaut.starter.feature.other.template.readme)1 BuildTool (io.micronaut.starter.options.BuildTool)1 Language (io.micronaut.starter.options.Language)1 Options (io.micronaut.starter.options.Options)1 RockerTemplate (io.micronaut.starter.template.RockerTemplate)1 Template (io.micronaut.starter.template.Template)1