Coder Social home page Coder Social logo

sviperll / static-mustache Goto Github PK

View Code? Open in Web Editor NEW
28.0 28.0 4.0 154 KB

Template engine for java with statically checked and compiled templates. Compilation is performed alone with java sources.

License: BSD 3-Clause "New" or "Revised" License

Java 99.58% HTML 0.42%
java mustache template-engine type-safe

static-mustache's People

Contributors

dependabot[bot] avatar sviperll avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

static-mustache's Issues

Decide how to deal with searching key in parent contexts.

The most basic tag type is the variable. A {{name}} tag in a basic template will try to find the name key in the current context. If there is no name key, the parent contexts will be checked recursively. If the top context is reached and the name key is still not found, nothing will be rendered.
MUSTACHE(5).

To do or not to do so.

Add support for annotating interface methods

Now we have the following code structure:

@GenerateRenderableAdapter(
    template = "user.mustache",
    adapterName = "RenderableHtmlUserAdapter"
)
public class User {
    // ...
}
class Main {
    public static void main(String[] args) throws IOException {
        User user = new User("John Doe", 21, new String[] {"Knowns nothing"}, list);
        Renderable<Html> renderable = new RenderableHtmlUserAdapter(user);

        // Any appendable will do: StringBuilder, Writer, OutputStream
        Renderer renderer = renderable.createRenderer(System.out);

        // Write rendered template
        renderer.render();
    }
}

It's sometimes better to centralize template references in one place like this:

// No annotations, just plain old Java-object
class User {
    // ...
}
// No annotations, just plain old Java-object
class Order {
    // ...
}
@GenerateRenderablesFacade(className = "DefaultMyRenderables")
interface MyRenderables {
    @RenderableFactoryMethod(tamplate = "com/github/sviperll/mysuperall/user.mustache")
    Renderable<Html> renderableUser(User user);

    @RenderableFactoryMethod(tamplate = "com/github/sviperll/mysuperall/order.mustache")
    Renderable<Html> renderableOrder(Order user);
}
class Main {
    public static void main(String[] args) throws IOException {
        User user = new User("John Doe", 21, new String[] {"Knowns nothing"}, list);
        Order order = new Order(BigDecimal.valueOf(145), Money.USD);
        MyRenderables renderables = new DefaultMyRenderables();
        Renderable<Html> renderableUser = renderables.renderableUser(user);
        Renderable<Html> renderableOrder = renderables.renderableOrder(order);
        // ...
    }
}

Future of static mustache

Hi @sviperll !

A long time ago I started a similar project for handlebars. I never got it off the ground partly because handlebars is far more complicated (and dynamic). I recently decided I needed a type safe mustache and thus used your project as a starting point.

Our fork is here: https://github.com/snaphop/static-mustache

I have changed the project greatly (while still retaining most of the namespace/structure) and have allowed it to basically implement v1.3 of the Mustache Spec (actually runs a test suite against it) which allows template inheritance among other things. I have also updated the project jdk 17 and allowed more types like Optional and Map to be used.

All is good however there are changes I need to do now that will require a great amount of restructuring, reformatting as well as renaming.

Thus I will be hosting a new repository with a different name. I will retain as much of your copyright notice on the files that still resemble your work and the project will continue to use the BSD3 license.

EDIT: I will leave the old fork for some time if you would prefer hosting/owning your fork and just want to merge my changes into yours.

I will also create an organization that will own the new project that you can join if you would like to participate in continued development with me (and whoever else).

Anyway I want to greatly thank you for providing the excellent skeleton to an excellent idea.

Cheers

-Adam

Support for rendering non primitive types.

According to readme: "Any boxed or unboxed primitive type is rendered with toString method. Strings are rendered as is. Rendering of other Java-types as mustache-variable is compile-time error.".

It makes difficult to render java.util.Date or java.util.UUID or java.net.URI values.

Maybe it would be better to have an option to specify classes, which values should be rendered using overloaded Object.toString() method.

Or it would be helpful to have a sort of guide for dealing with such cases.

Repurpose static-mustache to allow SQL-query templates

class User {
    // ...
}
class UserFilter {
    // ...
}
@GenerateRenderablesFacade(className = "DefaultSuperAppQueries")
interface SuperAppQueries {
    @RenderableFactoryMethod(tamplate = "com/github/sviperll/mysuperall/user.sql.mustache")
    Query findUsers(UserFilter user);
}
@GenerateRenderablesFacade(className = "DefaultSuperAppViews")
interface SuperAppViews {
    @RenderableFactoryMethod(tamplate = "com/github/sviperll/mysuperall/user.html.mustache")
    Renderable<Html> renderableUser(User user);
}
class Main {
    public static void main(String[] args) throws IOException {
        SuperAppQueries queries = new DefaultSuperAppQueries();
        UserFilter filter = UserFilter.builder().orderThan(21).nameLike("Snow").build();
        Query query = queries.findUsersQuery(filter);
        User user;
        try (Connection connection = dataSource.getConnection()) {
            SqlSupplier<ResultSet> queryRunner = query.createRunner(connection);
            try (ResultSet resultSet = queryRunner.get()) {
                UserReader reader = new UserReader(resultSet);
                user = reader.readUser();
            }
        }
        SuperAppViews views = new DefaultSuperAppViews();
        Renderable<Html> renderableUser = views.renderableUser(user);
        Renderer renderer = renderable.createRenderer(System.out);
        renderer.render();
    }
}

Add continious integration and switch to Continious Delivery

Ideally we should have

  • development branch
  • beta branch
  • master branch

Merge to master branch should trigger release to maven-central and merge of the same changes to beta branch.
Merge to beta branch should trigger release to maven-central with *-beta version.

I think it's ok to switch to gradle if it's easier to support development process

Documentation

Provide documentation.

Documentation should contain

  • Mission statement with clear vision of project future. It's current philosophy and mileage. It should be useful in evaluating possible design decisions.
  • Differences from mustache
  • Roadmap with list of planned features.
  • Comprehensive description of current functionality
    • Overview
    • Detailed list of used Java-types and their interpretation in static-mustache

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.