<commit_before>var Generator = require('yeoman-generator'),
	chalk = require('chalk');

module.exports = class extends Generator {

	constructor(args, opts) {
	    super(args, opts);

	    this.promptQuestion = [];

	    // This method adds support for a `--babel` flag
	    this.option('babel');
	}

	initializing () {
    	this.log('Initializing the generator ...');

    	this.promptQuestion = [{
    		type: 'input',
		    name: 'appName',
		    message: 'Your site name',
		    default: 'ITArverne'
		},{
		    type: 'input',
		    name: 'appUrl',
		    message: 'Your url domain',
		    default: function(response){
		    	return response.appName.toLowerCase()+'.itarverne.com';
		    }
		},{
		    type: 'input',
		    name: 'lang',
		    message: 'Put the lag of your website'
		},{
		    type: 'input',
		    name: 'alt',
		    message: 'Put the alternate url for the meta tag'
		},{
			when: function (response) {
				return response.alternate;
			},
		    type: 'input',
		    name: 'alt-lang',
		    message: 'Put the alternate url lang for the meta tag : ',
		    validate: function(lang){
		    	if(lang.trim().length == 0)
		    		return "The alternate url lang for the meta tag is required !";

		 		return !lang.trim().length == 0
		    }
		},{
		    type: 'input',
		    name: 'title',
		    message: 'Put the website title'
		},{
		    type: 'input',
		    name: 'desc',
		    message: 'Put the website description'
		},{
		    type: 'input',
		    name: 'icoPath',
		    message: 'Put the website ico path',
		    default: 'linux or windows path supported'
		},{
		    type: 'input',
		    name: 'icoPathApple',
		    message: 'Put the website png path for apple ico',
		    default: 'linux or windows path supported'
		},{
		    type: 'input',
		    name: 'codeGTM',
		    message: 'Put the following code for Google Tag Management (GTM-XXXXXXX)'
		},{
		    type: 'confirm',
		    name: 'putTwitter',
		    message: 'Do you want to put share and follow twitter button ?',
		    default: 'N'
		},{
			when: function (response) {
				return response.putTwitter;
			},
		    type: 'input',
		    name: 'nameTwitter',
		    message: 'Put the twitter username : ',
		    validate: function(username){
		    	if(username.trim().length == 0)
		    		return "Your twitter username is required !";

		 		return !username.trim().length == 0
		    }
		},{
			when: function (response) {
				return response.putTwitter;
			},
		    type: 'input',
		    name: 'urlTwitter',
		    message: 'Put the url to share in twitter : ',
		    default: function(response){
		    	return response.appUrl;
		    }
		},{
			when: function (response) {
				return response.putTwitter;
			},
		    type: 'input',
		    name: 'authorTwitter',
		    message: 'Put the author in twitter : ',
		    validate: function(author){
		    	if(author.trim().length == 0)
		    		return "The twitter author is required !";

		 		return !author.trim().length == 0
		    }
		},{
		    type: 'confirm',
		    name: 'putFacebook',
		    message: 'Do you want to put share and like Facebook button ?',
		    default: 'N'
		},{
			when: function (response) {
				return response.putFacebook;
			},
		    type: 'input',
		    name: 'appIdFacebook',
		    message: 'Put the AppId Facebook : ',
		    validate: function(appId){
		    	if(appId.trim().length == 0 || isNaN(appId))
		    		return "Your facebook appId have to be numeric !";

		 		return !appId.trim().length == 0
		    }
		},{
			when: function (response) {
				return response.putFacebook;
			},
		    type: 'input',
		    name: 'urlFacebook',
		    message: 'Put the URL Facebook : ',
		    validate: function(url){
		    	if(url.trim().length == 0)
		    		return "The Facebook url is required !";

		 		return !url.trim().length == 0
		    }
		},{
		    type: 'confirm',
		    name: 'putLinkedin',
		    message: 'Do you want to put share and follow LinkedIn button ?',
		    default: 'N'
		},{
			when: function (response) {
				return response.putLinkedin;
			},
		    type: 'input',
		    name: 'urlLinkedin',
		    message: 'Put the LinkedIn url : ',
		    validate: function(url){
		    	if(url.trim().length == 0)
		    		return "The LinkedIn url is required !";

		 		return !url.trim().length == 0
		    }
		},{
			type: 'input',
		    name: 'mail',
		    message: 'Put the mail to get in touch : ',
		    validate: function(mail){
		    	const atpos = mail.indexOf("@");
				const dotpos = mail.lastIndexOf(".");
				if (atpos < 1 || ( dotpos - atpos < 2 ))
				{
					return "The mail is wrong !";
				}

		 		return true;
		    }
		}];
  	}

	prompting () {
	  var done = this.async();

	  this.prompt(this.promptQuestion)
	  	.then((prompt) => {
	        this.props = prompt;
	        done();
		});
	}

  	configuring () {
    	this.log(chalk.bold.cyan('Configuring the generator ...'));
  	}

	default () {
    	this.log('Default the generator ...');
  	}

	writing () {
		this.log(chalk.bold.cyan('Analyzing the inputs ...'));

		if(this.fs.exists(this.props.icoPath)){
			if(this.props.icoPath.includes('.ico')){
				this.fs.copy(this.props.icoPath, 'public/favicon.ico');
			}
			else {
				this.log(chalk.bold.yellow('No favicon configured, wrong extension only .iso available !'));
			}
		} else {
			this.log(chalk.bold.yellow('No favicon configured, wrong path !'));
		}

		if(this.fs.exists(this.props.icoPathApple)){
			if(this.props.icoPath.includes('.png')){
				this.fs.copy(this.props.icoPath, 'public/apple-touch-icon.png');
			}
			else {
				this.log(chalk.bold.yellow('No favicon configured for apple, wrong extension only .png available !'));
			}
		} else {
			this.log(chalk.bold.yellow('No favicon configured for apple, wrong path !'));
		}

		if(this.props.codeGTM != this.promptQuestion[3].default){
			var regex = new RegExp('^GTM-[0-9A-Z]{7}$');
			if(!regex.test(this.props.codeGTM)){
				this.props.codeGTM = '';
				this.log(chalk.bold.red('Wrong Google Tag Management code provided, script not included !'));
			}
		} else {
			this.log(chalk.bold.yellow('No Google Tag Management code provided, script not included !'));
		}

		const user, domain, extension;
		if(this.props.mail){
			user = this.props.mail.split("@")[0];
			domain = this.props.mail.split("@")[1].split('.')[0];
			extension = this.props.mail.split("@")[1].split('.')[1];
		}

		this.fs.copyTpl(
			this.templatePath('index.html'),
			this.destinationPath('testyo/index.html'), // public instead of testyo
			{
				appName: this.props.appName,
				lang: this.props.lang,
				alt: this.props.alt,
				altLang: this.props.altLang,
				url: this.props.appUrl,
				gtm: this.props.codeGTM,
				title: this.props.title,
				desc: this.props.desc,
				putTwitter: this.props.putTwitter,
				nameTwitter: this.props.nameTwitter,
				urlTwitter: this.props.urlTwitter,
				authorTwitter: this.props.authorTwitter,
				putFacebook: this.props.putFacebook,
				appIdFacebook: this.props.appIdFacebook,
				urlFacebook: this.props.urlFacebook,
				putLinkedin: this.props.putLinkedin,
				urlLinkedin: this.props.urlLinkedin,
				userMail: user,
				domainMail: domain,
				extMail: extension
			}
		);

		this.fs.copyTpl(
			this.templatePath('cookies.html'),
			this.destinationPath('testyo/cookies.html'), // public instead of testyo
			{
				appName: this.props.appName,
				lang: this.props.lang,
				alt: this.props.alt,
				altLang: this.props.altLang,
				url: this.props.appUrl,
				gtm: this.props.codeGTM,
				title: this.props.title,
				desc: this.props.desc,
				putTwitter: this.props.putTwitter,
				nameTwitter: this.props.nameTwitter,
				urlTwitter: this.props.urlTwitter,
				authorTwitter: this.props.authorTwitter,
				putFacebook: this.props.putFacebook,
				appIdFacebook: this.props.appIdFacebook,
				urlFacebook: this.props.urlFacebook,
				putLinkedin: this.props.putLinkedin,
				urlLinkedin: this.props.urlLinkedin,
				userMail: user,
				domainMail: domain,
				extMail: extension
			}
		);

		this.fs.copyTpl(
			this.templatePath('scripts/react/main-react.jsx'),
			this.destinationPath('testyo/scripts/react/main-react.jsx'), // public instead of testyo
			{
				appName: this.props.appName,
				url: this.props.appUrl,
				gtm: this.props.codeGTM,
				title: this.props.title,
				desc: this.props.desc,
				putTwitter: this.props.putTwitter,
				nameTwitter: this.props.nameTwitter,
				urlTwitter: this.props.urlTwitter,
				authorTwitter: this.props.authorTwitter,
				putFacebook: this.props.putFacebook,
				appIdFacebook: this.props.appIdFacebook,
				urlFacebook: this.props.urlFacebook,
				putLinkedin: this.props.putLinkedin,
				urlLinkedin: this.props.urlLinkedin,
				userMail: user,
				domainMail: domain,
				extMail: extension
			}
		);
	}

	conflicts () {
    	this.log('conflicts the generator ...');
  	}

  	install () {
    	this.log('install the generator ...');
  	}

  	end () {
  		this.log('\n');
  		this.log(chalk.bold.green('The website '+ this.props.appName + ' generated succeded !'));
  		this.log(chalk.bold.green('You can launch this command to see your website : grunt build'));
  	}

  	_myMethod(){
    	this.log('_myMethod ...');
  	}

};
<commit_msg>Initialize const<commit_after>var Generator = require('yeoman-generator'),
	chalk = require('chalk');

