<commit_before>var frisby = require('../lib/frisby');

describe('Frisby object setup', function() {

  it('global setup should be empty', function() {
    expect({
      request: {
        headers: {},
        inspectOnFailure: false,
        json: false,
        baseUri: ''
      }
    }).to.deep.equal(frisby.globalSetup());
  });

  it('should have empty request properties on creation', function() {
    var f1 = frisby.create('test 1');

    expect({
      headers: {},
      inspectOnFailure: false,
      json: false,
      baseUri: ''
    }).to.deep.equal(f1.current.request);
  });

  it('should be independent of other Frisby objects', function() {
    var f1 = frisby.create('test 1');
    var f2 = frisby.create('test 2');

    // Equal setup
    expect(f1.current.request).to.deep.equal(f2.current.request);

    // Different describe statements
    expect(f1.current.describe).not.to.deep.equal(f2.current.describe);

    // Add header only to f1
    f1.addHeaders({
      'Accept': 'application/json'
    });
    f2.addHeaders({
      'Accept': 'application/x-www-form-urlencoded'
    });

    // Different setup
    expect(f1.current.request).not.to.deep.equal(f2.current.request);
  });

  it('should default to json = false', function() {
    expect({
      request: {
        headers: {},
        inspectOnFailure: false,
        json: false,
        baseUri: ''
      }
    }).to.deep.equal(frisby.globalSetup());

    expect(frisby.create('mytest').get('/path').current.outgoing.json).to.deep.equal(false);
  });

  it('should switch to json default = true when global config is configured json', function() {
    frisby.globalSetup({
      request: {
        headers: {},
        inspectOnFailure: false,
        json: true
      }
    });

    expect({
      request: {
        headers: {},
        inspectOnFailure: false,
        json: true
      }
    }).to.deep.equal(frisby.globalSetup());

    expect(frisby.create('mytest').get('/path').current.outgoing.json).to.deep.equal(true);
  });

  it('should be overridable by the params parameter json=false', function() {
    frisby.globalSetup({
      request: {
        headers: {},
        inspectOnFailure: false,
        json: true
      }
    });

    expect({
      request: {
        headers: {},
        inspectOnFailure: false,
        json: true
      }
    }).to.deep.equal(frisby.globalSetup());

    expect(frisby.create('mytest').get('/path', {
      json: false
    }).current.outgoing.json).to.equal(false);
  });

  it('should switch to inspectOnFailure default = true when global config is configured inspectOnFailure', function() {
    frisby.globalSetup({
      request: {
        headers: {},
        inspectOnFailure: true,
        json: false
      }
    });

    expect({
      request: {
        headers: {},
        inspectOnFailure: true,
        json: false
      }
    }).to.deep.equal(frisby.globalSetup());

    expect(frisby.create('mytest').get('/path').current.outgoing.inspectOnFailure).to.deep.equal(true);
  });

  it('should be overridable by the params parameter inspectOnFailure=false', function() {
    frisby.globalSetup({
      request: {
        headers: {},
        inspectOnFailure: true,
        json: false
      }
    });

    expect({
      request: {
        headers: {},
        inspectOnFailure: true,
        json: false
      }
    }).to.deep.equal(frisby.globalSetup());

    expect(frisby.create('mytest').get('/path', {
      inspectOnFailure: false
    }).current.outgoing.inspectOnFailure).to.equal(false);
  });

});
<commit_msg>Adding more tests. Increases coverage slightly.<commit_after>var frisby = require('../lib/frisby');

describe('Frisby object setup', function() {

  it('global setup should be empty', function() {
    expect({
      request: {
        headers: {},
        inspectOnFailure: false,
        json: false,
        baseUri: ''
      }
    }).to.deep.equal(frisby.globalSetup());
  });

  it('should have empty request properties on creation', function() {
    var f1 = frisby.create('test 1');

    expect({
      headers: {},
      inspectOnFailure: false,
      json: false,
      baseUri: ''
    }).to.deep.equal(f1.current.request);
  });

  it('should be independent of other Frisby objects', function() {
    var f1 = frisby.create('test 1');
    var f2 = frisby.create('test 2');

    // Equal setup
    expect(f1.current.request).to.deep.equal(f2.current.request);

    // Different describe statements
    expect(f1.current.describe).not.to.deep.equal(f2.current.describe);

    // Add header only to f1
    f1.addHeaders({
      'Accept': 'application/json'
    });
    f2.addHeaders({
      'Accept': 'application/x-www-form-urlencoded'
    });

    // Different setup
    expect(f1.current.request).not.to.deep.equal(f2.current.request);
  });

  it('should be able to add and remove headers', function() {
    var f1 = frisby.create('test 1');

    // Add header only to f1
    f1.addHeaders({
      'accept': 'application/json'
    });

    // verify that the header is set correctly
    expect(f1.current.request.headers).to.deep.equal({
        'accept': 'application/json'
    });

    // remove the header
    f1.removeHeader('accept');

    // verify that the header is set correctly
    expect(f1.current.request.headers).to.deep.equal({});
  });

  it('should be overrite headers with the same key', function() {
    var f1 = frisby.create('test 1');

    // Add header only to f1
    f1.addHeaders({
      'accept': 'application/json'
    });

    // verify that the header is set correctly
    expect(f1.current.request.headers).to.deep.equal({
      'accept': 'application/json'
    });

    // Add a new accept header
    f1.addHeaders({
      'accept': 'json'
    });

    // verify that there is only one header
    expect(f1.current.request.headers).to.deep.equal({
      'accept': 'json'
    });
  });

  it('should default to json = false', function() {
    expect({
      request: {
        headers: {},
        inspectOnFailure: false,
        json: false,
        baseUri: ''
      }
    }).to.deep.equal(frisby.globalSetup());

    expect(frisby.create('mytest').get('/path').current.outgoing.json).to.deep.equal(false);
  });

  it('should switch to json default = true when global config is configured json', function() {
    frisby.globalSetup({
      request: {
        headers: {},
        inspectOnFailure: false,
        json: true
      }
    });

    expect({
      request: {
        headers: {},
        inspectOnFailure: false,
        json: true
      }
    }).to.deep.equal(frisby.globalSetup());

    expect(frisby.create('mytest').get('/path').current.outgoing.json).to.deep.equal(true);
  });

  it('should should be able to reset the request object with reset()', function() {
      frisby.globalSetup({
          request: {
              headers: { 'X-Stuff': 'stuff header' },
              json: true,
              baseUri: 'https://some.base.url.com/'
          }
      });

      // verify that the global config was set properly
      expect({
          request: {
              headers: { 'X-Stuff': 'stuff header' },
              json: true,
              baseUri: 'https://some.base.url.com/'
          }
      }).to.deep.equal(frisby.globalSetup());

      // verify that the request object has been reset
      expect(frisby.create('mytest').reset().current.request).to.deep.equal({
        headers: {}
      });
  });

  it('should be overridable by the params parameter json=false', function() {
    frisby.globalSetup({
      request: {
        headers: {},
        inspectOnFailure: false,
        json: true
      }
    });

    expect({
      request: {
        headers: {},
        inspectOnFailure: false,
        json: true
      }
    }).to.deep.equal(frisby.globalSetup());

    expect(frisby.create('mytest').get('/path', {
      json: false
    }).current.outgoing.json).to.equal(false);
  });

  it('should switch to inspectOnFailure default = true when global config is configured inspectOnFailure', function() {
    frisby.globalSetup({
      request: {
        headers: {},
        inspectOnFailure: true,
        json: false
      }
    });

    expect({
      request: {
        headers: {},
        inspectOnFailure: true,
        json: false
      }
    }).to.deep.equal(frisby.globalSetup());

    expect(frisby.create('mytest').get('/path').current.outgoing.inspectOnFailure).to.deep.equal(true);
  });

  it('should be overridable by the params parameter inspectOnFailure=false', function() {
    frisby.globalSetup({
      request: {
        headers: {},
        inspectOnFailure: true,
        json: false
      }
    });

    expect({
      request: {
        headers: {},
        inspectOnFailure: true,
        json: false
      }
    }).to.deep.equal(frisby.globalSetup());

    expect(frisby.create('mytest').get('/path', {
      inspectOnFailure: false
    }).current.outgoing.inspectOnFailure).to.equal(false);
  });

});
<|endoftext|>


