<commit_before>module.exports = function(grunt) {
    grunt.util.linefeed = '\n';

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        config: grunt.file.readYAML('../config/config.yml'),

        filesBoltJs: [
            'lib/bolt/console.js',
            'lib/bolt/fnc-helpers.js',
            'lib/bolt/activity.js',
            'lib/bolt/bind-fileupload.js',
            'lib/bolt/make-uri-slug.js',
            'lib/bolt/video-embed.js',
            'lib/bolt/geolocation.js',
            'lib/bolt/upload-files.js',
            'lib/bolt/obj-sidebar.js',
            'lib/bolt/obj-navpopups.js',
            'lib/bolt/obj-moments.js',
            'lib/bolt/obj-files.js',
            'lib/bolt/obj-stack.js',
            'lib/bolt/obj-folders.js',
            'lib/bolt/obj-datetime.js',
            'lib/bolt/extend.js',
            'lib/bolt/init.js',
            'lib/bolt/start.js'
        ],

        /*
         * WATCH: Run predefined tasks whenever watched file patterns are added, changed or deleted
         */
        watch: {
            options: {
                spawn: false,
                livereload: true
            },
            sass: {
                files: [
                    'sass/*.scss',
                    'sass/**/*.scss'
                ],
                tasks: [
                    'sass:boltCss',
                    'eol:boltCss'
                ]
            },
            boltJs: {
                files: [
                    "<%= filesBoltJs %>"
                ],
                tasks: [
                    'jshint:boltJs',
                    'uglify:boltJs'
                ]
            },
            gruntfile: {
                files: [
                    'Gruntfile.js'
                ],
                options: {
                    reload: true
                }
            }
        },

        /*
         * SASS: Compile Sass to CSS
         */
        sass: {
            boltCss: {
                options: {
                    outputStyle: 'compressed',
                    includePaths: [
                        'node_modules/bootstrap-sass/assets/stylesheets/',
                        'node_modules/font-awesome/scss/'
                    ],
                    lineNumbers: false,
                    unixNewlines: true,
                    banner: "/**\n" +
                            " * These are Bolt's COMPILED CSS files!\n" +
                            " * Do not edit these files, because all changes will be lost.\n" +
                            " * You can edit ../scss/app.scss & ../scss/app-old-ie.scss, and run 'grunt' to generate this file.\n" +
                            " */\n",
                    precision: 5
                },
                files: {
                    'css/bolt-old-ie.css': 'sass/app-old-ie.scss',
                    'css/bolt.css': 'sass/app.scss'
                }
            }
        },

        /*
         * EOL: Convert line endings
         */
        eol: {
            boltCss: {
                options: {
                    eol: 'lf',
                    replace: true
                },
                files: {
                    src: [
                        'css/bolt-old-ie.css',
                        'css/bolt.css'
                    ]
                }
            },
            prepareCkeditor: {
                options: {
                    eol: 'lf',
                    replace: true
                },
                files: {
                    src: [
                        'lib/ckeditor-*/*.js',  'lib/ckeditor-*/**/*.js',
                        'lib/ckeditor-*/*.css', 'lib/ckeditor-*/**/*.css',
                        'lib/ckeditor-*/*.md',  'lib/ckeditor-*/**/*.md',
                        'lib/ckeditor-*/*.txt', 'lib/ckeditor-*/**/*.txt'
                    ]
                }
            }
        },

        /*
         * COPY: Copy files and folders
         */
        copy: {
            installFonts: {
                files: [{
                    expand: true,
                    flatten: true,
                    src: [
                        'node_modules/font-awesome/fonts/*'
                    ],
                    filter: 'isFile',
                    dest: 'fonts/'
                }]
            }
        },

        /*
         * CONCAT: Concatenate files
         */
        concat: {
            installLibJs: {
                options: {
                    separator: '\n\n'
                },
                nonull: true,
                src: [
                    'lib/jquery-1.11.2/jquery.min.js',                              //  96 kb
                    'lib/jquery-ui-1.10.3/jquery-ui.custom.min.js',                 //  96 kb
                    'lib/bootstrap-file-input/bootstrap-file-input.min.js',         //   1 kb
                    'lib/jquery-tagcloud/jquery-tagcloud.min.js',                   //   1 kb
                    'lib/jquery-hotkeys/jquery-hotkeys.min.js',                     //   2 kb
                    'lib/jquery-watchchanges/jquery-watchchanges.min.js',           //   1 kb
                    'lib/jquery-cookie-1.4.0/jquery-cookie.min.js',                 //   1 kb
                    'lib/jquery-formatdatetime-1.1.4/jquery-formatdatetime.min.js', //   3 kb
                    'lib/jquery-fileupload-5.26/jquery-iframe-transport.min.js',    //   2 kb
                    'lib/jquery-fileupload-5.26/jquery-fileupload.min.js',          //  15 kb
                    'lib/underscore-1.7.0/underscore-min.js',                       //  16 kb
                    'lib/backbone/backbone-min.js',                                 //  20 kb
                    'lib/bootstrap-sass.generated/bootstrap.min.js',                //   2 kb
                    'lib/magnific-popup-1.0.0/magnific-popup.min.js',               //  21 kb
                    'lib/select2-3.5.1/select2.min.js',                             //  66 kb
                    'node_modules/moment/min/moment.min.js',                        //  35 kb
                    'lib/bootbox-4.3.0/bootbox.min.js',                             //   9 kb
                    'lib/modernizr-2.8.3/modernizr.custom.min.js'                   //   5 kb
                ],
                dest: 'js/lib.min.js'
            }
        },

        /*
         * CSSMIN: Compress CSS files
         */
        cssmin: {
            installLibCss: {
                options: {
                    compatibility: 'ie8',
                    relativeTo: 'css/',
                    target: 'css/'
                },
                files: {
                    'css/lib.css': [
                        'lib/jquery-ui-1.10.3/jquery-ui.custom.min.css',      // 20 kb
                        'lib/magnific-popup-1.0.0/magnific-popup.css',        //  9 kb
                        'lib/select2-3.5.1/select2.css',                      // 19 kb
                        'lib/jquery-fileupload-5.26/jquery-fileupload-ui.css' //  2 kb
                    ]
                }
            }
        },

        /*
         * UGLIFY: Minify files with UglifyJS
         */
        uglify: {
            prepareLibJs: {
                options: {
                    preserveComments: 'some'
                },
                files: [{
                    expand: true,
                    ext: '.min.js',
                    src: [
                        'lib/bootstrap-file-input/bootstrap-file-input.js',
                        'lib/jquery-cookie-1.4.0/jquery-cookie.js',
                        'lib/jquery-fileupload-5.26/jquery-fileupload.js',
                        'lib/jquery-fileupload-5.26/jquery-iframe-transport.js',
                        'lib/jquery-formatdatetime-1.1.4/jquery-formatdatetime.js',
                        'lib/jquery-hotkeys/jquery-hotkeys.js',
                        'lib/jquery-tagcloud/jquery-tagcloud.js',
                        'lib/jquery-watchchanges/jquery-watchchanges.js'
                    ]
                }]
            },
            installLocaleDatepicker: {
                options: {
                    preserveComments: 'some'
                },
                files: [{
                    expand: true,
                    ext: '.min.js',
                    cwd: 'lib/datepicker',
                    src: '*.js',
                    dest: 'js/locale/datepicker',
                    rename: function (destBase, destPath) {
                        return destBase + '/' + destPath.replace('datepicker-', '').replace('-', '_');
                    }
                }]
            },
            installLocaleMoment: {
                options: {
                    preserveComments: 'some'
                },
                files: [{
                    expand: true,
                    ext: '.min.js',
                    cwd: 'node_modules/moment/locale',
                    src: '*.js',
                    dest: 'js/locale/moment',
                    rename: function (destBase, destPath) {
                        return destBase + '/' + destPath.replace(/([a-z]+)-([a-z]+)/, function (_, a, b) {
                            return a + '_' + b.toUpperCase();
                        });
                    }
                }]
            },
            prepareBootstrapJs: {
                files: {
                    'lib/bootstrap-sass.generated/bootstrap.min.js': [
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/alert.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/button.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/dropdown.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/tab.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/transition.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/modal.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/tooltip.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/popover.js'
                    ]
                }
            },
            boltJs: {
                options: {
                    banner: "/**\n" +
                            " * These are Bolt's COMPILED JS files!\n" +
                            " * You can edit files in <js/src/*.js> and run 'grunt' to generate this file.\n" +
                            " */",
                    sourceMap: true
                },
                files: {
                    'js/bolt.min.js': ["<%= filesBoltJs %>"]
                }
            }
        },

        /*
         * JSHINT: Validates files with JSHint
         */
        jshint: {
            boltJs: {
                options: {
                    browser: true,      // Defines globals exposed by modern browsers
                    curly: true,        // Always put curly braces around blocks
                    devel: true,        // Defines globals that are usually used for logging/debugging
                    immed: true,        // Prohibits the use of immediate function invocations without parentheses
                    indent: 4,          // Tab width
                    latedef: true,      // Prohibits the use of a variable before it was defined
                    maxlen: 120,        // Maximum length of a line
                    noarg: true,        // Prohibits the use of arguments.caller and arguments.callee
                    nonbsp: true,       // Warns about "non-breaking whitespace" characters
                    singleGroups: true, // Prohibits the use of the grouping operator for single-expression statements
                    undef: true,        // Prohibits the use of undeclared variables
                    globals: {
                        // Bolt
                        bolt: true,                 // src/console.js
                        FilelistHolder: true,       // src/upload-files.js
                        Files: true,                // src/obj-files.js
                        Folders: true,              // src/obj-folders.js
                        init: true,                 // src/init.js
                        Moments: true,              // src/obj-moments.js
                        Navpopups: true,            // src/obj-navpopups.js
                        Sidebar: true,              // src/obj-sidebar.js
                        Stack: true,                // src/obj-stack.js
                        site: true,                 // src/extend.js/extend.twig
                        baseurl: true,              // src/extend.js/extend.twig
                        rootpath: true,             // src/extend.js/extend.twig
                        // Bolt global functions
                        bindFileUpload: true,       // src/bindfileuploads.js
                        bindGeolocation: true,      // src/geolocation.js
                        bindVideoEmbed: true,       // src/video-embed.js
                        getSelectedItems: true,     // src/fnc-helpers.js
                        makeUri: true,              // src/make-uri-slug.js
                        makeUriAjax: true,          // src/make-uri-slug.js
                        stopMakeUri: true,          // src/make-uri-slug.js
                        updateLatestActivity: true, // src/activity.js
                        validateContent: true,      // src/fnc-helpers.js
                        // Vendor
                        $: true,                    // jQuery
                        _: true,                    // underscore.js
                        Backbone: true,             // backbone.min.js
                        bootbox: true,              // bootbox.min.js
                        CKEDITOR: true,             // ckeditor.js
                        CodeMirror: true,           // ckeditor.js
                        google: true,               // Google
                        jQuery: true,               // jQuery
                        moment: true,               // moment.min.js
                        UAParser: true              // ua-parser.min.js
                    }
                },
                src: ["<%= filesBoltJs %>"]
            }
        },

        /*
         * REMOVE: Remove directory and files
         */
        remove: {
            prepareCkeditor: {
                dirList: [
                    'lib/ckeditor-4.4.7/adapters',
                    'lib/ckeditor-4.4.7/samples'
                ]
            }
        },

        /*
         * BOM: Byte Order Mark (BOM) removal
         */
        bom: {
            prepareCkeditor: {
                src: [
                    'lib/ckeditor-*/*.js',
                    'lib/ckeditor-*/**/*.js'
                ]
            }
        }
    });

    require('load-grunt-tasks')(grunt);

    /*** DEFAULT TASK:  Watches for changes of Bolts own css and js files ***/
    grunt.registerTask(
        'default',
        [
            'watch'
        ]
    );

    /*** UPDATE BOLT TASK:  Creates Bolts own css and js files ***/
    grunt.registerTask(
        'updateBolt',
        [
            'sass:boltCss',
            'eol:boltCss',
            'jshint:boltJs',
            'uglify:boltJs'
        ]
    );

    /*** UPDATE LIB TASK:  Builds library css/js. Run after one of the externals is updated ***/
    grunt.registerTask(
        'updateLib',
        [
            // Prepare
            'uglify:prepareBootstrapJs',        // Concat bootstrap scripts into one minified file
            'uglify:prepareLibJs',              // Create minified versions of library scripts that don't have them
            'remove:prepareCkeditor',           // Remove unneeded direcories from downloaded ckeditor
            'bom:prepareCkeditor',              // Remove unneeded bom from downloaded ckeditor
            'eol:prepareCkeditor',              // Convert CRLF to LF from downloaded ckeditor
            // Install
            'copy:installFonts',                // Copies fonts                       => view/fonts/*
            'cssmin:installLibCss',             // Concats and minifies library css   => view/css/lib.css
            'concat:installLibJs',              // Concats minified library scripts   => view/js/lib.min.js
            'uglify:installLocaleDatepicker',   // Copies minified datepicker locale  => view/js/locale/datepicker/*
            'uglify:installLocaleMoment'        // Copies minified moment.js locale   => view/js/locale/datepicker/*
        ]
    );
};
<commit_msg>Remove version numbers as of #2628<commit_after>module.exports = function(grunt) {
    grunt.util.linefeed = '\n';

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        config: grunt.file.readYAML('../config/config.yml'),

        filesBoltJs: [
            'lib/bolt/console.js',
            'lib/bolt/fnc-helpers.js',
            'lib/bolt/activity.js',
            'lib/bolt/bind-fileupload.js',
            'lib/bolt/make-uri-slug.js',
            'lib/bolt/video-embed.js',
            'lib/bolt/geolocation.js',
            'lib/bolt/upload-files.js',
            'lib/bolt/obj-sidebar.js',
            'lib/bolt/obj-navpopups.js',
            'lib/bolt/obj-moments.js',
            'lib/bolt/obj-files.js',
            'lib/bolt/obj-stack.js',
            'lib/bolt/obj-folders.js',
            'lib/bolt/obj-datetime.js',
            'lib/bolt/extend.js',
            'lib/bolt/init.js',
            'lib/bolt/start.js'
        ],

        /*
         * WATCH: Run predefined tasks whenever watched file patterns are added, changed or deleted
         */
        watch: {
            options: {
                spawn: false,
                livereload: true
            },
            sass: {
                files: [
                    'sass/*.scss',
                    'sass/**/*.scss'
                ],
                tasks: [
                    'sass:boltCss',
                    'eol:boltCss'
                ]
            },
            boltJs: {
                files: [
                    "<%= filesBoltJs %>"
                ],
                tasks: [
                    'jshint:boltJs',
                    'uglify:boltJs'
                ]
            },
            gruntfile: {
                files: [
                    'Gruntfile.js'
                ],
                options: {
                    reload: true
                }
            }
        },

        /*
         * SASS: Compile Sass to CSS
         */
        sass: {
            boltCss: {
                options: {
                    outputStyle: 'compressed',
                    includePaths: [
                        'node_modules/bootstrap-sass/assets/stylesheets/',
                        'node_modules/font-awesome/scss/'
                    ],
                    lineNumbers: false,
                    unixNewlines: true,
                    banner: "/**\n" +
                            " * These are Bolt's COMPILED CSS files!\n" +
                            " * Do not edit these files, because all changes will be lost.\n" +
                            " * You can edit ../scss/app.scss & ../scss/app-old-ie.scss, and run 'grunt' to generate this file.\n" +
                            " */\n",
                    precision: 5
                },
                files: {
                    'css/bolt-old-ie.css': 'sass/app-old-ie.scss',
                    'css/bolt.css': 'sass/app.scss'
                }
            }
        },

        /*
         * EOL: Convert line endings
         */
        eol: {
            boltCss: {
                options: {
                    eol: 'lf',
                    replace: true
                },
                files: {
                    src: [
                        'css/bolt-old-ie.css',
                        'css/bolt.css'
                    ]
                }
            },
            prepareCkeditor: {
                options: {
                    eol: 'lf',
                    replace: true
                },
                files: {
                    src: [
                        'lib/ckeditor/*.js',  'lib/ckeditor/**/*.js',
                        'lib/ckeditor/*.css', 'lib/ckeditor/**/*.css',
                        'lib/ckeditor/*.md',  'lib/ckeditor/**/*.md',
                        'lib/ckeditor/*.txt', 'lib/ckeditor/**/*.txt'
                    ]
                }
            }
        },

        /*
         * COPY: Copy files and folders
         */
        copy: {
            installFonts: {
                files: [{
                    expand: true,
                    flatten: true,
                    src: [
                        'node_modules/font-awesome/fonts/*'
                    ],
                    filter: 'isFile',
                    dest: 'fonts/'
                }]
            }
        },

        /*
         * CONCAT: Concatenate files
         */
        concat: {
            installLibJs: {
                options: {
                    separator: '\n\n'
                },
                nonull: true,
                src: [
                    'lib/jquery-1.11.2/jquery.min.js',                              //  96 kb
                    'lib/jquery-ui-1.10.3/jquery-ui.custom.min.js',                 //  96 kb
                    'lib/bootstrap-file-input/bootstrap-file-input.min.js',         //   1 kb
                    'lib/jquery-tagcloud/jquery-tagcloud.min.js',                   //   1 kb
                    'lib/jquery-hotkeys/jquery-hotkeys.min.js',                     //   2 kb
                    'lib/jquery-watchchanges/jquery-watchchanges.min.js',           //   1 kb
                    'lib/jquery-cookie-1.4.0/jquery-cookie.min.js',                 //   1 kb
                    'lib/jquery-formatdatetime-1.1.4/jquery-formatdatetime.min.js', //   3 kb
                    'lib/jquery-fileupload-5.26/jquery-iframe-transport.min.js',    //   2 kb
                    'lib/jquery-fileupload-5.26/jquery-fileupload.min.js',          //  15 kb
                    'lib/underscore-1.7.0/underscore-min.js',                       //  16 kb
                    'lib/backbone/backbone-min.js',                                 //  20 kb
                    'lib/bootstrap-sass.generated/bootstrap.min.js',                //   2 kb
                    'lib/magnific-popup-1.0.0/magnific-popup.min.js',               //  21 kb
                    'lib/select2-3.5.1/select2.min.js',                             //  66 kb
                    'node_modules/moment/min/moment.min.js',                        //  35 kb
                    'lib/bootbox-4.3.0/bootbox.min.js',                             //   9 kb
                    'lib/modernizr-2.8.3/modernizr.custom.min.js'                   //   5 kb
                ],
                dest: 'js/lib.min.js'
            }
        },

        /*
         * CSSMIN: Compress CSS files
         */
        cssmin: {
            installLibCss: {
                options: {
                    compatibility: 'ie8',
                    relativeTo: 'css/',
                    target: 'css/'
                },
                files: {
                    'css/lib.css': [
                        'lib/jquery-ui-1.10.3/jquery-ui.custom.min.css',      // 20 kb
                        'lib/magnific-popup-1.0.0/magnific-popup.css',        //  9 kb
                        'lib/select2-3.5.1/select2.css',                      // 19 kb
                        'lib/jquery-fileupload-5.26/jquery-fileupload-ui.css' //  2 kb
                    ]
                }
            }
        },

        /*
         * UGLIFY: Minify files with UglifyJS
         */
        uglify: {
            prepareLibJs: {
                options: {
                    preserveComments: 'some'
                },
                files: [{
                    expand: true,
                    ext: '.min.js',
                    src: [
                        'lib/bootstrap-file-input/bootstrap-file-input.js',
                        'lib/jquery-cookie-1.4.0/jquery-cookie.js',
                        'lib/jquery-fileupload-5.26/jquery-fileupload.js',
                        'lib/jquery-fileupload-5.26/jquery-iframe-transport.js',
                        'lib/jquery-formatdatetime-1.1.4/jquery-formatdatetime.js',
                        'lib/jquery-hotkeys/jquery-hotkeys.js',
                        'lib/jquery-tagcloud/jquery-tagcloud.js',
                        'lib/jquery-watchchanges/jquery-watchchanges.js'
                    ]
                }]
            },
            installLocaleDatepicker: {
                options: {
                    preserveComments: 'some'
                },
                files: [{
                    expand: true,
                    ext: '.min.js',
                    cwd: 'lib/datepicker',
                    src: '*.js',
                    dest: 'js/locale/datepicker',
                    rename: function (destBase, destPath) {
                        return destBase + '/' + destPath.replace('datepicker-', '').replace('-', '_');
                    }
                }]
            },
            installLocaleMoment: {
                options: {
                    preserveComments: 'some'
                },
                files: [{
                    expand: true,
                    ext: '.min.js',
                    cwd: 'node_modules/moment/locale',
                    src: '*.js',
                    dest: 'js/locale/moment',
                    rename: function (destBase, destPath) {
                        return destBase + '/' + destPath.replace(/([a-z]+)-([a-z]+)/, function (_, a, b) {
                            return a + '_' + b.toUpperCase();
                        });
                    }
                }]
            },
            prepareBootstrapJs: {
                files: {
                    'lib/bootstrap-sass.generated/bootstrap.min.js': [
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/alert.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/button.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/dropdown.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/tab.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/transition.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/modal.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/tooltip.js',
                        'node_modules/bootstrap-sass/assets/javascripts/bootstrap/popover.js'
                    ]
                }
            },
            boltJs: {
                options: {
                    banner: "/**\n" +
                            " * These are Bolt's COMPILED JS files!\n" +
                            " * You can edit files in <js/src/*.js> and run 'grunt' to generate this file.\n" +
                            " */",
                    sourceMap: true
                },
                files: {
                    'js/bolt.min.js': ["<%= filesBoltJs %>"]
                }
            }
        },

        /*
         * JSHINT: Validates files with JSHint
         */
        jshint: {
            boltJs: {
                options: {
                    browser: true,      // Defines globals exposed by modern browsers
                    curly: true,        // Always put curly braces around blocks
                    devel: true,        // Defines globals that are usually used for logging/debugging
                    immed: true,        // Prohibits the use of immediate function invocations without parentheses
                    indent: 4,          // Tab width
                    latedef: true,      // Prohibits the use of a variable before it was defined
                    maxlen: 120,        // Maximum length of a line
                    noarg: true,        // Prohibits the use of arguments.caller and arguments.callee
                    nonbsp: true,       // Warns about "non-breaking whitespace" characters
                    singleGroups: true, // Prohibits the use of the grouping operator for single-expression statements
                    undef: true,        // Prohibits the use of undeclared variables
                    globals: {
                        // Bolt
                        bolt: true,                 // src/console.js
                        FilelistHolder: true,       // src/upload-files.js
                        Files: true,                // src/obj-files.js
                        Folders: true,              // src/obj-folders.js
                        init: true,                 // src/init.js
                        Moments: true,              // src/obj-moments.js
                        Navpopups: true,            // src/obj-navpopups.js
                        Sidebar: true,              // src/obj-sidebar.js
                        Stack: true,                // src/obj-stack.js
                        site: true,                 // src/extend.js/extend.twig
                        baseurl: true,              // src/extend.js/extend.twig
                        rootpath: true,             // src/extend.js/extend.twig
                        // Bolt global functions
                        bindFileUpload: true,       // src/bindfileuploads.js
                        bindGeolocation: true,      // src/geolocation.js
                        bindVideoEmbed: true,       // src/video-embed.js
                        getSelectedItems: true,     // src/fnc-helpers.js
                        makeUri: true,              // src/make-uri-slug.js
                        makeUriAjax: true,          // src/make-uri-slug.js
                        stopMakeUri: true,          // src/make-uri-slug.js
                        updateLatestActivity: true, // src/activity.js
                        validateContent: true,      // src/fnc-helpers.js
                        // Vendor
                        $: true,                    // jQuery
                        _: true,                    // underscore.js
                        Backbone: true,             // backbone.min.js
                        bootbox: true,              // bootbox.min.js
                        CKEDITOR: true,             // ckeditor.js
                        CodeMirror: true,           // ckeditor.js
                        google: true,               // Google
                        jQuery: true,               // jQuery
                        moment: true,               // moment.min.js
                        UAParser: true              // ua-parser.min.js
                    }
                },
                src: ["<%= filesBoltJs %>"]
            }
        },

        /*
         * REMOVE: Remove directory and files
         */
        remove: {
            prepareCkeditor: {
                dirList: [
                    'lib/ckeditor/adapters',
                    'lib/ckeditor/samples'
                ]
            }
        },

        /*
         * BOM: Byte Order Mark (BOM) removal
         */
        bom: {
            prepareCkeditor: {
                src: [
                    'lib/ckeditor/*.js',
                    'lib/ckeditor/**/*.js'
                ]
            }
        }
    });

    require('load-grunt-tasks')(grunt);

    /*** DEFAULT TASK:  Watches for changes of Bolts own css and js files ***/
    grunt.registerTask(
        'default',
        [
            'watch'
        ]
    );

    /*** UPDATE BOLT TASK:  Creates Bolts own css and js files ***/
    grunt.registerTask(
        'updateBolt',
        [
            'sass:boltCss',
            'eol:boltCss',
            'jshint:boltJs',
            'uglify:boltJs'
        ]
    );

    /*** UPDATE LIB TASK:  Builds library css/js. Run after one of the externals is updated ***/
    grunt.registerTask(
        'updateLib',
        [
            // Prepare
            'uglify:prepareBootstrapJs',        // Concat bootstrap scripts into one minified file
            'uglify:prepareLibJs',              // Create minified versions of library scripts that don't have them
            'remove:prepareCkeditor',           // Remove unneeded direcories from downloaded ckeditor
            'bom:prepareCkeditor',              // Remove unneeded bom from downloaded ckeditor
            'eol:prepareCkeditor',              // Convert CRLF to LF from downloaded ckeditor
            // Install
            'copy:installFonts',                // Copies fonts                       => view/fonts/*
            'cssmin:installLibCss',             // Concats and minifies library css   => view/css/lib.css
            'concat:installLibJs',              // Concats minified library scripts   => view/js/lib.min.js
            'uglify:installLocaleDatepicker',   // Copies minified datepicker locale  => view/js/locale/datepicker/*
            'uglify:installLocaleMoment'        // Copies minified moment.js locale   => view/js/locale/datepicker/*
        ]
    );
};
<|endoftext|>


<commit_before>/*
 * Copyright 2012 Karl Düüna <karl.dyyna@gmail.com> All rights reserved.
 */
'use strict';

var vows = require('vows');
var assert = require('assert');
var spec = require('vows/lib/vows/reporters/spec');
var d = require('./data');
var utils = require('./utils');

vows.describe('Easy-config').addBatch({
  'Simple include':{
    topic:function(){
      this.callback(null, require('../lib/config'));
    },
    'is correct':function(config){
      assert.strictEqual(true, utils.deepDiff(config, d.simple));
    },
    'Extend':function(config){
      config.extend({correct:false});
      assert.strictEqual(true, utils.deepDiff(config, d.simpleE));
    }
  }
}).addBatch({
  'With env false':{
    topic:function(){
      this.callback(null, require('../lib/config').loadConfig({env:false}));
    },
    'is correct':function(config){
      assert.strictEqual(true, utils.deepDiff(config, d.noEnv));
    }
  }
}).addBatch({
  'With other folder':{
    topic:function(){
      this.callback(null, require('../lib/config').loadConfig({folder:'other'}));
    },
    'is correct':function(config){
      assert.strictEqual(true, utils.deepDiff(config, d.other));
    }
  }
}).addBatch({
  'With no NS':{
    topic:function(){
      this.callback(null, require('../lib/config').loadConfig({ns:false}));
    },
    'is correct':function(config){
      assert.strictEqual(true, utils.deepDiff(config, d.noNS));
    }
  }
}).run({reporter:spec});<commit_msg>Fix tests<commit_after>/*
 * Copyright 2012 Karl Düüna <karl.dyyna@gmail.com> All rights reserved.
 */
