<commit_before>// Generated on <%= (new Date).toISOString().split('T')[0] %> using <%= pkg.name %> <%= pkg.version %>
'use strict';

module.exports = function (grunt) {

	// Project configuration
	grunt.initConfig({

		// Watches files for changes and runs tasks based on the changed files
		watch: {
			compass: {
				files: ['assets/scss/**/*.scss'],
				tasks: ['compass', 'autoprefixer:dev'],
				options: {
					spawn: false,
					interrupt: true
				}
			},
			livereload: {
				options: {
					livereload: true
				},
				files: [
					'*.html',
					'assets/scss/**/*.scss',
					//'assets/css/*.css',
					'assets/img/**/*.{gif,jpeg,jpg,png,svg}',
					'assets/js/**/*.js'
				]
			}
		},

		// The actual grunt server settings
		connect: {
			options: {
				port: 8000,
				livereload: 35729,
				hostname: '0.0.0.0',
				//open: true
			},
			dev: {
				options: {
					base: '.'
				}
			},
			dist: {
				options: {
					base: 'dist',
					livereload: false,
					keepalive: true
				}
			}
		},

		// Empties folders to start fresh
		clean: {
			dist: {
				files: [{
					dot: true,
					src: [
						'.tmp',
						'dist/*',
						'!dist/.git*'
					]
				}]
			},
			server: '.tmp'
		},

		// Compiles Sass to CSS and generates necessary files if requested
		compass: {
			dist: {
				options: {
					sassDir: 'assets/scss',
					cssDir: '.tmp',
					noLineComments: true
				}
			}
		},

		// Add vendor prefixed styles
		autoprefixer: {
			options: {
				browsers: ['last 2 version', 'ie >= 8', 'Android 3'] // add Android 3 for Android 4.3- gradients
			},
			dev: {
				files: [{
					expand: true,
					cwd: '.tmp',
					src: '**/*.css',
					dest: 'assets/css'
				}]
			},
			dist: {
				files: [{
					expand: true,
					cwd: '.tmp',
					src: '**/*.css',
					dest: '.tmp/prefixed'
				}]
			}
		},

		// combine media queris
		cmq: {
			dist: {
				files: {
					'assets/css': ['.tmp/prefixed/**/*.css']
				}
			}
		},

		/*uncss: {
			dist: {
				options: {
					//stylesheets: ['assets/css/main.css']
				},
				files: {
					'css/tidy.css': ['*.html']
				}
			}
		},*/

		uglify: {
			options: {
				squeeze: {dead_code: false},
				codegen: {quote_keys: true}
			},
			jquery: {
				src: 'bower_components/jquery/dist/jquery.min.js',
				dest: 'dist/assets/js/jquery.js'
			}
		},

		// Reads HTML for usemin blocks to enable smart builds that automatically
		// concat, minify and revision files. Creates configurations in memory so
		// additional tasks can operate on them
		useminPrepare: {
			options: {
				dest: 'dist'
			},
			html: 'index.html'
		},

		// Performs rewrites based on rev and the useminPrepare configuration
		usemin: {
			/*options: {
				assetsDirs: ['assets']
			},*/
			html: ['dist/*.html']
		},

		// The following *-min tasks produce minified files in the dist folder
		imagemin: {
			dist: {
				files: [{
					expand: true,
					cwd: 'assets/img',
					src: '**/*.{gif,jpeg,jpg,png}',
					dest: 'dist/assets/img'
				}]
			}
		},
		svgmin: {
			dist: {
				files: [{
					expand: true,
					cwd: 'assets/img',
					src: '**/*.svg',
					dest: 'dist/assets/img'
				}]
			}
		},
		htmlmin: {
			dist: {
				options: {
					removeComments: true,
					removeCommentsFromCDATA: true,
					removeCDATASectionsFromCDATA: true,
					collapseWhitespace: true,
					collapseBooleanAttributes: true,
					removeAttributeQuotes: true,
					removeRedundantAttributes: true,
					useShortDoctype: true,
					removeEmptyAttributes: true,
					removeOptionalTags: true,
					minifyJS: true,
					minifyCSS: true
				},
				files: [{
					expand: true,
					cwd: 'dist',
					src: '*.html',
					dest: 'dist'
				}]
			}
		},

		// Copies remaining files to places other tasks can use
		copy: {
			dist: {
				files: [{
					expand: true,
					dot: true,
					cwd: '.',
					dest: 'dist',
					src: [
						'*.{ico,png,txt,xml}',
						'.htaccess',
						'*.html',
						'assets/font/**/*.{svg,ttf,eot,woff}',
						'assets/js/jquery-1.8.0.js'
					]
				}]
			}
		},

		// Run some tasks in parallel to speed up build process
		concurrent: {
			dist: [
				'compass',
				'imagemin',
				'svgmin',
				'copy:dist'
			]
		}
	});

	// Load grunt tasks automaticly
	require('load-grunt-tasks')(grunt);

	grunt.registerTask('default', [
		'clean:server',
		'compass',
		'autoprefixer:dev',
		'connect:dev',
		'watch'
	]);

	grunt.registerTask('serve', [
		'build',
		'connect:dist'
	]);

	grunt.registerTask('build', [
		'clean:dist',
		'useminPrepare',
		'concurrent:dist',
		'autoprefixer:dist',
		'cmq',
		//uncss,
		'concat',
		'cssmin',
		'uglify',
		'usemin',
		'htmlmin'
	]);
};
<commit_msg>Comment Gruntfile better, remove commented uncss<commit_after>// Generated on <%= (new Date).toISOString().split('T')[0] %> using <%= pkg.name %> <%= pkg.version %>
'use strict';

