<commit_before>/*
    Copyright 2014 Leafbird

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

*/

(function(arg) {

    this.json;

    this.Leafbird = function(arg) {
        if(!(this instanceof Leafbird)) {
            return new Leafbird(arg);
        }

        this.json = arg;
    };

    Leafbird.prototype.print = function(element, _attr) {

        if(!(element instanceof HTMLElement)) {
            throw new SyntaxError("Invalid HTMLElement.", element);
        }

        var reducedJSON = this.json;

        if(_attr == undefined) {
            // undefined print all JSON
        }
        else if(_attr.indexOf("#") == 0) { // find id in JSON
            console.log("id");
        }
        else if(_attr.indexOf(".") == 0) { // find label in JSON
            console.log("label");
        }
        else {
            throw new SyntaxError("JSONAttribute '" + _attr + "' is not valid.",
                                                                    _attr);
        }

        element.innerHTML = buildHTML(reducedJSON);

    };

    Leafbird.prototype.find = function(property, _value) {

        json = this.json;
        json;

    };

    var buildHTML = function(json) {
        json = json.inputs[0];

        var html = "";

        // check if obj is input or group
        if(json.hasOwnProperty("type")) {
            html += buildInput(json);
        }
        else {
            // recursive groups
        }

        return html;
    };

    var buildInput = function(json, _placeholder) {

        // validar se tem placeholder para gera label ou nao.
        var html = '<label>'+json.label+'</label>';

        switch(json.type) {

            case "text":
            case "number":
                html += '<input id="'+json.id+'" name="'+json.id+'" type="'+json.type+'" />';
                break;
            case "boolean":
                break;
            case "select":
                break
            default:
                throw new SyntaxError("Invalid InputType.", json.type);
        }

        return html;
    };

    window.Leafbird = Leafbird, window.lb = Leafbird;

})();<commit_msg>New fix to find elements in json to print.<commit_after>/*
    Copyright 2014 Leafbird

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

(function(arg) {

  this.json;
  var dom_objs;

  this.Leafbird = function(arg) {
    if(!(this instanceof Leafbird)) {
      return new Leafbird(arg);
    }

    this.json = arg;
  };

  Leafbird.prototype.find = function(property, _value, _json) { //TODO: Add contains to find values

    var arr_found = [];
    json = (_json == undefined) ? this.json : _json;

    if(json.hasOwnProperty(property) && 
        (_value == undefined || json[property] == _value)) {
      arr_found.push(json);
    }

    for(i in json) {
      if(json[i] instanceof Array) {
        for(j in json[i]) {
          found = this.find(property, _value, json[i][j]);
          if(found.length > 0)
            arr_found = arr_found.concat(found);
        }
      }
    }

    return arr_found;
  };

  Leafbird.prototype.print = function(element, _attr) {

    if(!(element instanceof HTMLElement)) {
      throw new SyntaxError("Invalid HTMLElement.", element);
    }

    var reducedJSON = [];

    if(_attr == undefined) {
      reducedJSON.push(this.json);
    }
    else if(_attr.indexOf("#") == 0) {
      reducedJSON = this.find("id", _attr.substring(1));
    }
    else if(_attr.indexOf(".") == 0) {
      reducedJSON = this.find("class", _attr.substring(1));
    }
    else if(_attr.indexOf("$") == 0) {
      reducedJSON = this.find("label", _attr.substring(1));
    }
    else {
      throw new SyntaxError("JSONAttribute '" + _attr + "' is not valid.", 
                                                                   _attr);
    }

    var html = "";
    for(i in reducedJSON) {
      html += buildHTML(reducedJSON[i]);
    }

    element.innerHTML = html;
  };

  var buildHTML = function(json) {

    var html = "";

    if(json.hasOwnProperty("type")) {
      html += buildInput(json);
    }
    else {
      for(i in json) {
        if(json[i] instanceof Array) {
          for(j in json[i]) {
            html += buildHTML(json[i][j]);
          }
        }
      }
    }

    return html;
  };

  var buildInputElement = function(json) {

    var label = document.createElement("label");
    label.setAttribute("for", json.id);
    label.appendChild(document.createTextNode(json.label));

    var input = document.createElement("input");
    input.setAttribute("id", json.id);
    input.setAttribute("name", json.id);
    input.setAttribute("type", json.type);
    input.setAttribute("placeholder", json.label);
  };

  var buildInput = function(json, _placeholder) {

    // check placeholder and label to genarate html.
    var html = '<label for="'+json.id+'">'+json.label+'</label>';

    switch(json.type) {

      case "text":
      case "number":
        html += '<input id="'+json.id+'" name="'+json.id+'" type="'+json.type+'" />';
        break;
      case "boolean":
        break;
      case "select": // select-check to checkbox
        break
      default:
        throw new SyntaxError("Invalid InputType.", json.type);
    }

    return html;
  };

  window.Leafbird = Leafbird, window.lb = Leafbird;

})();
{'fraction_non_alphanumeric': 0.12750512860975224, 'fraction_numerical': 0.004102887801798958, 'mean_word_length': 2.0471153846153847, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1304083', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1767, 'n_words': 501}