Skip to content

Commit

Permalink
set ver 0.96.00.beta, edit doc, clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
vkiryukhin committed Mar 1, 2012
1 parent ff7d2b2 commit acfa3a3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
6 changes: 3 additions & 3 deletions html/basicsql.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<p>This is an example of a SQL statement.</p>

<p>
vkBeautify SQL parser covers only SELECT statement as most javascript developers most time have deal with SELECT.
As SQL syntax itself is very large and complex, some complex statements can be formatted not as perfect as you'd
make it manually. But anyway, this tool helps you to save time on reading unformatted SQL statement.
vkBeautify SQL parser covers only SELECT statement as most javascript developers have deal with SELECT-based queries.
As SELECT syntax itself is very large and flexible, some complex nested statements can be formatted not as perfect as you'd
make it manually. But anyway, it helps you to save time on reading unformatted SQL statement.
</p>
<p>Click on "<b>Pretty Print</b>" button to beatify the text. </p>
<p>Click on "<b>Minify</b>" button to minify the text (not sure if anybody needs it, but I keep it for consistency :)<br/><br/>
Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function loadTemplate(name)
break;

case 'basicsql':
$('#ta').width(600);
$('#ta').width(500);
$('#leftpanel').show();
document.getElementById('ta').value = "SELECT ca.proj_id AS proj_id, ca.ca_name AS proj_name, ca.ca_date_start AS proj_start, ca.ca_date_end AS proj_end,(SELECT COUNT(*) FROM rotations r WHERE r.proj_id = proj_id AND r.r_status = 'R' GROUP BY r.proj_id) r_count, (SELECT count(*) FROM rotations r WHERE r.proj_id = proj_id AND r.channel_id = 24 ) r_rtb_count FROM projs ca, clients c, proj_auth caa WHERE ca.client_id = 12345 AND ca.client_id = c.client_id AND ca_type = 'zzz' AND c.agency_id = 0 AND ca.client_id = NVL( caa.client_id, ca.client_id ) AND proj_id = NVL( caa.proj_id, proj_id ) AND caa.contact_id = 7890";
$('#rightpanel').empty().load('html/basicsql.html');
Expand Down
26 changes: 12 additions & 14 deletions vkbeautify.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* vkBeautify - javascript plugin to pretty-print or minify text in XML, JSON and CSS formats.
*
* Version - 0.95.01.beta
* Version - 0.96.00.beta
* Copyright (c) 2012 Vadim Kiryukhin
* vkiryukhin @ gmail.com
* http://www.eslinstructor.net/vkbeautify/
Expand All @@ -10,8 +10,8 @@
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* vkbeautify.xml|json|css(text ) - pretty print XML, JSON or CSS text;
* vkbeautify.xmlmin|jsonmin|cssmin(text, preserveComments ) - minify XML, JSON or CSS text;
* vkbeautify.xml|json|css|sql(text ) - pretty print XML, JSON, CSS or SQL text;
* vkbeautify.xmlmin|jsonmin|cssmin|sqlmin(text, preserveComments ) - minify XML, JSON, CSS or SQL text;
*
* PARAMETERS:
*
Expand All @@ -22,20 +22,21 @@
*
* USAGE:
*
* vkbeautify.xml(text);
* vkbeautify.json(text);
* vkbeautify.css(text);
* vkbeautify.xmlmin( text [, true]);
* vkbeautify.jsonmin(text);
* vkbeautify.cssmin( text [, true]);
* var foo = vkbeautify.xml(text);
* var foo = vkbeautify.json(text);
* var foo = vkbeautify.css(text);
* var foo = vkbeautify.sql(text);
* var foo = vkbeautify.xmlmin( text [, true]);
* var foo = vkbeautify.jsonmin(text);
* var foo = vkbeautify.cssmin( text [, true]);
* var foo = vkbeautify.sqlmin(text);
*
*/

(function() {

function vkbeautify(){
this.shift = ['\n']; // array of shifts
//this.step = ' '; // 2 spaces
this.step = ' '; // 4 spaces
var maxdeep = 100, // nesting level
ix = 0;
Expand Down Expand Up @@ -277,18 +278,15 @@ vkbeautify.prototype.sql = function(text, brakeOnComma) {

if( /\s{0,}\(\s{0,}SELECT\s{0,}/.exec(ar[ix])) {
deep++;
//parenthesisLevel = isSubquery(ar[ix], parenthesisLevel);
str += this.shift[deep]+ar[ix];
} else
if( /\'/.exec(ar[ix]) ) {
//parenthesisLevel = isSubquery(ar[ix], parenthesisLevel);
if(parenthesisLevel<1 && deep) {
deep--;
}
str += ar[ix];
}
else {
//parenthesisLevel = isSubquery(ar[ix], parenthesisLevel);
str += this.shift[deep]+ar[ix];
if(parenthesisLevel<1 && deep) {
deep--;
Expand All @@ -297,7 +295,7 @@ vkbeautify.prototype.sql = function(text, brakeOnComma) {
var junk = 0;
}

str = str.replace(/^\n{1,}/,'')/*.replace(/\n[ \t]{0,}/g,"\n");*/.replace(/\n{1,}/g,"\n");
str = str.replace(/^\n{1,}/,'').replace(/\n{1,}/g,"\n");
return str;
}

Expand Down

0 comments on commit acfa3a3

Please sign in to comment.