Commits

Gary Chambers  committed 3778252

Refactored template module.

  • Participants
  • Parent commits 09e60a1

Comments (0)

Files changed (1)

File src/addons/template.js

 	var Template,
 
 		_compileTemplate,
-		_loadTemplate;
+		_loadTemplate,
+
+		_cache,
+		_config,
+		_engines;
+
+	_cache = Jazz.Storage.load("template:cache");
+	_config = Jazz.Storage.load("template:config");
+	_engines = Jazz.Storage.load("template:engines");
 
 	/**
 	Compiles a template string into a dynamic function.
 		context = template.options.context;
 		path = template.options.path;
 
-		func = Template.Cache.get(path);
+		func = _cache.get(path);
 
 		if(func)
 		{
 
 		Jazz.ajax.get(path, function(tmpl)
 		{
-			func = Template.Config.get("engine", _compileTemplate)(tmpl);
+			func = Template.compile(tmpl);
 			func(context);
-			Template.Cache.set(path, func);
+			_cache.set(path, func);
 		});
 	};
 
 		_loadTemplate(this);
 	};
 
-	Jazz.iter.forEach(["Cache", "Config", "Engines"], function(key)
-	{
-		Template[ key ] = Jazz.Storage.load("template:" + key.toLowerCase());
-	});
-
 	Jazz.obj.extend(Template, {
 		/**
+		Compiles the template string to
+		a function.
+
+		@method compile
+		@param {String} tmpl
+		@return {Function}
+		**/
+		compile: function compile( tmpl )
+		{
+			return _config.get("engine", _compileTemplate)( tmpl );
+		},
+
+		/**
 		Registers an alternative templating engine.
 
 		@method register
 		**/
 		register: function register(name, fn)
 		{
-			Template.Engines.set(name, fn);
+			_engines.set(name, fn);
 		},
 
 		/**
 		**/
 		use: function use(name)
 		{
-			Template.Config.set("engine",
-				Template.Engines.get(name)
+			_config.set("engine",
+				_engines.get(name)
 			);
 		}
 	});
 		}
 	});
 
+	Template.config = _config;
+
 	return Template;
 
 })(this, this.document));