sviperll / static-mustache Goto Github PK
View Code? Open in Web Editor NEWTemplate engine for java with statically checked and compiled templates. Compilation is performed alone with java sources.
License: BSD 3-Clause "New" or "Revised" License
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
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.
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);
// ...
}
}
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
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.
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();
}
}
See spec.
It would be useful to have a list of Mustache features, not yet implemented in Static-Mustache.
Ideally we should have
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
Provide documentation.
Documentation should contain
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.