module.exports = function (grunt) {

	// Project configuration
	grunt.initConfig({
		// ===============================================================
		// WATCH
		// ===============================================================
		// Watches files for changes and runs tasks based on the changed files
		watch: {
			compass: {
				files: ['assets/scss/**/*.scss'],
				tasks: ['compass', 'autoprefixer:dev'],
				options: {
					spawn: false,
					interrupt: true
				}
			},
			livereload: {
				options: {
					livereload: true
				},
				files: [
					'*.html',
					'assets/scss/**/*.scss',
					//'assets/css/*.css',
					'assets/img/**/*.{gif,jpeg,jpg,png,svg}',
					'assets/js/**/*.js'
				]
			}
		},

		// ===============================================================
		// SERVER
		// ===============================================================
		// The actual grunt server settings
		connect: {
			options: {
				port: 8000,
				livereload: 35729,
				hostname: '0.0.0.0',
				//open: true
			},
			dev: {
				options: {
					base: '.'
				}
			},
			dist: {
				options: {
					base: 'dist',
					livereload: false,
					keepalive: true
				}
			}
		},

		// ===============================================================
		// CLEAN
		// ===============================================================
		// Empties folders to start fresh
		clean: {
			dist: {
				files: [{
					dot: true,
					src: [
						'.tmp',
						'dist/*',
						'!dist/.git*'
					]
				}]
			},
			server: '.tmp'
		},

		// ===============================================================
		// CSS
		// ===============================================================
		// Compiles Sass to CSS and generates necessary files if requested
		compass: {
			dist: {
				options: {
					sassDir: 'assets/scss',
					cssDir: '.tmp',
					noLineComments: true
				}
			}
		},

		// Add vendor prefixed styles
		autoprefixer: {
			options: {
				browsers: ['last 2 version', 'ie >= 8', 'Android 3'] // add Android 3 for Android 4.3- gradients
			},
			dev: {
				files: [{
					expand: true,
					cwd: '.tmp',
					src: '**/*.css',
					dest: 'assets/css'
				}]
			},
			dist: {
				files: [{
					expand: true,
					cwd: '.tmp',
					src: '**/*.css',
					dest: '.tmp/prefixed'
				}]
			}
		},

		// Combine media queris
		cmq: {
			dist: {
				files: {
					'assets/css': ['.tmp/prefixed/**/*.css']
				}
			}
		},

		uglify: {
			options: {
				squeeze: {dead_code: false},
				codegen: {quote_keys: true}
			},
			jquery: {
				src: 'bower_components/jquery/dist/jquery.min.js',
				dest: 'dist/assets/js/jquery.js'
			}
		},

		// ===============================================================
		// USEMIN - CSS + JS + HTML rewrites
		// ===============================================================
		// Reads HTML for usemin blocks to enable smart builds that automatically
		// concat, minify and revision files. Creates configurations in memory so
		// additional tasks can operate on them
		useminPrepare: {
			options: {
				dest: 'dist'
			},
			html: 'index.html'
		},

		// Performs rewrites based on rev and the useminPrepare configuration
		usemin: {
			/*options: {
				assetsDirs: ['assets']
			},*/
			html: ['dist/*.html']
		},

		// ===============================================================
		// IMAGES
		// ===============================================================
		// The following *-min tasks produce minified files in the dist folder
		imagemin: {
			dist: {
				files: [{
					expand: true,
					cwd: 'assets/img',
					src: '**/*.{gif,jpeg,jpg,png}',
					dest: 'dist/assets/img'
				}]
			}
		},
		svgmin: {
			dist: {
				files: [{
					expand: true,
					cwd: 'assets/img',
					src: '**/*.svg',
					dest: 'dist/assets/img'
				}]
			}
		},

		// ===============================================================
		// HTML
		// ===============================================================
		htmlmin: {
			dist: {
				options: {
					removeComments: true,
					removeCommentsFromCDATA: true,
					removeCDATASectionsFromCDATA: true,
					collapseWhitespace: true,
					collapseBooleanAttributes: true,
					removeAttributeQuotes: true,
					removeRedundantAttributes: true,
					useShortDoctype: true,
					removeEmptyAttributes: true,
					removeOptionalTags: true,
					minifyJS: true,
					minifyCSS: true
				},
				files: [{
					expand: true,
					cwd: 'dist',
					src: '*.html',
					dest: 'dist'
				}]
			}
		},

		// ===============================================================
		// FONTS, HTML, ETC
		// ===============================================================
		// Copies remaining files to places other tasks can use
		copy: {
			dist: {
				files: [{
					expand: true,
					dot: true,
					cwd: '.',
					dest: 'dist',
					src: [
						'*.{ico,png,txt,xml}',
						'.htaccess',
						'*.html',
						'assets/font/**/*.{svg,ttf,eot,woff}',
						'assets/js/jquery-1.8.0.js'
					]
				}]
			}
		},

	// ===============================================================
	// TASKS
	// ===============================================================

		// Run some tasks in parallel to speed up build process
		concurrent: {
			dist: [
				'compass',
				'imagemin',
				'svgmin',
				'copy:dist'
			]
		}
	});

	// Load grunt tasks automaticly
	require('load-grunt-tasks')(grunt);

	grunt.registerTask('default', [
		'clean:server',
		'compass',
		'autoprefixer:dev',
		'connect:dev',
		'watch'
	]);

	grunt.registerTask('serve', [
		'build',
		'connect:dist'
	]);

	grunt.registerTask('build', [
		'clean:dist',
		'useminPrepare',
		'concurrent:dist',
		'autoprefixer:dist',
		'cmq',
		'concat',
		'cssmin',
		'uglify',
		'usemin',
		'htmlmin'
	]);
};
<|endoftext|>


