Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

cenobites/vraptor-mustache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vraptor-mustache

Handles download by reading from a mustache template.

Using it

  1. In a Maven project's pom.xml file:
    
<dependency>
	<groupId>es.cenobit.vraptor</groupId>
  	<artifactId>vraptor-mustache</artifactId>
  	<version>1.0</version>
</dependency>
  1. Put vraptor-mustache-VERSION.jar and dependencies in your WEB-INF/lib folder.
  2. In your project create templates.

Template

ID;Name;Description;Price;Status;
{{items}}{{id}};{{name}};{{description}};{{price}};{{status}};
{{/items}}

Item

public class Item {

	private Long id;
	private String name;
	private String url;
	private Double price;
	private Boolean status;

	public Item(Long id, String name, String url, Double price, Boolean status) {
		super();
		this.id = id;
		this.name = name;
		this.url = url;
		this.price = price;
		this.status = status;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public Boolean getStatus() {
		return status;
	}

	public void setStatus(Boolean status) {
		this.status = status;
	}
}

Controller

@Resource
public class TemplateController {

	private final Result result;
	private ServletContext servletContext;

	public TemplateController(Result result, ServletContext servletContext) {
		this.result = result;
		this.servletContext = servletContext;
	}

	@Path("/download")
	public Download download() {
		List<Item> items = new ArrayList<Item>();
		items.add(new Item(1L, "VRaptor", "http://vraptor.caelum.com.br/", 22.50, true));
		items.add(new Item(2L, "Mustache", "http://mustache.github.io/", 34.40, true));
		items.add(new Item(3L, "Cenobit.es", "http://cenobit.es/", 6.66, true));
		
		Map<String, Object> scope = new HashMap<String, Object>();
		scope.put("items", items);

		File file = new File(this.servletContext.getRealPath("/WEB-INF/classes/templates/template.mustache"));
		return new MustacheDownload(file, scope, "application/vnd.ms-excel", "template.cvs");
	}
}

Project Information

  • Author: Cenobit Technologies, Inc.
  • Version: 1.0 of 2013/10/15
  • License: Apache License 2.0

About

Handles download by reading from a mustache template

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages