<commit_before>/*
    newT
        a JavaScript template library

    author: <NAME> | https://twitter.com/jeffreytierney
    project home: https://github.com/jeffreytierney/newT
    liscense: (see author)
    
    Usage:
    
        Create a new 'newT' -- a JS represention of DOM Template w/ event capabilities
        
            newT.save("id_name", function( data ) {
                // use the () for multiline return of DOM elements via newT.  
                // the second param is the 'contents' of the element
                // this sample is a simple string derived from data when newT.render() is called          
                return ( 
                    newT.div({clss : "my_css_class"}, data.foo)
                )
            });
            
        Converter syntax for Element CSS Class Attribute: "clss"
        
        Render DOM Elements
            @param string "id_name" template name
            @param (any) the data to pass to the method used in the second parameter of newT.save("name", func);
            newT.render("id_name", { foo : "hello world bars" } );
            
            
        Render DOM with options and scope
        
            newT.render("id_name", {}, {
                scope : obj_scope || this
                data : { } // will be overriden completely - not extended
                preData : func // execute w/ scope passed in
                pre : func // excuted w/ scope passed in
            })
            
            
        On Script Load
            On script load, the newT (or temp name is assigned) is initialized.
                This single instance allows convience referrals to complex structures through the 
                newT iterface
                
        Use with innerHTML
            newT.renderToString("id_name", {
                foo : "I come back as a string, no a DOM node"
            });
            

        Iteration
            newT.each(["one", "two"], function( data, idx ) {
                console.log("data", data);
                console.log("index position", idx);
            })
        
        Innerards:
            newT.templates.global will provide current "templates"

*/

