#  Draco Econometrics
#  Copyright (C) 2009 Approximatrix, LLC
#  http://www.approximatrix.com
#  
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.

require 'erb'

import com.approximatrix.draco.editor.wizard.PluginWizardData
import com.approximatrix.draco.application.plugin.PluginType

module Plugin
  module Templates

    class TemplateBuilder

		include com.approximatrix.draco.editor.wizard.IPluginCreator

    	def initialize(plugindata)
	    	raise ArgumentError unless plugindata.is_a? PluginWizardData
	    	
	    	@data = plugindata
	    	
	    	template = nil
		    template = File.join(File.dirname(__FILE__),'regression.template') if @data.getPluginType == PluginType.regression  
		    template = File.join(File.dirname(__FILE__),'analysis.template') if @data.getPluginType == PluginType.analysis
		    
    		tf = File.open(template,"r")
			@template = tf.read() unless tf.nil?
			tf.close unless tf.nil?
			
			# java.lang.System.out.println(@template)
	    end
	    
	    def getPluginText
	    	if(not @template.nil?)
				eng = ERB.new(@template)
				eng.result binding
			else
				nil
			end
		end
	    
	end
  end # module Templates
end # module Plugin