 {join} = require 'path'
 
-getPartials = (source)->  # Return list of patial filenames in the source.
+parsePartials = (source)->  # Return list of patial filenames in the source.
 	{scan} = require 'hogan.js'
 	result = []
 	scanned = scan source


	partials = {}
	# Get Partials #
	partial_files = getPartials source

	if partial_files.length
		{existsSync} = require 'path'
		for file in partial_files
			filepath = join options.root, file

			if existsSync filepath
				partials[file] = readFile filepath
			else if options.defaultEngine and existsSync filepath+=".#{options.defaultEngine}"
				partials[file] = readFile filepath
				
	return ->
		return compiled.render options, partials

	{readFileSync} = require 'fs'
	return readFileSync(file).toString() # TODO better way to read file, especially large ones.

{existsSync} = require 'path'
makePartials = (partials, list, root, defaultEngine)->
	for file in list
		filepath = join root, file

		if existsSync filepath
			partials[file] = readFile filepath
		else if defaultEngine and existsSync filepath+=".#{defaultEngine}"
			partials[file] = readFile filepath
	

exports.compile = (source='', options)->
	hogan = require 'hogan.js'
	compiled = hogan.compile source