<commit_before>(function (scope, _) {

    var Utils = {
        is_intercepted: function (a, b) {
            return !(a.x + a.width <= b.x || b.x + b.width <= a.x || a.y + a.height <= b.y || b.y + b.height <= a.y);
        }
    };

    var id_seq = 0;

    var GridStackEngine = function (width, onchange) {
        this.width = width;

        this.nodes = [];
        this.onchange = onchange || function () {};
    };

    GridStackEngine.prototype._fix_collisions = function (node) {
        this.nodes = _.sortBy(this.nodes, function (n) { return -(n.x + n.y * this.width); }, this);

        while (true) {
            var collision_node = _.find(this.nodes, function (n) {
                return n != node && Utils.is_intercepted(n, node);
            }, this);
            if (typeof collision_node == 'undefined') {
                return;
            }
            this.move_node(collision_node, collision_node.x, node.y + node.height,
                collision_node.width, collision_node.height, true);
        }
    };

    GridStackEngine.prototype._pack_nodes = function () {
        this.nodes = _.sortBy(this.nodes, function (n) { return n.x + n.y * this.width; }, this);

        _.each(this.nodes, function (n, i) {
            while (n.y > 0) {
                var new_y = n.y - 1;
                var can_be_moved = i == 0;

                if (i > 0) {
                    var collision_node = _.chain(this.nodes)
                        .first(i)
                        .find(function (bn) {
                            return Utils.is_intercepted({x: n.x, y: new_y, width: n.width, height: n.height}, bn);
                        })
                        .value();
                    can_be_moved = typeof collision_node == 'undefined';
                }

                if (!can_be_moved) {
                    break;
                }
                n.y = new_y;
            }
        }, this);
    };

    GridStackEngine.prototype._prepare_node = function (node, moving) {
        node = _.defaults(node || {}, {width: 1, height: 1, x: 0, y: 0 });

        node.x = parseInt('' + node.x);
        node.y = parseInt('' + node.y);
        node.width = parseInt('' + node.width);
        node.height = parseInt('' + node.height);

        if (node.width > this.width) {
            node.width = this.width;
        }
        else if (node.width < 1) {
            node.width = 1;
        }

        if (node.height < 1) {
            node.height = 1;
        }

        if (node.x < 0) {
            node.x = 0;
        }

        if (node.x + node.width > this.width) {
            if (moving) {
                node.x = this.width - node.width;
            }
            else {
                node.width = this.width - node.x;
            }
        }

        if (node.y < 0) {
            node.y = 0;
        }

        return node;
    };

    GridStackEngine.prototype._notify = function () {
        this.onchange(this.nodes);
    };

    GridStackEngine.prototype.add_node = function(node) {
        node = this._prepare_node(node);

        if (typeof node.max_width != 'undefined') node.width = Math.min(node.width, node.max_width);
        if (typeof node.max_height != 'undefined') node.height = Math.min(node.height, node.max_height);
        if (typeof node.min_width != 'undefined') node.width = Math.max(node.width, node.min_width);
        if (typeof node.min_height != 'undefined') node.height = Math.max(node.height, node.min_height);

        node._id = ++id_seq;
        this.nodes.push(node);
        this._fix_collisions(node);
        this._pack_nodes();
        this._notify();
        return node;
    };

    GridStackEngine.prototype.remove_node = function (node) {
        node._id = null;
        this.nodes = _.without(this.nodes, node);
        this._pack_nodes();
        this._notify(node);
    };

    GridStackEngine.prototype.move_node = function (node, x, y, width, height, no_pack) {
        if (typeof x == 'undefined') x = node.x;
        if (typeof y == 'undefined') y = node.y;
        if (typeof width == 'undefined') width = node.width;
        if (typeof height == 'undefined') height = node.height;

        if (typeof node.max_width != 'undefined') width = Math.min(width, node.max_width);
        if (typeof node.max_height != 'undefined') height = Math.min(height, node.max_height);
        if (typeof node.min_width != 'undefined') width = Math.max(width, node.min_width);
        if (typeof node.min_height != 'undefined') height = Math.max(height, node.min_height);

        if (node.x == x && node.y == y && node.width == width && node.height == height) {
            return node;
        }

        var moving = node.x != x;

        node.x = x;
        node.y = y;
        node.width = width;
        node.height = height;

        node = this._prepare_node(node, moving);

        this._fix_collisions(node);
        if (!no_pack) {
            this._pack_nodes();
            this._notify();
        }
        return node;
    };

    GridStackEngine.prototype.get_grid_height = function () {
        return _.reduce(this.nodes, function (memo, n) { return Math.max(memo, n.y + n.height); }, 0);
    };

    var GridStack = function (el, opts) {
        var self = this;

        this.container = $(el);

        this.opts = _.defaults(opts || {}, {
            width: 12,
            item_class: 'grid-stack-item',
            placeholder_class: 'grid-stack-placeholder',
            handle: '.grid-stack-item-content',
            cell_height: 60,
            vertical_margin: 20
        });

        this.grid = new GridStackEngine(this.opts.width, function (nodes) {
            _.each(nodes, function (n) {
                n.el
                    .attr('data-gs-x', n.x)
                    .attr('data-gs-y', n.y)
                    .attr('data-gs-width', n.width)
                    .attr('data-gs-height', n.height);
            });
        });

        this.container.find('.' + this.opts.item_class).each(function (index, el) {
            self._prepare_element(el);
        });

        this.placeholder = $('

').hide();
        this.container.append(this.placeholder);
        this.container.height((this.grid.get_grid_height()) * (this.opts.cell_height + this.opts.vertical_margin) - this.opts.vertical_margin);
    };

    GridStack.prototype._update_container_height = function () {
        this.container.height(this.grid.get_grid_height() * (this.opts.cell_height + this.opts.vertical_margin) - this.opts.vertical_margin);
    };

    GridStack.prototype._prepare_element = function (el) {
        var self = this;
        el = $(el);

        var node = self.grid.add_node({
            x: el.attr('data-gs-x'),
            y: el.attr('data-gs-y'),
            width: el.attr('data-gs-width'),
            height: el.attr('data-gs-height'),
            max_width: el.attr('data-gs-max-width'),
            min_width: el.attr('data-gs-min-width'),
            max_height: el.attr('data-gs-max-height'),
            min_height: el.attr('data-gs-min-height'),
            el: el
        });
        el.data('_gridstack_node', node);

        var cell_width, cell_height = this.opts.cell_height + this.opts.vertical_margin / 2;

        var on_start_moving = function (event, ui) {
            var o = $(this);
            cell_width = Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
            self.placeholder
                .attr('data-gs-x', o.attr('data-gs-x'))
                .attr('data-gs-y', o.attr('data-gs-y'))
                .attr('data-gs-width', o.attr('data-gs-width'))
                .attr('data-gs-height', o.attr('data-gs-height'))
                .show();
            node.el = self.placeholder;
        };

        var on_end_moving = function (event, ui) {
            var o = $(this);
            node.el = o;
            self.placeholder.hide();
            o
                .attr('data-gs-x', node.x)
                .attr('data-gs-y', node.y)
                .attr('data-gs-width', node.width)
                .attr('data-gs-height', node.height)
                .removeAttr('style');
            self._update_container_height();
        };

        el.draggable({
            handle: this.opts.handle,
            scroll: true,
            appendTo: 'body',

            start: on_start_moving,
            stop: on_end_moving,
            drag: function (event, ui) {
                var x = Math.round(ui.position.left / cell_width),
                    y = Math.floor(ui.position.top / cell_height);
                self.grid.move_node(node, x, y);
                self._update_container_height();
            }
        });
        if (!el.attr('data-gs-no-resize')) {
            el.resizable({
                autoHide: true,
                handles: 'se',
                minHeight: this.opts.cell_height - 10,
                minWidth: 70,

                start: on_start_moving,
                stop: on_end_moving,
                resize: function (event, ui) {
                    var width = Math.round(ui.size.width / cell_width),
                        height = Math.round(ui.size.height / cell_height);
                    self.grid.move_node(node, node.x, node.y, width, height);
                    self._update_container_height();
                }
            });
        }
    };

    GridStack.prototype.add_widget = function (el, x, y, width, height) {
        el = $(el);
        if (typeof x != 'undefined') el.attr('data-gs-x', x);
        if (typeof y != 'undefined') el.attr('data-gs-y', y);
        if (typeof width != 'undefined') el.attr('data-gs-width', width);
        if (typeof height != 'undefined') el.attr('data-gs-height', height);
        this.container.append(el);
        this._prepare_element(el);
    };

    GridStack.prototype.remove_widget = function (el) {
        var node = $(el).data('_gridstack_node');
        this.grid.remove_node(node);
        el.remove();
    };

    scope.GridStackUI = GridStack;

    $.fn.gridstack = function (opts) {
        return this.each(function () {
            if (!$(this).data('gridstack')) {
                $(this).data('gridstack', new GridStack(this, opts));
            }
        });
    };

})(window, _);
<commit_msg>add `auto` option<commit_after>(function (scope, _) {

    var Utils = {
        is_intercepted: function (a, b) {
            return !(a.x + a.width <= b.x || b.x + b.width <= a.x || a.y + a.height <= b.y || b.y + b.height <= a.y);
        }
    };

    var id_seq = 0;

    var GridStackEngine = function (width, onchange) {
        this.width = width;

        this.nodes = [];
        this.onchange = onchange || function () {};
    };

    GridStackEngine.prototype._fix_collisions = function (node) {
        this.nodes = _.sortBy(this.nodes, function (n) { return -(n.x + n.y * this.width); }, this);

        while (true) {
            var collision_node = _.find(this.nodes, function (n) {
                return n != node && Utils.is_intercepted(n, node);
            }, this);
            if (typeof collision_node == 'undefined') {
                return;
            }
            this.move_node(collision_node, collision_node.x, node.y + node.height,
                collision_node.width, collision_node.height, true);
        }
    };

    GridStackEngine.prototype._pack_nodes = function () {
        this.nodes = _.sortBy(this.nodes, function (n) { return n.x + n.y * this.width; }, this);

        _.each(this.nodes, function (n, i) {
            while (n.y > 0) {
                var new_y = n.y - 1;
                var can_be_moved = i == 0;

                if (i > 0) {
                    var collision_node = _.chain(this.nodes)
                        .first(i)
                        .find(function (bn) {
                            return Utils.is_intercepted({x: n.x, y: new_y, width: n.width, height: n.height}, bn);
                        })
                        .value();
                    can_be_moved = typeof collision_node == 'undefined';
                }

                if (!can_be_moved) {
                    break;
                }
                n.y = new_y;
            }
        }, this);
    };

    GridStackEngine.prototype._prepare_node = function (node, moving) {
        node = _.defaults(node || {}, {width: 1, height: 1, x: 0, y: 0 });

        node.x = parseInt('' + node.x);
        node.y = parseInt('' + node.y);
        node.width = parseInt('' + node.width);
        node.height = parseInt('' + node.height);

        if (node.width > this.width) {
            node.width = this.width;
        }
        else if (node.width < 1) {
            node.width = 1;
        }

        if (node.height < 1) {
            node.height = 1;
        }

        if (node.x < 0) {
            node.x = 0;
        }

        if (node.x + node.width > this.width) {
            if (moving) {
                node.x = this.width - node.width;
            }
            else {
                node.width = this.width - node.x;
            }
        }

        if (node.y < 0) {
            node.y = 0;
        }

        return node;
    };

    GridStackEngine.prototype._notify = function () {
        this.onchange(this.nodes);
    };

    GridStackEngine.prototype.add_node = function(node) {
        node = this._prepare_node(node);

        if (typeof node.max_width != 'undefined') node.width = Math.min(node.width, node.max_width);
        if (typeof node.max_height != 'undefined') node.height = Math.min(node.height, node.max_height);
        if (typeof node.min_width != 'undefined') node.width = Math.max(node.width, node.min_width);
        if (typeof node.min_height != 'undefined') node.height = Math.max(node.height, node.min_height);

        node._id = ++id_seq;
        this.nodes.push(node);
        this._fix_collisions(node);
        this._pack_nodes();
        this._notify();
        return node;
    };

    GridStackEngine.prototype.remove_node = function (node) {
        node._id = null;
        this.nodes = _.without(this.nodes, node);
        this._pack_nodes();
        this._notify(node);
    };

    GridStackEngine.prototype.move_node = function (node, x, y, width, height, no_pack) {
        if (typeof x == 'undefined') x = node.x;
        if (typeof y == 'undefined') y = node.y;
        if (typeof width == 'undefined') width = node.width;
        if (typeof height == 'undefined') height = node.height;

        if (typeof node.max_width != 'undefined') width = Math.min(width, node.max_width);
        if (typeof node.max_height != 'undefined') height = Math.min(height, node.max_height);
        if (typeof node.min_width != 'undefined') width = Math.max(width, node.min_width);
        if (typeof node.min_height != 'undefined') height = Math.max(height, node.min_height);

        if (node.x == x && node.y == y && node.width == width && node.height == height) {
            return node;
        }

        var moving = node.x != x;

        node.x = x;
        node.y = y;
        node.width = width;
        node.height = height;

        node = this._prepare_node(node, moving);

        this._fix_collisions(node);
        if (!no_pack) {
            this._pack_nodes();
            this._notify();
        }
        return node;
    };

    GridStackEngine.prototype.get_grid_height = function () {
        return _.reduce(this.nodes, function (memo, n) { return Math.max(memo, n.y + n.height); }, 0);
    };

    var GridStack = function (el, opts) {
        var self = this;

        this.container = $(el);

        this.opts = _.defaults(opts || {}, {
            width: 12,
            item_class: 'grid-stack-item',
            placeholder_class: 'grid-stack-placeholder',
            handle: '.grid-stack-item-content',
            cell_height: 60,
            vertical_margin: 20,
            auto: true
        });

        this.grid = new GridStackEngine(this.opts.width, function (nodes) {
            _.each(nodes, function (n) {
                n.el
                    .attr('data-gs-x', n.x)
                    .attr('data-gs-y', n.y)
                    .attr('data-gs-width', n.width)
                    .attr('data-gs-height', n.height);
            });
        });

        if (this.opts.auto) {
            this.container.find('.' + this.opts.item_class).each(function (index, el) {
                self._prepare_element(el);
            });
        }

        this.placeholder = $('

').hide();
        this.container.append(this.placeholder);
        this.container.height((this.grid.get_grid_height()) * (this.opts.cell_height + this.opts.vertical_margin) - this.opts.vertical_margin);
    };

    GridStack.prototype._update_container_height = function () {
        this.container.height(this.grid.get_grid_height() * (this.opts.cell_height + this.opts.vertical_margin) - this.opts.vertical_margin);
    };

    GridStack.prototype._prepare_element = function (el) {
        var self = this;
        el = $(el);

        var node = self.grid.add_node({
            x: el.attr('data-gs-x'),
            y: el.attr('data-gs-y'),
            width: el.attr('data-gs-width'),
            height: el.attr('data-gs-height'),
            max_width: el.attr('data-gs-max-width'),
            min_width: el.attr('data-gs-min-width'),
            max_height: el.attr('data-gs-max-height'),
            min_height: el.attr('data-gs-min-height'),
            el: el
        });
        el.data('_gridstack_node', node);

        var cell_width, cell_height = this.opts.cell_height + this.opts.vertical_margin / 2;

        var on_start_moving = function (event, ui) {
            var o = $(this);
            cell_width = Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
            self.placeholder
                .attr('data-gs-x', o.attr('data-gs-x'))
                .attr('data-gs-y', o.attr('data-gs-y'))
                .attr('data-gs-width', o.attr('data-gs-width'))
                .attr('data-gs-height', o.attr('data-gs-height'))
                .show();
            node.el = self.placeholder;
        };

        var on_end_moving = function (event, ui) {
            var o = $(this);
            node.el = o;
            self.placeholder.hide();
            o
                .attr('data-gs-x', node.x)
                .attr('data-gs-y', node.y)
                .attr('data-gs-width', node.width)
                .attr('data-gs-height', node.height)
                .removeAttr('style');
            self._update_container_height();
        };

        el.draggable({
            handle: this.opts.handle,
            scroll: true,
            appendTo: 'body',

            start: on_start_moving,
            stop: on_end_moving,
            drag: function (event, ui) {
                var x = Math.round(ui.position.left / cell_width),
                    y = Math.floor(ui.position.top / cell_height);
                self.grid.move_node(node, x, y);
                self._update_container_height();
            }
        });
        if (!el.attr('data-gs-no-resize')) {
            el.resizable({
                autoHide: true,
                handles: 'se',
                minHeight: this.opts.cell_height - 10,
                minWidth: 70,

                start: on_start_moving,
                stop: on_end_moving,
                resize: function (event, ui) {
                    var width = Math.round(ui.size.width / cell_width),
                        height = Math.round(ui.size.height / cell_height);
                    self.grid.move_node(node, node.x, node.y, width, height);
                    self._update_container_height();
                }
            });
        }
    };

    GridStack.prototype.add_widget = function (el, x, y, width, height) {
        el = $(el);
        if (typeof x != 'undefined') el.attr('data-gs-x', x);
        if (typeof y != 'undefined') el.attr('data-gs-y', y);
        if (typeof width != 'undefined') el.attr('data-gs-width', width);
        if (typeof height != 'undefined') el.attr('data-gs-height', height);
        this.container.append(el);
        this._prepare_element(el);
    };

    GridStack.prototype.remove_widget = function (el) {
        var node = $(el).data('_gridstack_node');
        this.grid.remove_node(node);
        el.remove();
    };

    scope.GridStackUI = GridStack;

    $.fn.gridstack = function (opts) {
        return this.each(function () {
            if (!$(this).data('gridstack')) {
                $(this).data('gridstack', new GridStack(this, opts));
            }
        });
    };

})(window, _);
<|endoftext|>


<commit_before>// ==UserScript==
// @author      Robert Slifka (github @rslifka)
// @connect     docs.google.com
// @connect     rslifka.github.io
// @copyright   2017-2018, Robert Slifka (https://github.com/rslifka/fate_of_all_fools)
// @description Enhancements to the Destiny Item Manager
// @grant       GM_addStyle
// @grant       GM_getResourceText
// @grant       GM_getValue
// @grant       GM_log
// @grant       GM_setValue
// @grant       GM_xmlhttpRequest
// @homepage    https://github.com/rslifka/fate_of_all_fools
// @license     MIT; https://raw.githubusercontent.com/rslifka/fate_of_all_fools/master/LICENSE.txt
// @match       https://*.destinyitemmanager.com/*
// @name        Fate of All Fools
// @require     https://rslifka.github.io/fate_of_all_fools/fateOfAllFools.js
// @resource    fateOfAllFoolsCSS https://rslifka.github.io/fate_of_all_fools/fateOfAllFools.css
// @run-at      document-start
// @supportURL  https://github.com/rslifka/fate_of_all_fools/issues
// @version     565
// ==/UserScript==
<commit_msg>AUTO-CREATED Release Artifact v566 c/o Travis<commit_after>// ==UserScript==
// @author      Robert Slifka (github @rslifka)
// @connect     docs.google.com
// @connect     rslifka.github.io
// @copyright   2017-2018, Robert Slifka (https://github.com/rslifka/fate_of_all_fools)
// @description Enhancements to the Destiny Item Manager
// @grant       GM_addStyle
// @grant       GM_getResourceText
// @grant       GM_getValue
// @grant       GM_log
// @grant       GM_setValue
// @grant       GM_xmlhttpRequest
// @homepage    https://github.com/rslifka/fate_of_all_fools
// @license     MIT; https://raw.githubusercontent.com/rslifka/fate_of_all_fools/master/LICENSE.txt
// @match       https://*.destinyitemmanager.com/*
// @name        Fate of All Fools
// @require     https://rslifka.github.io/fate_of_all_fools/fateOfAllFools.js
// @resource    fateOfAllFoolsCSS https://rslifka.github.io/fate_of_all_fools/fateOfAllFools.css
// @run-at      document-start
// @supportURL  https://github.com/rslifka/fate_of_all_fools/issues
// @version     566
// ==/UserScript==
<|endoftext|>


<commit_before>/**
 * Created by Songzhou Yang on 12/1/2016.
 */

const mongoose = require('mongoose')

const NoticeSchema = new mongoose.Schema({
  sequenceNum: {
    type: Number,
    index: true
  },
  title: String,
  publishTime: String,
  state: String,
  content: String
})

const DocumentSchema = new mongoose.Schema({
  sequenceNum: {
    type: Number,
    index: true
  },
  title: {
    type: String,
    index: true
  },
  explanation: String,
  updatingTime: String,
  state: String,
  size: String,
  url: String
})

const AssignmentSchema = new mongoose.Schema({
  sequenceNum: {
    type: Number,
    index: true
  },
  title: {
    type: String,
    index: true
  },
  detail: String,
  startDate: String,
  dueDate: String,
  state: String,
  size: String,
  evaluatingTeacher: String,
  evaluatingDate: String,
  comment: String,
  grade: Number
})

const CourseSchema = new mongoose.Schema({
  courseName: {
    type: String,
    index: true
  },
  courseID: {
    type: String,
    index: true
  },
  unsubmittedOperations: Number,
  unreadNotice: Number,
  newFile: Number,
  notices: [NoticeSchema],
  documents: [DocumentSchema],
  assignments: [AssignmentSchema]
}, {
  toObject: {
    transform: (doc, ret) => {
      delete ret._id
    }
  }
})

const Course = mongoose.model('Course', CourseSchema)

module.exports.Course = Course
module.exports.CourseSchema = CourseSchema
<commit_msg>update notice model<commit_after>/**
 * Created by Songzhou Yang on 12/1/2016.
 */

const mongoose = require('mongoose')

const NoticeSchema = new mongoose.Schema({
  sequenceNum: {
    type: Number,
    index: true
  },
  title: String,
  publisher: String,
  publishTime: String,
  state: String,
  content: String
}, {
  toObject: {
    transform: (doc, ret) => {
      delete ret._id
    }
  }
})

const DocumentSchema = new mongoose.Schema({
  sequenceNum: {
    type: Number,
    index: true
  },
  title: {
    type: String,
    index: true
  },
  explanation: String,
  updatingTime: String,
  state: String,
  size: String,
  url: String
})

const AssignmentSchema = new mongoose.Schema({
  sequenceNum: {
    type: Number,
    index: true
  },
  title: {
    type: String,
    index: true
  },
  detail: String,
  startDate: String,
  dueDate: String,
  state: String,
  size: String,
  evaluatingTeacher: String,
  evaluatingDate: String,
  comment: String,
  grade: Number
})

const CourseSchema = new mongoose.Schema({
  courseName: {
    type: String,
    index: true
  },
  courseID: {
    type: String,
    index: true
  },
  unsubmittedOperations: Number,
  unreadNotice: Number,
  newFile: Number,
  notices: [NoticeSchema],
  documents: [DocumentSchema],
  assignments: [AssignmentSchema]
}, {
  toObject: {
    transform: (doc, ret) => {
      delete ret._id
    }
  }
})

const Notice = mongoose.model('Notice', NoticeSchema)
const Course = mongoose.model('Course', CourseSchema)

module.exports.Notice = Notice
module.exports.Course = Course
module.exports.CourseSchema = CourseSchema
<|endoftext|>


<commit_before>'use strict';

module.exports = function(grunt) {
	// Unified Watch Object
	var watchFiles = {
		//serverViews: ['app/views/**/*.*'],
		//serverJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js'],
		//clientViews: ['public/modules/**/views/**/*.html'],
		//clientJS: ['public/js/*.js', 'public/modules/**/*.js'],
		//clientCSS: ['public/modules/**/*.css'],
		//mochaTests: ['app/tests/**/*.js']
	};

	// Project Configuration
	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),
		watch: {
			serverViews: {
				files: watchFiles.serverViews,
				options: {
					livereload: true
				}
			},
			serverJS: {
				files: watchFiles.serverJS,
				tasks: ['jshint'],
				options: {
					livereload: true
				}
			},
			clientViews: {
				files: watchFiles.clientViews,
				options: {
					livereload: true,
				}
			},
			clientJS: {
				files: watchFiles.clientJS,
				tasks: ['jshint'],
				options: {
					livereload: true
				}
			},
			clientCSS: {
				files: watchFiles.clientCSS,
				tasks: ['csslint'],
				options: {
					livereload: true
				}
			}
		},
		jshint: {
			all: {
				src: watchFiles.clientJS.concat(watchFiles.serverJS),
				options: {
					jshintrc: true
				}
			}
		},
		csslint: {
			options: {
				csslintrc: '.csslintrc',
			},
			all: {
				src: watchFiles.clientCSS
			}
		},
		uglify: {
			production: {
				options: {
					mangle: false
				},
				files: {
					'public/dist/application.min.js': 'public/dist/application.js'
				}
			}
		},
		cssmin: {
			combine: {
				files: {
					'public/dist/application.min.css': '<%= applicationCSSFiles %>'
				}
			}
		},
		nodemon: {
			dev: {
				script: 'server.js',
				options: {
					nodeArgs: ['--debug'],
					ext: 'js,html',
					watch: watchFiles.serverViews.concat(watchFiles.serverJS)
				}
			}
		},
		'node-inspector': {
			custom: {
				options: {
					'web-port': 1337,
					'web-host': 'localhost',
					'debug-port': 5858,
					'save-live-edit': true,
					'no-preload': true,
					'stack-trace-limit': 50,
					'hidden': []
				}
			}
		},
		ngAnnotate: {
			production: {
				files: {
					'public/dist/application.js': '<%= applicationJavaScriptFiles %>'
				}
			}
		},
		concurrent: {
			default: ['nodemon', 'watch'],
			debug: ['nodemon', 'watch', 'node-inspector'],
			options: {
				logConcurrentOutput: true,
				limit: 10
			}
		},
		env: {
			test: {
				NODE_ENV: 'test'
			},
			secure: {
				NODE_ENV: 'secure'
			}
		},
		mochaTest: {
			src: watchFiles.mochaTests,
			options: {
				reporter: 'spec',
				require: 'server.js'
			}
		},
		karma: {
			unit: {
				configFile: 'karma.conf.js'
			}
		}
	});

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

	// Making grunt default to force in order not to break the project.
	grunt.option('force', true);

	// A Task for loading the configuration object
	grunt.task.registerTask('loadConfig', 'Task that loads the config into a grunt option.', function() {
		var init = require('./config/init')();
		var config = require('./config/config');

		grunt.config.set('applicationJavaScriptFiles', config.assets.js);
		grunt.config.set('applicationCSSFiles', config.assets.css);
	});

	// Default task(s).
	grunt.registerTask('default', ['lint', 'concurrent:default']);

	// Debug task.
	grunt.registerTask('debug', ['lint', 'concurrent:debug']);

	// Secure task(s).
	grunt.registerTask('secure', ['env:secure', 'lint', 'concurrent:default']);

	// Lint task(s).
	grunt.registerTask('lint', ['jshint', 'csslint']);

	// Build task(s).
	grunt.registerTask('build', ['lint', 'loadConfig', 'ngAnnotate', 'uglify', 'cssmin']);

	// Test task.
	grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']);
};
<commit_msg>commented out file watching in gruntfile.js<commit_after>'use strict';

