// Path: engine/src/main/java/com/impossibl/stencil/api/TemplateSource.java
// public interface TemplateSource extends Closeable {
//   
//   /**
//    * Get the absolute URI of template source.
//    * 
//    * @return Absolute URI of template source
//    * @throws IOException
//    */
//   public URI getURI() throws IOException;
//   
//   /**
//    * Opens a reader for the template source text.
//    * 
//    * @return Reader for the template source text
//    * @throws IOException
//    */
//   public Reader openReader() throws IOException;
//   
//   /**
//    * Get a unique tag for the template source. Generally a hash (MD5, SHA1,
//    * etc) of the source text.
//    * 
//    * @return Unique tag for the source text
//    * @throws IOException
//    */
//   public String getTag() throws IOException;
//   
// }


import static com.google.common.base.Charsets.UTF_8;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.net.URI;
import com.google.common.hash.Hashing;
import com.impossibl.stencil.api.TemplateSource;
package com.impossibl.stencil.api.impl;




/**
 * Template source that holds the source text passed in inside the source
 * object itself. 
 * 
 * @author kdubb
 *
 */
public class InlineTemplateSource implements TemplateSource {
	
	URI uri;
	String text;

	public InlineTemplateSource(String text) {
		this.text = text;
		this.uri = URI.create("file:" + hash(text));
	}
	
	/**
	 * Get MD5 hash of the source text
	 * 
	 * @param text Source text to hash
	 * @return MD5 hash of the source text
	 */
	static String hash(String text) {
// Path: engine/src/main/java/com/impossibl/stencil/api/TemplateSource.java
// public interface TemplateSource extends Closeable {
//   
//   /**
//    * Get the absolute URI of template source.
//    * 
//    * @return Absolute URI of template source
//    * @throws IOException
//    */
//   public URI getURI() throws IOException;
//   
//   /**
//    * Opens a reader for the template source text.
//    * 
//    * @return Reader for the template source text
//    * @throws IOException
//    */
//   public Reader openReader() throws IOException;
//   
//   /**
//    * Get a unique tag for the template source. Generally a hash (MD5, SHA1,
//    * etc) of the source text.
//    * 
//    * @return Unique tag for the source text
//    * @throws IOException
//    */
//   public String getTag() throws IOException;
//   
// }


// Path: engine/src/main/java/com/impossibl/stencil/api/impl/InlineTemplateSource.java
import static com.google.common.base.Charsets.UTF_8;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.net.URI;
import com.google.common.hash.Hashing;
import com.impossibl.stencil.api.TemplateSource;

package com.impossibl.stencil.api.impl;




/**
 * Template source that holds the source text passed in inside the source
 * object itself. 
 * 
 * @author kdubb
 *
 */
public class InlineTemplateSource implements TemplateSource {
	
	URI uri;
	String text;

	public InlineTemplateSource(String text) {
		this.text = text;
		this.uri = URI.create("file:" + hash(text));
	}
	
	/**
	 * Get MD5 hash of the source text
	 * 
	 * @param text Source text to hash
	 * @return MD5 hash of the source text
	 */
	static String hash(String text) {
		return Hashing.md5().hashString(text, UTF_8).toString();