Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
core
java-compiler
spring
test
.gitignore
.travis.yml
LICENSE.txt
NOTICE.txt
README.md
pom.xml

README.md

Histone Template Engine 2 Build Status Coverage Status Maven Central

Histone — powerful and flexible template engine, which can be used for HTML - code generation as well as any other kind of text - documents. Histone implementations exists for the web - browser as well as for the server (Java and PHP), it allows you to use same templates on the server and on the client. Built - in extension mechanism allows you to extend default template engine features, by adding your own methods and properties for the particular project. Templates has clean and simple syntax and can be stored either as source code or as compiled code that can be executed with the maximum performance wherever it's needed.

Histone Template Engine Java Implementation

Documentation

Using Histone from Maven

To use histone in your maven project you should add new maven dependency to your pom.xml

<dependency>
    <groupId>com.github.megafonweblab.histone</groupId>
    <artifactId>histone-java-v2</artifactId>
    <version>1.0.1</version>
</dependency>

Sources tree

Standart Maven project structure. |- src/ project sources |- assembly/ file with maven-assembly-plugin assembly descriptor |- etc/ file for maven-licence-plugin checks |- main/ main sources |- test/ tests sources

Distribution archive contents

|- libs/ histone-java dependency libraries
|- histone-java-A.B.C.jar histone-java library
|- LICENSE.txt Apache v2.0 license file
|- NOTICE.txt file with copyright info
|- README.md this file

Clone, Build and Run test

For Windows users before clone repo:

git config —global core.autocrlf false

Clone repo:

git clone https://github.com/MegafonWebLab/histone-java2 histone-java2

Go to the repo:

cd histone-java2

Run test:

mvn clean test

Build and Run test:

mvn clean package

Base Example:

import ru.histone.v2.evaluator.Context;
import ru.histone.v2.evaluator.Evaluator;
import ru.histone.v2.evaluator.resource.HistoneResourceLoader;
import ru.histone.v2.evaluator.resource.SchemaResourceLoader;
import ru.histone.v2.parser.Parser;
import ru.histone.v2.parser.node.ExpAstNode;
import ru.histone.v2.property.DefaultPropertyHolder;
import ru.histone.v2.rtti.RunTimeTypeInfo;

import java.util.LinkedHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Example {
    public static void main(String[] args) {
        // for evaluating AST-tree
        final Evaluator evaluator = new Evaluator();
        // for parsing string template
        final Parser parser = new Parser();
        // base executor service
        final ExecutorService executorService = Executors.newFixedThreadPool(10); 
        // base resource loader
        final HistoneResourceLoader loader = new SchemaResourceLoader(executorService);
        // singleton with predefined functions
        final RunTimeTypeInfo runTimeTypeInfo = new RunTimeTypeInfo(executorService, loader, evaluator, parser); 
        final String baseUri = "http://localhost/";
        // context for evaluating
        final Context ctx = Context.createRoot(baseUri, runTimeTypeInfo, new DefaultPropertyHolder()); 
        
        // parsing template and create AST-tree
        final ExpAstNode node = parser.process("{{var x = 'Hello world!!'}}{{x}}", baseUri);
        // evaluate AST-tree
        final String res = evaluator.process(node, ctx);
        
        System.out.println(res);
    }
}