Skip to content

Commit

Permalink
both int and str indent is implemented. Doc done.
Browse files Browse the repository at this point in the history
  • Loading branch information
vkiryukhin committed Apr 14, 2012
1 parent f925964 commit c2e0cfa
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 61 deletions.
21 changes: 19 additions & 2 deletions html/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,28 @@
<td class="functionDoc">
<p>This is a very basic example of a document.</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. <br/>
Check "Preserve Comments" box if you want to keep comments. Or uncheck it
<p>Click on "<b>Minify</b>" button to minify the text. </p>
<p>
Check "<b>Preserve Comments</b>" box if you want to keep comments. Or uncheck it
if you want do delete comments from minified XML or CSS. As JSON doesn't have
comments, the parameter doesn't affect jsonmin function
</p>
<p>
<b>Custom Indent Pattern:</b> <br/>
By default indent pattern is 4 white spaces. However, user can customize as pattern size
as pattern characters.
There are 2 ways to customize indent pattern:
<ul><li>
set number of white spaces as numeric value:<br/> 2, 4, etc.<br/>
</li><li>
set desired pattern as a string, for example:<br/>
<b>'. . . .'</b><br/>
<b>'____'</b><br/>
<b>'- - - -'</b><br/>
<b>'&nbsp; &nbsp; &nbsp; &nbsp;'</b>&nbsp; - &nbsp;string of white spaces is also valid.<br/>
</li></ul>
<b>Note:</b> <i>minify() function works only with whitespace pattern.</i>
</p>
</td>

</tr></table>
22 changes: 19 additions & 3 deletions html/basicsql.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,30 @@
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.
<br/><br/>
Note: <i> "Preserve Comments" is not implemented for SQL part of the application.</i>
</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/>
<span style="font-size:80%">"Preserve Comments" is not implemented for SQL part of the application. </span>
<p>Click on "<b>Minify</b>" button to minify the text (not sure if anybody needs it, but I keep it for consistency :)
</p>
<p>

<b>Custom Indent Pattern:</b> <br/>
By default indent pattern is 4 white spaces. However, user can customize as pattern size
as pattern characters.
There are 2 ways to customize indent pattern:
<ul><li>
set number of white spaces as numeric value:<br/> 2, 4, etc.<br/>
</li><li>
set desired pattern as a string, for example:<br/>
<b>'. . . .'</b><br/>
<b>'____'</b><br/>
<b>'- - - -'</b><br/>
<b>'&nbsp; &nbsp; &nbsp; &nbsp;'</b>&nbsp; - &nbsp;string of white spaces is also valid.<br/>
</li></ul>
Clear input to return to the default indent pattern. <br/><br/>
<b>Note:</b> <i>minify() function works only with whitespace pattern.</i>
</p>
<p></p>
</td>

</tr></table>
61 changes: 43 additions & 18 deletions html/doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,55 @@

<li>Usage:
<ul>
<li>Pretty print: <code>vkbeautify.xml|json|css|sql(text);</code></li>
<li>Minify: <code>vkbeautify.xmlmin|jsonmin|cssmin|sqlmin(text [,preserveComments]);</code></li>
<li><b>Pretty print</b> <br/><br/>
<code>vkbeautify.xml(text [,indent_pattern]);</code>
<br/><code>vkbeautify.json(text [,indent_pattern]);</code>
<br/><code>vkbeautify.css(text [,indent_pattern]);</code>
<br/><code>vkbeautify.sql(text [,indent_pattern]);</code>
<br/><br/>
<code>@text</code> - String; text to beatufy;
<br/>

<code>@indent_pattern</code> - Integer | String;
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>Integer</code> - number of white spaces;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>String</code> - character string to visualize indentation ( can also be a set of white spaces )<br/>
</li>
<!--li>Minify: <code>vkbeautify.xmlmin|jsonmin|cssmin|sqlmin(text [,preserveComments]);</code></li-->
</ul>
</li>
<li>Parameters:

<ul>
<li><code>@text</code> - String; XML, JSON, CSS or SQL text to beatufy;</li>
<li><code>@preserveComments</code> - Bool; [optional] flag, which is used in minxml and mincss functions only. <br/>
Set this flag to true to prevent removing comments from <code>@text</code>;
<li><code>Return</code> - String</li>

<li><b>Minify</b> <br/><br/>
<code>vkbeautify.xmlmin(text [,preserve_comments]);</code>
<br/><code>vkbeautify.jsonmin(text);</code>
<br/><code>vkbeautify.cssmin(text [,preserve_comments]);</code>
<br/><code>vkbeautify.sqlmin(text);</code><br/><br/>
<code>@text</code> - String; text to minify;
<br/>
<code>@preserve_comments</code> - Bool; [optional];<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set this flag to true to prevent removing comments from <code>@text</code>
( <code>minxml</code> and <code>mincss</code> functions only. )
<br/>

</li>
<!--li>Minify: <code>vkbeautify.xmlmin|jsonmin|cssmin|sqlmin(text [,preserveComments]);</code></li-->
</ul>
<br/>
</li>


<li>Usage Examples:<br/>
<li>Examples:<br/>
<ul>
<li><code>vkbeautify.xml(text);</code> // pretty print <b>XML</b></li>
<li><code>vkbeautify.json(text);</code> // pretty print <b>JSON</b> </li>
<li><code>vkbeautify.css(text);</code> // pretty print <b>CSS</b> </li>
<li><code>vkbeautify.sql(text);</code> // pretty print <b>SQL</b> <br/><br/></li>
<li><code>vkbeautify.xmlmin(text [, true]);</code>// minify <b>XML</b> </li>
<li><code>vkbeautify.jsonmin(text);</code>// minify <b>JSON</b> </li>
<li><code>vkbeautify.cssmin(text[, true]);</code>// minify <b>CSS</b> </li>
<li><code>vkbeautify.sqlmin(text);</code>// minify <b>SQL</b> </li>
<li><code>vkbeautify.xml(text);</code> <span class="comment">// pretty print XML</span></li>
<li><code>vkbeautify.json(text, 4 );</code> <span class="comment">// pretty print JSON </span></li>
<li><code>vkbeautify.css(text, '. . . .');</code> <span class="comment">// pretty print CSS</span> </li>
<li><code>vkbeautify.sql(text, '----');</code> <span class="comment">// pretty print SQL</span> <br/><br/></li>


<li><code>vkbeautify.xmlmin(text, true);</code><span class="comment">// minify XML, preserve comments</span> </li>
<li><code>vkbeautify.jsonmin(text);</code><span class="comment">// minify JSON</span> </li>
<li><code>vkbeautify.cssmin(text);</code><span class="comment">// minify CSS, remove comments ( default )</span> </li>
<li><code>vkbeautify.sqlmin(text);</code><span class="comment">// minify SQL </span></li>
</ul>
</li>
</ul>
Expand Down
11 changes: 1 addition & 10 deletions html/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@
<li>other cases when you need to create, edit or check content of an XML, JSON, CSS or SQL file.</li>
</ul>

<p><b>This plugin:</b></p>
<ol style="list-style-type:lower-alpha">
<li>less then 5k minified</li>
<li>no configuration is needed</li>
<li>simple to use: it is a single function with one parameter</li>
<li>takes less then <b>5 mSec</b> to process 50K text<br/>
<small>( Celeron 2.2 GHz, 2.0GB, any of 3 major browsers) </small>
</li>
</ol>
</p>


</td></tr></table>
22 changes: 19 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ <h1>vkBeautify </h1>
<div id="mode">XML </div>
<div style="float:left; margin-left:7em;"><input id="count" type="text" size="5" /> chars</div><br clear="all"/>
<textarea id="ta" style="height:400px;" onclick="countChars()"></textarea>
<div>
<input type="button" onclick="beatify()" value="Pretty Print"/>
<!--div>
<input type="button" onclick="beautify()" value="Pretty Print"/>
<span style="display:inline-block;border:solid 1px #cccccc;padding:5px;margin-left:2em;margin-right:2em;">
<input type="button" onclick="minify()" value="Minify"/>
<input id="preservews" type="checkbox" />
Expand All @@ -81,8 +81,24 @@ <h1>vkBeautify </h1>
</span>
</span>
<input type="button" onclick="document.getElementById('ta').value='';" value="Clear"/>
</div>
</div-->
<table style=""><tr>
<td><input type="button" onclick="beautify()" value="Pretty Print"/></td>
<td><span style="display:inline-block;border:solid 1px #cccccc;padding:5px;margin-left:1em;margin-right:2em;">
<input type="button" onclick="minify()" value="Minify"/>
<input id="preservews" type="checkbox" />
<span style="display:inline-block;width:7em; margin:0px;font-size:75%;">
Preserve Comments
</span>
</span></td>
<td>
<div style="width:8em; margin:0px;font-size:75%;">custom puttern</div>
<input id="custom_pattern" type="text" size="12" value=""/>
</td>
</tr></table>

</div>


<div id="rightpanel"></div>

Expand Down
4 changes: 3 additions & 1 deletion main.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,6 @@ a:visited {color:black;}
.h5 {margin-bottom:1em; font-weight:bold;}
.h6 {margin-bottom:1em; font-weight:bold;text-align:center;margin-bottom:0.5em;}
.highlight {background-color:#FFFF00;}
.comment {color:green;}
.comment {color:green;font-size:85%;}


23 changes: 17 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,30 @@ $(document).ready(function()
$('#rightpanel').empty().load('html/overview.html');
});

function beatify() {
var ta = document.getElementById('ta');
function beautify() {

var ta = document.getElementById('ta'),
cp = document.getElementById('custom_pattern').value;

cp = cp.replace(/\'/g,'').replace(/\"/g,'');

if ( !isNaN(parseInt(cp)) ) { // argument is integer
cp = parseInt(cp);
} else {
cp = cp ? cp : 4;
}

if($('#mode').html() == 'XML') {
ta.value = vkbeautify.xml(ta.value);
ta.value = vkbeautify.xml(ta.value,cp);
} else
if($('#mode').html() == 'JSON') {
ta.value = vkbeautify.json(ta.value);
ta.value = vkbeautify.json(ta.value,cp);
} else
if($('#mode').html() == 'CSS') {
ta.value = vkbeautify.css(ta.value);
ta.value = vkbeautify.css(ta.value,cp);
}
if($('#mode').html() == 'SQL') {
ta.value = vkbeautify.sql(ta.value);
ta.value = vkbeautify.sql(ta.value,cp);
}
countChars();
}
Expand Down
40 changes: 22 additions & 18 deletions vkbeautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,31 @@
(function() {

function createShiftArr(step) {
/*
var space = '';
switch(step) {
case 1: space = ' '; break;
case 2: space = ' '; break;
case 3: space = ' '; break;
case 4: space = ' '; break;
case 5: space = ' '; break;
case 6: space = ' '; break;
case 7: space = ' '; break;
case 8: space = ' '; break;
case 9: space = ' '; break;
case 10: space = ' '; break;
case 11: space = ' '; break;
case 12: space = ' '; break;
default: space = ' '; break;

var space = ' ';

if ( isNaN(parseInt(step)) ) { // argument is string
space = step;
} else { // argument is integer
switch(step) {
case 1: space = ' '; break;
case 2: space = ' '; break;
case 3: space = ' '; break;
case 4: space = ' '; break;
case 5: space = ' '; break;
case 6: space = ' '; break;
case 7: space = ' '; break;
case 8: space = ' '; break;
case 9: space = ' '; break;
case 10: space = ' '; break;
case 11: space = ' '; break;
case 12: space = ' '; break;
}
}
*/

var shift = ['\n']; // array of shifts
for(ix=0;ix<100;ix++){
shift.push(shift[ix]+step);
shift.push(shift[ix]+space);
}
return shift;
}
Expand Down

0 comments on commit c2e0cfa

Please sign in to comment.