-
-
Save vadviktor/7a22fc7999e5d57018ad1f01679cdeee to your computer and use it in GitHub Desktop.
PHP Array Data Extractor for the IntelliJ IDEA Platform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function eachWithIdx(iterable, f) { var i = iterable.iterator(); var idx = 0; while (i.hasNext()) f(i.next(), idx++); } | |
function mapEach(iterable, f) { var vs = []; eachWithIdx(iterable, function (i) { vs.push(f(i));}); return vs; } | |
function escape(str) { | |
str = com.intellij.openapi.util.text.StringUtil.escapeXml(str); | |
return str; | |
} | |
function quote(str) { | |
return '"' + str + '"'; | |
} | |
var NEWLINE = "\n"; | |
function output() { for (var i = 0; i < arguments.length; i++) { OUT.append(arguments[i]); } } | |
function outputRow(items) { | |
output("\tarray(", NEWLINE); | |
for (var i = 0; i < items.length; i++) { | |
if ( i > 0 ) { output(',', NEWLINE); } | |
output('\t\t', quote(items[i][0]), ' => ', quote(items[i][1])); | |
} | |
output(NEWLINE, "\t)"); | |
} | |
output("<?php", NEWLINE, | |
"$exported_data = array(", NEWLINE); | |
eachWithIdx(ROWS, function (row, idx) { | |
if ( idx > 0 ) { output(',', NEWLINE); } | |
outputRow(mapEach(COLUMNS, function (col) { return [col.name(), FORMATTER.format(row, col)]; })) | |
}); | |
output(NEWLINE, ")", NEWLINE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment