<commit_before>(function($) {
	$.widget("ui.tlc",{
		options : {
			templateid : null, //optional.  if set, the template will be appended to the target element.
//having any data is optional. A template ID only can be specified, thus allowing an instance to be added to the DOM w/ no interpolation.
			dataset : {}, //used to interpolate the template. can be passed in directly or can be set w/ datapointer/extendByDatapointers
			datapointer : null, //can be used to set data. ($._app.data[datapointer] )
			extendByDatapointers : new Array(), //an array of datapointers. will merge all the data into one object prior to translation
//if dataAttribs is set, these will be added to this.element as both s data- .  data- will be prepended if not already set.
			dataAttribs : null,
			verb : 'transmogrify' //acceptable values are transmogrify, translate or template (transmogrify requires template and does both apply template and translate).
			// for verb, may later offer a dwiw which tries to intelligently guess what to do. 
			},
		_init : function(){
			var o = this['options'];
			this.element.data('isTLC',true);  //a data tag to key off of so a destroy can be run, if need be.
			//one of these three must be set or running this doesn't really serve any purpose.
			if(o.templateid || o.dataset || o.datapointer || !$.isEmptyObject(o.extendByDatapointers))	{
				//first, resolve 'dataset' so that singular object can be used for any translations.
				if(o.datapointer)	{
					$.extend(o.dataset,$._app.data[o.datapointer]);
					}
				if(!$.isEmptyObject(o.extendByDatapointers))	{
					this._handleDatapointers();
					}
				if($._app.vars.debug == 'tlc')	{
					dump("BEGIN tlc _init. verb: "+o.verb); dump(o.dataset,'debug');
					}
				if(o.verb == 'transmogrify')	{
					var $instance = this.transmogrify();
					this._handleDataAttribs($instance);
					this.element.append($instance);		
					}
				else if(o.verb == 'translate')	{
//					dump(" -> o.dataset"); dump(o.dataset); dump(this.element.html(),'debug');
					var $instance = this.translate();
					this._handleDataAttribs($instance);
					}
				else if(o.verb == 'template')	{
					var $instance = this.template();
					this._handleDataAttribs($instance);
					this.element.append($instance);
					}
				else	{
					dump("in tlc() jquery function, an invalid verb ["+o.verb+"] was specified.","warn");
					}
				}
			else	{
				dump('In $.tlc, no templateid or data was supplied. tlc is not going to accomplish anything without either data or a template.','warn');
				}
			}, //_init

		_setOption : function(option,value)	{
			$.Widget.prototype._setOption.apply( this, arguments ); //method already exists in widget factory, so call original.
			}, //_setOption
		_handleDatapointers : function()	{
			var o = this['options'];
			//'data' could be a pointer, which we don't want to modify, so we extend a blank object and add data in the mix.
			//add all the datapointers into one object. 'may' run into issues here if keys are shared. shouldn't be too much of an issue in the admin interface.
			if(o.extendByDatapointers && o.extendByDatapointers.length)	{
//				dump(" -> datapointers have been extended for tlc");
				var L = o.extendByDatapointers.length;
				for(var i = 0; i < L; i += 1)	{
//					dump(" -> o.extendByDatapointers[i]: "+o.extendByDatapointers[i]); dump($._app.data[o.extendByDatapointers[i]]);
					
					if($._app.data[o.extendByDatapointers[i]])	{
						$.extend(true,this['options'].dataset,$._app.data[o.extendByDatapointers[i]]);
						}
					}
				}
//			dump(" -> this['options'].dataset: "); dump(this['options'].dataset);
			},
		_handleDataAttribs : function($tag)	{
			var o = this['options'];
	//		_app.u.dump(" -> eleAttr is NOT empty");
			if(!$.isEmptyObject(o.dataAttribs) && $tag instanceof jQuery)	{
				var tmp = {};
				for(var index in o.dataAttribs)	{
					if(typeof o.dataAttribs[index] == 'object')	{
						//can't output an object as a string. later, if/when data() is used, this may be supported.
						}
					else if(index.match("^[a-zA-Z0-9_\-]*$"))	{
						tmp[((index.indexOf('data-') === 0) ? '' : 'data-' + index).toLowerCase()] = o.dataAttribs[index]
						}
					else	{
						//can't have non-alphanumeric characters in 
						}
					}
				if(!$.isEmptyObject(tmp)){
	//				dump(" -> obj: "); dump(tmp);
					$tag.attr(tmp).data(o.dataAttribs);
					}

				}
			},
		template : function()	{
			return new tlc().getTemplateInstance(this['options'].templateid);
			},
		translate : function()	{
			if($._app.vars.debug == 'tlc')	{dump(" dataset for tlc: "); dump(this['options'].dataset);}
			return new tlc().translate(this.element,this['options'].dataset);
			},
		transmogrify : function()	{
			var self = this;
//the tlc core code and this plugin are intentionally independant. allows tlc to be run directly. ex: buildQueriesFromTemplate
			var instance = new tlc();
			var $tmp = instance.runTLC({
				templateid : self['options'].templateid,
				dataset : self['options'].dataset
				});
			return $tmp
			}
		
		});

	})(jQuery);



