Skip to content

complate/complate-spring

main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
bin
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

complate-spring

- Server-Side Rendering of JSX based views in Spring MVC

Maven Central License Open Issues Build Status Quality Gate Status Code Coverage

complate adapter that can be used in Spring MVC for Server-Side rendering JSX based views.

Quick Start

Download the jar through Maven:

<dependency>
  <groupId>org.complate</groupId>
  <artifactId>complate-spring-mvc</artifactId>
  <version>0.7.0</version>
</dependency>

To configure the relevant parts within your Spring Boot application you need to add a configuration class like the one shown below.

@Configuration
public class ComplateConfiguration {

    @Bean
    public ComplateSource complateSource(
            @Value("classpath:/templates/complate/bundle.js") Resource resource) {
        /*
         * Note that you have to make sure that the `/templates/complate/bundle.js`
         * file exists within your classpath on runtime and that this file exports
         * a function named `render` by default that has a matching signature:
         *
         * ```
         * export default function render(view, params, stream) {
         *     ...
         * }
         * ```
         *
         * Within this function you can use a complate Renderer to render JSX
         * based views. Because you then need to transpile your JavaScript code
         * you can use faucet or any other bundler that has support for
         * transpiling *.jsx files.
         */
        return new ResourceComplateSource(resource);
    }

    @Bean
    public ComplateRenderer complateRenderer(ComplateSource source) {
        /*
         * Note that it's possible to add global bindings or customize other
         * options via the builder for the GraalComplateRenderer.
         *
         * Because `GraalComplateRenderer` only evaluates the given `ComplateSource`
         * on instantiation changes made to this source afterwards will not be
         * picked up. If you want to re-evaluate the `ComplateSource` on every call
         * to `render` you can wrap the `GraalComplateRenderer` within an
         * `ComplateReEvaluatingRenderer`.
         *
         * If you encounter problems that may be related with the multi threaded
         * nature of a Spring web application you can wrap the `GraalComplateRenderer`
         * (or `ComplateReEvaluatingRenderer`) within an `ComplateThreadLocalRenderer`.
         * This will create an instance that is exclusively used within a thread.
         *
         * If you do not want to use the Graal base renderer for the time being
         * there is a `NashornComplateRenderer`, too. Note that this will not work
         * with a more recent JDK because Nashorn was removed.
         */
        return new GraalComplateRenderer.of(source).build();
    }

    @Bean
    public ComplateViewResolver complateViewResolver(ComplateRenderer renderer) {
        return new ComplateViewResolver(renderer);
    }
}

If you want to use the latest unstable version 0.8.0-SNAPSHOT you need to configure Sonatype's OSS Nexus as snapshot repository:

<repository>
  <id>ossrh</id>
  <name>Sonatype OSS Snapshot Repository</name>
  <url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>

Release History

See CHANGELOG.md

Code of Conduct

Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

License

complate-spring is Open Source software released under the Apache 2.0 license.