module.exports = class extends Generator {

	constructor(args, opts) {
	    super(args, opts);

	    this.promptQuestion = [];

	    // This method adds support for a `--babel` flag
	    this.option('babel');
	}

	initializing () {
    	this.log('Initializing the generator ...');

    	this.promptQuestion = [{
    		type: 'input',
		    name: 'appName',
		    message: 'Your site name',
		    default: 'ITArverne'
		},{
		    type: 'input',
		    name: 'appUrl',
		    message: 'Your url domain',
		    default: function(response){
		    	return response.appName.toLowerCase()+'.itarverne.com';
		    }
		},{
		    type: 'input',
		    name: 'lang',
		    message: 'Put the lag of your website'
		},{
		    type: 'input',
		    name: 'alt',
		    message: 'Put the alternate url for the meta tag'
		},{
			when: function (response) {
				return response.alternate;
			},
		    type: 'input',
		    name: 'alt-lang',
		    message: 'Put the alternate url lang for the meta tag : ',
		    validate: function(lang){
		    	if(lang.trim().length == 0)
		    		return "The alternate url lang for the meta tag is required !";

		 		return !lang.trim().length == 0
		    }
		},{
		    type: 'input',
		    name: 'title',
		    message: 'Put the website title'
		},{
		    type: 'input',
		    name: 'desc',
		    message: 'Put the website description'
		},{
		    type: 'input',
		    name: 'icoPath',
		    message: 'Put the website ico path',
		    default: 'linux or windows path supported'
		},{
		    type: 'input',
		    name: 'icoPathApple',
		    message: 'Put the website png path for apple ico',
		    default: 'linux or windows path supported'
		},{
		    type: 'input',
		    name: 'codeGTM',
		    message: 'Put the following code for Google Tag Management (GTM-XXXXXXX)'
		},{
		    type: 'confirm',
		    name: 'putTwitter',
		    message: 'Do you want to put share and follow twitter button ?',
		    default: 'N'
		},{
			when: function (response) {
				return response.putTwitter;
			},
		    type: 'input',
		    name: 'nameTwitter',
		    message: 'Put the twitter username : ',
		    validate: function(username){
		    	if(username.trim().length == 0)
		    		return "Your twitter username is required !";

		 		return !username.trim().length == 0
		    }
		},{
			when: function (response) {
				return response.putTwitter;
			},
		    type: 'input',
		    name: 'urlTwitter',
		    message: 'Put the url to share in twitter : ',
		    default: function(response){
		    	return response.appUrl;
		    }
		},{
			when: function (response) {
				return response.putTwitter;
			},
		    type: 'input',
		    name: 'authorTwitter',
		    message: 'Put the author in twitter : ',
		    validate: function(author){
		    	if(author.trim().length == 0)
		    		return "The twitter author is required !";

		 		return !author.trim().length == 0
		    }
		},{
		    type: 'confirm',
		    name: 'putFacebook',
		    message: 'Do you want to put share and like Facebook button ?',
		    default: 'N'
		},{
			when: function (response) {
				return response.putFacebook;
			},
		    type: 'input',
		    name: 'appIdFacebook',
		    message: 'Put the AppId Facebook : ',
		    validate: function(appId){
		    	if(appId.trim().length == 0 || isNaN(appId))
		    		return "Your facebook appId have to be numeric !";

		 		return !appId.trim().length == 0
		    }
		},{
			when: function (response) {
				return response.putFacebook;
			},
		    type: 'input',
		    name: 'urlFacebook',
		    message: 'Put the URL Facebook : ',
		    validate: function(url){
		    	if(url.trim().length == 0)
		    		return "The Facebook url is required !";

		 		return !url.trim().length == 0
		    }
		},{
		    type: 'confirm',
		    name: 'putLinkedin',
		    message: 'Do you want to put share and follow LinkedIn button ?',
		    default: 'N'
		},{
			when: function (response) {
				return response.putLinkedin;
			},
		    type: 'input',
		    name: 'urlLinkedin',
		    message: 'Put the LinkedIn url : ',
		    validate: function(url){
		    	if(url.trim().length == 0)
		    		return "The LinkedIn url is required !";

		 		return !url.trim().length == 0
		    }
		},{
			type: 'input',
		    name: 'mail',
		    message: 'Put the mail to get in touch : ',
		    validate: function(mail){
		    	const atpos = mail.indexOf("@");
				const dotpos = mail.lastIndexOf(".");
				if (atpos < 1 || ( dotpos - atpos < 2 ))
				{
					return "The mail is wrong !";
				}

		 		return true;
		    }
		}];
  	}

	prompting () {
	  var done = this.async();

	  this.prompt(this.promptQuestion)
	  	.then((prompt) => {
	        this.props = prompt;
	        done();
		});
	}

  	configuring () {
    	this.log(chalk.bold.cyan('Configuring the generator ...'));
  	}

	default () {
    	this.log('Default the generator ...');
  	}

	writing () {
		this.log(chalk.bold.cyan('Analyzing the inputs ...'));

		if(this.fs.exists(this.props.icoPath)){
			if(this.props.icoPath.includes('.ico')){
				this.fs.copy(this.props.icoPath, 'public/favicon.ico');
			}
			else {
				this.log(chalk.bold.yellow('No favicon configured, wrong extension only .iso available !'));
			}
		} else {
			this.log(chalk.bold.yellow('No favicon configured, wrong path !'));
		}

		if(this.fs.exists(this.props.icoPathApple)){
			if(this.props.icoPath.includes('.png')){
				this.fs.copy(this.props.icoPath, 'public/apple-touch-icon.png');
			}
			else {
				this.log(chalk.bold.yellow('No favicon configured for apple, wrong extension only .png available !'));
			}
		} else {
			this.log(chalk.bold.yellow('No favicon configured for apple, wrong path !'));
		}

		if(this.props.codeGTM != this.promptQuestion[3].default){
			var regex = new RegExp('^GTM-[0-9A-Z]{7}$');
			if(!regex.test(this.props.codeGTM)){
				this.props.codeGTM = '';
				this.log(chalk.bold.red('Wrong Google Tag Management code provided, script not included !'));
			}
		} else {
			this.log(chalk.bold.yellow('No Google Tag Management code provided, script not included !'));
		}

		const user = "",
			domain = "",
			extension="";
		if(this.props.mail){
			user = this.props.mail.split("@")[0];
			domain = this.props.mail.split("@")[1].split('.')[0];
			extension = this.props.mail.split("@")[1].split('.')[1];
		}

		this.fs.copyTpl(
			this.templatePath('index.html'),
			this.destinationPath('testyo/index.html'), // public instead of testyo
			{
				appName: this.props.appName,
				lang: this.props.lang,
				alt: this.props.alt,
				altLang: this.props.altLang,
				url: this.props.appUrl,
				gtm: this.props.codeGTM,
				title: this.props.title,
				desc: this.props.desc,
				putTwitter: this.props.putTwitter,
				nameTwitter: this.props.nameTwitter,
				urlTwitter: this.props.urlTwitter,
				authorTwitter: this.props.authorTwitter,
				putFacebook: this.props.putFacebook,
				appIdFacebook: this.props.appIdFacebook,
				urlFacebook: this.props.urlFacebook,
				putLinkedin: this.props.putLinkedin,
				urlLinkedin: this.props.urlLinkedin,
				userMail: user,
				domainMail: domain,
				extMail: extension
			}
		);

		this.fs.copyTpl(
			this.templatePath('cookies.html'),
			this.destinationPath('testyo/cookies.html'), // public instead of testyo
			{
				appName: this.props.appName,
				lang: this.props.lang,
				alt: this.props.alt,
				altLang: this.props.altLang,
				url: this.props.appUrl,
				gtm: this.props.codeGTM,
				title: this.props.title,
				desc: this.props.desc,
				putTwitter: this.props.putTwitter,
				nameTwitter: this.props.nameTwitter,
				urlTwitter: this.props.urlTwitter,
				authorTwitter: this.props.authorTwitter,
				putFacebook: this.props.putFacebook,
				appIdFacebook: this.props.appIdFacebook,
				urlFacebook: this.props.urlFacebook,
				putLinkedin: this.props.putLinkedin,
				urlLinkedin: this.props.urlLinkedin,
				userMail: user,
				domainMail: domain,
				extMail: extension
			}
		);

		this.fs.copyTpl(
			this.templatePath('scripts/react/main-react.jsx'),
			this.destinationPath('testyo/scripts/react/main-react.jsx'), // public instead of testyo
			{
				appName: this.props.appName,
				url: this.props.appUrl,
				gtm: this.props.codeGTM,
				title: this.props.title,
				desc: this.props.desc,
				putTwitter: this.props.putTwitter,
				nameTwitter: this.props.nameTwitter,
				urlTwitter: this.props.urlTwitter,
				authorTwitter: this.props.authorTwitter,
				putFacebook: this.props.putFacebook,
				appIdFacebook: this.props.appIdFacebook,
				urlFacebook: this.props.urlFacebook,
				putLinkedin: this.props.putLinkedin,
				urlLinkedin: this.props.urlLinkedin,
				userMail: user,
				domainMail: domain,
				extMail: extension
			}
		);
	}

	conflicts () {
    	this.log('conflicts the generator ...');
  	}

  	install () {
    	this.log('install the generator ...');
  	}

  	end () {
  		this.log('\n');
  		this.log(chalk.bold.green('The website '+ this.props.appName + ' generated succeded !'));
  		this.log(chalk.bold.green('You can launch this command to see your website : grunt build'));
  	}

  	_myMethod(){
    	this.log('_myMethod ...');
  	}

};
<|endoftext|>