//creates an instance of the template, in memory.
//interpolates all data-tlc on that template.
//returns the template.
var tlc = function()	{
	
//used w/ peg parser for tlc errors.
	this.buildErrorMessage = function(e) {
//		dump(e.message);
		return e.line !== undefined && e.column !== undefined ? "Line " + e.line + ", column " + e.column + ": " + e.message : e.message;
		}

	this.createTemplate = function(templateid)	{
		if(templateid)	{
			var $tmp = $($._app.u.jqSelector('#',templateid));
			this.handleTemplates($tmp); //make sure no <template>'s are inside the template or they could get added to the DOM multiple times.
			return $tmp.length ? $._app.model.makeTemplate($tmp,templateid) : false;
			}
		else	{dump("Unable to execute maketemplate in tlc.createTemplate because no templateid was specified."); return false;}
		}
	
	this.getTemplateInstance = function(templateid)	{
		if($._app.vars.debug == 'tlc')	{
			dump(" -> tlc.getTemplateInstance was executed for templateid: "+templateid);
			}

		var r; //what is returned. either a jquery instance of the template OR false (invalid template)
		if(templateid && $._app.templates[templateid])	{
			r = $._app.templates[templateid].clone(true);
			}
		else if(this.createTemplate(templateid))	{ //createTemplate returns a boolean.
			r = $._app.templates[templateid].clone(true);
			}
		else	{r = false} //invalid template.
		this.element = r; //create a global reference to the element that's being translated. allows bind ~tag to be scoped.
		return r;
		}

	this.handleTemplates = function($target)	{
		$("template",$target).each(function(index){
			//for a <template>, the content makes up the template itself. adding <template> back onto the DOM wouldn't accomplish much.
			$._app.model.makeTemplate($(this).html(),$(this).attr('id'));
			});
		}

// ### FUTURE -> allows --datapointer='appProductDetail' to be set and this could be used to gather what datasets should be acquired.
// would return an object.
//	this.gatherDatapointers = function(){}'

	this.translate = function($ele,dataset)	{
//		dump("BEGIN tlc.translate");
//		dump(" -> dataset: "); dump(dataset);
		dump(" ------------------> start tlc.translate <------------------");
		if($ele instanceof jQuery && dataset)	{
			var _self = this;
			this.handleTemplates($ele); //create any required templates that are in the html. (email uses this).
			$("[data-tlc]",$ele).addBack("[data-tlc]").each(function(index,value){ //addBack ensures the container element of the template parsed if it has a tlc.
				var $tag = $(this), tlc = $tag.data('tlc');
//			
				if($._app.vars.debug == 'tlc')	{
					dump("----------------> start new $tag. tlc: \n"+$(this).data('tlc')+" <-----------------");
					}
				var commands = {};
				dump(" typeof pegParser: "+(typeof window.pegParser));
				dump(" typeof pegParser['parse']: "+(typeof window.pegParser['parse']));
				try{
					commands = window.pegParser['parse']("bind $var '.pretty';");
					}
				catch(e)	{
					dump("TLC error: "+_self.buildErrorMessage(e)+" for: "+tlc);
					}
	
				if(commands && !$.isEmptyObject(commands))	{
					_self.executeCommands(commands,{
						tags : {
							'$tag' : $tag
							}, //an object of tags.
						focusTag : '$tag' //the pointer to the tag that is currently in focus.
						},dataset);
					}
				else	{
					dump("couldn't parse a tlc: "+$tag.data('tlc'),'warn');
					//could not parse tlc. error already reported.
					}
	//			dump("----------------> end $tag <-----------------");
				});<commit_msg>tlc debug<commit_after>(function($) {
	$.widget("ui.tlc",{
		options : {
			templateid : null, //optional.  if set, the template will be appended to the target element.
//having any data is optional. A template ID only can be specified, thus allowing an instance to be added to the DOM w/ no interpolation.
			dataset : {}, //used to interpolate the template. can be passed in directly or can be set w/ datapointer/extendByDatapointers
			datapointer : null, //can be used to set data. ($._app.data[datapointer] )
			extendByDatapointers : new Array(), //an array of datapointers. will merge all the data into one object prior to translation
//if dataAttribs is set, these will be added to this.element as both s data- .  data- will be prepended if not already set.
			dataAttribs : null,
			verb : 'transmogrify' //acceptable values are transmogrify, translate or template (transmogrify requires template and does both apply template and translate).
			// for verb, may later offer a dwiw which tries to intelligently guess what to do. 
			},
		_init : function(){
			var o = this['options'];
			this.element.data('isTLC',true);  //a data tag to key off of so a destroy can be run, if need be.
			//one of these three must be set or running this doesn't really serve any purpose.
			if(o.templateid || o.dataset || o.datapointer || !$.isEmptyObject(o.extendByDatapointers))	{
				//first, resolve 'dataset' so that singular object can be used for any translations.
				if(o.datapointer)	{
					$.extend(o.dataset,$._app.data[o.datapointer]);
					}
				if(!$.isEmptyObject(o.extendByDatapointers))	{
					this._handleDatapointers();
					}
				if($._app.vars.debug == 'tlc')	{
					dump("BEGIN tlc _init. verb: "+o.verb); dump(o.dataset,'debug');
					}
				if(o.verb == 'transmogrify')	{
					var $instance = this.transmogrify();
					this._handleDataAttribs($instance);
					this.element.append($instance);		
					}
				else if(o.verb == 'translate')	{
//					dump(" -> o.dataset"); dump(o.dataset); dump(this.element.html(),'debug');
					var $instance = this.translate();
					this._handleDataAttribs($instance);
					}
				else if(o.verb == 'template')	{
					var $instance = this.template();
					this._handleDataAttribs($instance);
					this.element.append($instance);
					}
				else	{
					dump("in tlc() jquery function, an invalid verb ["+o.verb+"] was specified.","warn");
					}
				}
			else	{
				dump('In $.tlc, no templateid or data was supplied. tlc is not going to accomplish anything without either data or a template.','warn');
				}
			}, //_init

		_setOption : function(option,value)	{
			$.Widget.prototype._setOption.apply( this, arguments ); //method already exists in widget factory, so call original.
			}, //_setOption
		_handleDatapointers : function()	{
			var o = this['options'];
			//'data' could be a pointer, which we don't want to modify, so we extend a blank object and add data in the mix.
			//add all the datapointers into one object. 'may' run into issues here if keys are shared. shouldn't be too much of an issue in the admin interface.
			if(o.extendByDatapointers && o.extendByDatapointers.length)	{
//				dump(" -> datapointers have been extended for tlc");
				var L = o.extendByDatapointers.length;
				for(var i = 0; i < L; i += 1)	{
//					dump(" -> o.extendByDatapointers[i]: "+o.extendByDatapointers[i]); dump($._app.data[o.extendByDatapointers[i]]);
					
					if($._app.data[o.extendByDatapointers[i]])	{
						$.extend(true,this['options'].dataset,$._app.data[o.extendByDatapointers[i]]);
						}
					}
				}
//			dump(" -> this['options'].dataset: "); dump(this['options'].dataset);
			},
		_handleDataAttribs : function($tag)	{
			var o = this['options'];
	//		_app.u.dump(" -> eleAttr is NOT empty");
			if(!$.isEmptyObject(o.dataAttribs) && $tag instanceof jQuery)	{
				var tmp = {};
				for(var index in o.dataAttribs)	{
					if(typeof o.dataAttribs[index] == 'object')	{
						//can't output an object as a string. later, if/when data() is used, this may be supported.
						}
					else if(index.match("^[a-zA-Z0-9_\-]*$"))	{
						tmp[((index.indexOf('data-') === 0) ? '' : 'data-' + index).toLowerCase()] = o.dataAttribs[index]
						}
					else	{
						//can't have non-alphanumeric characters in 
						}
					}
				if(!$.isEmptyObject(tmp)){
	//				dump(" -> obj: "); dump(tmp);
					$tag.attr(tmp).data(o.dataAttribs);
					}

				}
			},
		template : function()	{
			return new tlc().getTemplateInstance(this['options'].templateid);
			},
		translate : function()	{
			if($._app.vars.debug == 'tlc')	{dump(" dataset for tlc: "); dump(this['options'].dataset);}
			return new tlc().translate(this.element,this['options'].dataset);
			},
		transmogrify : function()	{
			var self = this;
//the tlc core code and this plugin are intentionally independant. allows tlc to be run directly. ex: buildQueriesFromTemplate
			var instance = new tlc();
			var $tmp = instance.runTLC({
				templateid : self['options'].templateid,
				dataset : self['options'].dataset
				});
			return $tmp
			}
		
		});

	})(jQuery);



//creates an instance of the template, in memory.
//interpolates all data-tlc on that template.
//returns the template.
var tlc = function()	{
	
//used w/ peg parser for tlc errors.
	this.buildErrorMessage = function(e) {
//		dump(e.message);
		return e.line !== undefined && e.column !== undefined ? "Line " + e.line + ", column " + e.column + ": " + e.message : e.message;
		}

	this.createTemplate = function(templateid)	{
		if(templateid)	{
			var $tmp = $($._app.u.jqSelector('#',templateid));
			this.handleTemplates($tmp); //make sure no <template>'s are inside the template or they could get added to the DOM multiple times.
			return $tmp.length ? $._app.model.makeTemplate($tmp,templateid) : false;
			}
		else	{dump("Unable to execute maketemplate in tlc.createTemplate because no templateid was specified."); return false;}
		}
	
	this.getTemplateInstance = function(templateid)	{
		if($._app.vars.debug == 'tlc')	{
			dump(" -> tlc.getTemplateInstance was executed for templateid: "+templateid);
			}

		var r; //what is returned. either a jquery instance of the template OR false (invalid template)
		if(templateid && $._app.templates[templateid])	{
			r = $._app.templates[templateid].clone(true);
			}
		else if(this.createTemplate(templateid))	{ //createTemplate returns a boolean.
			r = $._app.templates[templateid].clone(true);
			}
		else	{r = false} //invalid template.
		this.element = r; //create a global reference to the element that's being translated. allows bind ~tag to be scoped.
		return r;
		}

	this.handleTemplates = function($target)	{
		$("template",$target).each(function(index){
			//for a <template>, the content makes up the template itself. adding <template> back onto the DOM wouldn't accomplish much.
			$._app.model.makeTemplate($(this).html(),$(this).attr('id'));
			});
		}

// ### FUTURE -> allows --datapointer='appProductDetail' to be set and this could be used to gather what datasets should be acquired.
// would return an object.
//	this.gatherDatapointers = function(){}'

	this.translate = function($ele,dataset)	{
//		dump("BEGIN tlc.translate");
//		dump(" -> dataset: "); dump(dataset);
		dump(" ------------------> start tlc.translate <------------------");
		if($ele instanceof jQuery && dataset)	{
			var _self = this;
			this.handleTemplates($ele); //create any required templates that are in the html. (email uses this).
			$("[data-tlc]",$ele).addBack("[data-tlc]").each(function(index,value){ //addBack ensures the container element of the template parsed if it has a tlc.
				var $tag = $(this), tlc = $tag.data('tlc');
//			
				if($._app.vars.debug == 'tlc')	{
					dump("----------------> start new $tag. tlc: \n"+$(this).data('tlc')+" <-----------------");
					}
				var commands = {};
//				dump(" typeof pegParser: "+(typeof window.pegParser));
//				dump(" typeof pegParser['parse']: "+(typeof window.pegParser['parse']));
				dump(" typeof tlc: "+(typeof tlc));
				try{
					commands = window.pegParser['parse'](tlc.toString());
					}
				catch(e)	{
					dump("TLC error: "+_self.buildErrorMessage(e)+" for: "+tlc);
					}
	
				if(commands && !$.isEmptyObject(commands))	{
					_self.executeCommands(commands,{
						tags : {
							'$tag' : $tag
							}, //an object of tags.
						focusTag : '$tag' //the pointer to the tag that is currently in focus.
						},dataset);
					}
				else	{
					dump("couldn't parse a tlc: "+$tag.data('tlc'),'warn');
					//could not parse tlc. error already reported.
					}
	//			dump("----------------> end $tag <-----------------");
				});
{'fraction_non_alphanumeric': 0.16585507246376813, 'fraction_numerical': 0.0005797101449275362, 'mean_word_length': 3.088883621711306, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4354750', 'n_tokens_mistral': 6415, 'n_tokens_neox': 5395, 'n_words': 1592}