module.exports = function(grunt) {
	// Unified Watch Object
	//var watchFiles = {
	//	serverViews: ['app/views/**/*.*'],
	//	serverJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js'],
	//	clientViews: ['public/modules/**/views/**/*.html'],
	//	clientJS: ['public/js/*.js', 'public/modules/**/*.js'],
	//	clientCSS: ['public/modules/**/*.css'],
	//	mochaTests: ['app/tests/**/*.js']
	//};

	var watchFiles = {};

	// Project Configuration
	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),
		watch: {
			serverViews: {
				files: watchFiles.serverViews,
				options: {
					livereload: true
				}
			},
			serverJS: {
				files: watchFiles.serverJS,
				tasks: ['jshint'],
				options: {
					livereload: true
				}
			},
			clientViews: {
				files: watchFiles.clientViews,
				options: {
					livereload: true,
				}
			},
			clientJS: {
				files: watchFiles.clientJS,
				tasks: ['jshint'],
				options: {
					livereload: true
				}
			},
			clientCSS: {
				files: watchFiles.clientCSS,
				tasks: ['csslint'],
				options: {
					livereload: true
				}
			}
		},
		jshint: {
			all: {
				src: watchFiles.clientJS.concat(watchFiles.serverJS),
				options: {
					jshintrc: true
				}
			}
		},
		csslint: {
			options: {
				csslintrc: '.csslintrc',
			},
			all: {
				src: watchFiles.clientCSS
			}
		},
		uglify: {
			production: {
				options: {
					mangle: false
				},
				files: {
					'public/dist/application.min.js': 'public/dist/application.js'
				}
			}
		},
		cssmin: {
			combine: {
				files: {
					'public/dist/application.min.css': '<%= applicationCSSFiles %>'
				}
			}
		},
		nodemon: {
			dev: {
				script: 'server.js',
				options: {
					nodeArgs: ['--debug'],
					ext: 'js,html',
					watch: watchFiles.serverViews.concat(watchFiles.serverJS)
				}
			}
		},
		'node-inspector': {
			custom: {
				options: {
					'web-port': 1337,
					'web-host': 'localhost',
					'debug-port': 5858,
					'save-live-edit': true,
					'no-preload': true,
					'stack-trace-limit': 50,
					'hidden': []
				}
			}
		},
		ngAnnotate: {
			production: {
				files: {
					'public/dist/application.js': '<%= applicationJavaScriptFiles %>'
				}
			}
		},
		concurrent: {
			default: ['nodemon', 'watch'],
			debug: ['nodemon', 'watch', 'node-inspector'],
			options: {
				logConcurrentOutput: true,
				limit: 10
			}
		},
		env: {
			test: {
				NODE_ENV: 'test'
			},
			secure: {
				NODE_ENV: 'secure'
			}
		},
		mochaTest: {
			src: watchFiles.mochaTests,
			options: {
				reporter: 'spec',
				require: 'server.js'
			}
		},
		karma: {
			unit: {
				configFile: 'karma.conf.js'
			}
		}
	});

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

	// Making grunt default to force in order not to break the project.
	grunt.option('force', true);

	// A Task for loading the configuration object
	grunt.task.registerTask('loadConfig', 'Task that loads the config into a grunt option.', function() {
		var init = require('./config/init')();
		var config = require('./config/config');

		grunt.config.set('applicationJavaScriptFiles', config.assets.js);
		grunt.config.set('applicationCSSFiles', config.assets.css);
	});

	// Default task(s).
	grunt.registerTask('default', ['lint', 'concurrent:default']);

	// Debug task.
	grunt.registerTask('debug', ['lint', 'concurrent:debug']);

	// Secure task(s).
	grunt.registerTask('secure', ['env:secure', 'lint', 'concurrent:default']);

	// Lint task(s).
	grunt.registerTask('lint', ['jshint', 'csslint']);

	// Build task(s).
	grunt.registerTask('build', ['lint', 'loadConfig', 'ngAnnotate', 'uglify', 'cssmin']);

	// Test task.
	grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']);
};
<|endoftext|>