<commit_before>define(function(require, exports, module) {
    main.consumes = ["Previewer", "preview", "layout", "vfs"];
    main.provides = ["preview.browser"];
    return main;

    function main(options, imports, register) {
        var Previewer   = imports.Previewer;
        var layout      = imports.layout;
        var preview     = imports.preview;

        /***** Initialization *****/

        var plugin = new Previewer("Ajax.org", main.consumes, {
            caption  : "Browser",
            index    : 10,
            divider  : true,
            selector : function(path){
                return path.match(/(?:\.html|\.htm|\.xhtml)$|^https?\:\/\//);
            }
        });

        var BASEPATH = preview.previewUrl;

        /***** Methods *****/

        function calcRootedPath(url){
            if (url.substr(0, BASEPATH.length) == BASEPATH)
                return url.substr(BASEPATH.length);
            return url;
        }

        /***** Lifecycle *****/

        plugin.on("load", function(){
        });
        plugin.on("documentLoad", function(e){
            var doc     = e.doc;
            var session = doc.getSession();
            var tab     = doc.tab;
            var editor  = e.editor;

            var iframe = document.createElement("iframe");
            iframe.setAttribute("nwfaketop", true);
            iframe.setAttribute("nwdisable", true);

            iframe.style.width    = "100%";
            iframe.style.height   = "100%";
            iframe.style.border   = 0;
            iframe.style.backgroundColor = "rgba(255, 255, 255, 0.88)";

            iframe.addEventListener("load", function(){
                if (!iframe.src) return;

                var path = calcRootedPath(iframe.src);

                tab.title   =
                tab.tooltip = "[B] " + path;
                session.lastSrc  = iframe.src;

                if (options.local)
                    plugin.activeSession.add(iframe.contentWindow.location.href);

                editor.setLocation(path);
                tab.className.remove("loading");
            });
            session.iframe = iframe;

            session.editor = editor;
            editor.container.appendChild(session.iframe);
        });
        plugin.on("documentUnload", function(e){
            var doc    = e.doc;
            var iframe = doc.getSession().iframe;
            iframe.parentNode.removeChild(iframe);

            doc.tab.className.remove("loading");
        });
        plugin.on("documentActivate", function(e){
            var session = e.doc.getSession();
            var path = calcRootedPath(session.iframe.src);

            session.iframe.style.display = "block";
            session.editor.setLocation(path);
            session.editor.setButtonStyle("Browser", "page_white.png");
        });
        plugin.on("documentDeactivate", function(e){
            var session = e.doc.getSession();
            session.iframe.style.display = "none";
        });
        plugin.on("navigate", function(e){
            var tab    = plugin.activeDocument.tab;
            var iframe = plugin.activeSession.iframe;
            var url = e.url.match(/^[a-z]\w{1,4}\:\/\//)
                ? e.url
                : BASEPATH + e.url;

            tab.className.add("loading");
            iframe.src = url;

            var path = calcRootedPath(url);
            tab.title   =
            tab.tooltip = "[B] " + path;
            plugin.activeSession.editor.setLocation(path);
        });
        plugin.on("update", function(e){
            var iframe = plugin.activeSession.iframe;
            if (e.saved)
                iframe.src = iframe.src;
        });
        plugin.on("reload", function(){
            var iframe = plugin.activeSession.iframe;
            var tab    = plugin.activeDocument.tab;
            tab.className.add("loading");
            iframe.src = iframe.src;
        });
        plugin.on("popout", function(){
            var src = plugin.activeSession.iframe.src;
            window.open(src);
        });
        plugin.on("enable", function(){

        });
        plugin.on("disable", function(){

        });
        plugin.on("unload", function(){
        });

        /***** Register and define API *****/

        /**
         * Previewer for content that the browser can display natively.
         **/
        plugin.freezePublicAPI({

        });

        register(null, {
            "preview.browser": plugin
        });
    }
});<commit_msg>basic preview workflow is there<commit_after>define(function(require, exports, module) {
    main.consumes = [
        "Previewer", "preview", "vfs", "c9", "tabManager", "watcher"
    ];
    main.provides = ["preview.browser"];
    return main;

    function main(options, imports, register) {
        var Previewer   = imports.Previewer;
        var tabManager  = imports.tabManager;
        var c9          = imports.c9;
        var preview     = imports.preview;
        var watcher     = imports.watcher;

        /***** Initialization *****/

        var plugin = new Previewer("Ajax.org", main.consumes, {
            caption  : "Browser",
            index    : 10,
            divider  : true,
            selector : function(path){
                return path.match(/(?:\.html|\.htm|\.xhtml)$|^https?\:\/\//);
            }
        });

        var BASEPATH = preview.previewUrl;
        var HTMLURL = (options.htmlurl || "/static/plugins/c9.ide.preview/previewers/markdown.html")

        if (HTMLURL[0] == "/")
            HTMLURL = location.protocol + "//" + location.host + HTMLURL;

        var counter       = 0;
        var previewOrigin = HTMLURL.match(/^(?:[^\/]|\/\/)*/)[0];

        /***** Methods *****/

        function calcRootedPath(url){
            if (url.substr(0, BASEPATH.length) == BASEPATH)
                return url.substr(BASEPATH.length);
            return url;
        }

        function initiate(session){
            // Add watchers to all styles and scripts and href
            [session.href].concat(session.styles, session.scripts).forEach(function(path){
                watcher.watch(path);
            });

            watcher.on("delete", function(e){
                debugger;
            });

            watcher.on("change", function(e){
                debugger;
            });

            // Attach to open tabs
            tabManager.getTabs().forEach(function(tab){
                if (!tab.path) return;
                initDocument({ tab: tab, path: tab.path });
            });

            // Listen for opening files
            tabManager.on("open", initDocument, session);

            function initDocument(e){
                var info = isKnownFile(e.path);
                if (info) {
                    var doc = e.tab.document;

                    doc.undoManager.on("change",
                        update.bind(null, doc, info), session);

                    if (doc.changed)
                        update(doc, info);
                }
            }

            function update(doc, info){
                var message = {
                    id      : session.id,
                    type    : "update",
                    url     : info.url
                };
                message[info.type] = doc.value;
                session.source.postMessage(message, "*");
            }

            function isKnownFile(path){
                var found;

                if (~session.href.indexOf(path))
                    return { url: session.href, type: "html" }

                function search(arr, type) {
                    if (arr.some(function(p){
                        if (~p.indexOf(path)) {
                            found = p;
                            return true;
                        }
                    })) {
                        return { url: found, type: type }
                    }
                }

                search(session.styles, "css");
                search(session.scripts, "code");
            }
        }

        /***** Lifecycle *****/

        plugin.on("load", function(){
        });
        plugin.on("documentLoad", function(e){
            var doc     = e.doc;
            var session = doc.getSession();
            var tab     = doc.tab;
            var editor  = e.editor;

            var iframe = document.createElement("iframe");
            iframe.setAttribute("nwfaketop", true);
            iframe.setAttribute("nwdisable", true);

            iframe.style.width    = "100%";
            iframe.style.height   = "100%";
            iframe.style.border   = 0;
            iframe.style.backgroundColor = "rgba(255, 255, 255, 0.88)";

            iframe.addEventListener("load", function(){
                if (!iframe.src) return;

                var path = calcRootedPath(iframe.src);

                tab.title   =
                tab.tooltip = "[B] " + path;
                session.lastSrc  = iframe.src;

                if (options.local)
                    plugin.activeSession.add(iframe.contentWindow.location.href);

                editor.setLocation(path);
                tab.className.remove("loading");
            });

            window.addEventListener("message", function(e) {
                if (c9.hosted && event.origin !== previewOrigin)
                    return;

                if (session.id != e.data.id)
                    return;

                if (e.data.message == "html.ready") {
                    session.source = e.source;

                    var data = e.data.data;
                    session.styles  = data.styles;
                    session.scripts = data.scripts;
                    session.href    = data.href;

                    initiate(session);
                }
            }, false);

            session.id     = "livepreview" + counter++;
            session.iframe = iframe;
            session.editor = editor;

            editor.container.appendChild(session.iframe);
        });
        plugin.on("documentUnload", function(e){
            var doc    = e.doc;
            var iframe = doc.getSession().iframe;
            iframe.parentNode.removeChild(iframe);

            doc.tab.className.remove("loading");
        });
        plugin.on("documentActivate", function(e){
            var session = e.doc.getSession();
            var path = calcRootedPath(session.iframe.src);

            session.iframe.style.display = "block";
            session.editor.setLocation(path);
            session.editor.setButtonStyle("Browser", "page_white.png");
        });
        plugin.on("documentDeactivate", function(e){
            var session = e.doc.getSession();
            session.iframe.style.display = "none";
        });
        plugin.on("navigate", function(e){
            var tab    = plugin.activeDocument.tab;
            var iframe = plugin.activeSession.iframe;
            var url = e.url.match(/^[a-z]\w{1,4}\:\/\//)
                ? e.url
                : BASEPATH + e.url;

            tab.className.add("loading");
            iframe.src = url + (~url.indexOf("?") ? "&" : "?")
                + "id=" + plugin.activeSession.id
                + "&host=" + location.origin;

            var path = calcRootedPath(url);
            tab.title   =
            tab.tooltip = "[B] " + path;
            plugin.activeSession.editor.setLocation(path);
        });
        plugin.on("update", function(e){
            // var iframe = plugin.activeSession.iframe;
            // if (e.saved)
            //     iframe.src = iframe.src;
        });
        plugin.on("reload", function(){
            var iframe = plugin.activeSession.iframe;
            var tab    = plugin.activeDocument.tab;
            tab.className.add("loading");
            iframe.src = iframe.src;
        });
        plugin.on("popout", function(){
            var src = plugin.activeSession.iframe.src;
            window.open(src);
        });
        plugin.on("enable", function(){

        });
        plugin.on("disable", function(){

        });
        plugin.on("unload", function(){
        });

        /***** Register and define API *****/

        /**
         * Previewer for content that the browser can display natively.
         **/
        plugin.freezePublicAPI({

        });

        register(null, {
            "preview.browser": plugin
        });
    }
});<|endoftext|>


<commit_before>// To add
//

// Helper classes
test.AClass = Ext.extend(Object, {
   constructor: function() {
      this.setMe = true;
   },

   doSomething: function() {
      this.didSomething = true;
   }
});

component('vrs.TestHalpers', function() {
   feature('toBeEmpty', function() {
      it('should pass when empty', function() {
         var empty_list = [];
         expect(empty_list).toBeEmpty();
      });
      it('should fail when list not empty', function() {
         var full_list = [1,2,3];
         expect(full_list).not.toBeEmpty();
      });
   });

   feature('toBeLength', function() {
      it('should work with empty', function() {
         var list = [];
         expect(list).toBeLength(0);
      });
      it('should work with elements', function() {
         var list = [1,2,3];
         expect(list).toBeLength(3);
      });
   });

   feature('replaceObj', function() {
      it('setup variable', function() {
         test.replaceVar = {value: 10};
      });
      it('should be set', function() {
         expect(test.replaceVar.value).toEqual(10);
      });
      it('should be replacable', function() {
         var temp_obj = {value: 20};
         test.helpers.replaceObj(test, 'replaceVar', temp_obj);
         expect(test.replaceVar.value).toEqual(20);
      });
      it('should go back to original value', function() {
         expect(test.replaceVar.value).toEqual(10);
      });
   });

   // --- createSpyClass ---- //
   feature('createSpyClass', function() {

      it('should mock the object construction', function() {
         jasmine.createSpyClass(test, 'AClass', ['doSomething']);
         var test_obj = new test.AClass();
         test_obj.doSomething();
         expect(test_obj.setMe).toBeUndefined();
         expect(test_obj.doSomething).toHaveBeenCalled();
      });

      it('should mock calls to methods', function() {
         jasmine.createSpyClass(test, 'AClass', ['doSomething']);
         test.AClass.prototype.doSomething.andCallFake(function() {
            this.faked = true;
         });

         var test_obj = new test.AClass();
         expect(test_obj.setMe).toBeUndefined();
         test_obj.doSomething();
         expect(test_obj.faked).toEqual(true);
      });

      it('should be instance of a class we can check', function() {
         jasmine.createSpyClass(test, 'AClass', ['doSomething']);
         var test_obj = new test.AClass();
         expect(test_obj).toEqual(jasmine.any(test.AClass));
      });

      it('should reset all prototypes along with constructor', function() {
         jasmine.createSpyClass(test, 'AClass', ['doSomething']);

         // first round
         var test_obj = new test.AClass();
         test_obj.doSomething();
         expect(test.AClass).toHaveBeenCalled();
         expect(test_obj.doSomething).toHaveBeenCalled();

         // reset
         test.AClass.reset();
         expect(test.AClass).not.toHaveBeenCalled();
         expect(test_obj.doSomething).not.toHaveBeenCalled();

         // second round
         test_obj = new test.AClass();
         test_obj.doSomething();
         expect(test.AClass).toHaveBeenCalled();
         expect(test_obj.doSomething).toHaveBeenCalled();
      });

      it('should call normal class when no spy', function() {
         var test_obj = new test.AClass();
         expect(test_obj.setMe).toEqual(true);
         test_obj.doSomething();
         expect(test_obj.didSomething).toEqual(true);
      });

   });

   // --- AJAX HELPERS -- //
   feature('Ajax Test Helpers', function() {
      var resp, response_cb,
          expectAjaxStep = test.helpers.expectAjaxStep;

      /** Callback to store the response. */
      response_cb = function(opts, success_val, response_val) {
         resp.opts     = opts;
         resp.success  = success_val;
         resp.response = response_val;
      };

      beforeEach(function() {
         resp = {};
      });

      it('should support testing url passed in', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'GET', callback: response_cb});
         expectAjaxStep({url: '/my_url'});
         expect(resp.success).toEqual(true);
         expect(resp.response.status).toEqual(200);
      });

      it('should support testing valid params passed to request (POST)', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'POST',
                           params: {p1: '10', p2: 20}, callback: response_cb});
         expectAjaxStep({params: {p1: '10', p2: '20'}});
         expect(resp.success).toEqual(true);
      });

      it('should support testing valid params passed to request (GET)', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'GET',
                           params: {p1: '10', p2: 20}, callback: response_cb});
         expectAjaxStep({params: {p1: '10', p2: '20'}});
         expect(resp.success).toEqual(true);
      });

      it('should support testing valid method passed in', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'PUT', callback: response_cb});
         expectAjaxStep({method: 'PUT'});
         expect(resp.success).toEqual(true);
      });

      it('should support testing valid headers passed in', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'GET',
                            headers: {h1: 'val1', h2: 20}, callback: response_cb});
         expectAjaxStep({headers: {h1: 'val1', h2: '20'}});
      });

      it('should support providing response text', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'GET', callback: response_cb});
         expectAjaxStep({url: '/my_url'}, {responseText: 'hello'});
         expect(resp.response.responseText).toEqual('hello');
      });

      it('should support providing response json object', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'GET', callback: response_cb});
         var json_obj = {var1: 'val'},
             resp_obj;
         expectAjaxStep({url: '/my_url'}, {jsonObj: json_obj});
         resp_obj = Ext.decode(resp.response.responseText);
         expect(resp_obj.var1).toEqual(json_obj.var1);
      });

      it('should support providing response headers', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'GET', callback: response_cb});
         expectAjaxStep({url: '/my_url'}, {headers: {h1: 'val'}});
         expect(resp.response.getAllResponseHeaders().h1).toEqual('val');
      });

      it('should throw exception if no request is pending', function() {
         expect(function() { expectAjaxStep(); }).toThrow('Could not find pending AJAX request');
      });
   });
});

