From c2e0cfabafa23e4529cfd872ee70bd93365bfd69 Mon Sep 17 00:00:00 2001 From: Vadim Kiryukhin Date: Fri, 13 Apr 2012 19:21:58 -0700 Subject: [PATCH] both int and str indent is implemented. Doc done. --- html/basic.html | 21 ++++++++++++++-- html/basicsql.html | 22 ++++++++++++++--- html/doc.html | 61 ++++++++++++++++++++++++++++++++-------------- html/overview.html | 11 +-------- index.html | 22 ++++++++++++++--- main.css | 4 ++- main.js | 23 ++++++++++++----- vkbeautify.js | 40 ++++++++++++++++-------------- 8 files changed, 143 insertions(+), 61 deletions(-) diff --git a/html/basic.html b/html/basic.html index ffbacbf..1e22141 100644 --- a/html/basic.html +++ b/html/basic.html @@ -6,11 +6,28 @@

This is a very basic example of a document.

Click on "Pretty Print" button to beatify the text.

-

Click on "Minify" button to minify the text.
-Check "Preserve Comments" box if you want to keep comments. Or uncheck it +

Click on "Minify" button to minify the text.

+

+Check "Preserve Comments" 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

+

+Custom Indent Pattern:
+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: +

+Note: minify() function works only with whitespace pattern. +

diff --git a/html/basicsql.html b/html/basicsql.html index 6d03baf..605d922 100644 --- a/html/basicsql.html +++ b/html/basicsql.html @@ -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. +

+Note: "Preserve Comments" is not implemented for SQL part of the application.

Click on "Pretty Print" button to beatify the text.

-

Click on "Minify" button to minify the text (not sure if anybody needs it, but I keep it for consistency :)

-"Preserve Comments" is not implemented for SQL part of the application. +

Click on "Minify" button to minify the text (not sure if anybody needs it, but I keep it for consistency :)

- +Custom Indent Pattern:
+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: +

+Clear input to return to the default indent pattern.

+Note: minify() function works only with whitespace pattern.

+

diff --git a/html/doc.html b/html/doc.html index 2ee1612..001aab3 100644 --- a/html/doc.html +++ b/html/doc.html @@ -15,30 +15,55 @@
  • Usage: -
  • -
  • Parameters: + +
  • + -
  • Usage Examples:
    +
  • Examples:
  • diff --git a/html/overview.html b/html/overview.html index f2a7136..5334410 100644 --- a/html/overview.html +++ b/html/overview.html @@ -21,15 +21,6 @@
  • other cases when you need to create, edit or check content of an XML, JSON, CSS or SQL file.
  • -

    This plugin:

    -
      -
    1. less then 5k minified
    2. -
    3. no configuration is needed
    4. -
    5. simple to use: it is a single function with one parameter
    6. -
    7. takes less then 5 mSec to process 50K text
      - ( Celeron 2.2 GHz, 2.0GB, any of 3 major browsers) -
    8. -
    -

    + diff --git a/index.html b/index.html index be9755f..d3a9896 100644 --- a/index.html +++ b/index.html @@ -71,8 +71,8 @@

    vkBeautify

    XML
    chars

    -
    - + + + + + +
    + + + + Preserve Comments + + +
    custom puttern
    + +
    +
    +
    diff --git a/main.css b/main.css index 3aff863..776d621 100644 --- a/main.css +++ b/main.css @@ -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%;} + + diff --git a/main.js b/main.js index 5624cb7..b0f92cd 100644 --- a/main.js +++ b/main.js @@ -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(); } diff --git a/vkbeautify.js b/vkbeautify.js index 4f1ada1..a899721 100644 --- a/vkbeautify.js +++ b/vkbeautify.js @@ -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; }