<commit_before>"use strict";

var VertxBuffer = org.vertx.java.core.buffer.Buffer;
var NettyBuffer = io.netty.buffer.ByteBuf;
var Unpooled    = io.netty.buffer.Unpooled;
var Charset     = java.nio.charset.Charset

var BufferWrap = io.nodyn.buffer.BufferWrap;

function Buffer() {
  if (!(this instanceof Buffer)) return new Buffer(arguments);

  var self = new JSAdapter(
    Buffer.prototype,
    {
      _buffer: {},
      _charsWritten: 0,
    },
    {
      __get__: function(name) {
        var index = Number(name);
        if ( ( typeof index ) == 'number' && ( ! isNaN(index) ) ) {
          if ( index >= this.length ) {
            return;
          }
          return this._buffer.getByte( index );
        }
      },
      __set__: function(name, value) {
        var index = Number(name);
        if ( ( typeof index) == 'number' && ( ! isNaN(index) ) ) {
          if ( index >= this.length ) {
            return;
          }
          var byte = Number(value) & 0xFF;
          this._buffer.putByte( index, byte );
          return byte;
        }
      }
    } );

  if ( arguments.length == 1 ) {
    var first = arguments[0];
    if ( first instanceof BufferWrap ) {
      self._buffer = first;
    }  else if ( first instanceof VertxBuffer ) {
      self._buffer = new BufferWrap( Unpooled.copiedBuffer( first.byteBuf ) );
    } else if ( first instanceof NettyBuffer ) {
      self._buffer = new BufferWrap( first );
    } else if ( ( typeof first ) == 'number' ) {
      self._buffer = new BufferWrap( first );
    } else if ( ( typeof first ) == 'string' ) {
      self._buffer = new BufferWrap( first.toString(), 'utf8' );
    } else if ( first.length ) {
      self._buffer = new BufferWrap( first.length );
      for ( var i = 0 ; i < first.length ; ++i ) {
        self[i] = first[i];
      }
    }
  } else if ( arguments.length == 2 ) {
    var str = arguments[0];
    var enc = encodingToJava( arguments[1] );
    self._buffer = new BufferWrap( str, enc );
  }

  self.toString = bufferToString;

  return self;
}

Object.defineProperty( Buffer, "_charsWritten", {
  get: function() {
    return BufferWrap._charsWritten;
  }
});

function encodingToJava(enc) {
  enc = enc.toLowerCase();
  if ( enc == 'binary' ) {
    return enc;
  }
  if ( enc == 'ascii' || enc == 'us-ascii') {
    return 'us-ascii';
  }

  if ( enc == 'utf8' || enc == 'utf-8') {
    return 'utf-8';
  }

  if ( enc == 'ucs2' || enc == 'utf16le' || enc == 'utf-16le' ) {
    return 'utf-16le';
  }

  if ( ! Buffer.isEncoding(enc) ) {
    throw new TypeError( 'Unknown encoding: ' + enc );
  }

  return enc;
}

Buffer.encodingToJava = encodingToJava;

Object.defineProperty( Buffer.prototype, "length", {
  get: function() {
    return this._buffer.length;
  }
} );

var bufferToString = function(enc,start,end) {
  if (arguments.length <= 1 && enc == null) {
    return this._buffer.toString( "utf8" );
  }

  if ( end > this._buffer.length ) {
    end = this._buffer.length;
  }

  var codec = Codec.get( enc );

  if ( ! codec ) {
    throw new TypeError( "Unknown encoding: " + enc );
  }

  if ( arguments.length == 1 ) {
    return codec.encode( this );
  }

  if ( arguments.length == 2 ) {
    return codec.encode( this.slice(start) );
  }

  if ( arguments.length == 3 ) {
    return codec.encode( this.slice(start,end) );
  }
};

Buffer.prototype._byteArray = function() {
  return this._buffer.byteArray();
}

Buffer.prototype._vertxBuffer = function() {
  return new VertxBuffer( this._buffer.byteBuf );
}

Buffer.prototype._nettyBuffer = function() {
  return this._buffer.byteBuf;
}

