[Javascript] Comments Creator v.1.0.0 stable.

Stato
Discussione chiusa ad ulteriori risposte.

Gfff

Utente Electrum
26 Luglio 2007
359
38
16
156
Ecco un mio script per generare commenti in linea con lo standard Javadoc:

links:
Codice:
Blog: http://deocorp.altervista.org/blog/projects/projectcomments-creator/
SourceForge: https://sourceforge.net/projects/commentscreator/
Script: http://ccreator.deocorp.org

Commentate^^
 
ah beh, finché fano quei topic in cui nn mettono codice, licenza e monate varie io all'index nn li aggiungo. Le normative per il posting vanno lette.
 
Codice:
$(document).ready(function () {
    function trim(str, charlist) {
        var whitespace, l = 0,
            i = 0;
        str += '';
        if (!charlist) {
            whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
        } else {
            charlist += '';
            whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
        }
        l = str.length;
        for (i = 0; i < l; i++) {
            if (whitespace.indexOf(str.charAt(i)) === -1) {
                str = str.substring(i);
                break;
            }
        }
        l = str.length;
        for (i = l - 1; i >= 0; i--) {
            if (whitespace.indexOf(str.charAt(i)) === -1) {
                str = str.substring(0, i + 1);
                break;
            }
        }
        return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
    }
    function ucwords(str) {
        return (str + '').replace(/^(.)|\s(.)/g, function ($1) {
            return $1.toUpperCase();
        });
    }
    const head = "/**";
    const left = " * ";
    const end = " */";
    const par = "<input type=\"text\" size=\"250\" value=\"param\" name=\"param\" >";
    const br = "<br />";
    const name = "<input type=\"text\" value=\"name\" name=\"nome\" >";

    function Create_par($content) {
        const len = 71;
        var numvolte = $content.length;
        var frase;
        var g;
        var text = "";
        var x;
        x = 0;
        var primo = true;
        while (x <= numvolte) {
            text = text + left;
            g = 0;
            frase = '';
            while (g < len) {
                if ($content[x] != undefined) {
                    if (($content[x] == '.') && ($content[x + 1] == " ")) {
                        frase = frase + $content[x] + $content[x + 1];
                        x++;
                    } else {
                        if ($content[x] == '\n') {
                            x++;
                            break;
                        } else {
                            frase = frase + $content[x];
                        }
                    }
                }
                g++;
                x++;
            }
            text = text + trim(frase) + "\n";
        }
        return text;
    }
    function param_creator(params) {
        var names = new Array();
        var parametres = new Array();
        params.filter(':even').each(function (index) {
            names[index] = $(this).val();
        }).css("background-color", "#bbbbff");
        params.filter(':odd').each(function (index) {
            parametres[index] = $(this).val();
        }).css("background-color", "#88FF3D");
        var content = new Array();
        for (var name in names) {
            content[names[name]] = parametres[name];
        }
        var text = '';
        for (var name in content) {
            text = text + "@param  " + name + '  ' + content[name] + "\n" + left + " \n";
        }
        return text;
    }
    $("pre#result").hide();
    $("div#params").hide();
    $("input:submit, button").button({
        icons: {
            primary: 'ui-icon-circle-check'
        }
    }).click(function () {
        var d = new Date();
        var min = d.getMilliseconds();
        var sec = d.getSeconds();
        d = (sec * 1000) + min;
        var content = $("#desc").val();
        var text;
        text = Create_par(content);
        text = head + "\n" + text;
        $("pre#result").html(text);
        content = $("#url").val();
        text = $("#name").val();
        $("pre#result").append("{@" + content + "}. " + ucwords(text) + "\n");
        content = $("#f").val();
        text = Create_par(content);
        $("pre#result").append(text + left + "\n" + left + "\n\n");
        text = param_creator($("div#params > input"));
        $("pre#result").append(text);
        content = $("input#result").val();
        $("pre#result").append("@return   " + ucwords(content) + "\n" + left + "\n");
        content = $("input#see").val();
        $("pre#result").append("@see      " + ucwords(content) + "\n" + end);
        $("pre#result").css("background-color", "#0033CC").css("color", "#FFFF00");
        $("pre#result").show("blind");
        var dd = new Date();
        min = dd.getMilliseconds();
        sec = dd.getSeconds();
        dd = (sec * 1000) + min;
        min = dd - d;
        $("#seconds").html("<b>Hai impiegato " + min + " millisecondi</b>");
    });
    $("textarea,input").addClass("ui-widget-content").resizable();
    $("h1,label").addClass("ui-widget-header");
    $('#switcher').themeswitcher();
    $("textarea").width($("h1").width());

    function vai(dest) {
        self.location.hash = dest;
        return false
    }
    $(".add").click(function () {
        $("pre#result").hide("blind");
        $("#params").append(name + br);
        $("#params").append(par + br + "<hr />");
        $("div#params").show("blind");
        vai("params");
    });
});
con http://jsbeautifier.org/
 
Codice:
$(document).ready(function(){
	

 
 function trim (str, charlist) {
/**
 * Strips whitespace from the beginning and end of a string
 * 
 * version: 1008.1718
 * discuss at: http://phpjs.org/functions/trim
 * original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
 * improved by: mdsjack (http://www.mdsjack.bo.it)
 * improved by: Alexander Ermolaev (http://snippets.dzone.com/user/Alexand
 * erErmolaev)
 * input by: Erkekjetter
 * improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
 * input by: DxGx
 * improved by: Steven Levithan (http://blog.stevenlevithan.com)
 * tweaked by: Jack
 * bugfixed by: Onno Marsman
{@http://phpjs.org/functions/trim}. Trim
 * example 1: trim('    Kevin van Zonneveld    ');
 * returns 1: 'Kevin van Zonneveld'
 * example 2: trim('Hello World', 'Hdle');
 * returns 2: 'o Wor'
 * example 3: trim(16, 1);
 * returns 3: 6
 * 
 * 

@param  string  String to trim
 *  
@param  Charset  char and word thar must be trimmed
 *  
@return   string trimmed
 * 
@see      string trimmed, string without chars and words unwanted
 */
    var whitespace, l = 0, i = 0;
    str += '';
    
    if (!charlist) {
        // default list
        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
    } else {
        // preg_quote custom list
        charlist += '';
        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
    }
    
    l = str.length;
    for (i = 0; i < l; i++) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(i);
            break;
        }
    }
    
    l = str.length;
    for (i = l - 1; i >= 0; i--) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    
    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}
 
 function ucwords(str) {
/**
 * Uppercase the first character of every word in a string
 * 
 * version: 1008.1718
 * discuss at: http://phpjs.org/functions/ucwords
 * original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
 * improved by: Waldo Malqui Silva
 * bugfixed by: Onno Marsman
 * improved by: Robin
 * 
{@http://phpjs.org/functions/ucwords}. Ucwords
 * example 1: ucwords('kevin van zonneveld');
 * returns 1: 'Kevin Van Zonneveld'
 * example 2: ucwords('HELLO WORLD');
 * returns 2: 'HELLO WORLD'
 * 
 * 

@param  string  Tring to capitalize
 *  
@return   string Capitalized
 * 
@see      string Capitalized, every word with the first letter uppercase
 */
    return (str + '').replace(/^(.)|\s(.)/g, function ($1) {
        return $1.toUpperCase();
	 });
}
  
 const head = "/**"; const left = " * "; const end =  " */"; 
 const par = "<input type=\"text\" size=\"250\" value=\"param\" name=\"param\" >" ; const br = "<br />";
 const name = "<input type=\"text\" value=\"name\" name=\"nome\" >" ; 
 
 	function Create_par ($content){
	
	const len = 71;
	
	var numvolte = $content.length;

	var frase; var g; var text = ""; var x;
	
	x = 0;
	var primo = true;
	while(x <= numvolte){
		
	 text = text + left;
	 g = 0;
	 frase = '';
	 while(g < len){

		if ($content[x] != undefined){
					if (($content[x] == '.') && ($content[x+1] == " ")){
						frase = frase + $content[x]+ $content[x+1];
						x++;
						
					}else{
						if($content[x] == '\n'){
							x++;
							break;
						}else{
							frase = frase + $content[x]; 
						}
					}
		}
		g++;
		x++;
	 }
		text = text + trim(frase) + "\n";
	}
		return text;
	}
	
	function param_creator(params){
	
	var names = new Array(); 
		var parametres = new Array();	
		

		params.filter(':even').each(function(index){
		
			names[index] = $(this).val();			
		
		}).css("background-color", "#bbbbff");//name
		params.filter(':odd').each(function(index){
		
			parametres[index] = $(this).val();
			
		
		}).css("background-color", "#88FF3D");//params
		
		var content =  new Array(); 
		
		for (var name in names) {  
		
			content[names[name]] = parametres[name];
		
		}  
		
		var text = '';
		
		for (var name in content) {  
		
			text = text +  "@param  " + name +'  '+ content[name]+"\n"+left+" \n";
		
		}		
			return text;
	
	}
	