<commit_msg>Add test for object equality.<commit_after>// To add
//

// Helper classes
test.AClass = Ext.extend(Object, {
   constructor: function() {
      this.setMe = true;
   },

   doSomething: function() {
      this.didSomething = true;
   }
});

test.BClass = Ext.extend(Object, {
   constructor: function() {
      this.setThat = true;
   }
});

component('vrs.TestHalpers', function() {
   feature('toBeEmpty', function() {
      it('should pass when empty', function() {
         var empty_list = [];
         expect(empty_list).toBeEmpty();
      });
      it('should fail when list not empty', function() {
         var full_list = [1,2,3];
         expect(full_list).not.toBeEmpty();
      });
   });

   feature('toBeLength', function() {
      it('should work with empty', function() {
         var list = [];
         expect(list).toBeLength(0);
      });
      it('should work with elements', function() {
         var list = [1,2,3];
         expect(list).toBeLength(3);
      });
   });

   feature('replaceObj', function() {
      it('setup variable', function() {
         test.replaceVar = {value: 10};
      });
      it('should be set', function() {
         expect(test.replaceVar.value).toEqual(10);
      });
      it('should be replacable', function() {
         var temp_obj = {value: 20};
         test.helpers.replaceObj(test, 'replaceVar', temp_obj);
         expect(test.replaceVar.value).toEqual(20);
      });
      it('should go back to original value', function() {
         expect(test.replaceVar.value).toEqual(10);
      });
   });

   // --- createSpyClass ---- //
   feature('createSpyClass', function() {

      it('should mock the object construction', function() {
         jasmine.createSpyClass(test, 'AClass', ['doSomething']);
         var test_obj = new test.AClass();
         test_obj.doSomething();
         expect(test_obj.setMe).toBeUndefined();
         expect(test_obj.doSomething).toHaveBeenCalled();
      });

      it('should mock calls to methods', function() {
         jasmine.createSpyClass(test, 'AClass', ['doSomething']);
         test.AClass.prototype.doSomething.andCallFake(function() {
            this.faked = true;
         });

         var test_obj = new test.AClass();
         expect(test_obj.setMe).toBeUndefined();
         test_obj.doSomething();
         expect(test_obj.faked).toEqual(true);
      });

      it('should be instance of a class we can check', function() {
         jasmine.createSpyClass(test, 'AClass', ['doSomething']);
         var test_obj = new test.AClass();
         expect(test_obj).toEqual(jasmine.any(test.AClass));
         var test_objb = new test.BClass();
         expect(test_objb).not.toEqual(jasmine.any(test.AClass));
         expect(test_objb).toEqual(jasmine.any(test.BClass));
      });

      it('should reset all prototypes along with constructor', function() {
         jasmine.createSpyClass(test, 'AClass', ['doSomething']);

         // first round
         var test_obj = new test.AClass();
         test_obj.doSomething();
         expect(test.AClass).toHaveBeenCalled();
         expect(test_obj.doSomething).toHaveBeenCalled();

         // reset
         test.AClass.reset();
         expect(test.AClass).not.toHaveBeenCalled();
         expect(test_obj.doSomething).not.toHaveBeenCalled();

         // second round
         test_obj = new test.AClass();
         test_obj.doSomething();
         expect(test.AClass).toHaveBeenCalled();
         expect(test_obj.doSomething).toHaveBeenCalled();
      });

      it('should call normal class when no spy', function() {
         var test_obj = new test.AClass();
         expect(test_obj.setMe).toEqual(true);
         test_obj.doSomething();
         expect(test_obj.didSomething).toEqual(true);
      });

   });

   // --- AJAX HELPERS -- //
   feature('Ajax Test Helpers', function() {
      var resp, response_cb,
          expectAjaxStep = test.helpers.expectAjaxStep;

      /** Callback to store the response. */
      response_cb = function(opts, success_val, response_val) {
         resp.opts     = opts;
         resp.success  = success_val;
         resp.response = response_val;
      };

      beforeEach(function() {
         resp = {};
      });

      it('should support testing url passed in', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'GET', callback: response_cb});
         expectAjaxStep({url: '/my_url'});
         expect(resp.success).toEqual(true);
         expect(resp.response.status).toEqual(200);
      });

      it('should support testing valid params passed to request (POST)', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'POST',
                           params: {p1: '10', p2: 20}, callback: response_cb});
         expectAjaxStep({params: {p1: '10', p2: '20'}});
         expect(resp.success).toEqual(true);
      });

      it('should support testing valid params passed to request (GET)', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'GET',
                           params: {p1: '10', p2: 20}, callback: response_cb});
         expectAjaxStep({params: {p1: '10', p2: '20'}});
         expect(resp.success).toEqual(true);
      });

      it('should support testing valid method passed in', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'PUT', callback: response_cb});
         expectAjaxStep({method: 'PUT'});
         expect(resp.success).toEqual(true);
      });

      it('should support testing valid headers passed in', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'GET',
                            headers: {h1: 'val1', h2: 20}, callback: response_cb});
         expectAjaxStep({headers: {h1: 'val1', h2: '20'}});
      });

      it('should support providing response text', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'GET', callback: response_cb});
         expectAjaxStep({url: '/my_url'}, {responseText: 'hello'});
         expect(resp.response.responseText).toEqual('hello');
      });

      it('should support providing response json object', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'GET', callback: response_cb});
         var json_obj = {var1: 'val'},
             resp_obj;
         expectAjaxStep({url: '/my_url'}, {jsonObj: json_obj});
         resp_obj = Ext.decode(resp.response.responseText);
         expect(resp_obj.var1).toEqual(json_obj.var1);
      });

      it('should support providing response headers', function() {
         Ext.Ajax.request({ url: '/my_url', method: 'GET', callback: response_cb});
         expectAjaxStep({url: '/my_url'}, {headers: {h1: 'val'}});
         expect(resp.response.getAllResponseHeaders().h1).toEqual('val');
      });

      it('should throw exception if no request is pending', function() {
         expect(function() { expectAjaxStep(); }).toThrow('Could not find pending AJAX request');
      });
   });
});

<|endoftext|>


<commit_before>
module.exports = function(grunt) {
    var shell = require('shelljs'),
        path = require('path'),
        notFast = ['htmllint', 'csscover', 'csslint'];

    grunt.registerFastTask = function(task, taskList) {
        taskList =
          grunt.option('fast') ?
            taskList.filter(function(t) {
                return notFast.indexOf(t) === -1;
            })
            : taskList;

        grunt.registerTask(task, taskList);
    };

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        less: {
            production: {
                options: {
                    paths: ["src/less/"],
                    ieCompat: true,
                },
                files: [{
                    expand: true,
                    cwd: 'src/less/',
                    src: ['*.less', '*.css'],
                    dest: 'build/preflight/',
                    ext: '.css'
                }]
            }
        },
        csslint: {
            production: {
                options: {
                    "overqualified-elements": false,
                    "qualified-headings": false,
                    "adjoining-classes": false,
                    "box-sizing": false,
                    "box-model": false,
                    "duplicate-background-images": false,
                    "ids": false,
                    "text-indent": false,
                    "unique-headings": false
                },
                src: ['build/preflight/*.css', '!build/preflight/cssgrids-min.css']
            }
        },
        htmllint: {
            all: ['build/*.html'],
        },
        cssmin: {
            combine: {
                files: {
                    'build/site.min.css': ['bower_components/normalize-css/normalize.css', 'build/preflight/*.css']
                }
            }
        },
        open : {
            all : {
                path: 'http://localhost:9292'
            }
        },
        connect : {
            all: {
                options:{
                    port: 9292,
                    hostname: "0.0.0.0",
                    middleware: function(connect, options) {
                      return [ connect.static('build') ];
                    }
                }
            }
        },
        watch : {
            dev : {
                files: ['src/**/*', 'templates/**/*','fragments/**/*'],
                tasks: ['default'],
                options: { livereload: true },
            },
            cms : {
                tasks: ['default_cms'],
                files: ['src/**/*', 'templates/**/*','fragments/**/*'],
                cms: true
            },
        },
        clean: {
            build: ["build/", "build.tar.gz"],
            preflight: ["build/preflight"]
        },
        compress: {
            production: {
                options: {
                    archive: 'build.tar.gz'
                },
                files: [{
                    src: ['build/**'],
                    dest: '.'
                }]
            }
        },
        copy: {
            static: {
                files: [
                    {
                        expand: true,
                        cwd: 'static/',
                        src: ['**'],
                        dest: 'build/',
                    },
                    {
                        expand: true,
                        cwd: 'src/js/',
                        src: ['**'],
                        dest: 'build/',
                    }
                ]
            }
        },
        cacheBust: {
            options: {
                encoding: 'utf8',
                algorithm: 'md5',
                length: 16
            },
            assets: {
                files: [{ src: ['build/**/*.html'] }]
            }
        },
        express: {
            default_option: {},
            options: {
                port: 9000,
                hostname: '*',
                server: path.resolve('./cms/app.js'),
            }
        },
        injectCMS: {
            cms: {
                files: [{ src: ['build/**/*.html'] }]
            }
        }

    });

    // verify normalize.css is installed because cssmin silently skips it if it's not
    grunt.registerTask("verifybower", "Make sure bower components are installed", function () {
        var file = 'bower_components/normalize-css/normalize.css';
        if(!grunt.file.exists(file)){
            console.log('Can\'t find ' + file);
            console.log('Run bower install');
            return false;
        }
        return true;
    });

    grunt.registerTask("csscover", "check CSS coverage", function () {

        var css_files = grunt.file.expand(['build/preflight/*.css', '!build/preflight/cssgrids-min.css']);
        var html_files = grunt.file.expand(['build/*.html']);

        if (css_files.length === 0) {
            grunt.log.warn("No CSS files to check coverage for.");
        }

        if (html_files.length === 0) {
            grunt.log.error("No HTML files to check coverage against.");
            return false;
        }

        grunt.log.writeln("Checking coverage for %d CSS file(s) against %d HTML file(s)", css_files.length, html_files.length);

        var args = html_files.map(function (f) { return "'" + f + "'"; }).join(" ");

        for (i = 0; i < css_files.length; ++i) {
            var css_file = css_files[i];
            var code = shell.exec("carton exec css-coverage '" + css_file + "' " + args).code;
            if (code) {
                return false;
            }
        }
    });

    grunt.registerTask("assemble_templates", "build HTML templates", function () {
        var withCMS = grunt.config.get("cms") ? " --with_cms" : "",
            code = shell.exec("carton exec bin/assemble-templates" + withCMS).code;

        if (code) {
            return false;
        }
    });

    grunt.registerTask("open_local", "open up file:/// url in browser", function () {
        var code = shell.exec("open build/new-plan.html").code;
        if (code) {
            return false;
        }
    });

    grunt.registerTask('cms', function() {
        grunt.task.run(['default_cms', 'express', 'watch:cms']);
    });

    grunt.registerTask('default_cms', function() {
        grunt.config.set('cms', true);
        grunt.task.run(['default','injectCMS']);
    });

    grunt.registerMultiTask('injectCMS', 'Inject cms js to html files', function() {
        var options = {};

        grunt.util._.extend(options, this.options());

        this.files.forEach(function(f) {
            f.src.map(function(filepath) {
                var data = grunt.file.read(filepath),
                    scriptTags = '',
                    cssTags = '<link rel="stylesheet" href="cms-static/cms.css" type="text/css" />',
                    ngAttrs = 'ng-app="iicms" ng-controller="iicmsCntrl" ';

                data = data.replace(/<\/head>/, cssTags + '');
                data = data.replace(/<body /, '<body ' + ngAttrs);
                data = data.replace(/<\/body>/, scriptTags + '');

                grunt.file.write(filepath, data);

            });
        });
    });

    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-csslint');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-html');
    grunt.loadNpmTasks('grunt-contrib-compress');
    grunt.loadNpmTasks('grunt-open');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-cache-bust');
    grunt.loadNpmTasks('grunt-express');

    grunt.registerFastTask('css', ['less', 'csslint', 'cssmin']);
    grunt.registerFastTask('html', ['assemble_templates', 'htmllint']);
    grunt.registerFastTask('static', ['copy:static']);

    grunt.registerFastTask('default', ['clean:build', 'verifybower', 'css', 'html', 'static', 'clean:preflight']);

    grunt.registerFastTask('archive', ['default', 'cacheBust', 'compress']);
    grunt.registerFastTask('dev', ['default','connect','open','watch:dev']);
    grunt.registerFastTask('local', ['default','open_local']);

};
<commit_msg>Add port option to cms<commit_after>
module.exports = function(grunt) {
    var shell = require('shelljs'),
        path = require('path'),
        notFast = ['htmllint', 'csscover', 'csslint'];

    grunt.registerFastTask = function(task, taskList) {
        taskList =
          grunt.option('fast') ?
            taskList.filter(function(t) {
                return notFast.indexOf(t) === -1;
            })
            : taskList;

        grunt.registerTask(task, taskList);
    };

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        less: {
            production: {
                options: {
                    paths: ["src/less/"],
                    ieCompat: true,
                },
                files: [{
                    expand: true,
                    cwd: 'src/less/',
                    src: ['*.less', '*.css'],
                    dest: 'build/preflight/',
                    ext: '.css'
                }]
            }
        },
        csslint: {
            production: {
                options: {
                    "overqualified-elements": false,
                    "qualified-headings": false,
                    "adjoining-classes": false,
                    "box-sizing": false,
                    "box-model": false,
                    "duplicate-background-images": false,
                    "ids": false,
                    "text-indent": false,
                    "unique-headings": false
                },
                src: ['build/preflight/*.css', '!build/preflight/cssgrids-min.css']
            }
        },
        htmllint: {
            all: ['build/*.html'],
        },
        cssmin: {
            combine: {
                files: {
                    'build/site.min.css': ['bower_components/normalize-css/normalize.css', 'build/preflight/*.css']
                }
            }
        },
        open : {
            all : {
                path: 'http://localhost:9292'
            }
        },
        connect : {
            all: {
                options:{
                    port: 9292,
                    hostname: "0.0.0.0",
                    middleware: function(connect, options) {
                      return [ connect.static('build') ];
                    }
                }
            }
        },
        watch : {
            dev : {
                files: ['src/**/*', 'templates/**/*','fragments/**/*'],
                tasks: ['default'],
                options: { livereload: true },
            },
            cms : {
                tasks: ['default_cms'],
                files: ['src/**/*', 'templates/**/*','fragments/**/*'],
                cms: true
            },
        },
        clean: {
            build: ["build/", "build.tar.gz"],
            preflight: ["build/preflight"]
        },
        compress: {
            production: {
                options: {
                    archive: 'build.tar.gz'
                },
                files: [{
                    src: ['build/**'],
                    dest: '.'
                }]
            }
        },
        copy: {
            static: {
                files: [
                    {
                        expand: true,
                        cwd: 'static/',
                        src: ['**'],
                        dest: 'build/',
                    },
                    {
                        expand: true,
                        cwd: 'src/js/',
                        src: ['**'],
                        dest: 'build/',
                    }
                ]
            }
        },
        cacheBust: {
            options: {
                encoding: 'utf8',
                algorithm: 'md5',
                length: 16
            },
            assets: {
                files: [{ src: ['build/**/*.html'] }]
            }
        },
        express: {
            default_option: {},
            options: {
                port: grunt.option('port') || 9000,
                hostname: '*',
                server: path.resolve('./cms/app.js'),
            }
        },
        injectCMS: {
            cms: {
                files: [{ src: ['build/**/*.html'] }]
            }
        }

    });

    // verify normalize.css is installed because cssmin silently skips it if it's not
    grunt.registerTask("verifybower", "Make sure bower components are installed", function () {
        var file = 'bower_components/normalize-css/normalize.css';
        if(!grunt.file.exists(file)){
            console.log('Can\'t find ' + file);
            console.log('Run bower install');
            return false;
        }
        return true;
    });

    grunt.registerTask("csscover", "check CSS coverage", function () {

        var css_files = grunt.file.expand(['build/preflight/*.css', '!build/preflight/cssgrids-min.css']);
        var html_files = grunt.file.expand(['build/*.html']);

        if (css_files.length === 0) {
            grunt.log.warn("No CSS files to check coverage for.");
        }

        if (html_files.length === 0) {
            grunt.log.error("No HTML files to check coverage against.");
            return false;
        }

        grunt.log.writeln("Checking coverage for %d CSS file(s) against %d HTML file(s)", css_files.length, html_files.length);

        var args = html_files.map(function (f) { return "'" + f + "'"; }).join(" ");

        for (i = 0; i < css_files.length; ++i) {
            var css_file = css_files[i];
            var code = shell.exec("carton exec css-coverage '" + css_file + "' " + args).code;
            if (code) {
                return false;
            }
        }
    });

    grunt.registerTask("assemble_templates", "build HTML templates", function () {
        var withCMS = grunt.config.get("cms") ? " --with_cms" : "",
            code = shell.exec("carton exec bin/assemble-templates" + withCMS).code;

        if (code) {
            return false;
        }
    });

    grunt.registerTask("open_local", "open up file:/// url in browser", function () {
        var code = shell.exec("open build/new-plan.html").code;
        if (code) {
            return false;
        }
    });

    grunt.registerTask('cms', function() {
        grunt.task.run(['default_cms', 'express', 'watch:cms']);
    });

    grunt.registerTask('default_cms', function() {
        grunt.config.set('cms', true);
        grunt.task.run(['default','injectCMS']);
    });

    grunt.registerMultiTask('injectCMS', 'Inject cms js to html files', function() {
        var options = {};

        grunt.util._.extend(options, this.options());

        this.files.forEach(function(f) {
            f.src.map(function(filepath) {
                var data = grunt.file.read(filepath),
                    scriptTags = '',
                    cssTags = '<link rel="stylesheet" href="cms-static/cms.css" type="text/css" />',
                    ngAttrs = 'ng-app="iicms" ng-controller="iicmsCntrl" ';

                data = data.replace(/<\/head>/, cssTags + '');
                data = data.replace(/<body /, '<body ' + ngAttrs);
                data = data.replace(/<\/body>/, scriptTags + '');

                grunt.file.write(filepath, data);

            });
        });
    });

    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-csslint');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-html');
    grunt.loadNpmTasks('grunt-contrib-compress');
    grunt.loadNpmTasks('grunt-open');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-cache-bust');
    grunt.loadNpmTasks('grunt-express');

    grunt.registerFastTask('css', ['less', 'csslint', 'cssmin']);
    grunt.registerFastTask('html', ['assemble_templates', 'htmllint']);
    grunt.registerFastTask('static', ['copy:static']);

    grunt.registerFastTask('default', ['clean:build', 'verifybower', 'css', 'html', 'static', 'clean:preflight']);

    grunt.registerFastTask('archive', ['default', 'cacheBust', 'compress']);
    grunt.registerFastTask('dev', ['default','connect','open','watch:dev']);
    grunt.registerFastTask('local', ['default','open_local']);

};
<|endoftext|>