Buffer.prototype.write = function(/*str,offset,len,enc*/) {

  var str = arguments[0];
  var offset = 0;
  var len = this.length - offset;
  var enc = 'utf8';

  if ( arguments.length == 1 ) {
    offset = 0;
  } else if ( arguments.length == 2 ) {
    if ( typeof arguments[1] == 'number' ) {
      offset = arguments[1];
    } else {
      enc = arguments[1];
    }
  } else if ( arguments.length == 3 ) {
    offset = arguments[1];
    if ( typeof arguments[2] == 'number' ) {
      len = arguments[2];
    } else {
      enc = arguments[2];
    }
  } else if ( arguments.length == 4 ) {
    offset = arguments[1];
    len = arguments[2];
    enc = arguments[3];
  }

  enc = encodingToJava(enc);

  return this._buffer.write( str, offset, len, enc );
};

Buffer.prototype.utf8Write = function(str, offset) {
  return this.write( str, offset, this.length, 'utf8' );
}

Buffer.prototype.copy = function(targetBuf,targetStart,sourceStart,sourceEnd) {
  if ( ! targetStart ) {
    targetStart = 0;
  }
  if ( ! sourceStart ) {
    sourceStart = 0;
  }
  if ( ! sourceEnd ) {
    sourceEnd = -1;
  }

  if ( targetStart > ( targetBuf.length - 1 ) ) {
    throw new RangeError( "targetStart out of bounds" );
  }

  return this._buffer.copy( targetBuf._buffer, targetStart, sourceStart, sourceEnd );
};

Buffer.prototype.slice = function(start,end) {
  if ( ! start ) {
    start = 0;
  }
  if ( ! end ) {
    end = -1;
  }
  return new Buffer( this._buffer.slice( start, end ) );
};

// 8-bit Unsigned

Buffer.prototype.readUInt8 = function(offset,noAssert) {
  return this._buffer.readUInt8( offset );
};

Buffer.prototype.writeUInt8 = function(value,offset,noAssert) {
  return this._buffer.writeUInt8( value, offset );
};

// 8-bit Signed

Buffer.prototype.readInt8 = function(offset,noAssert) {
  return this._buffer.readInt8(offset);
};

Buffer.prototype.writeInt8 = function(value,offset,noAssert) {
  return this._buffer.writeInt8( value, offset );
};

// 16-bit Unsigned

Buffer.prototype.readUInt16LE = function(offset,noAssert) {
  return this._buffer.readUInt16LE( offset );
};

Buffer.prototype.readUInt16BE = function(offset,noAssert) {
  return this._buffer.readUInt16BE( offset );
};

Buffer.prototype.writeUInt16LE = function(value,offset,noAssert) {
  return this._buffer.writeUInt16LE(value, offset);
};

Buffer.prototype.writeUInt16BE = function(value,offset,noAssert) {
  return this._buffer.writeUInt16BE(value, offset);
};

// 16-bit Signed

Buffer.prototype.readInt16LE = function(offset,noAssert) {
  return this._buffer.readInt16LE( offset );
};

Buffer.prototype.readInt16BE = function(offset,noAssert) {
  return this._buffer.readInt16BE( offset );
};

Buffer.prototype.writeInt16LE = function(value,offset,noAssert) {
  return this._buffer.writeInt16LE(value,offset);
};

Buffer.prototype.writeInt16BE = function(value,offset,noAssert) {
  return this._buffer.writeInt16BE(value,offset);
};

// 32-bit Unsigned

Buffer.prototype.readUInt32LE = function(offset,noAssert) {
  return this._buffer.readUInt32LE( offset );
};

Buffer.prototype.readUInt32BE = function(offset,noAssert) {
  return this._buffer.readUInt32BE( offset );
};

Buffer.prototype.writeUInt32LE = function(value,offset,noAssert) {
  return this._buffer.writeUInt32LE(value,offset);
};

Buffer.prototype.writeUInt32BE = function(value,offset,noAssert) {
  return this._buffer.writeUInt32BE(value,offset);
};

// 32-bit Signed

Buffer.prototype.readInt32LE = function(offset,noAssert) {
  return this._buffer.readInt32LE(offset);
};

Buffer.prototype.readInt32BE = function(offset,noAssert) {
  return this._buffer.readInt32BE(offset);
};

Buffer.prototype.writeInt32LE = function(value,offset,noAssert) {
  return this._buffer.writeInt32LE(value,offset);
};

Buffer.prototype.writeInt32BE = function(value,offset,noAssert) {
  return this._buffer.writeInt32BE(value, offset);
};

// Float

Buffer.prototype.readFloatLE = function(offset,noAssert) {
  return this._buffer.readFloatLE(offset);
};

Buffer.prototype.readFloatBE = function(offset,noAssert) {
  return this._buffer.readFloatBE(offset);
};

Buffer.prototype.writeFloatLE = function(value,offset,noAssert) {
  return this._buffer.writeFloatLE(value,offset);
};

Buffer.prototype.writeFloatBE = function(value,offset,noAssert) {
  return this._buffer.writeFloatBE(value,offset);
};

// Double

Buffer.prototype.readDoubleLE = function(offset,noAssert) {
  return this._buffer.readDoubleLE(offset);
};

Buffer.prototype.readDoubleBE = function(offset,noAssert) {
  return this._buffer.readDoubleBE(offset);
};

Buffer.prototype.writeDoubleLE = function(value,offset,noAssert) {
  return this._buffer.writeDoubleLE(value, offset);
};

Buffer.prototype.writeDoubleBE = function(value,offset,noAssert) {
  return this._buffer.writeDoubleBE(value,offset);
};

// Class functions

Buffer.prototype.fill = function(value,offset,end) {
  if ( ! offset ) {
    offset = 0;
  }

  if ( ! end ) {
    end = -1;
  }

  if ( end > this.length ) {
    throw new RangeError( 'end out of bounds' );
  }

  this._buffer.fill(value, offset, end);
};

// Class methods

Buffer.byteLength = function(str,enc) {
  if ( ! enc ) {
    enc = 'utf8';
  }

  return BufferWrap.byteLength(str, encodingToJava(enc));
}

Buffer.isEncoding = function(enc) {
  return [
    'ascii', 'us-ascii',
    'utf8', 'utf-8',
    'utf16le', 'utf-16le', 'ucs2',
    'base64',
    'binary',
    'hex' ].indexOf( enc ) >= 0;
}

Buffer.isBuffer = function(obj) {
  return Buffer.prototype.isPrototypeOf( obj );
}

Buffer.concat = function(list,len) {
  if ( ! list || list.length == 0 ) {
    return new Buffer(0);
  }

  if ( list.length == 1 ) {
    return list[0];
  }

  if ( ! len ) {
    len = 0;
    for ( var i = 0 ; i < list.length ; ++i ) {
      len += list[i].length;
    }
  }

  var b = new Buffer(len);
  var start = 0;

  for ( var i = 0 ; i < list.length ; ++i ) {
    start = list[i].copy( b, start );
  }

  return b;
}

module.exports.Buffer = Buffer;
module.exports.SlowBuffer = Buffer;
module.exports.buffer = {
  INSPECT_MAX_BYTES: 50
}

var Codec = require('nodyn/codec');
<commit_msg>Allow non-numeric properties to be set upon the backing-object for buffer.<commit_after>"use strict";

var VertxBuffer = org.vertx.java.core.buffer.Buffer;
var NettyBuffer = io.netty.buffer.ByteBuf;
var Unpooled    = io.netty.buffer.Unpooled;
var Charset     = java.nio.charset.Charset

var BufferWrap = io.nodyn.buffer.BufferWrap;

function Buffer() {
  if (!(this instanceof Buffer)) return new Buffer(arguments);

  var backingObject = {
    _buffer: {},
    _charsWritten: 0,
  };

  var self = new JSAdapter(
    Buffer.prototype,
    backingObject,
    {
      __get__: function(name) {
        var index = Number(name);
        if ( ( typeof index ) == 'number' && ( ! isNaN(index) ) ) {
          if ( index >= this.length ) {
            return;
          }
          return this._buffer.getByte( index );
        } else {
          return backingObject[name];
        }
      },
      __set__: function(name, value) {
        var index = Number(name);
        if ( ( typeof index) == 'number' && ( ! isNaN(index) ) ) {
          if ( index >= this.length ) {
            return;
          }
          var byte = Number(value) & 0xFF;
          this._buffer.putByte( index, byte );
          return byte;
        } else {
          backingObject[name] = value;
        }
      }
    } );

  if ( arguments.length == 1 ) {
    var first = arguments[0];
    if ( first instanceof BufferWrap ) {
      self._buffer = first;
    }  else if ( first instanceof VertxBuffer ) {
      self._buffer = new BufferWrap( Unpooled.copiedBuffer( first.byteBuf ) );
    } else if ( first instanceof NettyBuffer ) {
      self._buffer = new BufferWrap( first );
    } else if ( ( typeof first ) == 'number' ) {
      self._buffer = new BufferWrap( first );
    } else if ( ( typeof first ) == 'string' ) {
      self._buffer = new BufferWrap( first.toString(), 'utf8' );
    } else if ( first.length ) {
      self._buffer = new BufferWrap( first.length );
      for ( var i = 0 ; i < first.length ; ++i ) {
        self[i] = first[i];
      }
    }
  } else if ( arguments.length == 2 ) {
    var str = arguments[0];
    var enc = encodingToJava( arguments[1] );
    self._buffer = new BufferWrap( str, enc );
  }

  self.toString = bufferToString;

  return self;
}

Object.defineProperty( Buffer, "_charsWritten", {
  get: function() {
    return BufferWrap._charsWritten;
  }
});

function encodingToJava(enc) {
  enc = enc.toLowerCase();
  if ( enc == 'binary' ) {
    return enc;
  }
  if ( enc == 'ascii' || enc == 'us-ascii') {
    return 'us-ascii';
  }

  if ( enc == 'utf8' || enc == 'utf-8') {
    return 'utf-8';
  }

  if ( enc == 'ucs2' || enc == 'utf16le' || enc == 'utf-16le' ) {
    return 'utf-16le';
  }

  if ( ! Buffer.isEncoding(enc) ) {
    throw new TypeError( 'Unknown encoding: ' + enc );
  }

  return enc;
}

Buffer.encodingToJava = encodingToJava;

Object.defineProperty( Buffer.prototype, "length", {
  get: function() {
    return this._buffer.length;
  }
} );

var bufferToString = function(enc,start,end) {
  if (arguments.length <= 1 && enc == null) {
    return this._buffer.toString( "utf8" );
  }

  if ( end > this._buffer.length ) {
    end = this._buffer.length;
  }

  var codec = Codec.get( enc );

  if ( ! codec ) {
    throw new TypeError( "Unknown encoding: " + enc );
  }

  if ( arguments.length == 1 ) {
    return codec.encode( this );
  }

  if ( arguments.length == 2 ) {
    return codec.encode( this.slice(start) );
  }

  if ( arguments.length == 3 ) {
    return codec.encode( this.slice(start,end) );
  }
};