//---------------------------------------------Beginning
$("pre#result").hide();
$("div#params").hide();

$("input:submit, button").button({
            icons: {primary: 'ui-icon-circle-check'  }
 }).click(function(){
	 	var d = new Date();
		var min = d.getMilliseconds();
		var sec = d.getSeconds();
		
		d = (sec*1000) + min;
 
	var content = $("#desc").val();
	var text;
	
	text = Create_par(content);
	
	text = head + "\n" + text;
	$("pre#result").html(text);
	
	content = $("#url").val();
	text = $("#name").val();
	
	$("pre#result").append("{@"+content+"}. "+ucwords(text)+"\n");
	
	content = $("#f").val();
	
	text = Create_par(content);
	
	$("pre#result").append(text+left+"\n"+left+"\n\n");
	
	text = param_creator($("div#params > input"));
	
	$("pre#result").append(text);
	
	content = $("input#result").val();
	
	$("pre#result").append("@return   "+ucwords(content)+"\n"+left+"\n");
	
	content = $("input#see").val();
	$("pre#result").append("@see      "+ucwords(content)+"\n"+end);

	$("pre#result").css("background-color", "#0033CC").css("color", "#FFFF00");
	$("pre#result").show("blind");
	
    var dd = new Date();
	
	 min = dd.getMilliseconds();
	 sec = dd.getSeconds();
	
	dd = (sec*1000) + min;
	min = dd - d;
	$("#seconds").html("<b>Hai impiegato "+min+" millisecondi</b>");
});

$("textarea,input").addClass("ui-widget-content").resizable();
$("h1,label").addClass("ui-widget-header");
$('#switcher').themeswitcher();
$("textarea").width($("h1").width());

 function vai(dest){
self.location.hash=dest;
return false
}
 
 $(".add").click(function(){
	$("pre#result").hide("blind");	
	$("#params").append(name +  br);
	$("#params").append(par  +  br + "<hr />");
	$("div#params").show("blind");
	vai("params");
 });

 });

licenza GNU c'è scritto.
eccolo ^^
 
io se non mettete lo scherma come si deve non metto + nell'index, che è un lavoraccio. Guardate lo schema generale e mi va bene
 
~Comments Creator
  • Creator & Manteiner: Deo aka Gfff
  • Type: Development tool
  • Language: Javascript
  • Other dependencies: Jquery, Jquery UI and other GUI plugins
  • Platform: Indipendent(Browser)
  • Last stable release: 1.0.1
  • License: GNU GPL3
  • forum link: http://www.infernet.ws/showthread.php?tid=17193
  • Blog: http://deocorp.altervista.org/blog/projects/projectcomments-creator/
  • SourceForge: https://sourceforge.net/projects/commentscreator/
  • Script: http://ccreator.deocorp.org


Codice:
Updated Version {
  this( 1.0.0 => 1.0.1 )
}

eliminata la funzione trim, esisteva già nella libreria jquery.

Codice:
 var string = "   prova  ";
string = $.trim(string);

//diventerà "prova";
 
Stato
Discussione chiusa ad ulteriori risposte.