<commit_before>(function(window, document, undefined) {
    window.onload = init;
    function init() {
        //get the canvas
        var canvas = document.getElementById("mapcanvas");
        var c = canvas.getContext("2d");
        var cwidth = 960;
        var cheight = 540;
        var moves = {
            u: [0,-1],
            d: [0,1],
            l: [-1,0],
            r: [1,0]
        };
        document.getElementById("paintbtn").onclick = paint;

        function shuffle(array) {
          var currentIndex = array.length, temporaryValue, randomIndex ;

          // While there remain elements to shuffle...
          while (0 !== currentIndex) {

            // Pick a remaining element...
            randomIndex = Math.floor(Math.random() * currentIndex);
            currentIndex -= 1;

            // And swap it with the current element.
            temporaryValue = array[currentIndex];
            array[currentIndex] = array[randomIndex];
            array[randomIndex] = temporaryValue;
          }

          return array;
        }

        function reset(){
            c.clearRect ( 0 , 0 , canvas.width, canvas.height );
            c.beginPath();
        }

        function walk(start, stop){
            var distX = stop.x - start.x;
            var distY = stop.y - start.y;

            var walkSteps = [];
            for(var i = 0; i< Math.abs(distX); i++){
                if(distX < 0){
                    walkSteps.push(moves.l);
                } else {
                    walkSteps.push(moves.r);
                }
            }
            for(var i = 0; i< Math.abs(distY); i++){
                if(distY < 0){
                    walkSteps.push(moves.u);
                } else {
                    walkSteps.push(moves.d);
                }
            }

            var randSteps = 48;

            for(var i = 0; i< randSteps; i++){
                var rand =Math.floor(Math.random() * (2 - 1 + 1)) + 1;
                if(rand < 1){
                    walkSteps.push(moves.u);
                    walkSteps.push(moves.d);
                } else{
                    walkSteps.push(moves.l);
                    walkSteps.push(moves.r);
                }
            }

            return shuffle(walkSteps);
        }

        function createRoom(x, y, pw, ph){
            var randw = Math.floor((Math.random() * ((pw/2) - 1 + 1) + 1) );
            var randh = Math.floor((Math.random() * ((ph/2) - 1 + 1) + 1) );
            //alert(randw + ", " + randh);

            return [randw, randh];
        }

        function paint(){
            reset();

            var widthSelect = document.getElementById("width");
            var pathWidth = widthSelect.options[widthSelect.selectedIndex].value;

            var heightSelect = document.getElementById("height");
            var pathHeight = heightSelect.options[heightSelect.selectedIndex].value;
            //alert(pathWidth + ", " + pathHeight);
            for(var i = 0; i< pathWidth; i++){
                for(var j = 0; j< pathHeight; j++){

                    c.beginPath();
                    //c.lineWidth = 1;
                    c.fillStyle = "#000000";
                    c.fillRect(i*30, j*30, 30, 30);
                    c.stroke();
               }
           }
           var startpoint = {
               x: 0,
               y: 9
           }
           var endpoint = {
               x: 9,
               y: 0
           }
           var movingpoint = {
               x: 0,
               y: 9
           }
           var movingpointold = {
               x: 0,
               y: 9
           }
           var walkArray = walk(startpoint, endpoint);

           for (var i = 0; i< walkArray.length; i++){
               movingpoint.x = movingpoint.x + walkArray[i][0];
               movingpoint.y = movingpoint.y + walkArray[i][1];
               var oppcurrMoveX = -1 * walkArray[i][0];
               var oppcurrMoveY = -1 * walkArray[i][1];
               var index = -1;
               for(var j = i; j< walkArray.length; j++){
                   if(walkArray[j][0] == oppcurrMoveX && walkArray[j][1] == oppcurrMoveY){
                       index = j;
                       break;
                   }
               }
               if(movingpoint.x > pathWidth -1){
                   movingpoint.x = movingpoint.x - 1;
                   if (index > -1) {
                       walkArray.splice(index, 1);
                   }

               }
               if(movingpoint.x < 0){
                   movingpoint.x = movingpoint.x + 1;
                   if (index > -1) {
                       walkArray.splice(index, 1);
                   }

               }
               if(movingpoint.y > pathHeight -1){
                   movingpoint.y = movingpoint.y - 1;
                   if (index > -1) {
                       walkArray.splice(index, 1);
                   }

               }
               if( movingpoint.y < 0){
                   movingpoint.y = movingpoint.y + 1;
                   if (index > -1) {
                       walkArray.splice(index, 1);
                   }

               }

               var movedirX = movingpoint.x - movingpointold.x;
               var movedirY = movingpoint.y - movingpointold.y;

               for(var l = 0; l< 30; l++){
                   c.fillStyle = "#FFFFFF";
                   c.fillRect(movingpointold.x*30 + l*movedirX + 12, movingpointold.y*30 + l*movedirY + 12, 4, 4);
               }

               c.fillStyle = "#FFFFFF";
               c.fillRect(movingpoint.x*30, movingpoint.y*30, 28, 28);

               movingpointold.x = movingpoint.x;
               movingpointold.y = movingpoint.y;
           }

            /*
            for(var i = 0; i< Math.floor(pathWidth/2)+1; i++){
                for(var j = 0; j< Math.floor(pathHeight/2)+1; j++){
                    var randRoom = Math.floor((Math.random() * 9));
                    if(randRoom < 1){
                        roomDim = createRoom(i,j,pathWidth,pathHeight);
                        c.beginPath();
                        c.lineWidth = 3;
                        c.fillStyle = "#FFFFFF";
                        c.fillRect(i*30 + 0.5, j*30+ 0.5, roomDim[0]*30, roomDim[1]*30);
                        c.stroke();
                    }
                }
            }*/

            c.fillStyle = "#33CC33";
            c.fillRect(startpoint.x*30, startpoint.y*30, 30, 30);
            c.fillStyle = "#CC0000";
            c.fillRect(endpoint.x*30, endpoint.y*30, 30 ,30);
        }
    }
})(window, document, undefined);
<commit_msg>Update script.js<commit_after>(function(window, document, undefined) {
    window.onload = init;
    function init() {
        //get the canvas
        var canvas = document.getElementById("mapcanvas");
        var c = canvas.getContext("2d");
        var cwidth = 960;
        var cheight = 540;
        var moves = {
            u: [0,-1],
            d: [0,1],
            l: [-1,0],
            r: [1,0]
        };
        document.getElementById("paintbtn").onclick = paint;

        function shuffle(array) {
          var currentIndex = array.length, temporaryValue, randomIndex ;

          // While there remain elements to shuffle...
          while (0 !== currentIndex) {

            // Pick a remaining element...
            randomIndex = Math.floor(Math.random() * currentIndex);
            currentIndex -= 1;

            // And swap it with the current element.
            temporaryValue = array[currentIndex];
            array[currentIndex] = array[randomIndex];
            array[randomIndex] = temporaryValue;
          }

          return array;
        }

        function reset(){
            c.clearRect ( 0 , 0 , canvas.width, canvas.height );
            c.beginPath();
        }

        function walk(start, stop){
            var distX = stop.x - start.x;
            var distY = stop.y - start.y;

            var walkSteps = [];
            for(var i = 0; i< Math.abs(distX); i++){
                if(distX < 0){
                    walkSteps.push(moves.l);
                } else {
                    walkSteps.push(moves.r);
                }
            }
            for(var i = 0; i< Math.abs(distY); i++){
                if(distY < 0){
                    walkSteps.push(moves.u);
                } else {
                    walkSteps.push(moves.d);
                }
            }

            var randSteps = 48;

            for(var i = 0; i< randSteps; i++){
                var rand =Math.floor(Math.random() * (2 - 1 + 1)) + 1;
                if(rand < 1){
                    walkSteps.push(moves.u);
                    walkSteps.push(moves.d);
                } else{
                    walkSteps.push(moves.l);
                    walkSteps.push(moves.r);
                }
            }

            return shuffle(walkSteps);
        }

        function createRoom(x, y, pw, ph){
            var randw = Math.floor((Math.random() * ((pw/2) - 1 + 1) + 1) );
            var randh = Math.floor((Math.random() * ((ph/2) - 1 + 1) + 1) );
            //alert(randw + ", " + randh);

            return [randw, randh];
        }

        function paint(){
            reset();

            var widthSelect = document.getElementById("width");
            var pathWidth = widthSelect.options[widthSelect.selectedIndex].value;

            var heightSelect = document.getElementById("height");
            var pathHeight = heightSelect.options[heightSelect.selectedIndex].value;
            //alert(pathWidth + ", " + pathHeight);
            for(var i = 0; i< pathWidth; i++){
                for(var j = 0; j< pathHeight; j++){

                    c.beginPath();
                    //c.lineWidth = 1;
                    c.fillStyle = "#000000";
                    c.fillRect(i*30, j*30, 30, 30);
                    c.stroke();
               }
           }
           var startpoint = {
               x: 9,
               y: 0
           }
           var endpoint = {
               x: 0,
               y: 9
           }
           var movingpoint = {
               x: 9,
               y: 0
           }
           var movingpointold = {
               x: 9,
               y: 0
           }
           var walkArray = walk(startpoint, endpoint);

           for (var i = 0; i< walkArray.length; i++){
               movingpoint.x = movingpoint.x + walkArray[i][0];
               movingpoint.y = movingpoint.y + walkArray[i][1];
               var oppcurrMoveX = -1 * walkArray[i][0];
               var oppcurrMoveY = -1 * walkArray[i][1];
               var index = -1;
               for(var j = i; j< walkArray.length; j++){
                   if(walkArray[j][0] == oppcurrMoveX && walkArray[j][1] == oppcurrMoveY){
                       index = j;
                       break;
                   }
               }
               if(movingpoint.x > pathWidth -1){
                   movingpoint.x = movingpoint.x - 1;
                   if (index > -1) {
                       walkArray.splice(index, 1);
                   }

               }
               if(movingpoint.x < 0){
                   movingpoint.x = movingpoint.x + 1;
                   if (index > -1) {
                       walkArray.splice(index, 1);
                   }

               }
               if(movingpoint.y > pathHeight -1){
                   movingpoint.y = movingpoint.y - 1;
                   if (index > -1) {
                       walkArray.splice(index, 1);
                   }

               }
               if( movingpoint.y < 0){
                   movingpoint.y = movingpoint.y + 1;
                   if (index > -1) {
                       walkArray.splice(index, 1);
                   }

               }

               var movedirX = movingpoint.x - movingpointold.x;
               var movedirY = movingpoint.y - movingpointold.y;

               for(var l = 0; l< 30; l++){
                   c.fillStyle = "#FFFFFF";
                   c.fillRect(movingpointold.x*30 + l*movedirX + 12, movingpointold.y*30 + l*movedirY + 12, 4, 4);
               }

               c.fillStyle = "#FFFFFF";
               c.fillRect(movingpoint.x*30, movingpoint.y*30, 28, 28);

               movingpointold.x = movingpoint.x;
               movingpointold.y = movingpoint.y;
           }

            /*
            for(var i = 0; i< Math.floor(pathWidth/2)+1; i++){
                for(var j = 0; j< Math.floor(pathHeight/2)+1; j++){
                    var randRoom = Math.floor((Math.random() * 9));
                    if(randRoom < 1){
                        roomDim = createRoom(i,j,pathWidth,pathHeight);
                        c.beginPath();
                        c.lineWidth = 3;
                        c.fillStyle = "#FFFFFF";
                        c.fillRect(i*30 + 0.5, j*30+ 0.5, roomDim[0]*30, roomDim[1]*30);
                        c.stroke();
                    }
                }
            }*/

            c.fillStyle = "#33CC33";
            c.fillRect(startpoint.x*30, startpoint.y*30, 30, 30);
            c.fillStyle = "#CC0000";
            c.fillRect(endpoint.x*30, endpoint.y*30, 30 ,30);
        }
    }
})(window, document, undefined);
<|endoftext|>


<commit_before>/**
 * Generates a new project.
 * @module KickstartGenerator
 * @requires chalk
 * @requires mkdirp
 * @requires underscore.string
 * @requires yeoman-generator
 * @requires yosay
 * @author mail@markus-falk.com
 */

'use strict';

var

chalk = require('chalk'),
mkdirp = require('mkdirp'),
string = require('underscore.string'),
yeoman = require('yeoman-generator'),
yosay = require('yosay'),

KickstartGenerator = yeoman.generators.Base.extend({

  /**
   * Loads package.json and waits for callback to finish.
   * @function init
   * @private
   */
  init: function () {

    this.pkg = require('../package.json');

    this.on('end', function () {

      if(this.wysiwygCMS) {
        this.log('Don\'t forget to run: ' + chalk.yellow('yo kickstart:addcomponent backend'));
        this.log('\n');
      }
    });

  },

  /**
   * Ask user on project details.
   * @function askFor
   * @private
   */
  askFor: function () {
    var done = this.async();

    // Have Yeoman greet the user.
    this.log(yosay('Sit back and relax while I setup your project.'));

    var prompts = [
      {
        type: 'input',
        name: 'ProjectName',
        message: 'What is the project\'s name?'
      },
      {
        type: 'input',
        name: 'ProjectManager',
        message: 'Who is the project manager?'
      },
      {
        type: 'input',
        name: 'GraphicDesigner',
        message: 'Who is the graphic designer?'
      },
      {
        type: 'input',
        name: 'HTMLDeveloper',
        message: 'Who is developing the front end?'
      },
      {
        type: 'confirm',
        name: 'ProjectServer',
        message: 'Do you want to deploy to a webserver?',
        default: true,
      },
      {
        when: function(response) {
          return response.ProjectServer;
        },
        type: 'input',
        name: 'Username',
        message: 'What is the Username?'
      },
      {
        when: function(response) {
          return response.ProjectServer;
        },
        type: 'input',
        name: 'HostServer',
        message: 'What is the Hostserver?'
      },
      {
        when: function(response) {
          return response.ProjectServer;
        },
        type: 'input',
        name: 'DeployPath',
        message: 'What is the Deploymentpath?'
      },
      {
        type: 'confirm',
        name: 'wysiwygCMS',
        message: 'Do you need additional setup for your wysiwyg CMS?',
        default: false
      },
      {
        type: 'confirm',
        name: 'oldIE',
        message: 'Would you like to support legacy IE (<9)?',
        default: false
      },
      {
        type: 'confirm',
        name: 'livereload',
        message: 'Would you like include livereload.js into your sandbox.html?',
        default: true
      },
      {
        type: 'list',
        name: 'WCAG2',
        message: 'What WCAG2A level would you like to develop for?',
        choices: [{
          name: 'A',
          value: 'A'
        },
        {
          name: 'AA',
          value: 'AA'
        },
        {
          name: 'AAA',
          value: 'AAA'
        }]
      }
    ];

    this.prompt(prompts, function (answers) {

      // README
      this.GraphicDesigner = answers.GraphicDesigner;
      this.HTMLDeveloper = answers.HTMLDeveloper;
      this.ProjectManager = answers.ProjectManager;
      this.ProjectName = string.slugify(answers.ProjectName);
      this.ProjectServer = answers.ProjectServer;
      this.HostServer = answers.HostServer;
      this.Username = string.slugify(answers.Username);
      this.DeployPath = answers.DeployPath;

      // wysiwygCMS
      this.wysiwygCMS = answers.wysiwygCMS;

      // livereload
      this.livereload = answers.livereload;

      // Support level
      this.oldIE = answers.oldIE;
      this.WCAG2 = answers.WCAG2;

      done();
    }.bind(this));
  },

  /**
   * Create empty folders needed for project.
   * @function folders
   * @private
   */
  folders: function () {
    mkdirp.mkdirp('img');
  },

  /**
   * Create all package files from templates.
   * @function packagefiles
   * @private
   */
  packagefiles: function () {

    this.fs.copyTpl(
      this.templatePath('_accessibilityrc'),
      this.destinationPath('.accessibilityrc')
    );

    this.fs.copyTpl(
      this.templatePath('_bowerrc'),
      this.destinationPath('.bowerrc')
    );

    this.fs.copyTpl(
      this.templatePath('_gitignore'),
      this.destinationPath('.gitignore'),
      {
        ProjectServer: this.ProjectServer
      }
    );

    this.fs.copyTpl(
      this.templatePath('_gems.rb'),
      this.destinationPath('gems.rb')
    );

    this.fs.copyTpl(
      this.templatePath('_editorconfig'),
      this.destinationPath('.editorconfig')
    );

    this.fs.copyTpl(
      this.templatePath('_csslintrc'),
      this.destinationPath('.csslintrc')
    );

    this.fs.copyTpl(
      this.templatePath('_scsslintrc'),
      this.destinationPath('.scsslintrc')
    );

    this.fs.copyTpl(
      this.templatePath('_jshintrc'),
      this.destinationPath('.jshintrc')
    );

    this.fs.copyTpl(
      this.templatePath('_bower.json'),
      this.destinationPath('bower.json'),
      {
        ProjectName: this.ProjectName,
        oldIE: this.oldIE
      }
    );

    this.fs.copyTpl(
      this.templatePath('_gruntfile.js'),
      this.destinationPath('gruntfile.js'),
      {
        ProjectName: this.ProjectName,
        ProjectServer: this.ProjectServer,
        WCAG2: this.WCAG2,
        oldIE: this.oldIE
      }
    );

    this.fs.copyTpl(
      this.templatePath('_package.json'),
      this.destinationPath('package.json'),
      {
        ProjectName: this.ProjectName,
        ProjectServer: this.ProjectServer
      }
    );

    this.fs.copyTpl(
      this.templatePath('_clientConfig.json'),
      this.destinationPath('clientConfig.json'),
      {
        ProjectName: this.ProjectName,
        ProjectServer: this.ProjectServer
      }
    );

    this.fs.copyTpl(
      this.templatePath('_hostConfig.json'),
      this.destinationPath('hostConfig.json'),
      {
        ProjectName: this.ProjectName,
        ProjectServer: this.ProjectServer,
        Username: this.Username,
        HostServer: this.HostServer,
        DeployPath: this.DeployPath
      }
    );

    this.fs.copyTpl(
      this.templatePath('_readme.md'),
      this.destinationPath('README.md'),
      {
        ProjectName: this.ProjectName,
        WCAG2: this.WCAG2,
        oldIE: this.oldIE,
        GraphicDesigner: this.GraphicDesigner,
        HTMLDeveloper: this.HTMLDeveloper,
        ProjectManager: this.ProjectManager
      }
    );

  },

  /**
   * Create all javascript files from templates.
   * @function javascript
   * @private
   */
  javascript: function () {

    this.fs.copyTpl(
      this.templatePath('_frontend-template-setup.js'),
      this.destinationPath('components/' + this.ProjectName + '.js'),
      {
        oldIE: this.oldIE
      }
    );

    this.fs.copyTpl(
      this.templatePath('_main.js'),
      this.destinationPath('components/app/main.js'),
      {
        oldIE: this.oldIE
      }
    );
  },

  /**
   * Create all files needed for QUnit from templates.
   * @function qunit
   * @private
   */
  qunit: function () {

    this.fs.copyTpl(
      this.templatePath('qunit/_qunit-test-suite.html'),
      this.destinationPath('qunit/qunit-test-suite.html'),
      {
        ProjectName: this.ProjectName
      }
    );

    this.fs.copy(
      this.templatePath('qunit/_unit.js'),
      this.destinationPath('qunit/unit.js')
    );

    this.fs.copy(
      this.templatePath('qunit/_config.js'),
      this.destinationPath('qunit/config.js')
    );

  },

  /**
   * Create all scss files from templates.
   * @function styles
   * @private
   */
  styles: function () {
    this.fs.copyTpl(
      this.templatePath('_frontend-template-setup.scss'),
      this.destinationPath('components/' + this.ProjectName + '.scss')
    );
  },

  /**
   * Create all HTML files from templates.
   * @function html
   * @private
   */
  html: function () {
    this.fs.copyTpl(
      this.templatePath('_sandbox.html'),
      this.destinationPath('sandbox.html'),
      {
        ProjectName: this.ProjectName,
        oldIE: this.oldIE,
        wysiwygCMS: this.wysiwygCMS,
        livereload: this.livereload
      }
    );
  },

  /**
   * Create all images from templates.
   * @function images
   * @private
   */
  images: function () {

    this.fs.copy(
      this.templatePath('_favicon.ico'),
      this.destinationPath('favicon.ico')
    );

    this.fs.copy(
      this.templatePath('_apple-touch-icon.png'),
      this.destinationPath('apple-touch-icon.png')
    );

    this.fs.copy(
      this.templatePath('_windows-tile-icon.png'),
      this.destinationPath('windows-tile-icon.png')
    );

  },

  /**
   * Automatically install all dependencies.
   * @function install
   * @private
   */
  install: function () {

    if (!this.options['skip-install']) {
      // bower & npm
      this.installDependencies();

      // gems
      this.log('Running ' + chalk.yellow.bold('bundle install') + ' for you to install the required dependencies. If this fails, try running the command yourself.');
      this.log('\n');
      this.spawnCommand('bundle', ['install']);
    }

  }

});

module.exports = KickstartGenerator;
<commit_msg>[FEATURE] username as string<commit_after>/**
 * Generates a new project.
 * @module KickstartGenerator
 * @requires chalk
 * @requires mkdirp
 * @requires underscore.string
 * @requires yeoman-generator
 * @requires yosay
 * @author mail@markus-falk.com
 */

'use strict';

var

chalk = require('chalk'),
mkdirp = require('mkdirp'),
string = require('underscore.string'),
yeoman = require('yeoman-generator'),
yosay = require('yosay'),

KickstartGenerator = yeoman.generators.Base.extend({

  /**
   * Loads package.json and waits for callback to finish.
   * @function init
   * @private
   */
  init: function () {

    this.pkg = require('../package.json');

    this.on('end', function () {

      if(this.wysiwygCMS) {
        this.log('Don\'t forget to run: ' + chalk.yellow('yo kickstart:addcomponent backend'));
        this.log('\n');
      }
    });

  },

  /**
   * Ask user on project details.
   * @function askFor
   * @private
   */
  askFor: function () {
    var done = this.async();

    // Have Yeoman greet the user.
    this.log(yosay('Sit back and relax while I setup your project.'));

    var prompts = [
      {
        type: 'input',
        name: 'ProjectName',
        message: 'What is the project\'s name?'
      },
      {
        type: 'input',
        name: 'ProjectManager',
        message: 'Who is the project manager?'
      },
      {
        type: 'input',
        name: 'GraphicDesigner',
        message: 'Who is the graphic designer?'
      },
      {
        type: 'input',
        name: 'HTMLDeveloper',
        message: 'Who is developing the front end?'
      },
      {
        type: 'confirm',
        name: 'ProjectServer',
        message: 'Do you want to deploy to a webserver?',
        default: true,
      },
      {
        when: function(response) {
          return response.ProjectServer;
        },
        type: 'input',
        name: 'Username',
        message: 'What is the Username?'
      },
      {
        when: function(response) {
          return response.ProjectServer;
        },
        type: 'input',
        name: 'HostServer',
        message: 'What is the Hostserver?'
      },
      {
        when: function(response) {
          return response.ProjectServer;
        },
        type: 'input',
        name: 'DeployPath',
        message: 'What is the Deploymentpath?'
      },
      {
        type: 'confirm',
        name: 'wysiwygCMS',
        message: 'Do you need additional setup for your wysiwyg CMS?',
        default: false
      },
      {
        type: 'confirm',
        name: 'oldIE',
        message: 'Would you like to support legacy IE (<9)?',
        default: false
      },
      {
        type: 'confirm',
        name: 'livereload',
        message: 'Would you like include livereload.js into your sandbox.html?',
        default: true
      },
      {
        type: 'list',
        name: 'WCAG2',
        message: 'What WCAG2A level would you like to develop for?',
        choices: [{
          name: 'A',
          value: 'A'
        },
        {
          name: 'AA',
          value: 'AA'
        },
        {
          name: 'AAA',
          value: 'AAA'
        }]
      }
    ];

    this.prompt(prompts, function (answers) {

      // README
      this.GraphicDesigner = answers.GraphicDesigner;
      this.HTMLDeveloper = answers.HTMLDeveloper;
      this.ProjectManager = answers.ProjectManager;
      this.ProjectName = string.slugify(answers.ProjectName);
      this.ProjectServer = answers.ProjectServer;
      this.HostServer = answers.HostServer;
      this.Username = answers.Username;
      this.DeployPath = answers.DeployPath;

      // wysiwygCMS
      this.wysiwygCMS = answers.wysiwygCMS;

      // livereload
      this.livereload = answers.livereload;

      // Support level
      this.oldIE = answers.oldIE;
      this.WCAG2 = answers.WCAG2;

      done();
    }.bind(this));
  },

  /**
   * Create empty folders needed for project.
   * @function folders
   * @private
   */
  folders: function () {
    mkdirp.mkdirp('img');
  },

  /**
   * Create all package files from templates.
   * @function packagefiles
   * @private
   */
  packagefiles: function () {

    this.fs.copyTpl(
      this.templatePath('_accessibilityrc'),
      this.destinationPath('.accessibilityrc')
    );

    this.fs.copyTpl(
      this.templatePath('_bowerrc'),
      this.destinationPath('.bowerrc')
    );

    this.fs.copyTpl(
      this.templatePath('_gitignore'),
      this.destinationPath('.gitignore'),
      {
        ProjectServer: this.ProjectServer
      }
    );

    this.fs.copyTpl(
      this.templatePath('_gems.rb'),
      this.destinationPath('gems.rb')
    );

    this.fs.copyTpl(
      this.templatePath('_editorconfig'),
      this.destinationPath('.editorconfig')
    );

    this.fs.copyTpl(
      this.templatePath('_csslintrc'),
      this.destinationPath('.csslintrc')
    );

    this.fs.copyTpl(
      this.templatePath('_scsslintrc'),
      this.destinationPath('.scsslintrc')
    );

    this.fs.copyTpl(
      this.templatePath('_jshintrc'),
      this.destinationPath('.jshintrc')
    );

    this.fs.copyTpl(
      this.templatePath('_bower.json'),
      this.destinationPath('bower.json'),
      {
        ProjectName: this.ProjectName,
        oldIE: this.oldIE
      }
    );

    this.fs.copyTpl(
      this.templatePath('_gruntfile.js'),
      this.destinationPath('gruntfile.js'),
      {
        ProjectName: this.ProjectName,
        ProjectServer: this.ProjectServer,
        WCAG2: this.WCAG2,
        oldIE: this.oldIE
      }
    );

    this.fs.copyTpl(
      this.templatePath('_package.json'),
      this.destinationPath('package.json'),
      {
        ProjectName: this.ProjectName,
        ProjectServer: this.ProjectServer
      }
    );

    this.fs.copyTpl(
      this.templatePath('_clientConfig.json'),
      this.destinationPath('clientConfig.json'),
      {
        ProjectName: this.ProjectName,
        ProjectServer: this.ProjectServer
      }
    );

    this.fs.copyTpl(
      this.templatePath('_hostConfig.json'),
      this.destinationPath('hostConfig.json'),
      {
        ProjectName: this.ProjectName,
        ProjectServer: this.ProjectServer,
        Username: this.Username,
        HostServer: this.HostServer,
        DeployPath: this.DeployPath
      }
    );

    this.fs.copyTpl(
      this.templatePath('_readme.md'),
      this.destinationPath('README.md'),
      {
        ProjectName: this.ProjectName,
        WCAG2: this.WCAG2,
        oldIE: this.oldIE,
        GraphicDesigner: this.GraphicDesigner,
        HTMLDeveloper: this.HTMLDeveloper,
        ProjectManager: this.ProjectManager
      }
    );

  },

  /**
   * Create all javascript files from templates.
   * @function javascript
   * @private
   */
  javascript: function () {

    this.fs.copyTpl(
      this.templatePath('_frontend-template-setup.js'),
      this.destinationPath('components/' + this.ProjectName + '.js'),
      {
        oldIE: this.oldIE
      }
    );

    this.fs.copyTpl(
      this.templatePath('_main.js'),
      this.destinationPath('components/app/main.js'),
      {
        oldIE: this.oldIE
      }
    );
  },

  /**
   * Create all files needed for QUnit from templates.
   * @function qunit
   * @private
   */
  qunit: function () {

    this.fs.copyTpl(
      this.templatePath('qunit/_qunit-test-suite.html'),
      this.destinationPath('qunit/qunit-test-suite.html'),
      {
        ProjectName: this.ProjectName
      }
    );

    this.fs.copy(
      this.templatePath('qunit/_unit.js'),
      this.destinationPath('qunit/unit.js')
    );

    this.fs.copy(
      this.templatePath('qunit/_config.js'),
      this.destinationPath('qunit/config.js')
    );

  },

  /**
   * Create all scss files from templates.
   * @function styles
   * @private
   */
  styles: function () {
    this.fs.copyTpl(
      this.templatePath('_frontend-template-setup.scss'),
      this.destinationPath('components/' + this.ProjectName + '.scss')
    );
  },

  /**
   * Create all HTML files from templates.
   * @function html
   * @private
   */
  html: function () {
    this.fs.copyTpl(
      this.templatePath('_sandbox.html'),
      this.destinationPath('sandbox.html'),
      {
        ProjectName: this.ProjectName,
        oldIE: this.oldIE,
        wysiwygCMS: this.wysiwygCMS,
        livereload: this.livereload
      }
    );
  },

  /**
   * Create all images from templates.
   * @function images
   * @private
   */
  images: function () {

    this.fs.copy(
      this.templatePath('_favicon.ico'),
      this.destinationPath('favicon.ico')
    );

    this.fs.copy(
      this.templatePath('_apple-touch-icon.png'),
      this.destinationPath('apple-touch-icon.png')
    );

    this.fs.copy(
      this.templatePath('_windows-tile-icon.png'),
      this.destinationPath('windows-tile-icon.png')
    );

  },

  /**
   * Automatically install all dependencies.
   * @function install
   * @private
   */
  install: function () {

    if (!this.options['skip-install']) {
      // bower & npm
      this.installDependencies();

      // gems
      this.log('Running ' + chalk.yellow.bold('bundle install') + ' for you to install the required dependencies. If this fails, try running the command yourself.');
      this.log('\n');
      this.spawnCommand('bundle', ['install']);
    }

  }

});

module.exports = KickstartGenerator;
<|endoftext|>


<commit_before>import React from "react";

import {removeEnumerator} from "../utils/surveyUtils";
import {UnicodeIcon} from "../utils/generalUtils";

export default function SurveyCardList(props) {
    const topLevelNodes = props.surveyQuestions
        .filter(sq => sq.parentQuestion === -1)
        .sort((a, b) => a.id - b.id);

    return topLevelNodes.map((sq, index) =>
        <SurveyCard
            key={index}
            topLevelNodeIds={topLevelNodes.map(tln => tln.id)}
            cardNumber={index + 1}
            inDesignMode={props.inDesignMode}
            setProjectDetails={props.setProjectDetails}
            surveyQuestion={sq}
            surveyQuestions={props.surveyQuestions}
            surveyRules={props.surveyRules}
            removeAnswer={props.removeAnswer}
            removeQuestion={props.removeQuestion}
            newAnswerComponent={props.newAnswerComponent}
        />
    );
}

class SurveyCard extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            showQuestions: true,
        };
    }

    swapId = (val, checkVal, swapVal) =>
        val === checkVal ? swapVal
            : val === swapVal ? checkVal
                : val;

    swapQuestionIds = (upOrDown) => {
        const myId = this.props.surveyQuestion.id;
        const swapId = this.props.topLevelNodeIds[
            this.props.topLevelNodeIds.indexOf(this.props.surveyQuestion.id) + upOrDown
        ];
        this.props.setProjectDetails({
            surveyQuestions: this.props.surveyQuestions
                .map(sq => ({
                    ...sq,
                    id: this.swapId(sq.id, myId, swapId),
                    parentQuestion: this.swapId(sq.parentQuestion, myId, swapId),
                })),
        });
    };

    getRulesById = (id) =>
        (this.props.surveyRules || [])
            .filter(r => r.id === id)
            .map(r => r.ruleType === "text-match"
                ? "Question '" + r.questionsText + "' should match the pattern: " + r.regex + "."
                : r.ruleType === "numeric-range"
                    ? "Question '" + r.questionsText + "' should be between " + r.min + " and " + r.max + "."
                    : r.ruleType === "sum-of-answers"
                        ? "Questions '" + r.questionsText + "' should sum up to " + r.validSum + "."
                        : r.ruleType === "matching-sums"
                            ? "Sum of '" + r.questionSetText1 + "' should be equal to sum of  '" + r.questionSetText2 + "'."
                            : "Question1: " + r.questionText1 + ", Answer1: " + r.answerText1 + "' is not compatible with 'Question2: " + r.questionText2 + ", Answer2: " + r.answerText2 + "'.");

    render() {
        const {cardNumber, surveyQuestion, inDesignMode, topLevelNodeIds} = this.props;
        return (

                            <button
                                type="button"
                                className="btn btn-outline-lightgreen my-1 px-3 py-0"
                                onClick={() => this.setState({showQuestions: !this.state.showQuestions})}
                            >
                                {this.state.showQuestions ? "-" : "+"}
                            </button>

Survey Card Number {cardNumber}

                                {!this.state.showQuestions && `-- ${inDesignMode
                                    ? surveyQuestion.question
                                    : removeEnumerator(surveyQuestion.question)}`
                                }

                        {inDesignMode &&

                                <button
                                    type="button"
                                    className="btn btn-outline-lightgreen my-1 px-3 py-0"
                                    onClick={() => this.swapQuestionIds(-1)}
                                    disabled={surveyQuestion.id === topLevelNodeIds[0]}
                                    style={{opacity: surveyQuestion.id === topLevelNodeIds[0] ? "0.25" : "1.0"}}
                                >
                                    <UnicodeIcon icon="upCaret"/>
                                </button>
                                <button
                                    type="button"
                                    className="btn btn-outline-lightgreen my-1 px-3 py-0"
                                    onClick={() => this.swapQuestionIds(1)}
                                    disabled={surveyQuestion.id === topLevelNodeIds[topLevelNodeIds.length - 1]}
                                    style={{opacity: surveyQuestion.id === topLevelNodeIds[topLevelNodeIds.length - 1] ? "0.25" : "1.0"}}
                                >
                                    <UnicodeIcon icon="downCaret"/>
                                </button>

                        }

                    {this.state.showQuestions &&

                            <SurveyQuestionTree
                                indentLevel={0}
                                inDesignMode={this.props.inDesignMode}
                                newAnswerComponent={this.props.newAnswerComponent}
                                removeAnswer={this.props.removeAnswer}
                                removeQuestion={this.props.removeQuestion}
                                surveyQuestion={this.props.surveyQuestion}
                                surveyQuestions={this.props.surveyQuestions}
                                surveyRules={this.props.surveyRules}
                                getRulesById={this.getRulesById}
                            />

                    }

        );
    }
}

function SurveyQuestionTree({
    indentLevel,
    inDesignMode,
    newAnswerComponent,
    removeAnswer,
    removeQuestion,
    surveyQuestion,
    surveyQuestions,
    surveyRules,
    getRulesById,
}) {
    const childNodes = surveyQuestions.filter(sq => sq.parentQuestion === surveyQuestion.id);
    const parentQuestion = surveyQuestions.find(sq => sq.id === surveyQuestion.parentQuestion);
    return (
        <>

                {[...Array(indentLevel)].map((e, i) =>

                        <UnicodeIcon icon="rightArrow"/>

                )}

                        {inDesignMode &&
                            <button
                                type="button"
                                className="btn btn-outline-red py-0 px-2 mr-1"
                                onClick={() => removeQuestion(surveyQuestion.id)}
                            >
                                X
                            </button>
                        }

                            {inDesignMode ? surveyQuestion.question : removeEnumerator(surveyQuestion.question)}

                            {surveyQuestion.componentType &&

                                    Component Type:
                                    {surveyQuestion.componentType + " - " + surveyQuestion.dataType}

                            }
                            {surveyRules && surveyRules.length > 0 &&

                                    Rules:

                                        {surveyRules.map((rule, uid) =>
                                            [rule.questionId, rule.question1, rule.question2]
                                                .concat(rule.questions)
                                                .concat(rule.questionSetIds1)
                                                .concat(rule.questionSetIds2)
                                                .includes(surveyQuestion.id)
                                                && (

                                                            {"Rule " + rule.id + ": " + rule.ruleType}

                                                )
                                        )}

                            }
                            {surveyQuestion.parentQuestion > -1 &&
                                <>

                                        Parent Question:
                                        {inDesignMode
                                            ? parentQuestion.question
                                            : removeEnumerator(parentQuestion.question)
                                        }

                                        Parent Answer:
                                        {surveyQuestion.parentAnswer === -1
                                            ? "Any"
                                            : parentQuestion.answers
                                                .find(ans => ans.id === surveyQuestion.parentAnswer).answer
                                        }

                                </>
                            }

Answers:

                        {surveyQuestion.answers.map((surveyAnswer, uid) =>
                            <ExistingAnswer
                                key={uid}
                                answer={surveyAnswer.answer}
                                color={surveyAnswer.color}
                                removeAnswer={() => inDesignMode && removeAnswer(surveyQuestion.id, surveyAnswer.id)}
                            />
                        )}
                        {inDesignMode && newAnswerComponent(surveyQuestion)}

            {childNodes.map((surveyQuestion, uid) =>
                <SurveyQuestionTree
                    key={uid}
                    indentLevel={indentLevel + 1}
                    inDesignMode={inDesignMode}
                    newAnswerComponent={newAnswerComponent}
                    removeAnswer={removeAnswer}
                    removeQuestion={removeQuestion}
                    surveyQuestion={surveyQuestion}
                    surveyQuestions={surveyQuestions}
                    surveyRules={surveyRules}
                />
            )}
        </>
    );
}

function ExistingAnswer({answer, color, removeAnswer}) {
    return (

                {removeAnswer &&
                    <button
                        type="button"
                        className="btn btn-outline-red py-0 px-2 mr-1"
                        onClick={removeAnswer}
                    >
                        X
                    </button>
                }

                    {answer}

    );
}
<commit_msg>jeeze more formatting<commit_after>import React from "react";

import {removeEnumerator} from "../utils/surveyUtils";
import {UnicodeIcon} from "../utils/generalUtils";

export default function SurveyCardList(props) {
    const topLevelNodes = props.surveyQuestions
        .filter(sq => sq.parentQuestion === -1)
        .sort((a, b) => a.id - b.id);

    return topLevelNodes.map((sq, index) =>
        <SurveyCard
            key={index}
            topLevelNodeIds={topLevelNodes.map(tln => tln.id)}
            cardNumber={index + 1}
            inDesignMode={props.inDesignMode}
            setProjectDetails={props.setProjectDetails}
            surveyQuestion={sq}
            surveyQuestions={props.surveyQuestions}
            surveyRules={props.surveyRules}
            removeAnswer={props.removeAnswer}
            removeQuestion={props.removeQuestion}
            newAnswerComponent={props.newAnswerComponent}
        />
    );
}

class SurveyCard extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            showQuestions: true,
        };
    }

    swapId = (val, checkVal, swapVal) =>
        val === checkVal ? swapVal
            : val === swapVal ? checkVal
                : val;

    swapQuestionIds = (upOrDown) => {
        const myId = this.props.surveyQuestion.id;
        const swapId = this.props.topLevelNodeIds[
            this.props.topLevelNodeIds.indexOf(this.props.surveyQuestion.id) + upOrDown
        ];
        this.props.setProjectDetails({
            surveyQuestions: this.props.surveyQuestions
                .map(sq => ({
                    ...sq,
                    id: this.swapId(sq.id, myId, swapId),
                    parentQuestion: this.swapId(sq.parentQuestion, myId, swapId),
                })),
        });
    };

    getRulesById = (id) =>
        (this.props.surveyRules || [])
            .filter(r => r.id === id)
            .map(r => r.ruleType === "text-match"
                ? "Question '" + r.questionsText + "' should match the pattern: " + r.regex + "."
                : r.ruleType === "numeric-range"
                    ? "Question '" + r.questionsText + "' should be between " + r.min + " and " + r.max + "."
                    : r.ruleType === "sum-of-answers"
                        ? "Questions '" + r.questionsText + "' should sum up to " + r.validSum + "."
                        : r.ruleType === "matching-sums"
                            ? "Sum of '" + r.questionSetText1 + "' should be equal to sum of  '" + r.questionSetText2 + "'."
                            : "Question1: " + r.questionText1 + ", Answer1: " + r.answerText1 + "' is not compatible with 'Question2: " + r.questionText2 + ", Answer2: " + r.answerText2 + "'.");

    render() {
        const {cardNumber, surveyQuestion, inDesignMode, topLevelNodeIds} = this.props;
        return (

                            <button
                                type="button"
                                className="btn btn-outline-lightgreen my-1 px-3 py-0"
                                onClick={() => this.setState({showQuestions: !this.state.showQuestions})}
                            >
                                {this.state.showQuestions ? "-" : "+"}
                            </button>

Survey Card Number {cardNumber}

                                {!this.state.showQuestions &&
                                    `-- ${inDesignMode
                                        ? surveyQuestion.question
                                        : removeEnumerator(surveyQuestion.question)}`
                                }

                        {inDesignMode &&

                                <button
                                    type="button"
                                    className="btn btn-outline-lightgreen my-1 px-3 py-0"
                                    onClick={() => this.swapQuestionIds(-1)}
                                    disabled={surveyQuestion.id === topLevelNodeIds[0]}
                                    style={{opacity: surveyQuestion.id === topLevelNodeIds[0] ? "0.25" : "1.0"}}
                                >
                                    <UnicodeIcon icon="upCaret"/>
                                </button>
                                <button
                                    type="button"
                                    className="btn btn-outline-lightgreen my-1 px-3 py-0"
                                    onClick={() => this.swapQuestionIds(1)}
                                    disabled={surveyQuestion.id === topLevelNodeIds[topLevelNodeIds.length - 1]}
                                    style={{opacity: surveyQuestion.id === topLevelNodeIds[topLevelNodeIds.length - 1] ? "0.25" : "1.0"}}
                                >
                                    <UnicodeIcon icon="downCaret"/>
                                </button>

                        }

                    {this.state.showQuestions &&

                            <SurveyQuestionTree
                                indentLevel={0}
                                inDesignMode={this.props.inDesignMode}
                                newAnswerComponent={this.props.newAnswerComponent}
                                removeAnswer={this.props.removeAnswer}
                                removeQuestion={this.props.removeQuestion}
                                surveyQuestion={this.props.surveyQuestion}
                                surveyQuestions={this.props.surveyQuestions}
                                surveyRules={this.props.surveyRules}
                                getRulesById={this.getRulesById}
                            />

                    }

        );
    }
}

function SurveyQuestionTree({
    indentLevel,
    inDesignMode,
    newAnswerComponent,
    removeAnswer,
    removeQuestion,
    surveyQuestion,
    surveyQuestions,
    surveyRules,
    getRulesById,
}) {
    const childNodes = surveyQuestions.filter(sq => sq.parentQuestion === surveyQuestion.id);
    const parentQuestion = surveyQuestions.find(sq => sq.id === surveyQuestion.parentQuestion);
    return (
        <>

                {[...Array(indentLevel)].map((e, i) =>

                        <UnicodeIcon icon="rightArrow"/>

                )}

                        {inDesignMode &&
                            <button
                                type="button"
                                className="btn btn-outline-red py-0 px-2 mr-1"
                                onClick={() => removeQuestion(surveyQuestion.id)}
                            >
                                X
                            </button>
                        }

                            {inDesignMode ? surveyQuestion.question : removeEnumerator(surveyQuestion.question)}

                            {surveyQuestion.componentType &&

                                    Component Type:
                                    {surveyQuestion.componentType + " - " + surveyQuestion.dataType}

                            }
                            {surveyRules && surveyRules.length > 0 &&

                                    Rules:

                                        {surveyRules.map((rule, uid) =>
                                            [rule.questionId, rule.question1, rule.question2]
                                                .concat(rule.questions)
                                                .concat(rule.questionSetIds1)
                                                .concat(rule.questionSetIds2)
                                                .includes(surveyQuestion.id)
                                                && (

                                                            {"Rule " + rule.id + ": " + rule.ruleType}

                                                )
                                        )}

                            }
                            {surveyQuestion.parentQuestion > -1 &&
                                <>

                                        Parent Question:
                                        {inDesignMode
                                            ? parentQuestion.question
                                            : removeEnumerator(parentQuestion.question)
                                        }

                                        Parent Answer:
                                        {surveyQuestion.parentAnswer === -1
                                            ? "Any"
                                            : parentQuestion.answers
                                                .find(ans => ans.id === surveyQuestion.parentAnswer).answer
                                        }

                                </>
                            }

Answers:

                        {surveyQuestion.answers.map((surveyAnswer, uid) =>
                            <ExistingAnswer
                                key={uid}
                                answer={surveyAnswer.answer}
                                color={surveyAnswer.color}
                                removeAnswer={() => inDesignMode && removeAnswer(surveyQuestion.id, surveyAnswer.id)}
                            />
                        )}
                        {inDesignMode && newAnswerComponent(surveyQuestion)}

            {childNodes.map((surveyQuestion, uid) =>
                <SurveyQuestionTree
                    key={uid}
                    indentLevel={indentLevel + 1}
                    inDesignMode={inDesignMode}
                    newAnswerComponent={newAnswerComponent}
                    removeAnswer={removeAnswer}
                    removeQuestion={removeQuestion}
                    surveyQuestion={surveyQuestion}
                    surveyQuestions={surveyQuestions}
                    surveyRules={surveyRules}
                />
            )}
        </>
    );
}

function ExistingAnswer({answer, color, removeAnswer}) {
    return (

                {removeAnswer &&
                    <button
                        type="button"
                        className="btn btn-outline-red py-0 px-2 mr-1"
                        onClick={removeAnswer}
                    >
                        X
                    </button>
                }

                    {answer}

    );
}
<|endoftext|>


<commit_before>'use strict';
var join = require('path').join;
var yeoman = require('yeoman-generator');
var osLocale = require('os-locale');
var chalk = require('chalk');
var fs = require('fs');

module.exports = yeoman.generators.Base.extend({
  constructor: function () {
    yeoman.generators.Base.apply(this, arguments);

    // setup the test-framework property, Gruntfile template will need this
    this.option('test-framework', {
      desc: 'Test framework to be invoked',
      type: String,
      defaults: 'mocha'
    });
    this.testFramework = this.options['test-framework'];

    this.option('coffee', {
      desc: 'Use CoffeeScript',
      type: Boolean,
      defaults: false
    });
    this.coffee = this.options.coffee;

    this.pkg = require('../package.json');
  },

  askFor: function () {
    var done = this.async(),
        _this = this;

    //choose os locale
    osLocale(function (err, locale) {
      //=> 'en_US'
      if(locale == 'zh_CN'){
        _this.locale = JSON.parse(fs.readFileSync('./language/'+locale+'.json'));
      }else{
        _this.locale = JSON.parse(fs.readFileSync('./language/en_US.json'));
      }
      // welcome message
      if (!_this.options['skip-welcome-message']) {
        _this.log(require('yosay')());
        _this.log(chalk.magenta(_this.locale.welcome));
      }

      var prompts = [{
          name: 'name',
          message: _this.locale.name,
          default: 'myproject'
        },{
          name: 'description',
          message: _this.locale.description,
          default: 'This is a nuclear package!'
        },{
          type: 'checkbox',
          name: 'features',
          message: _this.locale.features,
          choices: [{
            name: 'Bootstrap',
            value: 'includeLess',
            checked: false
          },{
            name: 'Less',
            value: 'includeLess',
            checked: true
          },{
            name: 'Modernizr',
            value: 'includeModernizr',
            checked: true
          }]
      }];

      _this.prompt(prompts, function (answers) {
        var features = answers.features;

        function hasFeature(feat) {
          return features && features.indexOf(feat) !== -1;
        }
        _this.appname = this._.slugify(answers.name);
        _this.description = answers.description;

        _this.includeLess = hasFeature('includeLess');
        _this.includeBootstrap = hasFeature('includeBootstrap');
        _this.includeModernizr = hasFeature('includeModernizr');

        //this.includeLibLess = answers.libless;

        done();
      }.bind(_this));
    });
  },

  gruntfile: function () {
    this.template('Gruntfile.js');
  },

  packageJSON: function () {
    this.template('_package.json', 'package.json');
  },

  git: function () {
    this.template('gitignore', '.gitignore');
    this.copy('gitattributes', '.gitattributes');
  },

  bower: function () {
    var bower = {
      name: this._.slugify(this.appname),

      description: this.description,
      private: true,
      dependencies: {}
    };

    if (this.includeBootstrap) {
      var bs = 'bootstrap';
      bower.dependencies[bs] = '~3.2.0';
    } else {
      bower.dependencies.jquery = '~1.11.1';
      bower.dependencies['normalize.css'] = '~3.0.3';
    }

    if (this.includeModernizr) {
      bower.dependencies.modernizr = '~2.8.2';
    }

    this.copy('bowerrc', '.bowerrc');
    this.write('bower.json', JSON.stringify(bower, null, 2));
  },

  jshint: function () {
    this.copy('jshintrc', '.jshintrc');
  },

  editorConfig: function () {
    this.copy('editorconfig', '.editorconfig');
  },

  mainStylesheet: function () {
    var css = 'main.' + (this.includeLess ? 'le' : 'c') + 'ss';
    this.template(css, 'app/'+(this.includeLess ? 'less' : 'style')+'/' + css);
  },

  writeIndex: function () {
    this.indexFile = this.engine(
      this.readFileAsString(join(this.sourceRoot(), 'index.html')),
      this
    );

    // wire Bootstrap plugins
    if (this.includeBootstrap && !this.includeLess) {
      var bs = 'bower_components/bootstrap/js/';

      this.indexFile = this.appendFiles({
        html: this.indexFile,
        fileType: 'js',
        optimizedPath: 'scripts/plugins.js',
        sourceFileList: [
          bs + 'affix.js',
          bs + 'alert.js',
          bs + 'dropdown.js',
          bs + 'tooltip.js',
          bs + 'modal.js',
          bs + 'transition.js',
          bs + 'button.js',
          bs + 'popover.js',
          bs + 'carousel.js',
          bs + 'scrollspy.js',
          bs + 'collapse.js',
          bs + 'tab.js'
        ],
        searchPath: '.'
      });
    }

    this.indexFile = this.appendFiles({
      html: this.indexFile,
      fileType: 'js',
      optimizedPath: 'scripts/main.js',
      sourceFileList: ['scripts/main.js'],
      searchPath: ['app', '.tmp']
    });
  },

  app: function () {
    this.directory('app');
    this.mkdir('app/scripts');
    this.mkdir('app/styles');
    this.mkdir('app/images');
    this.write('app/index.html', this.indexFile);

    if (this.coffee) {
      this.copy('main.coffee', 'app/scripts/main.coffee');
    } else {
      this.copy('main.js', 'app/scripts/main.js');
    }
  },

  install: function () {
    this.on('end', function () {
      this.invoke(this.options['test-framework'], {
        options: {
          'skip-message': this.options['skip-install-message'],
          'skip-install': this.options['skip-install'],
          'coffee': this.options.coffee
        }
      });

      if (!this.options['skip-install']) {
        this.installDependencies({
          skipMessage: this.options['skip-install-message'],
          skipInstall: this.options['skip-install']
        });
      }
    });
  }
});
<commit_msg>修改中文策略<commit_after>'use strict';
var join = require('path').join;
var yeoman = require('yeoman-generator');
var osLocale = require('os-locale');
var chalk = require('chalk');
var fs = require('fs');

module.exports = yeoman.generators.Base.extend({
  constructor: function () {
    yeoman.generators.Base.apply(this, arguments);

    // setup the test-framework property, Gruntfile template will need this
    this.option('test-framework', {
      desc: 'Test framework to be invoked',
      type: String,
      defaults: 'mocha'
    });
    this.testFramework = this.options['test-framework'];

    this.option('coffee', {
      desc: 'Use CoffeeScript',
      type: Boolean,
      defaults: false
    });
    this.coffee = this.options.coffee;

    this.pkg = require('../package.json');
  },

  askFor: function () {
    var done = this.async(),
        _this = this;

    //choose os locale
    osLocale(function (err, locale) {
      //=> 'en_US'
      if(locale == 'zh_CN' || locale == 'zh_Hans' || locale == 'zh_Hant' || locale == 'zh_HK' || locale == 'zh_MO'){
        _this.locale = JSON.parse(fs.readFileSync('./language/'+locale+'.json'));
      }else{
        _this.locale = JSON.parse(fs.readFileSync('./language/en_US.json'));
      }
      // welcome message
      if (!_this.options['skip-welcome-message']) {
        _this.log(require('yosay')());
        _this.log(chalk.magenta(_this.locale.welcome));
      }

      var prompts = [{
          name: 'name',
          message: _this.locale.name,
          default: 'myproject'
        },{
          name: 'description',
          message: _this.locale.description,
          default: 'This is a nuclear package!'
        },{
          type: 'checkbox',
          name: 'features',
          message: _this.locale.features,
          choices: [{
            name: 'Bootstrap',
            value: 'includeLess',
            checked: false
          },{
            name: 'Less',
            value: 'includeLess',
            checked: true
          },{
            name: 'Modernizr',
            value: 'includeModernizr',
            checked: true
          }]
      }];

      _this.prompt(prompts, function (answers) {
        var features = answers.features;

        function hasFeature(feat) {
          return features && features.indexOf(feat) !== -1;
        }
        _this.appname = this._.slugify(answers.name);
        _this.description = answers.description;

        _this.includeLess = hasFeature('includeLess');
        _this.includeBootstrap = hasFeature('includeBootstrap');
        _this.includeModernizr = hasFeature('includeModernizr');

        //this.includeLibLess = answers.libless;

        done();
      }.bind(_this));
    });
  },

  gruntfile: function () {
    this.template('Gruntfile.js');
  },

  packageJSON: function () {
    this.template('_package.json', 'package.json');
  },

  git: function () {
    this.template('gitignore', '.gitignore');
    this.copy('gitattributes', '.gitattributes');
  },

  bower: function () {
    var bower = {
      name: this._.slugify(this.appname),

      description: this.description,
      private: true,
      dependencies: {}
    };

    if (this.includeBootstrap) {
      var bs = 'bootstrap';
      bower.dependencies[bs] = '~3.2.0';
    } else {
      bower.dependencies.jquery = '~1.11.1';
      bower.dependencies['normalize.css'] = '~3.0.3';
    }

    if (this.includeModernizr) {
      bower.dependencies.modernizr = '~2.8.2';
    }

    this.copy('bowerrc', '.bowerrc');
    this.write('bower.json', JSON.stringify(bower, null, 2));
  },

  jshint: function () {
    this.copy('jshintrc', '.jshintrc');
  },

  editorConfig: function () {
    this.copy('editorconfig', '.editorconfig');
  },

  mainStylesheet: function () {
    var css = 'main.' + (this.includeLess ? 'le' : 'c') + 'ss';
    this.template(css, 'app/'+(this.includeLess ? 'less' : 'style')+'/' + css);
  },

  writeIndex: function () {
    this.indexFile = this.engine(
      this.readFileAsString(join(this.sourceRoot(), 'index.html')),
      this
    );

    // wire Bootstrap plugins
    if (this.includeBootstrap && !this.includeLess) {
      var bs = 'bower_components/bootstrap/js/';

      this.indexFile = this.appendFiles({
        html: this.indexFile,
        fileType: 'js',
        optimizedPath: 'scripts/plugins.js',
        sourceFileList: [
          bs + 'affix.js',
          bs + 'alert.js',
          bs + 'dropdown.js',
          bs + 'tooltip.js',
          bs + 'modal.js',
          bs + 'transition.js',
          bs + 'button.js',
          bs + 'popover.js',
          bs + 'carousel.js',
          bs + 'scrollspy.js',
          bs + 'collapse.js',
          bs + 'tab.js'
        ],
        searchPath: '.'
      });
    }

    this.indexFile = this.appendFiles({
      html: this.indexFile,
      fileType: 'js',
      optimizedPath: 'scripts/main.js',
      sourceFileList: ['scripts/main.js'],
      searchPath: ['app', '.tmp']
    });
  },

  app: function () {
    this.directory('app');
    this.mkdir('app/scripts');
    this.mkdir('app/styles');
    this.mkdir('app/images');
    this.write('app/index.html', this.indexFile);

    if (this.coffee) {
      this.copy('main.coffee', 'app/scripts/main.coffee');
    } else {
      this.copy('main.js', 'app/scripts/main.js');
    }
  },

  install: function () {
    this.on('end', function () {
      this.invoke(this.options['test-framework'], {
        options: {
          'skip-message': this.options['skip-install-message'],
          'skip-install': this.options['skip-install'],
          'coffee': this.options.coffee
        }
      });

      if (!this.options['skip-install']) {
        this.installDependencies({
          skipMessage: this.options['skip-install-message'],
          skipInstall: this.options['skip-install']
        });
      }
    });
  }
});
<|endoftext|>


<commit_before>/**
 *

 *  Constructs a `ProAct.ObjectCore`.
 *  `ProAct.ObjectCore` is a {{#crossLink "ProAct.Core"}}{{/crossLink}} that manages all the
 *  {{#crossLink "ProAct.Property"}}{{/crossLink}} instances for a reactive ProAct.js object.
 *

 *

 *  It is responsible for all the {{#crossLink "ProAct.Property"}}{{/crossLink}} instances as well as
 *  initializing them and deciding which type of property corresponds to which field.
 *

 *

 *  `ProAct.ObjectCore` is part of the proact-properties module of ProAct.js.
 *

 *
 * ```
 *
 *  var object = {
 *    a: 4,
 *    b: 5,
 *    c: function () {
 *      return this.a + this.b;
 *    }
 *  };
 *  var core = new ProAct.ObjectCore(object);
 *
 *  console.log(object.c); // 9
 *
 *  object.a = 1;
 *  console.log(object.c); // 6
 *
 *  console.log(core.value('c')); // 6
 *
 *  core.set('b', 2));
 *  console.log(object.b); // 2
 *  console.log(object.c); // 3
 * ```
 *
 * @class ProAct.ObjectCore
 * @extends ProAct.Core
 * @constructor
 * @param {Object} object
 *      The shell objec arround this core. This should be plain JavaScript object.
 * @param {Object} meta
 *      Optional meta data to be used to define the observer-observable behavior of the object.
 *      For example transformations for its properties.
 */
function ObjectCore (object, meta) {
  this.properties = {};

  P.C.call(this, object, meta); // Super!
};
ProAct.ObjectCore = P.OC = ObjectCore;

