Git Product home page Git Product logo

histone-java2's Introduction

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);
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.