Buffer.prototype._byteArray = function() {
  return this._buffer.byteArray();
}

Buffer.prototype._vertxBuffer = function() {
  return new VertxBuffer( this._buffer.byteBuf );
}

Buffer.prototype._nettyBuffer = function() {
  return this._buffer.byteBuf;
}

Buffer.prototype.write = function(/*str,offset,len,enc*/) {

  var str = arguments[0];
  var offset = 0;
  var len = this.length - offset;
  var enc = 'utf8';

  if ( arguments.length == 1 ) {
    offset = 0;
  } else if ( arguments.length == 2 ) {
    if ( typeof arguments[1] == 'number' ) {
      offset = arguments[1];
    } else {
      enc = arguments[1];
    }
  } else if ( arguments.length == 3 ) {
    offset = arguments[1];
    if ( typeof arguments[2] == 'number' ) {
      len = arguments[2];
    } else {
      enc = arguments[2];
    }
  } else if ( arguments.length == 4 ) {
    offset = arguments[1];
    len = arguments[2];
    enc = arguments[3];
  }

  enc = encodingToJava(enc);

  return this._buffer.write( str, offset, len, enc );
};

Buffer.prototype.utf8Write = function(str, offset) {
  return this.write( str, offset, this.length, 'utf8' );
}

Buffer.prototype.copy = function(targetBuf,targetStart,sourceStart,sourceEnd) {
  if ( ! targetStart ) {
    targetStart = 0;
  }
  if ( ! sourceStart ) {
    sourceStart = 0;
  }
  if ( ! sourceEnd ) {
    sourceEnd = -1;
  }

  if ( targetStart > ( targetBuf.length - 1 ) ) {
    throw new RangeError( "targetStart out of bounds" );
  }

  return this._buffer.copy( targetBuf._buffer, targetStart, sourceStart, sourceEnd );
};

Buffer.prototype.slice = function(start,end) {
  if ( ! start ) {
    start = 0;
  }
  if ( ! end ) {
    end = -1;
  }
  return new Buffer( this._buffer.slice( start, end ) );
};

// 8-bit Unsigned

Buffer.prototype.readUInt8 = function(offset,noAssert) {
  return this._buffer.readUInt8( offset );
};

Buffer.prototype.writeUInt8 = function(value,offset,noAssert) {
  return this._buffer.writeUInt8( value, offset );
};

// 8-bit Signed

Buffer.prototype.readInt8 = function(offset,noAssert) {
  return this._buffer.readInt8(offset);
};

Buffer.prototype.writeInt8 = function(value,offset,noAssert) {
  return this._buffer.writeInt8( value, offset );
};

// 16-bit Unsigned

Buffer.prototype.readUInt16LE = function(offset,noAssert) {
  return this._buffer.readUInt16LE( offset );
};

Buffer.prototype.readUInt16BE = function(offset,noAssert) {
  return this._buffer.readUInt16BE( offset );
};

Buffer.prototype.writeUInt16LE = function(value,offset,noAssert) {
  return this._buffer.writeUInt16LE(value, offset);
};

Buffer.prototype.writeUInt16BE = function(value,offset,noAssert) {
  return this._buffer.writeUInt16BE(value, offset);
};

// 16-bit Signed

Buffer.prototype.readInt16LE = function(offset,noAssert) {
  return this._buffer.readInt16LE( offset );
};

Buffer.prototype.readInt16BE = function(offset,noAssert) {
  return this._buffer.readInt16BE( offset );
};

Buffer.prototype.writeInt16LE = function(value,offset,noAssert) {
  return this._buffer.writeInt16LE(value,offset);
};

Buffer.prototype.writeInt16BE = function(value,offset,noAssert) {
  return this._buffer.writeInt16BE(value,offset);
};

// 32-bit Unsigned

Buffer.prototype.readUInt32LE = function(offset,noAssert) {
  return this._buffer.readUInt32LE( offset );
};

Buffer.prototype.readUInt32BE = function(offset,noAssert) {
  return this._buffer.readUInt32BE( offset );
};

Buffer.prototype.writeUInt32LE = function(value,offset,noAssert) {
  return this._buffer.writeUInt32LE(value,offset);
};

Buffer.prototype.writeUInt32BE = function(value,offset,noAssert) {
  return this._buffer.writeUInt32BE(value,offset);
};

// 32-bit Signed

Buffer.prototype.readInt32LE = function(offset,noAssert) {
  return this._buffer.readInt32LE(offset);
};

Buffer.prototype.readInt32BE = function(offset,noAssert) {
  return this._buffer.readInt32BE(offset);
};

Buffer.prototype.writeInt32LE = function(value,offset,noAssert) {
  return this._buffer.writeInt32LE(value,offset);
};

Buffer.prototype.writeInt32BE = function(value,offset,noAssert) {
  return this._buffer.writeInt32BE(value, offset);
};

// Float

Buffer.prototype.readFloatLE = function(offset,noAssert) {
  return this._buffer.readFloatLE(offset);
};

Buffer.prototype.readFloatBE = function(offset,noAssert) {
  return this._buffer.readFloatBE(offset);
};

Buffer.prototype.writeFloatLE = function(value,offset,noAssert) {
  return this._buffer.writeFloatLE(value,offset);
};

Buffer.prototype.writeFloatBE = function(value,offset,noAssert) {
  return this._buffer.writeFloatBE(value,offset);
};

// Double

Buffer.prototype.readDoubleLE = function(offset,noAssert) {
  return this._buffer.readDoubleLE(offset);
};

Buffer.prototype.readDoubleBE = function(offset,noAssert) {
  return this._buffer.readDoubleBE(offset);
};

Buffer.prototype.writeDoubleLE = function(value,offset,noAssert) {
  return this._buffer.writeDoubleLE(value, offset);
};

Buffer.prototype.writeDoubleBE = function(value,offset,noAssert) {
  return this._buffer.writeDoubleBE(value,offset);
};

// Class functions

Buffer.prototype.fill = function(value,offset,end) {
  if ( ! offset ) {
    offset = 0;
  }

  if ( ! end ) {
    end = -1;
  }

  if ( end > this.length ) {
    throw new RangeError( 'end out of bounds' );
  }

  this._buffer.fill(value, offset, end);
};

// Class methods

Buffer.byteLength = function(str,enc) {
  if ( ! enc ) {
    enc = 'utf8';
  }

  return BufferWrap.byteLength(str, encodingToJava(enc));
}

Buffer.isEncoding = function(enc) {
  return [
    'ascii', 'us-ascii',
    'utf8', 'utf-8',
    'utf16le', 'utf-16le', 'ucs2',
    'base64',
    'binary',
    'hex' ].indexOf( enc ) >= 0;
}

Buffer.isBuffer = function(obj) {
  return Buffer.prototype.isPrototypeOf( obj );
}

Buffer.concat = function(list,len) {
  if ( ! list || list.length == 0 ) {
    return new Buffer(0);
  }

  if ( list.length == 1 ) {
    return list[0];
  }

  if ( ! len ) {
    len = 0;
    for ( var i = 0 ; i < list.length ; ++i ) {
      len += list[i].length;
    }
  }

  var b = new Buffer(len);
  var start = 0;

  for ( var i = 0 ; i < list.length ; ++i ) {
    start = list[i].copy( b, start );
  }

  return b;
}

module.exports.Buffer = Buffer;
module.exports.SlowBuffer = Buffer;
module.exports.buffer = {
  INSPECT_MAX_BYTES: 50
}

var Codec = require('nodyn/codec');
<|endoftext|>


<commit_before>'use strict';

module.exports = function (grunt) {
	var taskObject = {
		pkg: grunt.file.readJSON('package.json')
	};

    grunt.file.expand('grunt_tasks/*.js', '!grunt_tasks/_*.js').forEach(function(file) {
        var name = file.split('/');
        name = name[name.length - 1].replace('.js', '');
        var task = require('./'+ file);

        if(grunt.util._.isFunction(task)){
            task(grunt);
        } else {
            taskObject[name] = task;
        }
    });

	grunt.initConfig(taskObject);

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

	grunt.registerTask('default', ['lint']);
	grunt.registerTask('lint', ['jshint:all']);
	grunt.registerTask('test', ['nodeunit']);
	grunt.registerTask('acceptance-test', ['vagrant-up', '','vagrant-destroy']);
};<commit_msg>configured acceptance tests<commit_after>'use strict';

module.exports = function (grunt) {
	var taskObject = {
		pkg: grunt.file.readJSON('package.json')
	};

    grunt.file.expand('grunt_tasks/*.js', '!grunt_tasks/_*.js').forEach(function(file) {
        var name = file.split('/');
        name = name[name.length - 1].replace('.js', '');
        var task = require('./'+ file);

        if(grunt.util._.isFunction(task)){
            task(grunt);
        } else {
            taskObject[name] = task;
        }
    });

	grunt.initConfig(taskObject);

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

	grunt.registerTask('default', ['lint']);
	grunt.registerTask('lint', ['jshint:all']);
	grunt.registerTask('test', ['nodeunit']);
	grunt.registerTask('acceptance', ['vagrant-up', 'nodeunit','vagrant-destroy']);
};<|endoftext|>