<commit_before>import React, { Component } from 'react';
import { RaisedButton } from 'material-ui';

const styles = {
  button: {
    marginTop: 3,
    marginBottom: 3,
    height: 60,
    title: {
      fontSize: 16,
      fontWeight: 900,
    }
  }
};

export default class RunVariable extends Component {

  constructor(props) {
    super(props);
    this.handleSelect = this.handleSelect.bind(this);
  }

  handleSelect() {
    const { match, runActions } = this.props;
    const { id } = match.params;
    runActions.list(id);
  }

  render() {
    const { index, record, run } = this.props;
    const title = !run.vector ? record.translateWord : record.originalWord;
    const key = `${record.id}${index}`;
    return (<RaisedButton
      labelStyle={styles.button.title}
      onClick={this.handleSelect}
      label={title}
      style={styles.button}
      fullWidth={true}
      primary={true}
      key={key}
    />);

  }

}
<commit_msg>Run album done<commit_after>import React, { Component } from 'react';
import { RaisedButton } from 'material-ui';

const styles = {
  button: {
    marginTop: 3,
    marginBottom: 3,
    height: 60,
    title: {
      fontSize: 16,
      fontWeight: 900,
    }
  }
};

const initialState = {
  disabled: false,
}

export default class RunVariable extends Component {

  constructor(props) {
    super(props);
    this.handleSelect = this.handleSelect.bind(this);
    this.state = initialState;
  }

  handleSelect() {
    const { match, runActions, run, record } = this.props;
    const questionId = Number(run.question.id);
    const recordId = Number(record.id);
    if (recordId === questionId) {
      const { id } = match.params;
      runActions.list(id);
    } else {
      this.setState({
        disabled: true,
      });
    }
  }

  render() {
    const { index, record, run } = this.props;
    const title = !run.vector ? record.translateWord : record.originalWord;
    const key = `${record.id}${index}`;
    return (<RaisedButton
      labelStyle={styles.button.title}
      disabled={this.state.disabled}
      onClick={this.handleSelect}
      style={styles.button}
      fullWidth={true}
      primary={true}
      label={title}
      key={key}
    />);

  }

}
<|endoftext|>


<commit_before>var GumpleRush = GumpleRush || {};
var hrac = hrac || {};

