Laconic API for Apache Velocity
Clone or download
Latest commit d6cb986 Jan 12, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src #25: RelativePath - support plain relative path Oct 30, 2018
.0pdd.yml #2: Activate 0pdd integration Sep 28, 2018
.gitattributes #1: v0.1.0 Sep 28, 2018
.gitignore #1: v0.1.0 Sep 28, 2018
.pdd #2: Remove min/max estimates from 0pdd Jan 2, 2019
.rultor.yml #3: Activate Rultor Sep 28, 2018
.travis.yml #4: Activate Travis integration Sep 28, 2018
license.txt #1: v0.1.0 Sep 28, 2018
pom.xml #28: Rename project to `laconic-velocity` Jan 11, 2019
readme.md #28: readme cleanup Jan 12, 2019

readme.md

Maven Javadocs License: MIT Commit activity

Build Status 0pdd Dependency Status Known Vulnerabilities

DevOps By Rultor.com EO badge We recommend IntelliJ IDEA

Qulice SQ passed Codebeat Codacy Badge Codecov

ATTENTION: We're still in a very early alpha version, the API may and will change frequently. Please, use it at your own risk, until we release version 1.0.

Maven:

<dependency>
    <groupId>com.github.dgroup</groupId>
    <artifactId>velocity</artifactId>
</dependency>

Gradle:

dependencies {
    compile 'com.github.dgroup:velocity:<version>'
}

Get started

Generate the text/sql/xml/markdown/json/etc based on Apache Velocity template.

  1. Define velocity template query.sql
    select 1 from dual
    #if ($flag)
    union
    select 2 from dual
    #end
    in
    velocity $ tree
    ...
    |-- src
    |   |-- main
    |   |   |-- ...
    |   |
    |   `-- test
    |       |-- java
    |       |   `-- ...
    |       `-- resources
    |           `-- velocity
    |               |-- ...
    |               |-- query.sql
    |               |-- ...
    ...
    
    
  2. Define instance of velocity template using
    • full path to template
      @Test
      public void transformSql() throws TemplateException {
          MatcherAssert.assertThat(
              new Text("query.sql", "src/test/resources/velocity")
                  .compose(
                      new ArgOf("flag", true)
                   ),
              Matchers.equalTo(
                  "select 1 from dual\nunion\nselect 2 from dual\n"
              )
          );
      }
      See more.
    • hierarchical search
      @Test
      public void hierarchical() throws TemplateException {
          MatcherAssert.assertThat(
              new Text("query.sql", "src/test/resources"))
                  .compose(
                      new ArgOf("flag", true)
                  ),
              Matchers.equalTo(
                  "select 1 from dual\nunion\nselect 2 from dual\n"
              )
          );
      }
      You can also specify the multiple roots (more).
    • classpath template
      @Test
      public void classpath() throws TemplateException {
          MatcherAssert.assertThat(
              new Text(new RelativePath("velocity/query.sql"))
                  .compose(
                      new ArgOf("flag", true)
                  ),
              Matchers.equalTo(
                  "select 1 from dual\nunion\nselect 2 from dual\n"
              )
          );
      }
      See more.