<commit_before>module.exports = function(grunt) {

  grunt.initConfig({

      jshint: {
      files: ['./lib/hello.js','./lib/index.js'],
      options: {
        globals: {
          jQuery: true
        }
      }
    },

    uglify: {
      options: {
      mangle: false
        },

    my_target: {
      files: {
        'dest/output.min.js': ['./lib/hello.js','./lib/index.js']
      }
    }
  },

      /*env: {
      coverage: {
        APP_DIR_FOR_CODE_COVERAGE: '../test/coverage/instrument/app/'
      }
    },*/

      instrument: {
      files: 'lib/*.js',
      options: {
        lazy: true,
        basePath: 'test/coverage/instrument/'
      }
    },

  simplemocha: {
      options: {
          globals: ['chai'],
          timeout: 3000,
          ignoreLeaks: false,
          reporter: 'mochawesome'
    },
    all: { src: ['test/*-test.js'] }
  },

    /*storeCoverage: {
      options: {
        dir: 'test/coverage/reports'
      }
    },*/
/*    makeReport: {
      src: 'test/coverage/reports/**//**.json',
      options: {
        type: 'lcov',
        dir: 'test/coverage/reports',
        print: 'detail'
      }
    },*/

      plato: {
  your_task: {
    options : {
      jshint : grunt.file.readJSON('./node_modules/grunt-plato/.jshintrc')
     // simplemocha: grunt.file.readJSON('./node_modules/grunt-plato/test/plato_test.js')
    },
    files: {
      'reports': ['./lib/hello.js','./lib/index.js']
    }
  }
},
jasmine_node: {
        options: {
      forceExit: true,
      match: '.',
      matchall: false,
      extensions: 'js',
      specNameMatcher: 'spec'

    },
   //all1: ['spec/'],
	report: {
    type: 'html',
    options: {
        dir: 'bin/coverage/html'
    }
}
  }

});
// grunt.registerTask('coverage', ['instrument', 'simplemocha', /*'storeCoverage',*/ 'makeReport']);

  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-simple-mocha');
  grunt.loadNpmTasks('grunt-plato');
    grunt.loadNpmTasks('grunt-istanbul');
	grunt.loadNpmTasks('grunt-jasmine-node');
//  grunt.loadNpmTasks('grunt-mocha');

  grunt.registerTask('default', ['jshint','uglify','simplemocha','plato'/*,'makeReport'*/])
     grunt.registerTask('test', [ 'jasmine_node']);

};
<commit_msg>commited<commit_after>module.exports = function(grunt) {

  grunt.initConfig({

      jshint: {
      files: ['./lib/hello.js','./lib/index.js'],
      options: {
        globals: {
          jQuery: true
        }
      }
    },

    uglify: {
      options: {
      mangle: false
        },

    my_target: {
      files: {
        'dest/output.min.js': ['./lib/hello.js','./lib/index.js']
      }
    }
  },

      /*env: {
      coverage: {
        APP_DIR_FOR_CODE_COVERAGE: '../test/coverage/instrument/app/'
      }
    },*/

      instrument: {
      files: 'lib/*.js',
      options: {
        lazy: true,
        basePath: 'test/coverage/instrument/'
      }
    },

  simplemocha: {
      options: {
          globals: ['chai'],
          timeout: 3000,
          ignoreLeaks: false,
          reporter: 'mochawesome'
    },
    all: { src: ['test/*-test.js'] }
  },

    /*storeCoverage: {
      options: {
        dir: 'test/coverage/reports'
      }
    },*/
    makeReport: {
      src: 'test/coverage/reports/**//**.json',
      options: {
        type: 'lcov',
        dir: 'test/coverage/reports',
        print: 'detail'
      }
    },

      plato: {
  your_task: {
    options : {
      jshint : grunt.file.readJSON('./node_modules/grunt-plato/.jshintrc')
     // simplemocha: grunt.file.readJSON('./node_modules/grunt-plato/test/plato_test.js')
    },
    files: {
      'reports': ['./lib/hello.js','./lib/index.js']
    }
  }
},
jasmine_node: {
        options: {
      forceExit: true,
      match: '.',
      matchall: false,
      extensions: 'js',
      specNameMatcher: 'spec'

    },
   //all1: ['spec/'],
	report: {
    type: 'html',
    options: {
        dir: 'bin/coverage/html'
    }
}
  }

});
// grunt.registerTask('coverage', ['instrument', 'simplemocha', /*'storeCoverage',*/ 'makeReport']);

  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-simple-mocha');
  grunt.loadNpmTasks('grunt-plato');
    grunt.loadNpmTasks('grunt-istanbul');
	grunt.loadNpmTasks('grunt-jasmine-node');
//  grunt.loadNpmTasks('grunt-mocha');

  grunt.registerTask('default', ['jshint','uglify','simplemocha','plato','makeReport'])
     grunt.registerTask('test', [ 'jasmine_node']);

};
<|endoftext|>


<commit_before>module.exports = function (grunt) {
    "use strict";
    /*eslint-env node*/

    // This will measure the time spent in each task
    require("time-grunt")(grunt);

    // Check the number of stories
    var fs = require("fs"),
        storyCount = 0,
        copySettings = {
            init: {
                expand: true,
                cwd: "ref/",
                src: "*.js",
                dest: "src/"
            }
        };
    (function () {
        var index = 1,
            stats;
        while (true) { //eslint-disable-line no-constant-condition
            try {
                stats = fs.statSync("ref/us" + index);
            } catch (e) {
                break;
            }
            if (!stats.isDirectory()) {
                break;
            }
            ++storyCount;
            copySettings["us" + index] = {
                expand: true,
                cwd: "ref/us" + index + "/",
                src: "*.js",
                dest: "src/"
            };
            ++index;
        }
    }());

    // This will configure each task individually
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),

        // https://www.npmjs.com/package/grunt-serve
        connect: {
            server: {
                options: {
                    port: 9000
                }
            }
        },

        // https://www.npmjs.com/package/grunt-contrib-copy
        copy: copySettings,

        // https://www.npmjs.com/package/grunt-eslint
        eslint: {
            target: [
                "src/*.js"
            ]
        },

        // https://www.npmjs.com/package/grunt-mocha-test
        mochaTest: {
            test: {
                options: {
                    reporter: "spec",
                    require: [
                        "node.js"
                    ]
                },
                src: "src/test.js"
            },
            coverage: {
                options: {
                    quiet: true,
                    reporter: "html-cov",
                    captureFile: "tmp/coverage.html"
                },
                src: "src/test.js"
            },
            coverageJSON: {
                options: {
                    reporter: "json-cov",
                    quiet: true,
                    captureFile: "tmp/coverage.json"
                },
                src: "src/test.js"
            }
        },

        // https://www.npmjs.com/package/grunt-notify
        notify: {
            eslint: {
                options: {
                    title: "Training on functions stub",
                    message: "Verified with ESLint"
                }
            },
            coverage: {
                options: {
                    title: "Training on functions stub"
                }
            }
        },

        // https://www.npmjs.com/package/grunt-contrib-watch
        watch: {
            scripts: {
                files: ["src/*.js"],
                tasks: [
                    "eslint",
                    "notify:eslint",
                    "mochaTest",
                    "updateCoverage",
                    "notifySetCoverage",
                    "notify:coverage"
                ],
                options: {
                    spawn: true
                }
            }
        }

    });

    // Load the packages that adds features to grunt
    [
        "grunt-contrib-connect",
        "grunt-contrib-copy",
        "grunt-contrib-watch",
        "grunt-eslint",
        "grunt-mocha-test",
        "grunt-notify"
    ].forEach(function (packageName) {
        grunt.loadNpmTasks(packageName);
    });

    grunt.registerTask("md2html", "Converts User Story markdown to HTML", function () {
        var storyIndex = 0,
            showdown  = require("showdown"),
            converter = new showdown.Converter(),
            mdContent,
            htmlContent;
        while (storyIndex < storyCount) {
            ++storyIndex;
            mdContent = fs.readFileSync("ref/us" + storyIndex + "/README.md").toString();
            htmlContent = "<link rel=\"stylesheet\" href=\"../us.css\" />\r\n" + converter.makeHtml(mdContent);
            fs.writeFileSync("tmp/us" + storyIndex + ".html", htmlContent);
        }
    });

    grunt.registerTask("updateCoverage", "Append fix-coverage to the generated coverage file", function () {
        fs.writeFileSync("tmp/coverage.html", fs.readFileSync("tmp/coverage.html").toString()
            + fs.readFileSync("fix-coverage.html").toString());
    });

    grunt.registerTask("notifySetCoverage", function () {
        var coverageData = grunt.file.readJSON("tmp/coverage.json"),
            message = "Tested, coverage: ";
        if (coverageData.sloc) {
            message += Math.floor(1000 * coverageData.hits / coverageData.sloc) / 10 + "%";
        } else {
            message += "N/A";
        }
        grunt.config.set("notify.coverage.options.message", message);
    });

    // Default task
    grunt.registerTask("default", [
        "md2html",
        "connect:server",
        "watch"
    ]);

};
<commit_msg>Removes US conversions to HTML<commit_after>module.exports = function (grunt) {
    "use strict";
    /*eslint-env node*/

    // This will measure the time spent in each task
    require("time-grunt")(grunt);

    // Check the number of stories
    var fs = require("fs"),
        storyCount = 0,
        copySettings = {
            init: {
                expand: true,
                cwd: "ref/",
                src: "*.js",
                dest: "src/"
            }
        };
    (function () {
        var index = 1,
            stats;
        while (true) { //eslint-disable-line no-constant-condition
            try {
                stats = fs.statSync("ref/us" + index);
            } catch (e) {
                break;
            }
            if (!stats.isDirectory()) {
                break;
            }
            ++storyCount;
            copySettings["us" + index] = {
                expand: true,
                cwd: "ref/us" + index + "/",
                src: "*.js",
                dest: "src/"
            };
            ++index;
        }
    }());

    // This will configure each task individually
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),

        // https://www.npmjs.com/package/grunt-serve
        connect: {
            server: {
                options: {
                    port: 9000
                }
            }
        },

        // https://www.npmjs.com/package/grunt-contrib-copy
        copy: copySettings,

        // https://www.npmjs.com/package/grunt-eslint
        eslint: {
            target: [
                "src/*.js"
            ]
        },

        // https://www.npmjs.com/package/grunt-mocha-test
        mochaTest: {
            test: {
                options: {
                    reporter: "spec",
                    require: [
                        "node.js"
                    ]
                },
                src: "src/test.js"
            },
            coverage: {
                options: {
                    quiet: true,
                    reporter: "html-cov",
                    captureFile: "tmp/coverage.html"
                },
                src: "src/test.js"
            },
            coverageJSON: {
                options: {
                    reporter: "json-cov",
                    quiet: true,
                    captureFile: "tmp/coverage.json"
                },
                src: "src/test.js"
            }
        },

        // https://www.npmjs.com/package/grunt-notify
        notify: {
            eslint: {
                options: {
                    title: "Training on functions stub",
                    message: "Verified with ESLint"
                }
            },
            coverage: {
                options: {
                    title: "Training on functions stub"
                }
            }
        },

        // https://www.npmjs.com/package/grunt-contrib-watch
        watch: {
            scripts: {
                files: ["src/*.js"],
                tasks: [
                    "eslint",
                    "notify:eslint",
                    "mochaTest",
                    "updateCoverage",
                    "notifySetCoverage",
                    "notify:coverage"
                ],
                options: {
                    spawn: true
                }
            }
        }

    });

    // Load the packages that adds features to grunt
    [
        "grunt-contrib-connect",
        "grunt-contrib-copy",
        "grunt-contrib-watch",
        "grunt-eslint",
        "grunt-mocha-test",
        "grunt-notify"
    ].forEach(function (packageName) {
        grunt.loadNpmTasks(packageName);
    });

    grunt.registerTask("updateCoverage", "Append fix-coverage to the generated coverage file", function () {
        fs.writeFileSync("tmp/coverage.html", fs.readFileSync("tmp/coverage.html").toString()
            + fs.readFileSync("fix-coverage.html").toString());
    });

    grunt.registerTask("notifySetCoverage", function () {
        var coverageData = grunt.file.readJSON("tmp/coverage.json"),
            message = "Tested, coverage: ";
        if (coverageData.sloc) {
            message += Math.floor(1000 * coverageData.hits / coverageData.sloc) / 10 + "%";
        } else {
            message += "N/A";
        }
        grunt.config.set("notify.coverage.options.message", message);
    });

    // Default task
    grunt.registerTask("default", [
        "md2html",
        "connect:server",
        "watch"
    ]);

};
<|endoftext|>