GumpleRush.Honsey_Kong = function() {};
GumpleRush.Honsey_Kong.prototype = {

	preload: function() {
		this.time.advancedTiming = true;
	},
	create: function() {

		this.mapa = this.game.add.tilemap("honsey_kong_mapa");
		this.game.stage.backgroundColor = "#000000";
		this.mapa.addTilesetImage("tramy", "honsey_kong_dlazdice");

		this.kolize = this.mapa.createLayer("kolize");
		this.mapa.setCollisionBetween(1, 2, true, "kolize");
		this.game.world.setBounds(0, 0, 720, 450);

		this.seznam_dlazdic_kolize = this.kolize.getTiles(0, 0, this.game.world.width, this.game.world.height);
		for (var i = 0; i < this.seznam_dlazdic_kolize.length; i++) {
			if (this.seznam_dlazdic_kolize[i].index == 1) {
				this.seznam_dlazdic_kolize[i].setCollision(true, true, true, false); // left, right, top, bottom
			}
		}

		this.zebrik1 = this.add.sprite(540, 288, "zebrik");
		this.zebrik2 = this.add.sprite(540, 96, "zebrik");
		this.zebrik3 = this.add.sprite(160, 192, "zebrik");
		this.game.physics.arcade.enable(this.zebrik1);
		this.game.physics.arcade.enable(this.zebrik2);
		this.game.physics.arcade.enable(this.zebrik3);

		this.hrac = this.add.sprite(100, 300, "ruza");
		this.game.physics.arcade.enable(this.hrac);
		this.hrac.body.gravity.y = 1000;
		this.hrac.animations.add("beh", [2, 3], 5, true);
		this.hrac.animations.add("klid", [0, 4], 1, true);
		this.hrac.animations.add("skrceni", [4, 4], 1, true);
		this.hrac.skok = -255; //-225 je tak akorát, ale při vyšších číslech má hráč vyšší šanci na přeskočení barelu
		this.hrac.rychlost = 175;
		this.hrac.body.drag.x = 5000;
		this.hrac.zivoty = 3;

		this.barely = this.game.add.group();
		this.barely.enableBody = true;
		this.vytvoreniNovehoBarelu();
		this.game.time.events.loop(3000, this.vytvoreniNovehoBarelu, this);

		this.cursors = this.game.input.keyboard.createCursorKeys();
		this.wasd = {
			up: this.game.input.keyboard.addKey(Phaser.Keyboard.W),
			down: this.game.input.keyboard.addKey(Phaser.Keyboard.S),
			left: this.game.input.keyboard.addKey(Phaser.Keyboard.A),
			right: this.game.input.keyboard.addKey(Phaser.Keyboard.D),
		};
		this.skok = this.game.add.audio("skok");
		this.skok.volume = 0.6;

		this.klavesaF = this.game.input.keyboard.addKey(Phaser.Keyboard.F);
		this.klavesaF.onDown.add(this.celaObrazovka, this);

		stisk_a = false;
		stisk_b = false;
		stisk_l = false;
		stisk_p = false;

		if (!this.game.device.desktop) {
			this.game.input.onDown.add(this.celaObrazovkaMobil, this);

			this.button_a = this.game.add.button(524, 307, "button_a", null, this, 1, 0, 1, 0);
			this.button_a.fixedToCamera = true;
			this.button_a.events.onInputOver.add(function() { stisk_a = true; });
			this.button_a.events.onInputOut.add(function() { stisk_a = false; });
			this.button_a.events.onInputDown.add(function() { stisk_a = true; });
			this.button_a.events.onInputUp.add(function() { stisk_a = false; });

			this.button_b = this.game.add.button(622, 307, "button_b", null, this, 1, 0, 1, 0);
			this.button_b.fixedToCamera = true;
			this.button_b.events.onInputOver.add(function() { stisk_b = true; });
			this.button_b.events.onInputOut.add(function() { stisk_b = false; });
			this.button_b.events.onInputDown.add(function() { stisk_b = true; });
			this.button_b.events.onInputUp.add(function() { stisk_b = false; });

			this.button_l = this.game.add.button(2, 307, "button_l", null, this, 1, 0, 1, 0);
			this.button_l.fixedToCamera = true;
			this.button_l.events.onInputOver.add(function() { stisk_l = true; });
			this.button_l.events.onInputOut.add(function() { stisk_l = false; });
			this.button_l.events.onInputDown.add(function() { stisk_l = true; });
			this.button_l.events.onInputUp.add(function() { stisk_l = false; });

			this.button_p = this.game.add.button(100, 307, "button_p", null, this, 1, 0, 1, 0);
			this.button_p.fixedToCamera = true;
			this.button_p.events.onInputOver.add(function() { stisk_p = true; });
			this.button_p.events.onInputOut.add(function() { stisk_p = false; });
			this.button_p.events.onInputDown.add(function() { stisk_p = true; });
			this.button_p.events.onInputUp.add(function() { stisk_p = false; });
		}

		this.srdicka = this.game.add.image(this.game.world.width - 70, 10, "hearts");
		this.srdicka.cropEnabled = true;
		this.srdicka.kontrolacasu = 0;
		this.srdicka.frekvence = 1000;

		this.hudba = this.game.add.audio("honsey_kong_hudba");
		this.hudba.loop = true;
		this.hudba.play();

		this.hit = this.game.add.audio("hit");

	},
	vytvoreniNovehoBarelu: function() {
		this.barel = this.barely.create(150, 20, "barel");
		this.barel.body.gravity.y = 1000;
		this.barel.animations.add("kutaleni", [0, 1, 2, 3], 5, true);
		this.barel.animations.play("kutaleni");
		this.barel.body.velocity.x = 100;
		this.barel.body.bounce.x = 1;
		this.barel.body.bounce.y = 1;
		this.barel.anchor.setTo(0.5, 0.5);
		this.barel.outOfBoundsKill = true;
		this.barel.body.drag.y = 800;
	},
	celaObrazovkaMobil: function() {
		this.game.scale.startFullScreen(false);
	},
	celaObrazovka: function() {
		if (this.game.scale.isFullScreen) {
			this.game.scale.stopFullScreen();
		} else {
			this.game.scale.startFullScreen(false);
		}
	},
	testZebriku: function(a, b) {
		return this.game.physics.arcade.overlap(a, b);
	},
	update: function() {
		this.game.physics.arcade.collide(this.hrac, this.kolize);
		this.game.physics.arcade.collide(this.barely, this.kolize);

		if ((this.wasd.up.isDown || this.cursors.up.isDown || stisk_a) && this.hrac.body.blocked.down) {
			this.hrac.body.velocity.y = this.hrac.skok;
			this.skok.play();
		}
		if (this.cursors.right.isDown || this.wasd.right.isDown || stisk_p) {
			this.hrac.body.velocity.x = this.hrac.rychlost;
			this.hrac.animations.play("beh");
		} else if (this.cursors.left.isDown || this.wasd.left.isDown || stisk_l) {
			this.hrac.body.velocity.x = -this.hrac.rychlost;
			this.hrac.animations.play("beh");
		} else if ((this.wasd.down.isDown || this.cursors.down.isDown || stisk_b) && this.hrac.body.blocked.down) {
			this.hrac.animations.play("skrceni");
		} else {
			this.hrac.animations.play("klid");
		}

		if ((this.testZebriku(this.hrac, this.zebrik1) || this.testZebriku(this.hrac, this.zebrik2) || this.testZebriku(this.hrac, this.zebrik3)) && (this.wasd.up.isDown || this.cursors.up.isDown || stisk_a)) {
			this.hrac.body.velocity.y = -50;
		}

		if (this.game.physics.arcade.overlap(this.hrac, this.barely) && (this.game.time.now - this.srdicka.kontrolacasu > this.srdicka.frekvence)) {
				this.hrac.zivoty = this.hrac.zivoty - 1;
				this.hit.play();
				this.cropRect = new Phaser.Rectangle(0, 0, (this.hrac.zivoty / 3) * 50, 15);
				this.srdicka.crop(this.cropRect);
				this.srdicka.updateCrop();
				this.srdicka.kontrolacasu = this.game.time.now;
		}

		if (this.game.input.currentPointers == 0 && !this.game.input.activePointer.isMouse) {
			stisk_a = false;
			stisk_b = false;
			stisk_l = false;
			stisk_p = false;
		}

		if (this.hrac.zivoty < 1) {
			this.hudba.stop();
			this.game.state.start("Honsey_Kong");
		}
	},
	render: function() {
		this.game.debug.text(this.game.time.fps || 'neviem', 10, 10, "#1ec133", "Press Start 2P");
	}
};
<commit_msg>Vibrace a ošetření pádu do voidu<commit_after>var GumpleRush = GumpleRush || {};
var hrac = hrac || {};