(function (temp) {
  // Default global var name will be newT
  // can be overridden by passing something different
  // into the self executing wrapper function
  temp = temp || "newT";

  // internally refer to it as T for brevity sake
  var T = function(options) {
    this.init(options || {});
  }, regex_pattern=/\<[^\>]+\>|\&[^ ]+;/;

  T.prototype = {
    constructor: T.prototype.constructor,
    version : "1.1.1.1",
    init: function(options) {
      this.options = options;
      this.templates = {};
      this.__createMethods();
      return this;
    },
    // simple function to save the passed in template
    save: function(name, template) {
      var name_parts = name.split("."),
          ns = "global";
      name = name_parts[0];
      if(name_parts.length > 1) {
        ns = name_parts[1];
      }
      if(!this.templates.hasOwnProperty(ns)) { this.templates[ns] = {}; }
      this.templates[ns][name] = template;
      return this;
    },
    // create the elements for the template
    // and if an exisiting root el was passed in, append it to that root
    // either way, return the newly created element(s)
    render: function(name, data, opts) {
      var name_parts = name.split("."), 
          ns = "global",
          new_el;
      name = name_parts[0];
      if(name_parts.length > 1) {
        ns = name_parts[1];
      }
      
      opts = opts || {};
      opts.scope = opts.scope || null;
      opts.data = data;

      // if a preprocessing function is specified in the options, call it
      // use either the specified scope, or the default of null (set earlier)
      // params
      if (opts.preData) { opts.data = opts.preData.call(opts.scope, opts.data); }
      if (opts.pre) { var ret = opts.pre.call(opts.scope, opts.data); }
      
      new_el = this.templates[ns][name](opts.data);
      if(typeof new_el === "object" && new_el.length > 0) {
        var _new_el=new_el.slice(0);
        new_el=document.createDocumentFragment();
        for(var i in _new_el) {
            new_el.appendChild( _new_el[i] );
        }
      }

      if(opts.el) {
        opts.el.appendChild(new_el);
      }

      // if a posprocessing function is specified in the options, call it
      // use either the specified scope, or the default of null (set earlier)
      if (opts.post) { opts.post.call(opts.scope, new_el, opts.data); }
      return new_el;
    },
    renderToString: function(name, data, opts) {
      opts = opts || {};
      delete opts.el;

      var el = document.createElement("div");
      el.appendChild(this.render(name, data, opts));

      return el.innerHTML;

    },
    // function to iterate over a collection and render a template
    // for each item in the collection
    // uses a document fragment to collect each element and pass it back
    eachRender: function(data, template_name, opts) {
      opts = opts || {};
      var frag = document.createDocumentFragment();
      opts.el = frag;
      for(var i in data) {
        if(data.hasOwnProperty(i)) {
          this.render(template_name, data[i], opts);<commit_msg>update comment to also clarify param name change<commit_after>/*
    newT
        a JavaScript template library

    author: <NAME> | https://twitter.com/jeffreytierney
    project home: https://github.com/jeffreytierney/newT
    liscense: (see author)
    
    Usage:
    
        Create a new 'newT' -- a JS represention of DOM Template w/ event capabilities
        
            newT.save("id_name", function( data ) {
                // use the () for multiline return of DOM elements via newT.  
                // the second param is the 'contents' of the element
                // this sample is a simple string derived from data when newT.render() is called          
                return ( 
                    newT.div({clss : "my_css_class"}, data.foo)
                )
            });
            
        Converter syntax for Element CSS Class Attribute: "clss"
        
        Render DOM Elements
            @param string "id_name" template name
            @param (any) the data to pass to the method used in the second parameter of newT.save("name", func);
            newT.render("id_name", { foo : "hello world bars" } );
            
            
        Render DOM with options and scope
        
            newT.render("id_name", {}, {
                scope : obj_scope || this
                data : { } // will be overriden completely - not extended
                preData : func // execute w/ scope passed in
                pre : func // excuted w/ scope passed in
            })
            
            
        On Script Load
            On script load, the newT (or temp name is assigned) is initialized.
                This single instance allows convience referrals to complex structures through the 
                newT iterface
                
        Use with innerHTML
            newT.renderToString("id_name", {
                foo : "I come back as a string, no a DOM node"
            });
            

        Iteration
            newT.each(["one", "two"], function( data, idx ) {
                console.log("data", data);
                console.log("index position", idx);
            })
        
        Innerards:
            newT.templates.global will provide current "templates"

*/

(function (temp) {
  // Default global var name will be newT
  // can be overridden by passing something different
  // into the self executing wrapper function
  temp = temp || "newT";

  // internally refer to it as T for brevity sake
  var T = function(options) {
    this.init(options || {});
  }, regex_pattern=/\<[^\>]+\>|\&[^ ]+;/;

  T.prototype = {
    constructor: T.prototype.constructor,
    version : "1.1.1.1",
    init: function(options) {
      this.options = options;
      this.templates = {};
      this.__createMethods();
      return this;
    },
    // simple function to save the passed in template
    save: function(name, template) {
      var name_parts = name.split("."),
          ns = "global";
      name = name_parts[0];
      if(name_parts.length > 1) {
        ns = name_parts[1];
      }
      if(!this.templates.hasOwnProperty(ns)) { this.templates[ns] = {}; }
      this.templates[ns][name] = template;
      return this;
    },
    // create the elements for the template
    // and if an exisiting root el was passed in, append it to that root
    // either way, return the newly created element(s)
    render: function(name, data, opts) {
      var name_parts = name.split("."), 
          ns = "global",
          new_el;
      name = name_parts[0];
      if(name_parts.length > 1) {
        ns = name_parts[1];
      }
      
      opts = opts || {};
      opts.scope = opts.scope || null;
      opts.data = data;

      // if a preprocessing function is specified in the options, call it
      // use either the specified scope, or the default of null (set earlier)
      // params
      if (opts.preData) { opts.data = opts.preData.call(opts.scope, opts.data); }
      if (opts.pre) { var ret = opts.pre.call(opts.scope, opts.data); }
      
      new_el = this.templates[ns][name](opts.data);
      if(typeof new_el === "object" && new_el.length > 0) {
        var _new_el=new_el.slice(0);
        new_el=document.createDocumentFragment();
        for(var i in _new_el) {
            new_el.appendChild( _new_el[i] );
        }
      }

      if(opts.el) {
        opts.el.appendChild(new_el);
      }

      // if a posprocessing function is specified in the options, call it
      // use either the specified scope, or the default of null (set earlier)
      if (opts.post) { opts.post.call(opts.scope, new_el, opts.data); }
      return new_el;
    },
    renderToString: function(name, data, opts) {
      opts = opts || {};
      delete opts.el;

      var el = document.createElement("div");
      el.appendChild(this.render(name, data, opts));

      return el.innerHTML;

    },
    // function to iterate over a collection and render a previously saved template
    // for each item in the collection
    // uses a document fragment to collect each element and pass it back
    eachRender: function(data, template_name, opts) {
      opts = opts || {};
      var frag = document.createDocumentFragment();
      opts.el = frag;
      for(var i in data) {
        if(data.hasOwnProperty(i)) {
          this.render(template_name, data[i], opts);
{'fraction_non_alphanumeric': 0.10822510822510822, 'fraction_numerical': 0.002258610954263128, 'mean_word_length': 1.8323560767590619, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '576587', 'n_tokens_mistral': 2999, 'n_tokens_neox': 2911, 'n_words': 954}