Code Monkey home page Code Monkey logo

aramis's Introduction

Aramis

Aramis is a content centric templating engine, made for generating markup from any Content Management System. It's evolved from using and writing several less useful presentation frameworks over more than a decade.

The CMS typically provides content with different types, based on an ID. You only need to write a glue class to link your CMS to this framework.

public class MyContentProvider extends com.github.aramis.ContentProvider{
	public Object getContent(Object contentref){
		// find and return your content
	}
}

Aramis follows the MVC pattern. The model is provided from your CMS, controllers are pojos augmenting each content type, and the view uses an extension to the Mustache template language, which also has the concept of presenting content in different perspectives. Content rendering uses the tags [[ with a reference to the content, and an optional perspective name. Each content type has a template for each perspective. The main perspective is called the same as the model, and is named the same as the class - in lowercase with .art suffix.

myContentType.art

<h1>{{title}}</h1>

<ul class="related">
	{{#related}}
		[[ ID | listPerspective ]]
	{{/related}}
</ul>

myContentType-listPerspective.art

<li><a href="{{URL}}">{{name}}</a></li>

Given that the related items has the same content type, this will render as a title, and a list of links. Other content types can also be listed, and will be presented with their listPerspective template. If the template for a given perspective doesn't exist, the content simply isn't rendered.

The Aramis template language has three different flavors (or mustaches).

[[render content]]

Usage:

To render content, provide the ID to the desired content.

[[ content-ID ]]

To render content in a different perspective, add the name of the perspective, separated with a pipe |

[[ content-ID | list ]]

You can also include parameters to the sub context:

[[ content-ID | list | index:1, caption:'lorem ipsum...' ]]

{{mustache formatting}}

Plain mustache templating. An excelent description here: http://mustache.github.io/mustache.5.html

In brief:

Expression Description
{{expression}} evaluates and prints the result of the expression. HTML escaped.
{{{expression}}} evaluates and prints the result of the expression. Not HTML escaped.
{{#section}} Starts a section if variable doesn`t evaluate to false or an empty list. A section also loops over the elements if the expression is a list
{{/section}} Ends a section
{{^section}} Inverted section. Renders if expression is false or an empty list
{{!comment}} Comment. Not rendered
{{>partial}} Partial. Includes another template

<<decorator>>

Decorator layout pattern.

Create a decorator with your layout markup, and define one or more "holes" where your dynamic content will be inserted.

<html>
<body>
<<contentsection>>
</body>
</html>

In your template, define the decorator at the top, and the content of the sections

<<<decorator name>>>

<<#contentsection>>
<div>content of section</div>
<</contentsection>>

Project setup

Add the aramis dependency to you pom

		<dependency>
		    <groupId>com.github.kristianhelgesen.aramis</groupId>
		    <artifactId>aramis</artifactId>
		    <version>1.1</version>
		</dependency>			

Run:

ContentProvider contentProvider = new MyContentProvider();
RenderEngine renderEngine = new RenderEngine( contentProvider);

String articleReference = "article123";
renderEngine.render( System.out, articleReference);

The template to render the content must be in the same package as the content object, and be named the same as the class - in lowercase with .art suffix.

To add a template for rendering the content in a different perspective, add a dash, and the perspective name to the template name (before the suffix).

Add "Controller" to the model class name, and it is directly available in the template.

Article.java
ArticleController.java
article.art
article-list.art

To get the model object injected into the controller, simply add the model to the controllers constructor.

public ArticleController( Article a) {
  ...
}

To inject both the model and the reference to the controller, add both the model and the reference to the constructor.

public ArticleController( Article a, ArticleReference ref) {
  ...
}

To augment a property in the controller, simply define the same property in the controller. The controller getters have presedence over the model property getters.

public ArticleController( Article a) {
	public String getMyModelProperty(){
		return a.getMyModelProperty().toLowerCase();
	}
  ...
}

aramis's People

Contributors

kristianhelgesen avatar

Watchers

 avatar

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.