'use strict';

var vows = require('vows');
var assert = require('assert');
var spec = require('vows/lib/vows/reporters/spec');
var d = require('./data');
var utils = require('./utils');

try {
  process.chdir(__dirname);
}
catch (err) {
  console.log('Changing directory failed, test must be run with current working directory being ..easy-config/test');
  console.log('exiting');
  process.exit();
}

vows.describe('Easy-config').addBatch({
  'Simple include':{
    topic:function(){
      this.callback(null, require('../lib/config'));
    },
    'is correct':function(config){
      assert.strictEqual(true, utils.deepDiff(config, d.simple));
    },
    'Extend':function(config){
      config.extend({correct:false});
      assert.strictEqual(true, utils.deepDiff(config, d.simpleE));
    }
  }
}).addBatch({
  'With env false':{
    topic:function(){
      this.callback(null, require('../lib/config').loadConfig({env:false}));
    },
    'is correct':function(config){
      assert.strictEqual(true, utils.deepDiff(config, d.noEnv));
    }
  }
}).addBatch({
  'With other folder':{
    topic:function(){
      this.callback(null, require('../lib/config').loadConfig({folder:'other'}));
    },
    'is correct':function(config){
      assert.strictEqual(true, utils.deepDiff(config, d.other));
    }
  }
}).addBatch({
  'With no NS':{
    topic:function(){
      this.callback(null, require('../lib/config').loadConfig({ns:false}));
    },
    'is correct':function(config){
      assert.strictEqual(true, utils.deepDiff(config, d.noNS));
    }
  }
}).run({reporter:spec});<|endoftext|>


<commit_before>import { connect } from 'react-redux';

import RootScene from './RootScene';

const mapStateToProps = (store, props) => {
  const navState = store.navigation;
  return {
    activeRoute: navState[props.tabIndex] && navState[props.tabIndex].activeRoute,
    navigationMethod: navState[props.tabIndex] && navState[props.tabIndex].method
  };
};

export default connect(mapStateToProps)(RootScene);
<commit_msg>validate tab container props presence<commit_after>import { connect } from 'react-redux';

import RootScene from './RootScene';

const mapStateToProps = (store, props) => {
  if (!props.tabIndex && props.tabIndex !== 0) {
    throw new Error('prop "tabIndex" must be present in TabContainer');
  }
  const navState = store.navigation;
  return {
    activeRoute: navState[props.tabIndex] && navState[props.tabIndex].activeRoute,
    navigationMethod: navState[props.tabIndex] && navState[props.tabIndex].method
  };
};

export default connect(mapStateToProps)(RootScene);
<|endoftext|>


<commit_before>ZRF = {
    JUMP:          0,
    IF:            1,
    FORK:          2,
    FUNCTION:      3,
    IN_ZONE:       4,
    FLAG:          5,
    SET_FLAG:      6,
    POS_FLAG:      7,
    SET_POS_FLAG:  8,
    ATTR:          9,
    SET_ATTR:      10,
    PROMOTE:       11,
    MODE:          12,
    ON_BOARD_DIR:  13,
    ON_BOARD_POS:  14,
    PARAM:         15,
    LITERAL:       16,
    VERIFY:        20
};

