123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538 |
- //
- // DataGridRenderer.js
- // Part of Mr-Data-Converter
- //
- // Created by Shan Carter on 2010-10-18.
- //
- var DataGridRenderer = {
-
- //---------------------------------------
- // Actionscript
- //---------------------------------------
-
- as: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "//";
- var commentLineEnd = "";
- var outputText = "[";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
-
- //begin render loops
- for (var i=0; i < numRows; i++) {
- var row = dataGrid[i];
- outputText += "{";
- for (var j=0; j < numColumns; j++) {
- if ((headerTypes[j] == "int")||(headerTypes[j] == "float")) {
- var rowOutput = row[j] || "null";
- } else {
- var rowOutput = '"'+( row[j] || "" )+'"';
- };
- outputText += (headerNames[j] + ":" + rowOutput)
- if (j < (numColumns-1)) {outputText+=","};
- };
- outputText += "}";
- if (i < (numRows-1)) {outputText += ","+newLine};
- };
- outputText += "];";
-
-
- return outputText;
- },
-
-
- //---------------------------------------
- // ASP / VBScript
- //---------------------------------------
-
- asp: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "'";
- var commentLineEnd = "";
- var outputText = "";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
-
- //begin render loop
- for (var i=0; i < numRows; i++) {
- var row = dataGrid[i];
- for (var j=0; j < numColumns; j++) {
- if ((headerTypes[j] == "int")||(headerTypes[j] == "float")) {
- var rowOutput = row[j] || "null";
- } else {
- var rowOutput = '"'+( row[j] || "" )+'"';
- };
- outputText += 'myArray('+j+','+i+') = '+rowOutput+newLine;
- };
- };
- outputText = 'Dim myArray('+(j-1)+','+(i-1)+')'+newLine+outputText;
-
- return outputText;
- },
-
-
- //---------------------------------------
- // HTML Table
- //---------------------------------------
-
- html: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "<!--";
- var commentLineEnd = "-->";
- var outputText = "";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
-
- //begin render loop
- outputText += "<table>"+newLine;
- outputText += indent+"<thead>"+newLine;
- outputText += indent+indent+"<tr>"+newLine;
-
- for (var j=0; j < numColumns; j++) {
- outputText += indent+indent+indent+'<th class="'+headerNames[j]+'-cell">';
- outputText += headerNames[j];
- outputText += '</th>'+newLine;
- };
- outputText += indent+indent+"</tr>"+newLine;
- outputText += indent+"</thead>"+newLine;
- outputText += indent+"<tbody>"+newLine;
- for (var i=0; i < numRows; i++) {
- var row = dataGrid[i];
- var rowClassName = ""
- if (i === numRows-1) {
- rowClassName = ' class="lastRow"';
- } else if (i === 0){
- rowClassName = ' class="firstRow"';
- }
- outputText += indent+indent+"<tr"+rowClassName+">"+newLine;
- for (var j=0; j < numColumns; j++) {
- outputText += indent+indent+indent+'<td class="'+headerNames[j]+'-cell">';
- outputText += row[j]
- outputText += '</td>'+newLine
- };
- outputText += indent+indent+"</tr>"+newLine;
- };
- outputText += indent+"</tbody>"+newLine;
- outputText += "</table>";
-
- return outputText;
- },
-
-
- //---------------------------------------
- // JSON properties
- //---------------------------------------
-
- json: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "//";
- var commentLineEnd = "";
- var outputText = "[";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
-
- //begin render loop
- for (var i=0; i < numRows; i++) {
- var row = dataGrid[i];
- outputText += "{";
- for (var j=0; j < numColumns; j++) {
- if ((headerTypes[j] == "int")||(headerTypes[j] == "float")) {
- var rowOutput = row[j] || "null";
- } else {
- var rowOutput = '"' + ( row[j] || "" ) + '"';
- };
-
- outputText += ('"'+headerNames[j] +'"' + ":" + rowOutput );
-
- if (j < (numColumns-1)) {outputText+=","};
- };
- outputText += "}";
- if (i < (numRows-1)) {outputText += ","+newLine};
- };
- outputText += "]";
-
- return outputText;
- },
-
- //---------------------------------------
- // JSON Array of Columns
- //---------------------------------------
- jsonArrayCols: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "//";
- var commentLineEnd = "";
- var outputText = "";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
-
- //begin render loop
- outputText += "{"+newLine;
- for (var i=0; i < numColumns; i++) {
- outputText += indent+'"'+headerNames[i]+'":[';
- for (var j=0; j < numRows; j++) {
- if ((headerTypes[i] == "int")||(headerTypes[i] == "float")) {
- outputText += dataGrid[j][i] || 0;
- } else {
- outputText += '"'+(dataGrid[j][i] || "")+'"' ;
- }
- if (j < (numRows-1)) {outputText+=","};
- };
- outputText += "]";
- if (i < (numColumns-1)) {outputText += ","+newLine};
- };
- outputText += newLine+"}";
-
-
- return outputText;
- },
-
-
- //---------------------------------------
- // JSON Array of Rows
- //---------------------------------------
- jsonArrayRows: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "//";
- var commentLineEnd = "";
- var outputText = "";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
-
- //begin render loop
- outputText += "["+newLine;
- for (var i=0; i < numRows; i++) {
- outputText += indent+"[";
- for (var j=0; j < numColumns; j++) {
- if ((headerTypes[j] == "int")||(headerTypes[j] == "float")) {
- outputText += dataGrid[i][j] || 0;
- } else {
- outputText += '"'+(dataGrid[i][j] || "")+'"' ;
- }
- if (j < (numColumns-1)) {outputText+=","};
- };
- outputText += "]";
- if (i < (numRows-1)) {outputText += ","+newLine};
- };
- outputText += newLine+"]";
-
-
- return outputText;
- },
-
-
- //---------------------------------------
- // JSON Dictionary
- //---------------------------------------
- jsonDict: function(dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "//";
- var commentLineEnd = "";
- var outputText = "";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
- //begin render loop
- outputText += "{" + newLine;
- for (var i = 0; i < numRows; i++) {
- outputText += indent + '"' + dataGrid[i][0] + '": ';
- if (numColumns == 2) {
- outputText += _fmtVal(i, 1, dataGrid);
- } else {
- outputText += '{ ';
- for (var j = 1; j < numColumns; j++) {
- if (j > 1) outputText += ', ';
- outputText += '"' + headerNames[j] + '"' + ":" + _fmtVal(i, j, dataGrid);
- }
- outputText += '}';
- }
- if (i < (numRows - 1)) {
- outputText += "," + newLine;
- }
- }
- outputText += newLine + "}";
- function _fmtVal(i, j) {
- if ((headerTypes[j] == "int")||(headerTypes[j] == "float")) {
- return dataGrid[i][j] || 0;
- } else {
- return '"'+(dataGrid[i][j] || "")+'"' ;
- }
- }
- return outputText;
- },
- //---------------------------------------
- // MYSQL
- //---------------------------------------
- mysql: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "/*";
- var commentLineEnd = "*/";
- var outputText = "";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
- var tableName = "MrDataConverter"
-
- //begin render loop
- outputText += 'CREATE TABLE '+tableName+' (' + newLine;
- outputText += indent+"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"+newLine;
- for (var j=0; j < numColumns; j++) {
- var dataType = "VARCHAR(255)";
- if ((headerTypes[j] == "int")||(headerTypes[j] == "float")) {
- dataType = headerTypes[j].toUpperCase();
- };
- outputText += indent+""+headerNames[j]+" "+dataType;
- if (j < numColumns - 1) {outputText += ","};
- outputText += newLine;
- };
- outputText += ');' + newLine;
- outputText += "INSERT INTO "+tableName+" "+newLine+indent+"(";
- for (var j=0; j < numColumns; j++) {
- outputText += headerNames[j];
- if (j < numColumns - 1) {outputText += ","};
- };
- outputText += ") "+newLine+"VALUES "+newLine;
- for (var i=0; i < numRows; i++) {
- outputText += indent+"(";
- for (var j=0; j < numColumns; j++) {
- if ((headerTypes[j] == "int")||(headerTypes[j] == "float")) {
- outputText += dataGrid[i][j] || "null";
- } else {
- outputText += "'"+( dataGrid[i][j] || "" )+"'";
- };
-
- if (j < numColumns - 1) {outputText += ","};
- };
- outputText += ")";
- if (i < numRows - 1) {outputText += ","+newLine;};
- };
- outputText += ";";
-
- return outputText;
- },
-
-
- //---------------------------------------
- // PHP
- //---------------------------------------
- php: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "//";
- var commentLineEnd = "";
- var outputText = "";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
- var tableName = "MrDataConverter"
-
- //begin render loop
- outputText += "array(" + newLine;
- for (var i=0; i < numRows; i++) {
- var row = dataGrid[i];
- outputText += indent + "array(";
- for (var j=0; j < numColumns; j++) {
- if ((headerTypes[j] == "int")||(headerTypes[j] == "float")) {
- var rowOutput = row[j] || "null";
- } else {
- var rowOutput = '"'+(row[j] || "")+'"';
- };
- outputText += ('"'+headerNames[j]+'"' + "=>" + rowOutput)
- if (j < (numColumns-1)) {outputText+=","};
- };
- outputText += ")";
- if (i < (numRows-1)) {outputText += ","+newLine};
- };
- outputText += newLine + ");";
-
- return outputText;
- },
-
- //---------------------------------------
- // Python dict
- //---------------------------------------
-
- python: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "//";
- var commentLineEnd = "";
- var outputText = "[";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
-
- //begin render loop
- for (var i=0; i < numRows; i++) {
- var row = dataGrid[i];
- outputText += "{";
- for (var j=0; j < numColumns; j++) {
- if ((headerTypes[j] == "int")||(headerTypes[j] == "float")) {
- var rowOutput = row[j] || "None";
- } else {
- var rowOutput = '"'+(row[j] || "")+'"';
- };
-
- outputText += ('"'+headerNames[j] +'"' + ":" + rowOutput );
-
- if (j < (numColumns-1)) {outputText+=","};
- };
- outputText += "}";
- if (i < (numRows-1)) {outputText += ","+newLine};
- };
- outputText += "];";
-
- return outputText;
- },
-
-
- //---------------------------------------
- // Ruby
- //---------------------------------------
- ruby: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "#";
- var commentLineEnd = "";
- var outputText = "";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
- var tableName = "MrDataConverter"
-
- //begin render loop
- outputText += "[";
- for (var i=0; i < numRows; i++) {
- var row = dataGrid[i];
- outputText += "{";
- for (var j=0; j < numColumns; j++) {
- if ((headerTypes[j] == "int")||(headerTypes[j] == "float")) {
- var rowOutput = row[j] || "nil"
- } else {
- var rowOutput = '"'+(row[j] || "")+'"';
- };
- outputText += ('"'+headerNames[j]+'"' + "=>" + rowOutput)
- if (j < (numColumns-1)) {outputText+=","};
- };
- outputText += "}";
- if (i < (numRows-1)) {outputText += ","+newLine};
- };
- outputText += "];";
-
- return outputText;
- },
-
-
- //---------------------------------------
- // XML Nodes
- //---------------------------------------
- xml: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "<!--";
- var commentLineEnd = "-->";
- var outputText = "";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
-
- //begin render loop
- outputText = '<?xml version="1.0" encoding="UTF-8"?>' + newLine;
- outputText += "<rows>"+newLine;
- for (var i=0; i < numRows; i++) {
- var row = dataGrid[i];
- outputText += indent+"<row>"+newLine;
- for (var j=0; j < numColumns; j++) {
- outputText += indent+indent+'<'+headerNames[j]+'>';
- outputText += row[j] || ""
- outputText += '</'+headerNames[j]+'>'+newLine
- };
- outputText += indent+"</row>"+newLine;
- };
- outputText += "</rows>";
-
- return outputText;
-
- },
-
-
-
- //---------------------------------------
- // XML properties
- //---------------------------------------
- xmlProperties: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "<!--";
- var commentLineEnd = "-->";
- var outputText = "";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
-
- //begin render loop
- outputText = '<?xml version="1.0" encoding="UTF-8"?>' + newLine;
- outputText += "<rows>"+newLine;
- for (var i=0; i < numRows; i++) {
- var row = dataGrid[i];
- outputText += indent+"<row ";
- for (var j=0; j < numColumns; j++) {
- outputText += headerNames[j]+'=';
- outputText += '"' + row[j] + '" ';
- };
- outputText += "></row>"+newLine;
- };
- outputText += "</rows>";
-
- return outputText;
-
- },
-
- //---------------------------------------
- // XML Illustrator
- //---------------------------------------
- xmlIllustrator: function (dataGrid, headerNames, headerTypes, indent, newLine) {
- //inits...
- var commentLine = "<!--";
- var commentLineEnd = "-->";
- var outputText = "";
- var numRows = dataGrid.length;
- var numColumns = headerNames.length;
-
- //begin render loop
- outputText = '<?xml version="1.0" encoding="utf-8"?>' + newLine;
- outputText += '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN" "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd" [' + newLine;
- outputText += indent+'<!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">' + newLine;
- outputText += indent+'<!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">' + newLine;
- outputText += indent+'<!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/">' + newLine;
- outputText += indent+'<!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/">' + newLine;
- outputText += indent+'<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">' + newLine;
- outputText += indent+'<!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">' + newLine;
- outputText += ']>' + newLine;
- outputText += '<svg>' + newLine;
- outputText += '<variableSets xmlns="&ns_vars;">' + newLine;
- outputText += indent+'<variableSet varSetName="binding1" locked="none">' + newLine;
- outputText += indent+indent+'<variables>' + newLine;
- for (var i=0; i < numColumns; i++) {
- outputText += indent+indent+indent+'<variable varName="'+headerNames[i]+'" trait="textcontent" category="&ns_flows;"></variable>' + newLine;
- };
- outputText += indent+indent+'</variables>' + newLine;
- outputText += indent+indent+'<v:sampleDataSets xmlns:v="http://ns.adobe.com/Variables/1.0/" xmlns="http://ns.adobe.com/GenericCustomNamespace/1.0/">' + newLine;
-
- for (var i=0; i < numRows; i++) {
- var row = dataGrid[i];
- outputText += indent+indent+indent+'<v:sampleDataSet dataSetName="' + row[0] + '">'+newLine;
- for (var j=0; j < numColumns; j++) {
- outputText += indent+indent+indent+indent+'<'+headerNames[j]+'>'+newLine;
- outputText += indent+indent+indent+indent+indent+'<p>' + row[j] + '</p>' +newLine;
- outputText += indent+indent+indent+indent+'</'+headerNames[j]+'>'+newLine
- };
- outputText += indent+indent+indent+'</v:sampleDataSet>'+newLine;
- };
-
- outputText += indent+indent+'</v:sampleDataSets>' + newLine;
- outputText += indent+'</variableSet>' + newLine;
- outputText += '</variableSets>' + newLine;
- outputText += '</svg>' + newLine;
-
-
- return outputText;
-
- },
-
- }
|