GumpleRush.Honsey_Kong = function() {};
GumpleRush.Honsey_Kong.prototype = {

  preload: function() {
    this.time.advancedTiming = true;
  },
  create: function() {

    this.mapa = this.game.add.tilemap("honsey_kong_mapa");
    this.game.stage.backgroundColor = "#000000";
    this.mapa.addTilesetImage("tramy", "honsey_kong_dlazdice");

    this.kolize = this.mapa.createLayer("kolize");
    this.mapa.setCollisionBetween(1, 2, true, "kolize");
    this.game.world.setBounds(0, 0, 720, 450);

    this.seznam_dlazdic_kolize = this.kolize.getTiles(0, 0, this.game.world.width, this.game.world.height);
    for (var i = 0; i < this.seznam_dlazdic_kolize.length; i++) {
      if (this.seznam_dlazdic_kolize[i].index == 1) {
        this.seznam_dlazdic_kolize[i].setCollision(true, true, true, false); // left, right, top, bottom
      }
    }

    this.zebrik1 = this.add.sprite(540, 288, "zebrik");
    this.zebrik2 = this.add.sprite(540, 96, "zebrik");
    this.zebrik3 = this.add.sprite(160, 192, "zebrik");
    this.game.physics.arcade.enable(this.zebrik1);
    this.game.physics.arcade.enable(this.zebrik2);
    this.game.physics.arcade.enable(this.zebrik3);

    this.hrac = this.add.sprite(100, 300, "ruza");
    this.game.physics.arcade.enable(this.hrac);
    this.hrac.body.gravity.y = 1000;
    this.hrac.animations.add("beh", [2, 3], 5, true);
    this.hrac.animations.add("klid", [0, 4], 1, true);
    this.hrac.animations.add("skrceni", [4, 4], 1, true);
    this.hrac.skok = -255; //-225 je tak akorát, ale při vyšších číslech má hráč vyšší šanci na přeskočení barelu
    this.hrac.rychlost = 175;
    this.hrac.body.drag.x = 5000;
    this.hrac.zivoty = 3;

    this.barely = this.game.add.group();
    this.barely.enableBody = true;
    this.vytvoreniNovehoBarelu();
    this.game.time.events.loop(3000, this.vytvoreniNovehoBarelu, this);

    this.cursors = this.game.input.keyboard.createCursorKeys();
    this.wasd = {
      up: this.game.input.keyboard.addKey(Phaser.Keyboard.W),
      down: this.game.input.keyboard.addKey(Phaser.Keyboard.S),
      left: this.game.input.keyboard.addKey(Phaser.Keyboard.A),
      right: this.game.input.keyboard.addKey(Phaser.Keyboard.D),
    };
    this.skok = this.game.add.audio("skok");
    this.skok.volume = 0.6;

    this.klavesaF = this.game.input.keyboard.addKey(Phaser.Keyboard.F);
    this.klavesaF.onDown.add(this.celaObrazovka, this);

    stisk_a = false;
    stisk_b = false;
    stisk_l = false;
    stisk_p = false;

    if (!this.game.device.desktop) {
      this.game.input.onDown.add(this.celaObrazovkaMobil, this);

      this.button_a = this.game.add.button(524, 307, "button_a", null, this, 1, 0, 1, 0);
      this.button_a.fixedToCamera = true;
      this.button_a.events.onInputOver.add(function() { stisk_a = true; });
      this.button_a.events.onInputOut.add(function() { stisk_a = false; });
      this.button_a.events.onInputDown.add(function() { stisk_a = true; });
      this.button_a.events.onInputUp.add(function() { stisk_a = false; });

      this.button_b = this.game.add.button(622, 307, "button_b", null, this, 1, 0, 1, 0);
      this.button_b.fixedToCamera = true;
      this.button_b.events.onInputOver.add(function() { stisk_b = true; });
      this.button_b.events.onInputOut.add(function() { stisk_b = false; });
      this.button_b.events.onInputDown.add(function() { stisk_b = true; });
      this.button_b.events.onInputUp.add(function() { stisk_b = false; });

      this.button_l = this.game.add.button(2, 307, "button_l", null, this, 1, 0, 1, 0);
      this.button_l.fixedToCamera = true;
      this.button_l.events.onInputOver.add(function() { stisk_l = true; });
      this.button_l.events.onInputOut.add(function() { stisk_l = false; });
      this.button_l.events.onInputDown.add(function() { stisk_l = true; });
      this.button_l.events.onInputUp.add(function() { stisk_l = false; });

      this.button_p = this.game.add.button(100, 307, "button_p", null, this, 1, 0, 1, 0);
      this.button_p.fixedToCamera = true;
      this.button_p.events.onInputOver.add(function() { stisk_p = true; });
      this.button_p.events.onInputOut.add(function() { stisk_p = false; });
      this.button_p.events.onInputDown.add(function() { stisk_p = true; });
      this.button_p.events.onInputUp.add(function() { stisk_p = false; });
    }

    this.srdicka = this.game.add.image(this.game.world.width - 70, 10, "hearts");
    this.srdicka.cropEnabled = true;
    this.srdicka.kontrolacasu = 0;
    this.srdicka.frekvence = 1000;

    this.hudba = this.game.add.audio("honsey_kong_hudba");
    this.hudba.loop = true;
    this.hudba.play();

    this.hit = this.game.add.audio("hit");

  },
  vytvoreniNovehoBarelu: function() {
    this.barel = this.barely.create(150, 20, "barel");
    this.barel.body.gravity.y = 1000;
    this.barel.animations.add("kutaleni", [0, 1, 2, 3], 5, true);
    this.barel.animations.play("kutaleni");
    this.barel.body.velocity.x = 100;
    this.barel.body.bounce.x = 1;
    this.barel.body.bounce.y = 1;
    this.barel.anchor.setTo(0.5, 0.5);
    this.barel.outOfBoundsKill = true;
    this.barel.body.drag.y = 800;
  },
  celaObrazovkaMobil: function() {
    this.game.scale.startFullScreen(false);
  },
  celaObrazovka: function() {
    if (this.game.scale.isFullScreen) {
      this.game.scale.stopFullScreen();
    } else {
      this.game.scale.startFullScreen(false);
    }
  },
  testZebriku: function(a, b) {
    return this.game.physics.arcade.overlap(a, b);
  },
  uberHraciZivotu(x) {
    this.hrac.zivoty = this.hrac.zivoty - x;
    this.hit.play();
    window.navigator.vibrate(150);
    this.hrac.body.velocity.y = -100;
    this.cropRect = new Phaser.Rectangle(0, 0, (this.hrac.zivoty / 3) * 50, 15);
    this.srdicka.crop(this.cropRect);
    this.srdicka.updateCrop();
    this.srdicka.kontrolacasu = this.game.time.now;
  },
  update: function() {
    this.game.physics.arcade.collide(this.hrac, this.kolize);
    this.game.physics.arcade.collide(this.barely, this.kolize);

    if ((this.wasd.up.isDown || this.cursors.up.isDown || stisk_a) && this.hrac.body.blocked.down) {
      this.hrac.body.velocity.y = this.hrac.skok;
      this.skok.play();
    }
    if (this.cursors.right.isDown || this.wasd.right.isDown || stisk_p) {
      this.hrac.body.velocity.x = this.hrac.rychlost;
      this.hrac.animations.play("beh");
    } else if (this.cursors.left.isDown || this.wasd.left.isDown || stisk_l) {
      this.hrac.body.velocity.x = -this.hrac.rychlost;
      this.hrac.animations.play("beh");
    } else if ((this.wasd.down.isDown || this.cursors.down.isDown || stisk_b) && this.hrac.body.blocked.down) {
      this.hrac.animations.play("skrceni");
    } else {
      this.hrac.animations.play("klid");
    }

    if ((this.testZebriku(this.hrac, this.zebrik1) || this.testZebriku(this.hrac, this.zebrik2) || this.testZebriku(this.hrac, this.zebrik3)) && (this.wasd.up.isDown || this.cursors.up.isDown || stisk_a)) {
      this.hrac.body.velocity.y = -50;
    }

    if (this.game.physics.arcade.overlap(this.hrac, this.barely) && (this.game.time.now - this.srdicka.kontrolacasu > this.srdicka.frekvence) || (this.hrac.position.y > this.game.height + 100)) {
      this.uberHraciZivotu(1);
    }

    if (this.game.input.currentPointers == 0 && !this.game.input.activePointer.isMouse) {
      stisk_a = false;
      stisk_b = false;
      stisk_l = false;
      stisk_p = false;
    }

    if (this.hrac.zivoty < 1) {
      this.hudba.stop();
      this.game.state.start("Honsey_Kong");
    }
  },
  render: function() {
    this.game.debug.text(this.game.time.fps || 'neviem', 10, 10, "#1ec133", "Press Start 2P");
  }
};
<|endoftext|>


<commit_before>import express from 'express';
import path from 'path';
import dotenv from 'dotenv';

dotenv.config();

const app = express();
require('./config/routes.js')(app, express);

app.use(express.static(path.join(`${__dirname}/../build`)));
app.use(express.static(path.join(`${__dirname}/../public`)));

app.get('*', (request, response) => {
  response.sendFile(path.resolve(`${__dirname}/../public`, 'index.html'));
});

const server = app.listen(8003, () => {
  const host = server.address().address;
  const port = server.address().port;
  console.log('Example app listening at http://%s:%s', host, port);
});
<commit_msg>port number<commit_after>import express from 'express';
import path from 'path';
import dotenv from 'dotenv';

dotenv.config();

const app = express();
require('./config/routes.js')(app, express);

app.use(express.static(path.join(`${__dirname}/../build`)));
app.use(express.static(path.join(`${__dirname}/../public`)));

app.get('*', (request, response) => {
  response.sendFile(path.resolve(`${__dirname}/../public`, 'index.html'));
});

const server = app.listen(8888, () => {
  const host = server.address().address;
  const port = server.address().port;
  console.log('Example app listening at http://%s:%s', host, port);
});
<|endoftext|>