<commit_before>'use strict';

module.exports = function(grunt) {
    // Project Configuration
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        watch: {
            serverViews: {
                files: ['app/views/**'],
                options: {
                    livereload: true,
                }
            },
            serverJS: {
                files: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js'],
                tasks: ['jshint'],
                options: {
                    livereload: true,
                }
            },
            clientViews: {
                files: ['public/modules/**/views/*.html'],
                options: {
                    livereload: true,
                }
            },
            clientJS: {
                files: ['public/js/**/*.js', 'public/modules/**/*.js'],
                tasks: ['jshint'],
                options: {
                    livereload: true,
                }
            },
            clientCSS: {
                files: ['public/**/css/*.css'],
                tasks: ['csslint'],
                options: {
                    livereload: true,
                }
            }
        },
        jshint: {
            all: {
                src: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js', 'public/js/**/*.js', 'public/modules/**/*.js'],
                options: {
                    jshintrc: true
                }
            }
        },
        csslint: {
            options: {
                csslintrc: '.csslintrc',
            },
            all: {
                src: ['public/modules/**/css/*.css']
            }
        },
        uglify: {
            production: {
                options: {
                    mangle: false
                },
                files: {
                    'public/dist/application.min.js': '<%= applicationJavaScriptFiles %>'
                }
            }
        },
        cssmin: {
            combine: {
                files: {
                    'public/dist/application.min.css': '<%= applicationCSSFiles %>'
                }
            }
        },
        nodemon: {
            dev: {
                script: 'server.js',
                options: {
                    nodeArgs: ['--debug']
                }
            }
        },
        concurrent: {
            tasks: ['nodemon', 'watch'],
            options: {
                logConcurrentOutput: true
            }
        },
        env: {
            test: {
                NODE_ENV: 'test'
            }
        },
        mochaTest: {
            src: ['app/tests/**/*.js'],
            options: {
                reporter: 'spec',
                require: 'server.js'
            }
        },
        karma: {
            unit: {
                configFile: 'karma.conf.js'
            }
        }
    });

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

    // Making grunt default to force in order not to break the project.
    grunt.option('force', true);

    // A Task for loading the configuration object
    grunt.task.registerTask('loadConfig', 'Task that loads the config into a grunt option.', function() {
    	var init = require('./config/init')();
    	var config = require('./config/config');

    	grunt.config.set('applicationJavaScriptFiles', config.assets.js);
    	grunt.config.set('applicationCSSFiles', config.assets.css);
    });

    // Default task(s).
    grunt.registerTask('default', ['jshint', 'csslint', 'concurrent']);

    // Lint task(s).
    grunt.registerTask('lint', ['jshint', 'csslint']);

    // Build task(s).
    grunt.registerTask('build', ['jshint', 'csslint', 'loadConfig' ,'uglify', 'cssmin']);

    // Test task.
    grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']);
};<commit_msg>Add 'grunt debug' task<commit_after>'use strict';

module.exports = function(grunt) {
    // Project Configuration
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        watch: {
            serverViews: {
                files: ['app/views/**'],
                options: {
                    livereload: true,
                }
            },
            serverJS: {
                files: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js'],
                tasks: ['jshint'],
                options: {
                    livereload: true,
                }
            },
            clientViews: {
                files: ['public/modules/**/views/*.html'],
                options: {
                    livereload: true,
                }
            },
            clientJS: {
                files: ['public/js/**/*.js', 'public/modules/**/*.js'],
                tasks: ['jshint'],
                options: {
                    livereload: true,
                }
            },
            clientCSS: {
                files: ['public/**/css/*.css'],
                tasks: ['csslint'],
                options: {
                    livereload: true,
                }
            }
        },
        jshint: {
            all: {
                src: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js', 'public/js/**/*.js', 'public/modules/**/*.js'],
                options: {
                    jshintrc: true
                }
            }
        },
        csslint: {
            options: {
                csslintrc: '.csslintrc',
            },
            all: {
                src: ['public/modules/**/css/*.css']
            }
        },
        uglify: {
            production: {
                options: {
                    mangle: false
                },
                files: {
                    'public/dist/application.min.js': '<%= applicationJavaScriptFiles %>'
                }
            }
        },
        cssmin: {
            combine: {
                files: {
                    'public/dist/application.min.css': '<%= applicationCSSFiles %>'
                }
            }
        },
        nodemon: {
            dev: {
                script: 'server.js',
                options: {
                    nodeArgs: ['--debug']
                }
            }
        },
        'node-inspector': {
            custom: {
                options: {
                    'web-port': 1337,
                    'web-host': 'localhost',
                    'debug-port': 5858,
                    'save-live-edit': true,
                    'no-preload': true,
                    'stack-trace-limit': 50,
                    'hidden': []
                }
            }
        },
        concurrent: {
            default: ['nodemon', 'watch'],
            debug: ['nodemon', 'watch', 'node-inspector'],
             options: {
                logConcurrentOutput: true
            }
        },
        env: {
            test: {
                NODE_ENV: 'test'
            }
        },
        mochaTest: {
            src: ['app/tests/**/*.js'],
            options: {
                reporter: 'spec',
                require: 'server.js'
            }
        },
        karma: {
            unit: {
                configFile: 'karma.conf.js'
            }
        }
    });

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

    // Making grunt default to force in order not to break the project.
    grunt.option('force', true);

    // A Task for loading the configuration object
    grunt.task.registerTask('loadConfig', 'Task that loads the config into a grunt option.', function() {
    	var init = require('./config/init')();
    	var config = require('./config/config');

    	grunt.config.set('applicationJavaScriptFiles', config.assets.js);
    	grunt.config.set('applicationCSSFiles', config.assets.css);
    });

    // Default task(s).
    grunt.registerTask('default', ['jshint', 'csslint', 'concurrent:default']);

    // Debug task.
    grunt.registerTask('debug', ['jshint', 'csslint', 'concurrent:debug']);

    // Lint task(s).
    grunt.registerTask('lint', ['jshint', 'csslint']);

    // Build task(s).
    grunt.registerTask('build', ['jshint', 'csslint', 'loadConfig' ,'uglify', 'cssmin']);

    // Test task.
    grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']);
};<|endoftext|>


<commit_before>module.exports = function(grunt){
    grunt.initConfig({
        "pkg": "package.json",
        "jshint": {
            "files": ["src/**/*.js","test/**/*.js"],
            "options": {
                "curly": true,
                "eqeqeq": true,
                "latedef": true,
                "indent": 4,
                "noempty": true,
                "quotmark": "double",
                "undef": true
            }
        },
        "mochaTest": {
            "test": {
                "options": {
                    "reporter": "json"
                },
                "src": ["test/**/*.js"]
            }
        },
        "jsbeautifier" : {
            "default": {
                src: ["src/**/*.js", "test/**/*.js", "src/**/*.html","*/**.json"]
            },
            "options": {
                "html": {
                    "brace_style": "collapse",
                    "indent_char": " ",
                    "indent_scripts": "keep",
                    "indent_size": 4,
                    "max_preserve_newlines": 10,
                    "preserve_newlines": true,
                    "unformatted": ["a", "sub", "sup", "b", "i", "u"],
                    "wrap_line_length": 0
                },
                "js": {
                    "brace_style": "collapse",
                    "break_chained_methods": false,
                    "e4x": false,
                    "eval_code": false,
                    "indent_char": " ",
                    "indent_level": 0,
                    "indent_size": 4,
                    "indent_with_tabs": false,
                    "jslint_happy": true,
                    "keep_array_indentation": false,
                    "keep_function_indentation": false,
                    "max_preserve_newlines": 10,
                    "preserve_newlines": true,
                    "space_before_conditional": true,
                    "space_in_paren": false,
                    "unescape_strings": false,
                    "wrap_line_length": 80
                }
            }
        }
    });

    grunt.loadNpmTasks("grunt-contrib-uglify");
    grunt.loadNpmTasks("grunt-jsbeautifier");
    grunt.loadNpmTasks("grunt-contrib-jshint");
    grunt.loadNpmTasks("grunt-mocha-test");
    grunt.registerTask("default", ["jsbeautifier:default", "jshint"]);
    grunt.registerTask("test", ["jsbeautifier:default", "jshint","mochaTest"]);
    grunt.registerTask("speed", function(){require("./benchmark/solver.play");});
}
<commit_msg>removed auto-format in grunt<commit_after>module.exports = function(grunt){
    grunt.initConfig({
        "pkg": "package.json",
        "jshint": {
            "files": ["src/**/*.js","test/**/*.js"],
            "options": {
                "curly": true,
                "eqeqeq": true,
                "latedef": true,
                "indent": 4,
                "noempty": true,
                "quotmark": "double",
                "undef": true
            }
        },
        "mochaTest": {
            "test": {
                "options": {
                    "reporter": "spec"
                },
                "src": ["test/**/*.js"]
            }
        },
        "jsbeautifier" : {
            "default": {
                src: ["src/**/*.js", "test/**/*.js", "src/**/*.html","*/**.json"]
            },
            "options": {
                "html": {
                    "brace_style": "collapse",
                    "indent_char": " ",
                    "indent_scripts": "keep",
                    "indent_size": 4,
                    "max_preserve_newlines": 10,
                    "preserve_newlines": true,
                    "unformatted": ["a", "sub", "sup", "b", "i", "u"],
                    "wrap_line_length": 0
                },
                "js": {
                    "brace_style": "collapse",
                    "break_chained_methods": false,
                    "e4x": false,
                    "eval_code": false,
                    "indent_char": " ",
                    "indent_level": 0,
                    "indent_size": 4,
                    "indent_with_tabs": false,
                    "jslint_happy": true,
                    "keep_array_indentation": false,
                    "keep_function_indentation": false,
                    "max_preserve_newlines": 10,
                    "preserve_newlines": true,
                    "space_before_conditional": true,
                    "space_in_paren": false,
                    "unescape_strings": false,
                    "wrap_line_length": 80
                }
            }
        }
    });

    grunt.loadNpmTasks("grunt-contrib-uglify");
    grunt.loadNpmTasks("grunt-jsbeautifier");
    grunt.loadNpmTasks("grunt-contrib-jshint");
    grunt.loadNpmTasks("grunt-mocha-test");
    grunt.registerTask("default", ["jsbeautifier:default", "jshint"]);
    grunt.registerTask("test", ["jshint","mochaTest"]);
    grunt.registerTask("speed", function(){require("./benchmark/solver.play");});
}
<|endoftext|>


<commit_before>var http=require('http');
http.createServer(function(req,res){
	res.writeHead(200,{'Content-Type':'text/plain'});
	res.end('Hello World\n');
}).listen(1337,'127.0.0.1');<commit_msg>init test<commit_after>var http=require('http');
http.createServer(function(req,res){
	res.writeHead(200,{'Content-Type':'text/plain'});
	res.end('Hello World\n');
}).listen(1337,'127.0.0.1');
console.log('server start');<|endoftext|>