ProAct.ObjectCore.prototype = P.U.ex(Object.create(P.C.prototype), {

  /**
   * Reference to the constructor of this object.
   *
   * @memberof ProAct.ObjectCore
   * @instance
   * @constant
   * @default ProAct.ObjectCore
   */
  constructor: ProAct.ObjectCore,

  /**
   * A function to be set to the shell object's p field (if it is configured in @{link ProAct.Configuration}).
   *

   *  It uses its p argument if it is string to return the right {{#crossLink "ProAct.Property"}}{{/crossLink}} for passed field name.
   *

   *

   *  If the p argument is * or empty this ProAct.ObjectCore instance is returned.
   *

   *
   * @memberof ProAct.ObjectCore
   * @instance
   * @method value
   * @param {String} p
   *      The name of the managed {{#crossLink "ProAct.Property"}}{{/crossLink}} to retrieve. It can be set to * or skipped for this itself to be retrieved.
   * @return {Object}
   *      Managed {{#crossLink "ProAct.Property"}}{{/crossLink}} instance with field name equal to the passed p parameter or this.
   * @see {{#crossLink "ProAct.Property"}}{{/crossLink}}
   */
  value: function (p) {
    if (!p || p === '*') {
      return this;
    }

    return this.properties[p];
  },

  /**
   * Initializes all the {{#crossLink "ProAct.Property"}}{{/crossLink}} instances for the shellof this ProAct.ObjectCore.
   *

   *  Using the types of the fields of the shell object the right {{#crossLink "ProAct.Property"}}{{/crossLink}} instances are created and stored
   *  in this using {@link ProAct.ObjectCore#makeProp}.
   *

   *
   * @memberof ProAct.ObjectCore
   * @instance
   * @method setup
   * @see {@link ProAct.ObjectCore#makeProp}
   */
  setup: function () {
    var object = this.shell,
        property;

    for (property in object) {
      this.makeProp(property, null, this.meta[property]);
    }
  },

  /**
   * Creates a {{#crossLink "ProAct.Property"}}{{/crossLink}} instance for this's shell.
   *
   * @memberof ProAct.ObjectCore
   * @instance
   * @method makeProp
   * @param {String} property
   *      The name of the property, the name of the field in the shell.
   * @param {Array} listeners
   *      Initial listeners for 'change' of the property, can be skipped.
   * @param {String|Array} meta
   *      Meta information for the property to create, for example if the meta contains 'noprop', no property is created,
   *      and the initial value of the field is preserved. The meta is in format of the {@link ProAct.DSL}.
   * @return {ProAct.Property}
   *      The newly crated and stored in this property, or null if no property was created.
   * @throws {Error}
   *      If there is no field defined in the shell named as the passed property.
   * @see {@link ProAct.ObjectCore#setup}
   * @see {@link ProAct.DSL}
   */
  makeProp: function (property, listeners, meta) {
    var object = this.shell,
        conf = ProAct.Configuration,
        keyprops = conf.keyprops,
        keypropList = conf.keypropList,
        isF = P.U.isFunction,
        isA = P.U.isArrayObject,
        isO = P.U.isObject,
        result;

    if (meta && (meta === 'noprop' || (meta.indexOf && meta.indexOf('noprop') >= 0))) {
      return null;
    }

    if (keyprops && keypropList.indexOf(property) !== -1) {
      throw Error('The property name ' + property + ' is a key word for pro objects! Objects passed to ProAct.prob can not contain properties named as keyword properties.');
      return null;
    }

    if (object.hasOwnProperty(property)) {
      result = P.PP.provide(this.queueName, object, property, meta);
    }

    if (!result) {
      return null;
    }

    if (listeners) {
      this.properties[property].listeners.change = this.properties[property].listeners.change.concat(listeners);
    }

    if (meta && P.registry) {
      if (!P.U.isArray(meta)) {
        meta = [meta];
      }

      if (!(meta[0] instanceof ProAct.Property)) {
        P.registry.setup.apply(P.registry, [result].concat(meta));
      }
    }

    return result;
  },

  /**
   * Sets the value of a managed property. The interesting thing here is that
   * if the property does not exist this method creates it and stores a new field in the shell object
   * with the passed value.
   *

   *  The new field is reactive.
   *

   *
   * @memberof ProAct.ObjectCore
   * @instance
   * @method set
   * @param {String} property
   *      The name of the property to update/create.
   * @param {Object} value
   *      The value of the property to be set.
   * @see {@link ProAct.ObjectCore#makeProp}
   */
  set: function (property, value) {
    var object = this.shell;

    object[property] = value;
    if (this.properties[property]) {
      return;
    }

    this.makeProp(property);
  }
});
<commit_msg>ObjectCore documented.<commit_after>/**
 * @module proact-properties
 */

/**
 *

 *  Constructs a `ProAct.ObjectCore`.
 *  `ProAct.ObjectCore` is a {{#crossLink "ProAct.Core"}}{{/crossLink}} that manages all the
 *  {{#crossLink "ProAct.Property"}}{{/crossLink}} instances for a reactive ProAct.js object.
 *

 *

 *  It is responsible for all the {{#crossLink "ProAct.Property"}}{{/crossLink}} instances as well as
 *  initializing them and deciding which type of property corresponds to which field.
 *

 *

 *  `ProAct.ObjectCore` is part of the proact-properties module of ProAct.js.
 *

 *
 * ```
 *
 *  var object = {
 *    a: 4,
 *    b: 5,
 *    c: function () {
 *      return this.a + this.b;
 *    }
 *  };
 *  var core = new ProAct.ObjectCore(object);
 *
 *  console.log(object.c); // 9
 *
 *  object.a = 1;
 *  console.log(object.c); // 6
 *
 *  console.log(core.value('c')); // 6
 *
 *  core.set('b', 2));
 *  console.log(object.b); // 2
 *  console.log(object.c); // 3
 * ```
 *
 * @class ProAct.ObjectCore
 * @extends ProAct.Core
 * @constructor
 * @param {Object} object
 *      The shell objec arround this core. This should be plain JavaScript object.
 * @param {Object} meta
 *      Optional meta data to be used to define the observer-observable behavior of the object.
 *      For example transformations for its properties.
 */
function ObjectCore (object, meta) {
  this.properties = {};

  P.C.call(this, object, meta); // Super!
};
ProAct.ObjectCore = P.OC = ObjectCore;

ProAct.ObjectCore.prototype = P.U.ex(Object.create(P.C.prototype), {

  /**
   * Reference to the constructor of this object.
   *
   * @property constructor
   * @type ProAct.ObjectCore
   * @final
   * @for ProAct.ObjectCore
   */
  constructor: ProAct.ObjectCore,

  /**
   * A function to be set to the shell object's p field (if it is configured in {{#crossLink "ProAct.Configuration"}}{{/crossLink}}).
   *

   *  It uses its p argument if it is string to return the right {{#crossLink "ProAct.Property"}}{{/crossLink}} for passed field name.
   *

   *

   *  If the p argument is * or empty this `ProAct.ObjectCore` instance is returned.
   *

   *
   * ```
   *  core.value('a'); // returns the shell's 'a' value - shell.a.
   *  core.value('*'); // returns this.
   *  core.value(); // returns this.
   * ```
   *
   * @for ProAct.ObjectCore
   * @instance
   * @method value
   * @param {String} p
   *      The name of the managed {{#crossLink "ProAct.Property"}}{{/crossLink}} to retrieve.
   *      It can be set to * or skipped for this itself to be retrieved.
   * @return {Object}
   *      Managed {{#crossLink "ProAct.Property"}}{{/crossLink}} instance with field name equal to the passed p parameter or this.
   */
  value: function (p) {
    if (!p || p === '*') {
      return this;
    }

    return this.properties[p];
  },

  /**
   * Initializes all the {{#crossLink "ProAct.Property"}}{{/crossLink}} instances for the shellof this ProAct.ObjectCore.
   *

   *  Using the types of the fields of the shell object the right {{#crossLink "ProAct.Property"}}{{/crossLink}} instances are created and stored
   *  in this using {{#crossLink "ProAct.Configuration/makeProp:method"}}{{/crossLink}}.
   *

   *
   * @for ProAct.ObjectCore
   * @protected
   * @instance
   * @method setup
   */
  setup: function () {
    var object = this.shell,
        property;

    for (property in object) {
      this.makeProp(property, null, this.meta[property]);
    }
  },

  /**
   * Creates a {{#crossLink "ProAct.Property"}}{{/crossLink}} instance for this's shell.
   *
   * ```
   *  var shell = {a: 3};
   *  var core = new ProAct.Core(shell);
   *
   *  shell.b = function () { return this.a + 5; };
   *  core.makeProp('b');
   *
   *  console.log(shell.b); // 8
   *
   *  shell.a = 5;
   *  console.log(shell.b); // 10
   * ```
   *
   * @for ProAct.ObjectCore
   * @instance
   * @method makeProp
   * @param {String} property
   *      The name of the property, the name of the field in the shell.
   * @param {Array} listeners
   *      Initial listeners for 'change' of the property, can be skipped.
   * @param {String|Array} meta
   *      Meta information for the property to create, for example if the meta contains 'noprop', no property is created,
   *      and the initial value of the field is preserved. The meta is in format of the {{#crossLink "ProAct.DSL"}}{{/crossLink}}.
   * @return {ProAct.Property}
   *      The newly crated and stored in this property, or null if no property was created.
   * @throws {Error}
   *      If there is no field defined in the shell named as the passed property.
   */
  makeProp: function (property, listeners, meta) {
    var object = this.shell,
        conf = ProAct.Configuration,
        keyprops = conf.keyprops,
        keypropList = conf.keypropList,
        isF = P.U.isFunction,
        isA = P.U.isArrayObject,
        isO = P.U.isObject,
        result;

    if (meta && (meta === 'noprop' || (meta.indexOf && meta.indexOf('noprop') >= 0))) {
      return null;
    }

    if (keyprops && keypropList.indexOf(property) !== -1) {
      throw Error('The property name ' + property + ' is a key word for pro objects! Objects passed to ProAct.prob can not contain properties named as keyword properties.');
      return null;
    }

    if (object.hasOwnProperty(property)) {
      result = P.PP.provide(this.queueName, object, property, meta);
    }

    if (!result) {
      return null;
    }

    if (listeners) {
      this.properties[property].listeners.change = this.properties[property].listeners.change.concat(listeners);
    }

    if (meta && P.registry) {
      if (!P.U.isArray(meta)) {
        meta = [meta];
      }

      if (!(meta[0] instanceof ProAct.Property)) {
        P.registry.setup.apply(P.registry, [result].concat(meta));
      }
    }

    return result;
  },

  /**
   * Sets the value of a managed property. The interesting thing here is that
   * if the property does not exist this method creates it and stores a new field in the shell object
   * with the passed value.
   *

   *  The new field is reactive.
   *

   *
   * ```
   *  var shell = {a: 3};
   *  var core = new ProAct.Core(shell);
   *
   *  core.set('b', function () { return this.a + 5; });
   *
   *  console.log(shell.b); // 8
   *
   *  shell.a = 5;
   *  console.log(shell.b); // 10
   * ```
   *
   * @for ProAct.ObjectCore
   * @instance
   * @method set
   * @param {String} property
   *      The name of the property to update/create.
   * @param {Object} value
   *      The value of the property to be set.
   */
  set: function (property, value) {
    var object = this.shell;

    object[property] = value;
    if (this.properties[property]) {
      return;
    }

    this.makeProp(property);
  }
});
<|endoftext|>