Dagaz.Model.BuildDesign = function(design) {
    design.checkVersion("z2j", "2");
    design.checkVersion("smart-moves", "true");
    design.checkVersion("pass-turn", "forced");
    design.checkVersion("show-hints", "false");
    design.checkVersion("show-blink", "false");
    design.checkVersion("advisor-wait", "5");

    design.addDirection("nx");
    design.addDirection("bx");
    design.addDirection("wx");
    design.addDirection("wn");
    design.addDirection("bn");

    design.addPlayer("White", [0, 1, 2, 3, 4]);
    design.addPlayer("Black", [0, 2, 1, 4, 3]);

    design.addPosition("m1", [34, 33, 26, 12, 1]);
    design.addPosition("l1", [0, 0, 0, -1, 1]);
    design.addPosition("k1", [0, 0, 0, -1, 1]);
    design.addPosition("j1", [0, 0, 0, -1, 1]);
    design.addPosition("h1", [0, 0, 0, -1, 1]);
    design.addPosition("g1", [0, 0, 0, -1, 1]);
    design.addPosition("f1", [0, 0, 0, -1, 1]);
    design.addPosition("e1", [0, 0, 0, -1, 1]);
    design.addPosition("d1", [0, 0, 0, -1, 1]);
    design.addPosition("c1", [0, 0, 0, -1, 1]);
    design.addPosition("b1", [0, 0, 0, -1, 1]);
    design.addPosition("a1", [0, 0, 0, -1, 13]);
    design.addPosition("m2", [0, 0, 0, 1, -12]);
    design.addPosition("l2", [0, 0, 0, 1, -1]);
    design.addPosition("k2", [0, 0, 0, 1, -1]);
    design.addPosition("j2", [0, 0, 0, 1, -1]);
    design.addPosition("h2", [0, 0, 0, 1, -1]);
    design.addPosition("g2", [0, 0, 0, 1, -1]);
    design.addPosition("f2", [0, 0, 0, 1, -1]);
    design.addPosition("e2", [0, 0, 0, 1, -1]);
    design.addPosition("d2", [0, 0, 0, 1, -1]);
    design.addPosition("c2", [0, 0, 0, 1, -1]);
    design.addPosition("b2", [0, 0, 0, 1, -1]);
    design.addPosition("a2", [0, 0, 0, 2, -1]);
    design.addPosition("H2", [0, 1, 2, 3, 4]);
    design.addPosition("H1", [0, 1, 2, 3, 4]);
    design.addPosition("B8", [0, 0, 1, -15, -3]);
    design.addPosition("B7", [0, -1, 1, -16, -4]);
    design.addPosition("B6", [0, -1, 1, -17, -5]);
    design.addPosition("B5", [0, -1, 1, -18, -6]);
    design.addPosition("B4", [0, -1, 1, -19, -7]);
    design.addPosition("B3", [0, -1, 1, -20, -8]);
    design.addPosition("B2", [0, -1, 1, -21, -9]);
    design.addPosition("B1", [0, -1, 0, -22, -10]);
    design.addPosition("D1", [1, 0, 0, 0, 0]);
    design.addPosition("D2", [1, 0, 0, 0, 0]);
    design.addPosition("D3", [1, 0, 0, 0, 0]);
    design.addPosition("D4", [0, 1, 2, 3, 4]);

    design.addZone("home", 1, [23, 22, 21, 20, 19, 18]);
    design.addZone("home", 2, [11, 10, 9, 8, 7, 6]);
    design.addZone("dice", 1, [36, 37]);
    design.addZone("dice", 2, [34, 35]);

    design.addCommand(0, ZRF.FUNCTION,	24);	// from
    design.addCommand(0, ZRF.PARAM,	0);	// $1
    design.addCommand(0, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(0, ZRF.FUNCTION,	25);	// to
    design.addCommand(0, ZRF.FUNCTION,	28);	// end

    design.addCommand(1, ZRF.FUNCTION,	24);	// from
    design.addCommand(1, ZRF.PARAM,	0);	// $1
    design.addCommand(1, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(1, ZRF.PARAM,	1);	// $2
    design.addCommand(1, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(1, ZRF.FUNCTION,	25);	// to
    design.addCommand(1, ZRF.FUNCTION,	28);	// end

    design.addCommand(2, ZRF.FUNCTION,	24);	// from
    design.addCommand(2, ZRF.PARAM,	0);	// $1
    design.addCommand(2, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(2, ZRF.PARAM,	1);	// $2
    design.addCommand(2, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(2, ZRF.PARAM,	2);	// $3
    design.addCommand(2, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(2, ZRF.FUNCTION,	25);	// to
    design.addCommand(2, ZRF.FUNCTION,	28);	// end

    design.addCommand(3, ZRF.FUNCTION,	24);	// from
    design.addCommand(3, ZRF.PARAM,	0);	// $1
    design.addCommand(3, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(3, ZRF.PARAM,	1);	// $2
    design.addCommand(3, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(3, ZRF.PARAM,	2);	// $3
    design.addCommand(3, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(3, ZRF.PARAM,	3);	// $4
    design.addCommand(3, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(3, ZRF.FUNCTION,	25);	// to
    design.addCommand(3, ZRF.FUNCTION,	28);	// end

    design.addCommand(4, ZRF.FUNCTION,	24);	// from
    design.addCommand(4, ZRF.PARAM,	0);	// $1
    design.addCommand(4, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(4, ZRF.PARAM,	1);	// $2
    design.addCommand(4, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(4, ZRF.PARAM,	2);	// $3
    design.addCommand(4, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(4, ZRF.PARAM,	3);	// $4
    design.addCommand(4, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(4, ZRF.PARAM,	4);	// $5
    design.addCommand(4, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(4, ZRF.FUNCTION,	25);	// to
    design.addCommand(4, ZRF.FUNCTION,	28);	// end

    design.addCommand(5, ZRF.FUNCTION,	24);	// from
    design.addCommand(5, ZRF.PARAM,	0);	// $1
    design.addCommand(5, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(5, ZRF.PARAM,	1);	// $2
    design.addCommand(5, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(5, ZRF.PARAM,	2);	// $3
    design.addCommand(5, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(5, ZRF.PARAM,	3);	// $4
    design.addCommand(5, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(5, ZRF.PARAM,	4);	// $5
    design.addCommand(5, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(5, ZRF.PARAM,	5);	// $6
    design.addCommand(5, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(5, ZRF.FUNCTION,	25);	// to
    design.addCommand(5, ZRF.FUNCTION,	28);	// end

    design.addPiece("Man", 0);
    design.addMove(0, 0, [3], 0);
    design.addMove(0, 1, [3, 3], 0);
    design.addMove(0, 2, [3, 3, 3], 0);
    design.addMove(0, 3, [3, 3, 3, 3], 0);
    design.addMove(0, 4, [3, 3, 3, 3, 3], 0);
    design.addMove(0, 5, [3, 3, 3, 3, 3, 3], 0);

    design.addPiece("D1", 1, 1);
    design.addPiece("D2", 2, 2);
    design.addPiece("D3", 3, 3);
    design.addPiece("D4", 4, 4);
    design.addPiece("D5", 5, 5);
    design.addPiece("D6", 6, 6);

    design.setup("White", "Man", 11);
    design.setup("White", "Man", 10);
    design.setup("White", "Man", 9);
    design.setup("Black", "Man", 23);
    design.setup("Black", "Man", 22);
    design.setup("Black", "Man", 21);
}

Dagaz.View.configure = function(view) {
    view.defBoard("Board");
    view.defPiece("WhiteMan", "White Man");
    view.defPiece("BlackMan", "Black Man");
    view.defPiece("WhiteD1", "White D1");
    view.defPiece("BlackD1", "Black D1");
    view.defPiece("WhiteD2", "White D2");
    view.defPiece("BlackD2", "Black D2");
    view.defPiece("WhiteD3", "White D3");
    view.defPiece("BlackD3", "Black D3");
    view.defPiece("WhiteD4", "White D4");
    view.defPiece("BlackD4", "Black D4");
    view.defPiece("WhiteD5", "White D5");
    view.defPiece("BlackD5", "Black D5");
    view.defPiece("WhiteD6", "White D6");
    view.defPiece("BlackD6", "Black D6");

    view.defPosition("m1", 9, 10, 34, 150);
    view.defPosition("l1", 43, 10, 34, 150);
    view.defPosition("k1", 77, 10, 34, 150);
    view.defPosition("j1", 111, 10, 34, 150);
    view.defPosition("h1", 145, 10, 34, 150);
    view.defPosition("g1", 179, 10, 34, 150);
    view.defPosition("f1", 237, 10, 34, 150);
    view.defPosition("e1", 271, 10, 34, 150);
    view.defPosition("d1", 305, 10, 34, 150);
    view.defPosition("c1", 339, 10, 34, 150);
    view.defPosition("b1", 373, 10, 34, 150);
    view.defPosition("a1", 407, 10, 34, 150);
    view.defPosition("m2", 9, 190, 34, 150);
    view.defPosition("l2", 43, 190, 34, 150);
    view.defPosition("k2", 77, 190, 34, 150);
    view.defPosition("j2", 111, 190, 34, 150);
    view.defPosition("h2", 145, 190, 34, 150);
    view.defPosition("g2", 179, 190, 34, 150);
    view.defPosition("f2", 237, 190, 34, 150);
    view.defPosition("e2", 271, 190, 34, 150);
    view.defPosition("d2", 305, 190, 34, 150);
    view.defPosition("c2", 339, 190, 34, 150);
    view.defPosition("b2", 373, 190, 34, 150);
    view.defPosition("a2", 407, 190, 34, 150);
    view.defPosition("H2", 456, 10, 40, 150);
    view.defPosition("H1", 456, 190, 40, 150);
    view.defPosition("B8", 210, 40, 30, 30);
    view.defPosition("B7", 210, 70, 30, 30);
    view.defPosition("B6", 210, 100, 30, 30);
    view.defPosition("B5", 210, 130, 30, 30);
    view.defPosition("B4", 210, 160, 30, 30);
    view.defPosition("B3", 210, 190, 30, 30);
    view.defPosition("B2", 210, 220, 30, 30);
    view.defPosition("B1", 210, 250, 30, 30);
    view.defPosition("D1", 77, 160, 34, 29);
    view.defPosition("D2", 111, 160, 34, 29);
    view.defPosition("D3", 305, 160, 34, 29);
    view.defPosition("D4", 339, 160, 34, 29);
}
<commit_msg>Hypergammon (fixes)<commit_after>ZRF = {
    JUMP:          0,
    IF:            1,
    FORK:          2,
    FUNCTION:      3,
    IN_ZONE:       4,
    FLAG:          5,
    SET_FLAG:      6,
    POS_FLAG:      7,
    SET_POS_FLAG:  8,
    ATTR:          9,
    SET_ATTR:      10,
    PROMOTE:       11,
    MODE:          12,
    ON_BOARD_DIR:  13,
    ON_BOARD_POS:  14,
    PARAM:         15,
    LITERAL:       16,
    VERIFY:        20
};

Dagaz.Model.BuildDesign = function(design) {
    design.checkVersion("z2j", "2");
    design.checkVersion("smart-moves", "true");
    design.checkVersion("pass-turn", "forced");
    design.checkVersion("show-hints", "false");
    design.checkVersion("show-blink", "false");
    design.checkVersion("advisor-wait", "5");

    design.addDirection("nx");
    design.addDirection("bx");
    design.addDirection("wx");
    design.addDirection("wn");
    design.addDirection("bn");

    design.addPlayer("White", [0, 1, 2, 3, 4]);
    design.addPlayer("Black", [0, 2, 1, 4, 3]);

    design.addPosition("m1", [34, 33, 26, 12, 1]);
    design.addPosition("l1", [0, 0, 0, -1, 1]);
    design.addPosition("k1", [0, 0, 0, -1, 1]);
    design.addPosition("j1", [0, 0, 0, -1, 1]);
    design.addPosition("h1", [0, 0, 0, -1, 1]);
    design.addPosition("g1", [0, 0, 0, -1, 1]);
    design.addPosition("f1", [0, 0, 0, -1, 1]);
    design.addPosition("e1", [0, 0, 0, -1, 1]);
    design.addPosition("d1", [0, 0, 0, -1, 1]);
    design.addPosition("c1", [0, 0, 0, -1, 1]);
    design.addPosition("b1", [0, 0, 0, -1, 1]);
    design.addPosition("a1", [0, 0, 0, -1, 13]);
    design.addPosition("m2", [0, 0, 0, 1, -12]);
    design.addPosition("l2", [0, 0, 0, 1, -1]);
    design.addPosition("k2", [0, 0, 0, 1, -1]);
    design.addPosition("j2", [0, 0, 0, 1, -1]);
    design.addPosition("h2", [0, 0, 0, 1, -1]);
    design.addPosition("g2", [0, 0, 0, 1, -1]);
    design.addPosition("f2", [0, 0, 0, 1, -1]);
    design.addPosition("e2", [0, 0, 0, 1, -1]);
    design.addPosition("d2", [0, 0, 0, 1, -1]);
    design.addPosition("c2", [0, 0, 0, 1, -1]);
    design.addPosition("b2", [0, 0, 0, 1, -1]);
    design.addPosition("a2", [0, 0, 0, 2, -1]);
    design.addPosition("H2", [0, 0, 0, 0, 0]);
    design.addPosition("H1", [0, 0, 0, 0, 0]);
    design.addPosition("B8", [0, 0, 1, -15, -3]);
    design.addPosition("B7", [0, -1, 1, -16, -4]);
    design.addPosition("B6", [0, -1, 1, -17, -5]);
    design.addPosition("B5", [0, -1, 1, -18, -6]);
    design.addPosition("B4", [0, -1, 1, -19, -7]);
    design.addPosition("B3", [0, -1, 1, -20, -8]);
    design.addPosition("B2", [0, -1, 1, -21, -9]);
    design.addPosition("B1", [0, -1, 0, -22, -10]);
    design.addPosition("D1", [1, 0, 0, 0, 0]);
    design.addPosition("D2", [1, 0, 0, 0, 0]);
    design.addPosition("D3", [1, 0, 0, 0, 0]);
    design.addPosition("D4", [0, 0, 0, 0, 0]);

    design.addZone("home", 1, [23, 22, 21, 20, 19, 18]);
    design.addZone("home", 2, [11, 10, 9, 8, 7, 6]);
    design.addZone("dice", 1, [36, 37]);
    design.addZone("dice", 2, [34, 35]);

    design.addCommand(0, ZRF.FUNCTION,	24);	// from
    design.addCommand(0, ZRF.PARAM,	0);	// $1
    design.addCommand(0, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(0, ZRF.FUNCTION,	25);	// to
    design.addCommand(0, ZRF.FUNCTION,	28);	// end

    design.addCommand(1, ZRF.FUNCTION,	24);	// from
    design.addCommand(1, ZRF.PARAM,	0);	// $1
    design.addCommand(1, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(1, ZRF.PARAM,	0);	// $1
    design.addCommand(1, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(1, ZRF.FUNCTION,	25);	// to
    design.addCommand(1, ZRF.FUNCTION,	28);	// end

    design.addCommand(2, ZRF.FUNCTION,	24);	// from
    design.addCommand(2, ZRF.PARAM,	0);	// $1
    design.addCommand(2, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(2, ZRF.PARAM,	0);	// $1
    design.addCommand(2, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(2, ZRF.PARAM,	0);	// $1
    design.addCommand(2, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(2, ZRF.FUNCTION,	25);	// to
    design.addCommand(2, ZRF.FUNCTION,	28);	// end

    design.addCommand(3, ZRF.FUNCTION,	24);	// from
    design.addCommand(3, ZRF.PARAM,	0);	// $1
    design.addCommand(3, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(3, ZRF.PARAM,	0);	// $1
    design.addCommand(3, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(3, ZRF.PARAM,	0);	// $1
    design.addCommand(3, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(3, ZRF.PARAM,	0);	// $1
    design.addCommand(3, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(3, ZRF.FUNCTION,	25);	// to
    design.addCommand(3, ZRF.FUNCTION,	28);	// end

    design.addCommand(4, ZRF.FUNCTION,	24);	// from
    design.addCommand(4, ZRF.PARAM,	0);	// $1
    design.addCommand(4, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(4, ZRF.PARAM,	0);	// $1
    design.addCommand(4, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(4, ZRF.PARAM,	0);	// $1
    design.addCommand(4, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(4, ZRF.PARAM,	0);	// $1
    design.addCommand(4, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(4, ZRF.PARAM,	0);	// $1
    design.addCommand(4, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(4, ZRF.FUNCTION,	25);	// to
    design.addCommand(4, ZRF.FUNCTION,	28);	// end

    design.addCommand(5, ZRF.FUNCTION,	24);	// from
    design.addCommand(5, ZRF.PARAM,	0);	// $1
    design.addCommand(5, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(5, ZRF.PARAM,	0);	// $1
    design.addCommand(5, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(5, ZRF.PARAM,	0);	// $1
    design.addCommand(5, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(5, ZRF.PARAM,	0);	// $1
    design.addCommand(5, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(5, ZRF.PARAM,	0);	// $1
    design.addCommand(5, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(5, ZRF.PARAM,	0);	// $1
    design.addCommand(5, ZRF.FUNCTION,	22);	// navigate
    design.addCommand(5, ZRF.FUNCTION,	25);	// to
    design.addCommand(5, ZRF.FUNCTION,	28);	// end

    design.addPiece("Man", 0);
    design.addMove(0, 0, [3], 0, 1);
    design.addMove(0, 1, [3], 0, 2);
    design.addMove(0, 2, [3], 0, 3);
    design.addMove(0, 3, [3], 0, 4);
    design.addMove(0, 4, [3], 0, 5);
    design.addMove(0, 5, [3], 0, 6);

    design.addPiece("D1", 1, 1);
    design.addPiece("D2", 2, 2);
    design.addPiece("D3", 3, 3);
    design.addPiece("D4", 4, 4);
    design.addPiece("D5", 5, 5);
    design.addPiece("D6", 6, 6);

    design.setup("White", "Man", 11);
    design.setup("White", "Man", 10);
    design.setup("White", "Man", 9);
    design.setup("Black", "Man", 23);
    design.setup("Black", "Man", 22);
    design.setup("Black", "Man", 21);
}

Dagaz.View.configure = function(view) {
    view.defBoard("Board");
    view.defPiece("WhiteMan", "White Man");
    view.defPiece("BlackMan", "Black Man");
    view.defPiece("WhiteD1", "White D1");
    view.defPiece("BlackD1", "Black D1");
    view.defPiece("WhiteD2", "White D2");
    view.defPiece("BlackD2", "Black D2");
    view.defPiece("WhiteD3", "White D3");
    view.defPiece("BlackD3", "Black D3");
    view.defPiece("WhiteD4", "White D4");
    view.defPiece("BlackD4", "Black D4");
    view.defPiece("WhiteD5", "White D5");
    view.defPiece("BlackD5", "Black D5");
    view.defPiece("WhiteD6", "White D6");
    view.defPiece("BlackD6", "Black D6");

    view.defPosition("m1", 9, 10, 34, 150);
    view.defPosition("l1", 43, 10, 34, 150);
    view.defPosition("k1", 77, 10, 34, 150);
    view.defPosition("j1", 111, 10, 34, 150);
    view.defPosition("h1", 145, 10, 34, 150);
    view.defPosition("g1", 179, 10, 34, 150);
    view.defPosition("f1", 237, 10, 34, 150);
    view.defPosition("e1", 271, 10, 34, 150);
    view.defPosition("d1", 305, 10, 34, 150);
    view.defPosition("c1", 339, 10, 34, 150);
    view.defPosition("b1", 373, 10, 34, 150);
    view.defPosition("a1", 407, 10, 34, 150);
    view.defPosition("m2", 9, 190, 34, 150);
    view.defPosition("l2", 43, 190, 34, 150);
    view.defPosition("k2", 77, 190, 34, 150);
    view.defPosition("j2", 111, 190, 34, 150);
    view.defPosition("h2", 145, 190, 34, 150);
    view.defPosition("g2", 179, 190, 34, 150);
    view.defPosition("f2", 237, 190, 34, 150);
    view.defPosition("e2", 271, 190, 34, 150);
    view.defPosition("d2", 305, 190, 34, 150);
    view.defPosition("c2", 339, 190, 34, 150);
    view.defPosition("b2", 373, 190, 34, 150);
    view.defPosition("a2", 407, 190, 34, 150);
    view.defPosition("H2", 456, 10, 40, 150);
    view.defPosition("H1", 456, 190, 40, 150);
    view.defPosition("B8", 210, 40, 30, 30);
    view.defPosition("B7", 210, 70, 30, 30);
    view.defPosition("B6", 210, 100, 30, 30);
    view.defPosition("B5", 210, 130, 30, 30);
    view.defPosition("B4", 210, 160, 30, 30);
    view.defPosition("B3", 210, 190, 30, 30);
    view.defPosition("B2", 210, 220, 30, 30);
    view.defPosition("B1", 210, 250, 30, 30);
    view.defPosition("D1", 77, 160, 34, 29);
    view.defPosition("D2", 111, 160, 34, 29);
    view.defPosition("D3", 305, 160, 34, 29);
    view.defPosition("D4", 339, 160, 34, 29);
}
<|endoftext|>


<commit_before>import {
  settings,
  updateSetting,
  addUpdateListener,
  getSavedSettings,
  loadSettings,
  restoreDefaultSettings,
} from '../settings.js';
import {
  getNested,
  listKeys,
} from '../utils/objects.js';
import {
  button,
  header,
  input,
  row,
  select,
  title,
  settingInput,
  setting,
} from './components.js';
import {
  e,
  withValue,
} from './dom.js';

/**
 * Object with methods for interacting with the simulation
 *
 * @typedef MeebaFarmInterface
 * @prop {function(): void} pause
 * @prop {function(): void} resume
 * @prop {function(): void} reset
 */

const INTERFACE_ID = 'interface';
const STRING_SETTINGS = new Set(['core.seed', 'bodies.moteColor']);

const debugSettings = () => {
  let selected = '';
  const debugKeys = listKeys(settings).filter(key => key.slice(0, 5) !== 'core.');

  const debugInput = input('--', { style: { width: '5em' } });
  const debugSelect = select('Select Debug Setting...', {
    style: { width: '8em' },
    onchange: () => {
      selected = debugSelect.value;
      debugInput.placeholder = getNested(settings, selected.split('.'), '--');
      if (STRING_SETTINGS.has(selected)) {
        debugInput.type = 'text';
      } else {
        debugInput.type = 'number';
      }
    },
  }, ...debugKeys);

  return row(
    header('Experimental Debug Settings'),
    debugSelect,
    debugInput,
    button('Set', withValue(debugInput, value => updateSetting(selected, value))),
  );
};

const sizeSettings = () => {
  const widthInput = settingInput('width', { style: { width: '5em' } });
  const heightInput = settingInput('height', { style: { width: '5em' } });
  const setWidth = withValue(widthInput, value => updateSetting('width', value));
  const setHeight = withValue(heightInput, value => updateSetting('height', value));

  return row(
    header('Tank Size'),
    widthInput,
    e('span', { style: { 'margin-right': '0.5em' } }, 'x'),
    heightInput,
    button('Set', () => {
      setWidth();
      setHeight();
    }),
  );
};

const settingsLoader = () => {
  const saveStringInput = input('Paste a saved settings string');
  addUpdateListener(() => {
    const saved = getSavedSettings();
    if (saved) {
      saveStringInput.value = saved;
    }
  });

  return row(
    header('Load Settings'),
    saveStringInput,
    button('Load', withValue(saveStringInput, loadSettings)),
  );
};

/**
 * Returns an HTML element with the entire user interface
 *
 * @param {MeebaFarmInterface} MeebaFarm
 * @returns {HTMLDivElement}
 */
export const getInterface = ({ pause, resume, reset }) => (
  e('div', { id: INTERFACE_ID },
    title('Meeba Farm'),
    row(
      button('Pause', pause),
      button('Resume', resume),
      button('Reset', reset),
    ),
    setting('seed', 'Seed', { type: 'text' }),
    sizeSettings(),
    setting('startingBodies', 'Initial Meeba Count'),
    setting('moteSpawnRate', 'Mote Spawn Rate'),
    setting('energy', 'Kinetic Energy'),
    setting('temperature', 'Tank Temperature'),
    setting('volatility', 'Gene Volatility'),
    debugSettings(),
    settingsLoader(),
    row(button('Restore Default Settings', restoreDefaultSettings)),
    e('div', { style: { 'margin-top': '2em' } },
      e('small', {},
        e('em', {},
          e('div', { style: { 'margin-bottom': '0.25em' } }, 'Created by ',
            e('a', { href: 'https://github.com/delventhalz' }, 'Zac Delventhal')),
          e('div', {}, 'Learn more and report issues on ',
            e('a', { href: 'https://github.com/meeba-farm/meeba-farm' }, 'GitHub'))))))
);
<commit_msg>Fix debug input not updating to new value when set<commit_after>import {
  settings,
  updateSetting,
  addUpdateListener,
  getSavedSettings,
  loadSettings,
  restoreDefaultSettings,
} from '../settings.js';
import {
  getNested,
  listKeys,
} from '../utils/objects.js';
import {
  button,
  header,
  input,
  row,
  select,
  title,
  settingInput,
  setting,
} from './components.js';
import {
  e,
  withValue,
} from './dom.js';

/**
 * Object with methods for interacting with the simulation
 *
 * @typedef MeebaFarmInterface
 * @prop {function(): void} pause
 * @prop {function(): void} resume
 * @prop {function(): void} reset
 */

const INTERFACE_ID = 'interface';
const STRING_SETTINGS = new Set(['core.seed', 'bodies.moteColor']);

const debugSettings = () => {
  let selected = '';
  const debugKeys = listKeys(settings).filter(key => key.slice(0, 5) !== 'core.');

  const debugInput = input('--', { style: { width: '5em' } });
  const debugSelect = select('Select Debug Setting...', {
    style: { width: '8em' },
    onchange: () => {
      selected = debugSelect.value;
      debugInput.placeholder = getNested(settings, selected.split('.'), '--');
      if (STRING_SETTINGS.has(selected)) {
        debugInput.type = 'text';
      } else {
        debugInput.type = 'number';
      }
    },
  }, ...debugKeys);

  return row(
    header('Experimental Debug Settings'),
    debugSelect,
    debugInput,
    button('Set', withValue(debugInput, (value) => {
      updateSetting(selected, value);
      debugInput.placeholder = value;
    })),
  );
};

const sizeSettings = () => {
  const widthInput = settingInput('width', { style: { width: '5em' } });
  const heightInput = settingInput('height', { style: { width: '5em' } });
  const setWidth = withValue(widthInput, value => updateSetting('width', value));
  const setHeight = withValue(heightInput, value => updateSetting('height', value));

  return row(
    header('Tank Size'),
    widthInput,
    e('span', { style: { 'margin-right': '0.5em' } }, 'x'),
    heightInput,
    button('Set', () => {
      setWidth();
      setHeight();
    }),
  );
};

const settingsLoader = () => {
  const saveStringInput = input('Paste a saved settings string');
  addUpdateListener(() => {
    const saved = getSavedSettings();
    if (saved) {
      saveStringInput.value = saved;
    }
  });

  return row(
    header('Load Settings'),
    saveStringInput,
    button('Load', withValue(saveStringInput, loadSettings)),
  );
};

/**
 * Returns an HTML element with the entire user interface
 *
 * @param {MeebaFarmInterface} MeebaFarm
 * @returns {HTMLDivElement}
 */
export const getInterface = ({ pause, resume, reset }) => (
  e('div', { id: INTERFACE_ID },
    title('Meeba Farm'),
    row(
      button('Pause', pause),
      button('Resume', resume),
      button('Reset', reset),
    ),
    setting('seed', 'Seed', { type: 'text' }),
    sizeSettings(),
    setting('startingBodies', 'Initial Meeba Count'),
    setting('moteSpawnRate', 'Mote Spawn Rate'),
    setting('energy', 'Kinetic Energy'),
    setting('temperature', 'Tank Temperature'),
    setting('volatility', 'Gene Volatility'),
    debugSettings(),
    settingsLoader(),
    row(button('Restore Default Settings', restoreDefaultSettings)),
    e('div', { style: { 'margin-top': '2em' } },
      e('small', {},
        e('em', {},
          e('div', { style: { 'margin-bottom': '0.25em' } }, 'Created by ',
            e('a', { href: 'https://github.com/delventhalz' }, 'Zac Delventhal')),
          e('div', {}, 'Learn more and report issues on ',
            e('a', { href: 'https://github.com/meeba-farm/meeba-farm' }, 'GitHub'))))))
);
<|endoftext|>


<commit_before>var assert = require("assert"),
    path = require("path"),
    entities = require("../");

describe("Encode->decode test", function(){
	var testcases = [
		{
			input: "asdf & ÿ ü '",
			xml: "asdf & ÿ ü '",
			html: "asdf & ÿ ü '"
		}, {
			input: "&",
			xml: "&#38;",
			html: "&#38;"
		},
	];
	testcases.forEach(function(tc) {
		var encodedXML = entities.encodeXML(tc.input);
		it("should XML encode " + tc.input, function(){
			assert.equal(encodedXML, tc.xml);
		});
		it("should default to XML encode " + tc.input, function(){
			assert.equal(entities.encode(tc.input), tc.xml);
		});
		it("should XML decode " + encodedXML, function(){
			assert.equal(entities.decodeXML(encodedXML), tc.input);
		});
		it("should default to XML encode " + encodedXML, function(){
			assert.equal(entities.decode(encodedXML), tc.input);
		});
		it("should default strict to XML encode " + encodedXML, function(){
			assert.equal(entities.decodeStrict(encodedXML), tc.input);
		});

		var encodedHTML5 = entities.encodeHTML5(tc.input);
		it("should HTML5 encode " + tc.input, function(){
			assert.equal(encodedHTML5, tc.html);
		});
		it("should HTML5 decode " + encodedHTML5, function(){
			assert.equal(entities.decodeHTML(encodedHTML5), tc.input);
		});
	});
});

describe("Decode test", function(){
	var testcases = [
		{ input: "&amp;",  output: "&" },
		{ input: "&#38;",  output: "&" },
		{ input: "&#x26;", output: "&" },
		{ input: "&#X26;", output: "&" },
		{ input: "&#38;",  output: "&" },
		{ input: "&#38;", output: "&" },
		{ input: "&#38;", output: "&" },
		{ input: ":",     output: ":" },
		{ input: ":",     output: ":" },
		{ input: ":",     output: ":" },
		{ input: ":",     output: ":" }
	];
	testcases.forEach(function(tc) {
		it("should XML decode " + tc.input, function(){
			assert.equal(entities.decodeXML(tc.input), tc.output);
		});
		it("should HTML4 decode " + tc.input, function(){
			assert.equal(entities.decodeHTML(tc.input), tc.output);
		});
		it("should HTML5 decode " + tc.input, function(){
			assert.equal(entities.decodeHTML(tc.input), tc.output);
		});
	});
});

var levels = ["xml", "entities"];

describe("Documents", function(){
	levels
	.map(function(n){ return path.join("..", "maps", n); })
	.map(require)
	.forEach(function(doc, i){
		describe("Decode", function(){
			it(levels[i], function(){
				Object.keys(doc).forEach(function(e){
					for(var l = i; l < levels.length; l++){
						assert.equal(entities.decode("&" + e + ";", l), doc[e]);
					}
				});
			});
		});

		describe("Decode strict", function(){
			it(levels[i], function(){
				Object.keys(doc).forEach(function(e){
					for(var l = i; l < levels.length; l++){
						assert.equal(entities.decodeStrict("&" + e + ";", l), doc[e]);
					}
				});
			});
		});

		describe("Encode", function(){
			it(levels[i], function(){
				Object.keys(doc).forEach(function(e){
					for(var l = i; l < levels.length; l++){
						assert.equal(entities.decode(entities.encode(doc[e], l), l), doc[e]);
					}
				});
			});
		});
	});

	var legacy = require("../maps/legacy.json");

	describe("Legacy", function(){
		it("should decode", runLegacy);
	});

	function runLegacy(){
		Object.keys(legacy).forEach(function(e){
			assert.equal(entities.decodeHTML("&" + e), legacy[e]);
		});
	}
});

var astral = {
	"1D306": "\uD834\uDF06",
	"1D11E": "\uD834\uDD1E"
};

var astralSpecial = {
	"80":    "\u20AC",
	"110000": "\uFFFD"
};

describe("Astral entities", function(){
	Object.keys(astral).forEach(function(c){
		it("should decode " + astral[c], function(){
			assert.equal(entities.decode("&#x" + c + ";"), astral[c]);
		});

		it("should encode " + astral[c], function(){
			assert.equal(entities.encode(astral[c]), "&#x" + c + ";");
		});
	});

	Object.keys(astralSpecial).forEach(function(c){
		it("special should decode \\u" + c, function(){
			assert.equal(entities.decode("&#x" + c + ";"), astralSpecial[c]);
		});
	});
});
<commit_msg>test: added basic tests for `escape`<commit_after>var assert = require("assert"),
    path = require("path"),
    entities = require("../");

describe("Encode->decode test", function(){
	var testcases = [
		{
			input: "asdf & ÿ ü '",
			xml: "asdf & ÿ ü '",
			html: "asdf & ÿ ü '"
		}, {
			input: "&",
			xml: "&#38;",
			html: "&#38;"
		},
	];
	testcases.forEach(function(tc) {
		var encodedXML = entities.encodeXML(tc.input);
		it("should XML encode " + tc.input, function(){
			assert.equal(encodedXML, tc.xml);
		});
		it("should default to XML encode " + tc.input, function(){
			assert.equal(entities.encode(tc.input), tc.xml);
		});
		it("should XML decode " + encodedXML, function(){
			assert.equal(entities.decodeXML(encodedXML), tc.input);
		});
		it("should default to XML encode " + encodedXML, function(){
			assert.equal(entities.decode(encodedXML), tc.input);
		});
		it("should default strict to XML encode " + encodedXML, function(){
			assert.equal(entities.decodeStrict(encodedXML), tc.input);
		});

		var encodedHTML5 = entities.encodeHTML5(tc.input);
		it("should HTML5 encode " + tc.input, function(){
			assert.equal(encodedHTML5, tc.html);
		});
		it("should HTML5 decode " + encodedHTML5, function(){
			assert.equal(entities.decodeHTML(encodedHTML5), tc.input);
		});
	});
});

describe("Decode test", function(){
	var testcases = [
		{ input: "&amp;",  output: "&" },
		{ input: "&#38;",  output: "&" },
		{ input: "&#x26;", output: "&" },
		{ input: "&#X26;", output: "&" },
		{ input: "&#38;",  output: "&" },
		{ input: "&#38;", output: "&" },
		{ input: "&#38;", output: "&" },
		{ input: ":",     output: ":" },
		{ input: ":",     output: ":" },
		{ input: ":",     output: ":" },
		{ input: ":",     output: ":" }
	];
	testcases.forEach(function(tc) {
		it("should XML decode " + tc.input, function(){
			assert.equal(entities.decodeXML(tc.input), tc.output);
		});
		it("should HTML4 decode " + tc.input, function(){
			assert.equal(entities.decodeHTML(tc.input), tc.output);
		});
		it("should HTML5 decode " + tc.input, function(){
			assert.equal(entities.decodeHTML(tc.input), tc.output);
		});
	});
});

var levels = ["xml", "entities"];

describe("Documents", function(){
	levels
	.map(function(n){ return path.join("..", "maps", n); })
	.map(require)
	.forEach(function(doc, i){
		describe("Decode", function(){
			it(levels[i], function(){
				Object.keys(doc).forEach(function(e){
					for(var l = i; l < levels.length; l++){
						assert.equal(entities.decode("&" + e + ";", l), doc[e]);
					}
				});
			});
		});

		describe("Decode strict", function(){
			it(levels[i], function(){
				Object.keys(doc).forEach(function(e){
					for(var l = i; l < levels.length; l++){
						assert.equal(entities.decodeStrict("&" + e + ";", l), doc[e]);
					}
				});
			});
		});

		describe("Encode", function(){
			it(levels[i], function(){
				Object.keys(doc).forEach(function(e){
					for(var l = i; l < levels.length; l++){
						assert.equal(entities.decode(entities.encode(doc[e], l), l), doc[e]);
					}
				});
			});
		});
	});

	var legacy = require("../maps/legacy.json");

	describe("Legacy", function(){
		it("should decode", runLegacy);
	});

	function runLegacy(){
		Object.keys(legacy).forEach(function(e){
			assert.equal(entities.decodeHTML("&" + e), legacy[e]);
		});
	}
});

var astral = {
	"1D306": "\uD834\uDF06",
	"1D11E": "\uD834\uDD1E"
};

var astralSpecial = {
	"80":    "\u20AC",
	"110000": "\uFFFD"
};

describe("Astral entities", function(){
	Object.keys(astral).forEach(function(c){
		it("should decode " + astral[c], function(){
			assert.equal(entities.decode("&#x" + c + ";"), astral[c]);
		});

		it("should encode " + astral[c], function(){
			assert.equal(entities.encode(astral[c]), "&#x" + c + ";");
		});

		it("should escape " + astral[c], function(){
			assert.equal(entities.escape(astral[c]), "&#x" + c + ";");
		});
	});

	Object.keys(astralSpecial).forEach(function(c){
		it("special should decode \\u" + c, function(){
			assert.equal(entities.decode("&#x" + c + ";"), astralSpecial[c]);
		});
	});
});

describe("Escape", function(){
	it("should always decode ASCII chars", function(){
		for(var i = 0; i < 0x7F; i++){
			var c = String.fromCharCode(i);
			assert.equal(entities.decodeXML(entities.escape(c)), c);
		}
	});
});
<|endoftext|>


<commit_before>
(function() {
'use strict';

Elm.Debugger = null;
Elm.debuggerAttach = function(module, hotSwapState /* =undefined */) {
  return {
    make: function(runtime) {
      var wrappedModule = debugModule(module, runtime);
      Elm.Debugger = debuggerInit(wrappedModule, runtime, hotSwapState);
      dispatchElmDebuggerInit();
      return wrappedModule.moduleInstance;
    }
  };
};

function dispatchElmDebuggerInit() {
  if (parent.window) {
    var dispatch = function(_) {
      parent.window.postMessage("elmDebuggerInit", window.location.origin);
    };
    if (parent.window.document.readyState === "complete") {
      dispatch();
    }
    else {
      parent.window.addEventListener("load", dispatch);
    }
  }
}

function debugModule(module, runtime) {
  var programPaused = false;
  var recordedEvents = [];
  var asyncCallbacks = [];

  function wrapNotify(id, v) {
    var timestep = Date.now();

    if (programPaused) {
      // ignore async events generated while playing back
      // or user events while program is paused
      return false;
    }
    else {
      var changed = runtime.notify(id, v, timestep);
      recordEvent(id, v, timestep);
      if (parent.window) {
        parent.window.postMessage("elmNotify", window.location.origin);
      }
      return changed;
    }
  };

  function wrapRunDelayed(func, delayMs) {
    var cbObj = { func:func, delayMs:delayMs, timerId:0, executed:false };
    var timerId = setTimeout(function() {
        cbObj.executed = true;
        func();
      }, delayMs);
    cbObj.timerId = timerId;
    asyncCallbacks.push(cbObj);
    return timerId;
  }

  function recordEvent(id, v, timestep) {
    recordedEvents.push({ id:id, value:v, timestep:timestep });
  }

  function clearAsyncCallbacks() {
    asyncCallbacks.forEach(function(timer) {
      if (!timer.executed) {
        clearTimeout(timer.timerId);
      }
    });
  }

  function clearRecordedEvents() {
    recordedEvents = [];
  }

  function getRecordedEventsLength() {
    return recordedEvents.length;
  }

  function getRecordedEventAt(i) {
    return recordedEvents[i];
  }

  function copyRecordedEvents() {
    return recordedEvents.slice();
  }

  function loadRecordedEvents(events) {
    recordedEvents = events.slice();
  }

  function setPaused(v) {
    programPaused = v;
    if (programPaused) {
      clearAsyncCallbacks();
      tracePath.stopRecording();
    }
    else {
      // executeCallbacks should only be called when continuing, not when restarting.
      //executeCallbacks(asyncCallbacks, false);
      tracePath.startRecording();
    }
  }

  function getPaused() {
    return programPaused;
  }

  var wrappedRuntime = {
    notify: wrapNotify,
    runDelayed: wrapRunDelayed,
    node: runtime.node,
    display: runtime.display,
    id: runtime.id,
    addListener: runtime.addListener,
    inputs: runtime.inputs
  };

  var moduleInstance = module.make(wrappedRuntime);
  var moduleNodes = flattenNodes(wrappedRuntime.inputs);
  var tracePath = tracePathInit(runtime);

  return {
    moduleInstance: moduleInstance,
    moduleNodes: moduleNodes,
    initialNodeValues: saveNodeValues(moduleNodes),
    initialAsyncCallbacks: asyncCallbacks.slice(),
    // API functions
    clearAsyncCallbacks: clearAsyncCallbacks,
    clearRecordedEvents: clearRecordedEvents,
    getRecordedEventsLength: getRecordedEventsLength,
    getRecordedEventAt: getRecordedEventAt,
    copyRecordedEvents: copyRecordedEvents,
    loadRecordedEvents: loadRecordedEvents,
    getPaused: getPaused,
    setPaused: setPaused,
    tracePath: tracePath
  };
}

function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
  var Signal = Elm.Signal.make(runtime);

  var tracePathNode = A2(Signal.lift, debugModule.tracePath.graphicsUpdate, debugModule.moduleInstance.main);
  runtime.node.parentNode.appendChild(debugModule.tracePath.canvas);

  var eventCounter = 0;

  function resetProgram() {
    debugModule.clearAsyncCallbacks();
    restoreNodeValues(debugModule.moduleNodes, debugModule.initialNodeValues);
    redrawGraphics();
  }

  function restartProgram() {
    resetProgram();
    debugModule.tracePath.clearTraces();
    debugModule.clearRecordedEvents();
    debugModule.setPaused(false);
    executeCallbacks(debugModule.initialAsyncCallbacks, true);
  }

  function pauseProgram() {
    debugModule.setPaused(true);
    eventCounter = debugModule.getRecordedEventsLength();
  }

  function continueProgram() {
    if (debugModule.getPaused())
    {
      debugModule.setPaused(false);
    }
  }

  function stepTo(index) {
    if (!debugModule.getPaused()) {
      debugModule.setPaused(true);
      resetProgram();
    }

    if (index < 0 || index > getMaxSteps()) {
      throw "Index out of bounds: " + index;
    }

    if (index < eventCounter) {
      resetProgram();
      eventCounter = 0;
    }

    assert(index >= eventCounter, "index must be bad");
    while (eventCounter < index) {
      var nextEvent = debugModule.getRecordedEventAt(eventCounter);
      runtime.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);

      eventCounter += 1;
    }
    assert(eventCounter == index, "while loop didn't work");
  }

  function getMaxSteps() {
    return debugModule.getRecordedEventsLength();
  }

  function doPlayback(eventList) {
    var x = eventList.shift();
    var time = x[2];
    runtime.notify(x[0], x[1], x[2]);

    if (eventList.length > 0) {
      var delta = eventList[0][2] - time;
      setTimeout(function() { doPlayback(eventList); }, delta);
    }
  }

  function redrawGraphics() {
    var graphicsNode = debugModule.moduleInstance.main.kids[0];
    graphicsNode.recv(Date.now(), true, debugModule.moduleInstance.main.id);
  }

  function getHotSwapState() {
    if (debugModule.getPaused()) {
      return {
        recordedEvents: debugModule.copyRecordedEvents(),
        eventCounter: eventCounter
      };
    }
    else {
      return null;
    }
  }

  function dispose() {
    var parentNode = runtime.node.parentNode;
    parentNode.removeChild(debugModule.tracePath.canvas);
    parentNode.removeChild(runtime.node);
  }

  if (hotSwapState) {
    debugModule.setPaused(true);
    debugModule.loadRecordedEvents(hotSwapState.recordedEvents);

    // draw new trace path
    debugModule.tracePath.startRecording();
    stepTo(getMaxSteps());
    debugModule.tracePath.stopRecording();

    stepTo(hotSwapState.eventCounter);
  }

  var elmDebugger = {
      restart: restartProgram,
      pause: pauseProgram,
      kontinue: continueProgram,
      getMaxSteps: getMaxSteps,
      stepTo: stepTo,
      getPaused: debugModule.getPaused,
      getHotSwapState: getHotSwapState,
      dispose: dispose
  };

  return elmDebugger;
}

function Point(x, y) {
  this.x = x;
  this.y = y;

  this.translate = function(x, y) {
    return new Point(this.x + x, this.y + y);
  }

  this.equals = function(p) {
    return this.x == p.x && this.y == p.y;
  }
}

function tracePathInit(runtime) {
  var List = Elm.List.make(runtime);
  var tracePathCanvas = createCanvas();
  var tracePositions = {};
  var recordingTraces = true;

  function findPositions(currentScene) {
    var positions = {};
    function processElement(elem, offset) {
      if (elem.element.ctor == "Custom" && elem.element.type == "Collage")
      {
        List.map(F2(processForm)(offset))(elem.element.model.forms);
      }
      else if (elem.element.ctor == "Image" && elem.props.debugTracePathId)
      {
        positions[elem.props.debugTracePathId] = new Point(offset.x, offset.y);
      }
    }

    function processForm(offset, form) {
      if (form.form.ctor == "FElement")
      {
        processElement(form.form._0, offset.translate(form.x, -form.y));
      }
    }

    processElement(currentScene, new Point(0, 0));
    return positions;
  }

  function appendPositions(positions) {
    for (var id in positions) {
      var pos = positions[id];
      if (tracePositions.hasOwnProperty(id)) {
        var points = tracePositions[id];
        if (!pos.equals(points[points.length-1])) {
          points.push(pos);
        }
      }
      else {
        tracePositions[id] = [pos];
      }
    }
  }

  function graphicsUpdate(currentScene) {
    if (!recordingTraces) {
      return;
    }

    var ctx = tracePathCanvas.getContext('2d');
    ctx.clearRect(0, 0, tracePathCanvas.width, tracePathCanvas.height);

    ctx.save();
    ctx.translate(ctx.canvas.width/2, ctx.canvas.height/2);
    appendPositions(findPositions(currentScene));
    for (var id in tracePositions)
    {
      ctx.beginPath();
      var points = tracePositions[id];
      for (var i=0; i < points.length; i++)
      {
        var p = points[i];
        if (i == 0) {
          ctx.moveTo(p.x, p.y);
        }
        else {
          ctx.lineTo(p.x, p.y);
        }
      }
    }
    ctx.lineWidth = 1;
    ctx.strokeStyle = "black";
    ctx.stroke();

    ctx.restore();
  }

  function clearTraces() {
    tracePositions = {};
  }

  function stopRecording() {
    recordingTraces = false;
  }

  function startRecording() {
    recordingTraces = true;
  }

  return {
    graphicsUpdate: graphicsUpdate,
    canvas: tracePathCanvas,
    clearTraces: clearTraces,
    stopRecording: stopRecording,
    startRecording: startRecording
  }
}

function executeCallbacks(callbacks, reexecute) {
  callbacks.forEach(function(timer) {
    if (reexecute || !timer.executed) {
      var func = timer.func;
      func();
    }
  });
}

function createCanvas() {
  var c = document.createElement('canvas');
  c.width = window.innerWidth;
  c.height = window.innerHeight;
  c.style.position = "absolute";
  c.style.top = "0";
  c.style.left = "0";
  return c;
}

function assert(bool, msg) {
  if (!bool) {
    throw "Assertion error: " + msg;
  }
}

function saveNodeValues(allNodes) {
  var nodeValues = [];

  allNodes.forEach(function(node) {
    nodeValues.push({ value: node.value, id: node.id });
  });

  return nodeValues;
};

function restoreNodeValues(allNodes, nodeStates) {
  assert(allNodes.length == nodeStates.length, "saved program state has wrong length");
  for (var i=0; i < allNodes.length; i++) {
    var node = allNodes[i];
    var state = nodeStates[i];
    assert(node.id == state.id, "the nodes moved position");

    node.value = state.value;
  }
}

function flattenNodes(nodes) {
  var treeReduce = function(prev, cur, i, arr) {
    var flatKids = cur.kids.reduce(treeReduce, []);
    flatKids.push(cur);
    return prev.concat(flatKids);
  }

  return nodes.reduce(treeReduce, []);
};

}());
<commit_msg>Debugger: nicer trace path.<commit_after>
(function() {
'use strict';

Elm.Debugger = null;
Elm.debuggerAttach = function(module, hotSwapState /* =undefined */) {
  return {
    make: function(runtime) {
      var wrappedModule = debugModule(module, runtime);
      Elm.Debugger = debuggerInit(wrappedModule, runtime, hotSwapState);
      dispatchElmDebuggerInit();
      return wrappedModule.moduleInstance;
    }
  };
};

function dispatchElmDebuggerInit() {
  if (parent.window) {
    var dispatch = function(_) {
      parent.window.postMessage("elmDebuggerInit", window.location.origin);
    };
    if (parent.window.document.readyState === "complete") {
      dispatch();
    }
    else {
      parent.window.addEventListener("load", dispatch);
    }
  }
}

function debugModule(module, runtime) {
  var programPaused = false;
  var recordedEvents = [];
  var asyncCallbacks = [];

  function wrapNotify(id, v) {
    var timestep = Date.now();

    if (programPaused) {
      // ignore async events generated while playing back
      // or user events while program is paused
      return false;
    }
    else {
      var changed = runtime.notify(id, v, timestep);
      recordEvent(id, v, timestep);
      if (parent.window) {
        parent.window.postMessage("elmNotify", window.location.origin);
      }
      return changed;
    }
  };

  function wrapRunDelayed(func, delayMs) {
    var cbObj = { func:func, delayMs:delayMs, timerId:0, executed:false };
    var timerId = setTimeout(function() {
        cbObj.executed = true;
        func();
      }, delayMs);
    cbObj.timerId = timerId;
    asyncCallbacks.push(cbObj);
    return timerId;
  }

  function recordEvent(id, v, timestep) {
    recordedEvents.push({ id:id, value:v, timestep:timestep });
  }

  function clearAsyncCallbacks() {
    asyncCallbacks.forEach(function(timer) {
      if (!timer.executed) {
        clearTimeout(timer.timerId);
      }
    });
  }

  function clearRecordedEvents() {
    recordedEvents = [];
  }

  function getRecordedEventsLength() {
    return recordedEvents.length;
  }

  function getRecordedEventAt(i) {
    return recordedEvents[i];
  }

  function copyRecordedEvents() {
    return recordedEvents.slice();
  }

  function loadRecordedEvents(events) {
    recordedEvents = events.slice();
  }

  function setPaused(v) {
    programPaused = v;
    if (programPaused) {
      clearAsyncCallbacks();
      tracePath.stopRecording();
    }
    else {
      // executeCallbacks should only be called when continuing, not when restarting.
      //executeCallbacks(asyncCallbacks, false);
      tracePath.startRecording();
    }
  }

  function getPaused() {
    return programPaused;
  }

  var wrappedRuntime = {
    notify: wrapNotify,
    runDelayed: wrapRunDelayed,
    node: runtime.node,
    display: runtime.display,
    id: runtime.id,
    addListener: runtime.addListener,
    inputs: runtime.inputs
  };

  var moduleInstance = module.make(wrappedRuntime);
  var moduleNodes = flattenNodes(wrappedRuntime.inputs);
  var tracePath = tracePathInit(runtime);

  return {
    moduleInstance: moduleInstance,
    moduleNodes: moduleNodes,
    initialNodeValues: saveNodeValues(moduleNodes),
    initialAsyncCallbacks: asyncCallbacks.slice(),
    // API functions
    clearAsyncCallbacks: clearAsyncCallbacks,
    clearRecordedEvents: clearRecordedEvents,
    getRecordedEventsLength: getRecordedEventsLength,
    getRecordedEventAt: getRecordedEventAt,
    copyRecordedEvents: copyRecordedEvents,
    loadRecordedEvents: loadRecordedEvents,
    getPaused: getPaused,
    setPaused: setPaused,
    tracePath: tracePath
  };
}

function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
  var Signal = Elm.Signal.make(runtime);

  var tracePathNode = A2(Signal.lift, debugModule.tracePath.graphicsUpdate, debugModule.moduleInstance.main);
  runtime.node.parentNode.appendChild(debugModule.tracePath.canvas);

  var eventCounter = 0;

  function resetProgram() {
    debugModule.clearAsyncCallbacks();
    restoreNodeValues(debugModule.moduleNodes, debugModule.initialNodeValues);
    redrawGraphics();
  }

  function restartProgram() {
    resetProgram();
    debugModule.tracePath.clearTraces();
    debugModule.clearRecordedEvents();
    debugModule.setPaused(false);
    executeCallbacks(debugModule.initialAsyncCallbacks, true);
  }

  function pauseProgram() {
    debugModule.setPaused(true);
    eventCounter = debugModule.getRecordedEventsLength();
  }

  function continueProgram() {
    if (debugModule.getPaused())
    {
      debugModule.setPaused(false);
    }
  }

  function stepTo(index) {
    if (!debugModule.getPaused()) {
      debugModule.setPaused(true);
      resetProgram();
    }

    if (index < 0 || index > getMaxSteps()) {
      throw "Index out of bounds: " + index;
    }

    if (index < eventCounter) {
      resetProgram();
      eventCounter = 0;
    }

    assert(index >= eventCounter, "index must be bad");
    while (eventCounter < index) {
      var nextEvent = debugModule.getRecordedEventAt(eventCounter);
      runtime.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);

      eventCounter += 1;
    }
    assert(eventCounter == index, "while loop didn't work");
  }

  function getMaxSteps() {
    return debugModule.getRecordedEventsLength();
  }

  function doPlayback(eventList) {
    var x = eventList.shift();
    var time = x[2];
    runtime.notify(x[0], x[1], x[2]);

    if (eventList.length > 0) {
      var delta = eventList[0][2] - time;
      setTimeout(function() { doPlayback(eventList); }, delta);
    }
  }

  function redrawGraphics() {
    var graphicsNode = debugModule.moduleInstance.main.kids[0];
    graphicsNode.recv(Date.now(), true, debugModule.moduleInstance.main.id);
  }

  function getHotSwapState() {
    if (debugModule.getPaused()) {
      return {
        recordedEvents: debugModule.copyRecordedEvents(),
        eventCounter: eventCounter
      };
    }
    else {
      return null;
    }
  }

  function dispose() {
    var parentNode = runtime.node.parentNode;
    parentNode.removeChild(debugModule.tracePath.canvas);
    parentNode.removeChild(runtime.node);
  }

  if (hotSwapState) {
    debugModule.setPaused(true);
    debugModule.loadRecordedEvents(hotSwapState.recordedEvents);

    // draw new trace path
    debugModule.tracePath.startRecording();
    stepTo(getMaxSteps());
    debugModule.tracePath.stopRecording();

    stepTo(hotSwapState.eventCounter);
  }

  var elmDebugger = {
      restart: restartProgram,
      pause: pauseProgram,
      kontinue: continueProgram,
      getMaxSteps: getMaxSteps,
      stepTo: stepTo,
      getPaused: debugModule.getPaused,
      getHotSwapState: getHotSwapState,
      dispose: dispose
  };

  return elmDebugger;
}

function Point(x, y) {
  this.x = x;
  this.y = y;

  this.translate = function(x, y) {
    return new Point(this.x + x, this.y + y);
  }

  this.equals = function(p) {
    return this.x == p.x && this.y == p.y;
  }
}

function tracePathInit(runtime) {
  var List = Elm.List.make(runtime);
  var tracePathCanvas = createCanvas();
  var tracePositions = {};
  var recordingTraces = true;

  function findPositions(currentScene) {
    var positions = {};
    function processElement(elem, offset) {
      if (elem.element.ctor == "Custom" && elem.element.type == "Collage")
      {
        List.map(F2(processForm)(offset))(elem.element.model.forms);
      }
      else if (elem.element.ctor == "Image" && elem.props.debugTracePathId)
      {
        positions[elem.props.debugTracePathId] = new Point(offset.x, offset.y);
      }
    }

    function processForm(offset, form) {
      if (form.form.ctor == "FElement")
      {
        processElement(form.form._0, offset.translate(form.x, -form.y));
      }
    }

    processElement(currentScene, new Point(0, 0));
    return positions;
  }

  function appendPositions(positions) {
    for (var id in positions) {
      var pos = positions[id];
      if (tracePositions.hasOwnProperty(id)) {
        var points = tracePositions[id];
        if (!pos.equals(points[points.length-1])) {
          points.push(pos);
        }
      }
      else {
        tracePositions[id] = [pos];
      }
    }
  }

  function graphicsUpdate(currentScene) {
    if (!recordingTraces) {
      return;
    }

    var ctx = tracePathCanvas.getContext('2d');
    ctx.clearRect(0, 0, tracePathCanvas.width, tracePathCanvas.height);

    ctx.save();
    ctx.translate(ctx.canvas.width/2, ctx.canvas.height/2);
    appendPositions(findPositions(currentScene));
    for (var id in tracePositions)
    {
      ctx.beginPath();
      var points = tracePositions[id];
      for (var i=0; i < points.length; i++)
      {
        var p = points[i];
        if (i == 0) {
          ctx.moveTo(p.x, p.y);
        }
        else {
          ctx.lineTo(p.x, p.y);
        }
      }
      ctx.lineWidth = 1;
      ctx.strokeStyle = "#888a85";
      ctx.stroke();

      for (var i=0; i < points.length; i++)
      {
        var p = points[i];
        ctx.beginPath();
        ctx.arc(p.x, p.y, 2, 0, Math.PI * 2);
        ctx.fillStyle = "#2e3436";
        ctx.fill();
      }
    }

    ctx.restore();
  }

  function clearTraces() {
    tracePositions = {};
  }

  function stopRecording() {
    recordingTraces = false;
  }

  function startRecording() {
    recordingTraces = true;
  }

  return {
    graphicsUpdate: graphicsUpdate,
    canvas: tracePathCanvas,
    clearTraces: clearTraces,
    stopRecording: stopRecording,
    startRecording: startRecording
  }
}

function executeCallbacks(callbacks, reexecute) {
  callbacks.forEach(function(timer) {
    if (reexecute || !timer.executed) {
      var func = timer.func;
      func();
    }
  });
}

function createCanvas() {
  var c = document.createElement('canvas');
  c.width = window.innerWidth;
  c.height = window.innerHeight;
  c.style.position = "absolute";
  c.style.top = "0";
  c.style.left = "0";
  return c;
}

function assert(bool, msg) {
  if (!bool) {
    throw "Assertion error: " + msg;
  }
}

function saveNodeValues(allNodes) {
  var nodeValues = [];

  allNodes.forEach(function(node) {
    nodeValues.push({ value: node.value, id: node.id });
  });

  return nodeValues;
};

function restoreNodeValues(allNodes, nodeStates) {
  assert(allNodes.length == nodeStates.length, "saved program state has wrong length");
  for (var i=0; i < allNodes.length; i++) {
    var node = allNodes[i];
    var state = nodeStates[i];
    assert(node.id == state.id, "the nodes moved position");

    node.value = state.value;
  }
}

function flattenNodes(nodes) {
  var treeReduce = function(prev, cur, i, arr) {
    var flatKids = cur.kids.reduce(treeReduce, []);
    flatKids.push(cur);
    return prev.concat(flatKids);
  }

  return nodes.reduce(treeReduce, []);
};

}());
<|endoftext|>


<commit_before>var _ = require('lodash');
var postcss = require('postcss');
var expect  = require('chai').expect;

var plugin = require('../');

var test = function (input, output, opts, done) {
    postcss([ plugin(opts) ]).process(input).then(function (result) {
        expect(result.css).to.eql(output);
        expect(result.warnings()).to.be.empty;
        done();
    }).catch(function (error) {
        done(error);
    });
};

function propertyTest(german, english, value) {
    it('converts ' + german + ' to ' + english, function (done) {
        test(
            'a{ ' + german + ': ' + value + '; }',
            'a{ ' + english + ': ' + value + '; }',
            {},
            done
        );
    });
}

function valueTest(german, english, property) {
    it('converts ' + german + ' to ' + english, function (done) {
        test(
            'a{ ' + property + ': ' + german + '; }',
            'a{ ' + property + ': ' + english + '; }',
            {},
            done
        );
    });
}

describe('postcss-german-stylesheets', function () {
    // Test Properties
    _.forEach(plugin.mapProperties, function (value, key) {
        propertyTest(value, key, '10px');
    });

    // Test Values
    _.forEach(plugin.mapValues, function (value, key) {
        valueTest(value, key, 'color');
    });

    // Test important
    it('converts !wichtig to !important', function (done) {
        test('a{ color: white !wichtig; }', 'a{ color: white !important; }', {}, done);
    });
});
<commit_msg>fixed line length error<commit_after>var _ = require('lodash');
var postcss = require('postcss');
var expect  = require('chai').expect;

var plugin = require('../');

var test = function (input, output, opts, done) {
    postcss([ plugin(opts) ]).process(input).then(function (result) {
        expect(result.css).to.eql(output);
        expect(result.warnings()).to.be.empty;
        done();
    }).catch(function (error) {
        done(error);
    });
};

function propertyTest(german, english, value) {
    it('converts ' + german + ' to ' + english, function (done) {
        test(
            'a{ ' + german + ': ' + value + '; }',
            'a{ ' + english + ': ' + value + '; }',
            {},
            done
        );
    });
}

function valueTest(german, english, property) {
    it('converts ' + german + ' to ' + english, function (done) {
        test(
            'a{ ' + property + ': ' + german + '; }',
            'a{ ' + property + ': ' + english + '; }',
            {},
            done
        );
    });
}

describe('postcss-german-stylesheets', function () {
    // Test Properties
    _.forEach(plugin.mapProperties, function (value, key) {
        propertyTest(value, key, '10px');
    });

    // Test Values
    _.forEach(plugin.mapValues, function (value, key) {
        valueTest(value, key, 'color');
    });

    // Test important
    it('converts !wichtig to !important', function (done) {
        test(
            'a{ color: white !wichtig; }',
            'a{ color: white !important; }',
            {},
            done
        );
    });
});
<|endoftext|>