twigg-app 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/javascripts/_bootstrap.js +7 -0
- data/assets/javascripts/_jquery.js +19 -0
- data/assets/javascripts/_tables.js +3 -0
- data/assets/javascripts/_views.js +10 -0
- data/assets/javascripts/application.js +9 -0
- data/{public/application.js → assets/javascripts/views/_commit_set_bar_chart.js} +32 -34
- data/assets/javascripts/views/_russia.js +61 -0
- data/assets/javascripts/views/_tags.js +56 -0
- data/assets/javascripts/views/_tags_word_cloud.js +51 -0
- data/assets/stylesheets/_bootstrap_overrides.scss +15 -0
- data/assets/stylesheets/_footer.scss +28 -0
- data/assets/stylesheets/_global.scss +14 -0
- data/assets/stylesheets/_tables.scss +20 -0
- data/assets/stylesheets/application.scss +10 -0
- data/assets/stylesheets/d3/_bar_chart.scss +25 -0
- data/assets/stylesheets/d3/_bubble_chart.scss +22 -0
- data/lib/twigg-app/app/routes.rb +4 -0
- data/lib/twigg-app/app/server.rb +78 -21
- data/lib/twigg-app/app/version.rb +1 -1
- data/public/vendor/bootstrap/Gruntfile.js +32 -10
- data/public/vendor/bootstrap/README.md +2 -0
- data/public/vendor/bootstrap/_config.yml +5 -10
- data/public/vendor/bootstrap/_includes/footer.html +2 -1
- data/public/vendor/bootstrap/_includes/nav-components.html +33 -31
- data/public/vendor/bootstrap/_includes/nav-css.html +32 -22
- data/public/vendor/bootstrap/_includes/nav-getting-started.html +17 -1
- data/public/vendor/bootstrap/_includes/nav-javascript.html +1 -1
- data/public/vendor/bootstrap/_includes/nav-main.html +1 -1
- data/public/vendor/bootstrap/_includes/social-buttons.html +1 -1
- data/public/vendor/bootstrap/_layouts/default.html +18 -14
- data/public/vendor/bootstrap/_layouts/home.html +9 -6
- data/public/vendor/bootstrap/assets/css/docs.css +584 -396
- data/public/vendor/bootstrap/assets/ico/apple-touch-icon-114-precomposed.png +0 -0
- data/public/vendor/bootstrap/assets/ico/apple-touch-icon-144-precomposed.png +0 -0
- data/public/vendor/bootstrap/assets/ico/apple-touch-icon-57-precomposed.png +0 -0
- data/public/vendor/bootstrap/assets/ico/apple-touch-icon-72-precomposed.png +0 -0
- data/public/vendor/bootstrap/assets/ico/favicon.png +0 -0
- data/public/vendor/bootstrap/assets/js/application.js +2 -1
- data/public/vendor/bootstrap/assets/js/customizer.js +160 -45
- data/public/vendor/bootstrap/assets/js/filesaver.js +169 -0
- data/public/vendor/bootstrap/assets/js/jquery.js +6 -5
- data/public/vendor/bootstrap/assets/js/raw-files.js +3 -0
- data/public/vendor/bootstrap/bower.json +1 -1
- data/public/vendor/bootstrap/components.html +787 -364
- data/public/vendor/bootstrap/composer.json +1 -1
- data/public/vendor/bootstrap/css.html +413 -248
- data/public/vendor/bootstrap/customize.html +413 -447
- data/public/vendor/bootstrap/dist/css/bootstrap-theme.css +384 -0
- data/public/vendor/bootstrap/dist/css/bootstrap-theme.min.css +1 -0
- data/public/vendor/bootstrap/dist/css/bootstrap.css +3033 -1807
- data/public/vendor/bootstrap/dist/css/bootstrap.min.css +1 -1
- data/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.eot +0 -0
- data/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.svg +228 -0
- data/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.woff +0 -0
- data/public/vendor/bootstrap/dist/js/bootstrap.js +18 -12
- data/public/vendor/bootstrap/dist/js/bootstrap.min.js +1 -1
- data/public/vendor/bootstrap/examples/carousel/carousel.css +128 -0
- data/public/vendor/bootstrap/examples/carousel/index.html +201 -0
- data/public/vendor/bootstrap/examples/grid/grid.css +28 -0
- data/public/vendor/bootstrap/examples/grid/index.html +119 -0
- data/public/vendor/bootstrap/examples/jumbotron/index.html +111 -0
- data/public/vendor/bootstrap/examples/jumbotron/jumbotron.css +5 -0
- data/public/vendor/bootstrap/examples/jumbotron-narrow/index.html +78 -0
- data/public/vendor/bootstrap/examples/jumbotron-narrow/jumbotron-narrow.css +79 -0
- data/public/vendor/bootstrap/examples/justified-nav/index.html +79 -0
- data/public/vendor/bootstrap/examples/justified-nav/justified-nav.css +88 -0
- data/public/vendor/bootstrap/examples/navbar/index.html +83 -0
- data/public/vendor/bootstrap/examples/navbar/navbar.css +7 -0
- data/public/vendor/bootstrap/examples/navbar-fixed-top/index.html +86 -0
- data/public/vendor/bootstrap/examples/navbar-fixed-top/navbar-fixed-top.css +4 -0
- data/public/vendor/bootstrap/examples/navbar-static-top/index.html +87 -0
- data/public/vendor/bootstrap/examples/navbar-static-top/navbar-static-top.css +7 -0
- data/public/vendor/bootstrap/examples/non-responsive/index.html +96 -0
- data/public/vendor/bootstrap/examples/non-responsive/non-responsive.css +117 -0
- data/public/vendor/bootstrap/examples/offcanvas/index.html +127 -0
- data/public/vendor/bootstrap/examples/offcanvas/offcanvas.css +48 -0
- data/public/vendor/bootstrap/examples/offcanvas/offcanvas.js +5 -0
- data/public/vendor/bootstrap/examples/screenshots/carousel.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/grid.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/jumbotron-narrow.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/jumbotron.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/justified-nav.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/navbar-fixed.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/navbar-static.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/navbar.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/non-responsive.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/offcanvas.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/sign-in.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/starter-template.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/sticky-footer-navbar.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/sticky-footer.jpg +0 -0
- data/public/vendor/bootstrap/examples/screenshots/theme.jpg +0 -0
- data/public/vendor/bootstrap/examples/signin/index.html +46 -0
- data/public/vendor/bootstrap/examples/signin/signin.css +40 -0
- data/public/vendor/bootstrap/examples/starter-template/index.html +63 -0
- data/public/vendor/bootstrap/examples/starter-template/starter-template.css +7 -0
- data/public/vendor/bootstrap/examples/sticky-footer/index.html +51 -0
- data/public/vendor/bootstrap/examples/sticky-footer/sticky-footer.css +39 -0
- data/public/vendor/bootstrap/examples/sticky-footer-navbar/index.html +86 -0
- data/public/vendor/bootstrap/examples/sticky-footer-navbar/sticky-footer-navbar.css +46 -0
- data/public/vendor/bootstrap/examples/theme/index.html +387 -0
- data/public/vendor/bootstrap/examples/theme/theme.css +14 -0
- data/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
- data/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.svg +228 -0
- data/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
- data/public/vendor/bootstrap/getting-started.html +513 -22
- data/public/vendor/bootstrap/index.html +3 -4
- data/public/vendor/bootstrap/javascript.html +123 -115
- data/public/vendor/bootstrap/js/dropdown.js +3 -3
- data/public/vendor/bootstrap/js/modal.js +5 -3
- data/public/vendor/bootstrap/js/tests/unit/modal.js +19 -0
- data/public/vendor/bootstrap/js/tests/vendor/jquery.js +6 -5
- data/public/vendor/bootstrap/js/tooltip.js +9 -5
- data/public/vendor/bootstrap/js/transition.js +1 -1
- data/public/vendor/bootstrap/less/alerts.less +7 -11
- data/public/vendor/bootstrap/less/bootstrap.less +17 -21
- data/public/vendor/bootstrap/less/button-groups.less +14 -10
- data/public/vendor/bootstrap/less/buttons.less +3 -2
- data/public/vendor/bootstrap/less/carousel.less +6 -1
- data/public/vendor/bootstrap/less/dropdowns.less +22 -5
- data/public/vendor/bootstrap/less/forms.less +36 -15
- data/public/vendor/bootstrap/less/glyphicons.less +232 -0
- data/public/vendor/bootstrap/less/grid.less +9 -3
- data/public/vendor/bootstrap/less/input-groups.less +1 -1
- data/public/vendor/bootstrap/less/jumbotron.less +16 -5
- data/public/vendor/bootstrap/less/labels.less +9 -5
- data/public/vendor/bootstrap/less/mixins.less +73 -43
- data/public/vendor/bootstrap/less/modals.less +8 -0
- data/public/vendor/bootstrap/less/navbar.less +251 -189
- data/public/vendor/bootstrap/less/navs.less +13 -12
- data/public/vendor/bootstrap/less/pager.less +1 -1
- data/public/vendor/bootstrap/less/pagination.less +20 -9
- data/public/vendor/bootstrap/less/panels.less +28 -8
- data/public/vendor/bootstrap/less/progress-bars.less +6 -10
- data/public/vendor/bootstrap/less/responsive-utilities.less +120 -49
- data/public/vendor/bootstrap/less/scaffolding.less +37 -18
- data/public/vendor/bootstrap/less/tables.less +84 -59
- data/public/vendor/bootstrap/less/theme.less +232 -0
- data/public/vendor/bootstrap/less/thumbnails.less +8 -19
- data/public/vendor/bootstrap/less/type.less +2 -2
- data/public/vendor/bootstrap/less/variables.less +63 -50
- data/public/vendor/bootstrap/package.json +2 -1
- data/public/vendor/components-backbone/LICENSE +22 -0
- data/public/vendor/components-backbone/README.md +10 -0
- data/public/vendor/components-backbone/backbone-min.js +4 -0
- data/public/vendor/components-backbone/backbone.js +1571 -0
- data/public/vendor/components-backbone/bower.json +17 -0
- data/public/vendor/components-backbone/component.json +21 -0
- data/public/vendor/components-backbone/composer.json +37 -0
- data/public/vendor/components-backbone/package.json +24 -0
- data/public/vendor/d3.layout.cloud.js +401 -0
- data/public/vendor/replacejs/CHANGELOG.md +4 -0
- data/public/vendor/replacejs/replace.js +21 -2
- data/public/vendor/underscore/CNAME +1 -0
- data/public/vendor/underscore/CONTRIBUTING.md +9 -0
- data/public/vendor/underscore/LICENSE +22 -0
- data/public/vendor/underscore/README.md +19 -0
- data/public/vendor/underscore/Rakefile +10 -0
- data/public/vendor/underscore/docs/docco.css +192 -0
- data/public/vendor/underscore/docs/favicon.ico +0 -0
- data/public/vendor/underscore/docs/images/background.png +0 -0
- data/public/vendor/underscore/docs/images/underscore.png +0 -0
- data/public/vendor/underscore/docs/underscore.html +823 -0
- data/public/vendor/underscore/favicon.ico +0 -0
- data/public/vendor/underscore/index.html +2467 -0
- data/public/vendor/underscore/index.js +1 -0
- data/public/vendor/underscore/package.json +16 -0
- data/public/vendor/underscore/test/arrays.js +200 -0
- data/public/vendor/underscore/test/chaining.js +59 -0
- data/public/vendor/underscore/test/collections.js +453 -0
- data/public/vendor/underscore/test/functions.js +265 -0
- data/public/vendor/underscore/test/index.html +44 -0
- data/public/vendor/underscore/test/objects.js +570 -0
- data/public/vendor/underscore/test/speed.js +75 -0
- data/public/vendor/underscore/test/utility.js +266 -0
- data/public/vendor/underscore/test/vendor/jquery.js +9404 -0
- data/public/vendor/underscore/test/vendor/jslitmus.js +670 -0
- data/public/vendor/underscore/test/vendor/qunit.css +235 -0
- data/public/vendor/underscore/test/vendor/qunit.js +1977 -0
- data/public/vendor/underscore/test/vendor/runner.js +98 -0
- data/public/vendor/underscore/underscore-min.js +1 -0
- data/public/vendor/underscore/underscore.js +1226 -0
- data/views/dashboard.haml +1 -1
- data/views/layout.haml +8 -4
- metadata +132 -25
- data/public/vendor/bootstrap/_layouts/customize.html +0 -52
- data/public/vendor/bootstrap/assets/js/jquery.bbq.min.js +0 -1287
- data/public/vendor/bootstrap-glyphicons/CHANGELOG.md +0 -3
- data/public/vendor/bootstrap-glyphicons/CNAME +0 -1
- data/public/vendor/bootstrap-glyphicons/CONTRIBUTING.md +0 -54
- data/public/vendor/bootstrap-glyphicons/LICENSE +0 -19
- data/public/vendor/bootstrap-glyphicons/README.md +0 -61
- data/public/vendor/bootstrap-glyphicons/_config.yml +0 -12
- data/public/vendor/bootstrap-glyphicons/composer.json +0 -9
- data/public/vendor/bootstrap-glyphicons/css/bootstrap-glyphicons.css +0 -2
- data/public/vendor/bootstrap-glyphicons/css/bootstrap.css +0 -9
- data/public/vendor/bootstrap-glyphicons/css/docs.css +0 -160
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.eot +0 -0
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.otf +0 -0
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.svg +0 -175
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.ttf +0 -0
- data/public/vendor/bootstrap-glyphicons/fonts/glyphiconshalflings-regular.woff +0 -0
- data/public/vendor/bootstrap-glyphicons/index.html +0 -255
- data/public/vendor/bootstrap-glyphicons/less/bootstrap-glyphicons.less +0 -201
- data/public/vendor/bootstrap-glyphicons/package.json +0 -18
@@ -0,0 +1 @@
|
|
1
|
+
module.exports = require('./underscore');
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"name" : "underscore",
|
3
|
+
"description" : "JavaScript's functional programming helper library.",
|
4
|
+
"homepage" : "http://underscorejs.org",
|
5
|
+
"keywords" : ["util", "functional", "server", "client", "browser"],
|
6
|
+
"author" : "Jeremy Ashkenas <jeremy@documentcloud.org>",
|
7
|
+
"repository" : {"type": "git", "url": "git://github.com/documentcloud/underscore.git"},
|
8
|
+
"main" : "underscore.js",
|
9
|
+
"version" : "1.4.4",
|
10
|
+
"devDependencies": {
|
11
|
+
"phantomjs": "0.2.2"
|
12
|
+
},
|
13
|
+
"scripts": {
|
14
|
+
"test": "phantomjs test/vendor/runner.js test/index.html?noglobals=true"
|
15
|
+
}
|
16
|
+
}
|
@@ -0,0 +1,200 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
|
3
|
+
module("Arrays");
|
4
|
+
|
5
|
+
test("first", function() {
|
6
|
+
equal(_.first([1,2,3]), 1, 'can pull out the first element of an array');
|
7
|
+
equal(_([1, 2, 3]).first(), 1, 'can perform OO-style "first()"');
|
8
|
+
equal(_.first([1,2,3], 0).join(', '), "", 'can pass an index to first');
|
9
|
+
equal(_.first([1,2,3], 2).join(', '), '1, 2', 'can pass an index to first');
|
10
|
+
equal(_.first([1,2,3], 5).join(', '), '1, 2, 3', 'can pass an index to first');
|
11
|
+
var result = (function(){ return _.first(arguments); })(4, 3, 2, 1);
|
12
|
+
equal(result, 4, 'works on an arguments object.');
|
13
|
+
result = _.map([[1,2,3],[1,2,3]], _.first);
|
14
|
+
equal(result.join(','), '1,1', 'works well with _.map');
|
15
|
+
result = (function() { return _.take([1,2,3], 2); })();
|
16
|
+
equal(result.join(','), '1,2', 'aliased as take');
|
17
|
+
|
18
|
+
equal(_.first(null), undefined, 'handles nulls');
|
19
|
+
});
|
20
|
+
|
21
|
+
test("rest", function() {
|
22
|
+
var numbers = [1, 2, 3, 4];
|
23
|
+
equal(_.rest(numbers).join(", "), "2, 3, 4", 'working rest()');
|
24
|
+
equal(_.rest(numbers, 0).join(", "), "1, 2, 3, 4", 'working rest(0)');
|
25
|
+
equal(_.rest(numbers, 2).join(', '), '3, 4', 'rest can take an index');
|
26
|
+
var result = (function(){ return _(arguments).tail(); })(1, 2, 3, 4);
|
27
|
+
equal(result.join(', '), '2, 3, 4', 'aliased as tail and works on arguments object');
|
28
|
+
result = _.map([[1,2,3],[1,2,3]], _.rest);
|
29
|
+
equal(_.flatten(result).join(','), '2,3,2,3', 'works well with _.map');
|
30
|
+
result = (function(){ return _(arguments).drop(); })(1, 2, 3, 4);
|
31
|
+
equal(result.join(', '), '2, 3, 4', 'aliased as drop and works on arguments object');
|
32
|
+
});
|
33
|
+
|
34
|
+
test("initial", function() {
|
35
|
+
equal(_.initial([1,2,3,4,5]).join(", "), "1, 2, 3, 4", 'working initial()');
|
36
|
+
equal(_.initial([1,2,3,4],2).join(", "), "1, 2", 'initial can take an index');
|
37
|
+
var result = (function(){ return _(arguments).initial(); })(1, 2, 3, 4);
|
38
|
+
equal(result.join(", "), "1, 2, 3", 'initial works on arguments object');
|
39
|
+
result = _.map([[1,2,3],[1,2,3]], _.initial);
|
40
|
+
equal(_.flatten(result).join(','), '1,2,1,2', 'initial works with _.map');
|
41
|
+
});
|
42
|
+
|
43
|
+
test("last", function() {
|
44
|
+
equal(_.last([1,2,3]), 3, 'can pull out the last element of an array');
|
45
|
+
equal(_.last([1,2,3], 0).join(', '), "", 'can pass an index to last');
|
46
|
+
equal(_.last([1,2,3], 2).join(', '), '2, 3', 'can pass an index to last');
|
47
|
+
equal(_.last([1,2,3], 5).join(', '), '1, 2, 3', 'can pass an index to last');
|
48
|
+
var result = (function(){ return _(arguments).last(); })(1, 2, 3, 4);
|
49
|
+
equal(result, 4, 'works on an arguments object');
|
50
|
+
result = _.map([[1,2,3],[1,2,3]], _.last);
|
51
|
+
equal(result.join(','), '3,3', 'works well with _.map');
|
52
|
+
|
53
|
+
equal(_.last(null), undefined, 'handles nulls');
|
54
|
+
});
|
55
|
+
|
56
|
+
test("compact", function() {
|
57
|
+
equal(_.compact([0, 1, false, 2, false, 3]).length, 3, 'can trim out all falsy values');
|
58
|
+
var result = (function(){ return _.compact(arguments).length; })(0, 1, false, 2, false, 3);
|
59
|
+
equal(result, 3, 'works on an arguments object');
|
60
|
+
});
|
61
|
+
|
62
|
+
test("flatten", function() {
|
63
|
+
var list = [1, [2], [3, [[[4]]]]];
|
64
|
+
deepEqual(_.flatten(list), [1,2,3,4], 'can flatten nested arrays');
|
65
|
+
deepEqual(_.flatten(list, true), [1,2,3,[[[4]]]], 'can shallowly flatten nested arrays');
|
66
|
+
var result = (function(){ return _.flatten(arguments); })(1, [2], [3, [[[4]]]]);
|
67
|
+
deepEqual(result, [1,2,3,4], 'works on an arguments object');
|
68
|
+
});
|
69
|
+
|
70
|
+
test("without", function() {
|
71
|
+
var list = [1, 2, 1, 0, 3, 1, 4];
|
72
|
+
equal(_.without(list, 0, 1).join(', '), '2, 3, 4', 'can remove all instances of an object');
|
73
|
+
var result = (function(){ return _.without(arguments, 0, 1); })(1, 2, 1, 0, 3, 1, 4);
|
74
|
+
equal(result.join(', '), '2, 3, 4', 'works on an arguments object');
|
75
|
+
|
76
|
+
var list = [{one : 1}, {two : 2}];
|
77
|
+
ok(_.without(list, {one : 1}).length == 2, 'uses real object identity for comparisons.');
|
78
|
+
ok(_.without(list, list[0]).length == 1, 'ditto.');
|
79
|
+
});
|
80
|
+
|
81
|
+
test("uniq", function() {
|
82
|
+
var list = [1, 2, 1, 3, 1, 4];
|
83
|
+
equal(_.uniq(list).join(', '), '1, 2, 3, 4', 'can find the unique values of an unsorted array');
|
84
|
+
|
85
|
+
var list = [1, 1, 1, 2, 2, 3];
|
86
|
+
equal(_.uniq(list, true).join(', '), '1, 2, 3', 'can find the unique values of a sorted array faster');
|
87
|
+
|
88
|
+
var list = [{name:'moe'}, {name:'curly'}, {name:'larry'}, {name:'curly'}];
|
89
|
+
var iterator = function(value) { return value.name; };
|
90
|
+
equal(_.map(_.uniq(list, false, iterator), iterator).join(', '), 'moe, curly, larry', 'can find the unique values of an array using a custom iterator');
|
91
|
+
|
92
|
+
equal(_.map(_.uniq(list, iterator), iterator).join(', '), 'moe, curly, larry', 'can find the unique values of an array using a custom iterator without specifying whether array is sorted');
|
93
|
+
|
94
|
+
var iterator = function(value) { return value +1; };
|
95
|
+
var list = [1, 2, 2, 3, 4, 4];
|
96
|
+
equal(_.uniq(list, true, iterator).join(', '), '1, 2, 3, 4', 'iterator works with sorted array');
|
97
|
+
|
98
|
+
var result = (function(){ return _.uniq(arguments); })(1, 2, 1, 3, 1, 4);
|
99
|
+
equal(result.join(', '), '1, 2, 3, 4', 'works on an arguments object');
|
100
|
+
});
|
101
|
+
|
102
|
+
test("intersection", function() {
|
103
|
+
var stooges = ['moe', 'curly', 'larry'], leaders = ['moe', 'groucho'];
|
104
|
+
equal(_.intersection(stooges, leaders).join(''), 'moe', 'can take the set intersection of two arrays');
|
105
|
+
equal(_(stooges).intersection(leaders).join(''), 'moe', 'can perform an OO-style intersection');
|
106
|
+
var result = (function(){ return _.intersection(arguments, leaders); })('moe', 'curly', 'larry');
|
107
|
+
equal(result.join(''), 'moe', 'works on an arguments object');
|
108
|
+
});
|
109
|
+
|
110
|
+
test("union", function() {
|
111
|
+
var result = _.union([1, 2, 3], [2, 30, 1], [1, 40]);
|
112
|
+
equal(result.join(' '), '1 2 3 30 40', 'takes the union of a list of arrays');
|
113
|
+
|
114
|
+
var result = _.union([1, 2, 3], [2, 30, 1], [1, 40, [1]]);
|
115
|
+
equal(result.join(' '), '1 2 3 30 40 1', 'takes the union of a list of nested arrays');
|
116
|
+
});
|
117
|
+
|
118
|
+
test("difference", function() {
|
119
|
+
var result = _.difference([1, 2, 3], [2, 30, 40]);
|
120
|
+
equal(result.join(' '), '1 3', 'takes the difference of two arrays');
|
121
|
+
|
122
|
+
var result = _.difference([1, 2, 3, 4], [2, 30, 40], [1, 11, 111]);
|
123
|
+
equal(result.join(' '), '3 4', 'takes the difference of three arrays');
|
124
|
+
});
|
125
|
+
|
126
|
+
test('zip', function() {
|
127
|
+
var names = ['moe', 'larry', 'curly'], ages = [30, 40, 50], leaders = [true];
|
128
|
+
var stooges = _.zip(names, ages, leaders);
|
129
|
+
equal(String(stooges), 'moe,30,true,larry,40,,curly,50,', 'zipped together arrays of different lengths');
|
130
|
+
});
|
131
|
+
|
132
|
+
test('object', function() {
|
133
|
+
var result = _.object(['moe', 'larry', 'curly'], [30, 40, 50]);
|
134
|
+
var shouldBe = {moe: 30, larry: 40, curly: 50};
|
135
|
+
ok(_.isEqual(result, shouldBe), 'two arrays zipped together into an object');
|
136
|
+
|
137
|
+
result = _.object([['one', 1], ['two', 2], ['three', 3]]);
|
138
|
+
shouldBe = {one: 1, two: 2, three: 3};
|
139
|
+
ok(_.isEqual(result, shouldBe), 'an array of pairs zipped together into an object');
|
140
|
+
|
141
|
+
var stooges = {moe: 30, larry: 40, curly: 50};
|
142
|
+
ok(_.isEqual(_.object(_.pairs(stooges)), stooges), 'an object converted to pairs and back to an object');
|
143
|
+
|
144
|
+
ok(_.isEqual(_.object(null), {}), 'handles nulls');
|
145
|
+
});
|
146
|
+
|
147
|
+
test("indexOf", function() {
|
148
|
+
var numbers = [1, 2, 3];
|
149
|
+
numbers.indexOf = null;
|
150
|
+
equal(_.indexOf(numbers, 2), 1, 'can compute indexOf, even without the native function');
|
151
|
+
var result = (function(){ return _.indexOf(arguments, 2); })(1, 2, 3);
|
152
|
+
equal(result, 1, 'works on an arguments object');
|
153
|
+
equal(_.indexOf(null, 2), -1, 'handles nulls properly');
|
154
|
+
|
155
|
+
var numbers = [10, 20, 30, 40, 50], num = 35;
|
156
|
+
var index = _.indexOf(numbers, num, true);
|
157
|
+
equal(index, -1, '35 is not in the list');
|
158
|
+
|
159
|
+
numbers = [10, 20, 30, 40, 50]; num = 40;
|
160
|
+
index = _.indexOf(numbers, num, true);
|
161
|
+
equal(index, 3, '40 is in the list');
|
162
|
+
|
163
|
+
numbers = [1, 40, 40, 40, 40, 40, 40, 40, 50, 60, 70]; num = 40;
|
164
|
+
index = _.indexOf(numbers, num, true);
|
165
|
+
equal(index, 1, '40 is in the list');
|
166
|
+
|
167
|
+
numbers = [1, 2, 3, 1, 2, 3, 1, 2, 3];
|
168
|
+
index = _.indexOf(numbers, 2, 5);
|
169
|
+
equal(index, 7, 'supports the fromIndex argument');
|
170
|
+
});
|
171
|
+
|
172
|
+
test("lastIndexOf", function() {
|
173
|
+
var numbers = [1, 0, 1];
|
174
|
+
equal(_.lastIndexOf(numbers, 1), 2);
|
175
|
+
|
176
|
+
numbers = [1, 0, 1, 0, 0, 1, 0, 0, 0];
|
177
|
+
numbers.lastIndexOf = null;
|
178
|
+
equal(_.lastIndexOf(numbers, 1), 5, 'can compute lastIndexOf, even without the native function');
|
179
|
+
equal(_.lastIndexOf(numbers, 0), 8, 'lastIndexOf the other element');
|
180
|
+
var result = (function(){ return _.lastIndexOf(arguments, 1); })(1, 0, 1, 0, 0, 1, 0, 0, 0);
|
181
|
+
equal(result, 5, 'works on an arguments object');
|
182
|
+
equal(_.indexOf(null, 2), -1, 'handles nulls properly');
|
183
|
+
|
184
|
+
numbers = [1, 2, 3, 1, 2, 3, 1, 2, 3];
|
185
|
+
var index = _.lastIndexOf(numbers, 2, 2);
|
186
|
+
equal(index, 1, 'supports the fromIndex argument');
|
187
|
+
});
|
188
|
+
|
189
|
+
test("range", function() {
|
190
|
+
equal(_.range(0).join(''), '', 'range with 0 as a first argument generates an empty array');
|
191
|
+
equal(_.range(4).join(' '), '0 1 2 3', 'range with a single positive argument generates an array of elements 0,1,2,...,n-1');
|
192
|
+
equal(_.range(5, 8).join(' '), '5 6 7', 'range with two arguments a & b, a<b generates an array of elements a,a+1,a+2,...,b-2,b-1');
|
193
|
+
equal(_.range(8, 5).join(''), '', 'range with two arguments a & b, b<a generates an empty array');
|
194
|
+
equal(_.range(3, 10, 3).join(' '), '3 6 9', 'range with three arguments a & b & c, c < b-a, a < b generates an array of elements a,a+c,a+2c,...,b - (multiplier of a) < c');
|
195
|
+
equal(_.range(3, 10, 15).join(''), '3', 'range with three arguments a & b & c, c > b-a, a < b generates an array with a single element, equal to a');
|
196
|
+
equal(_.range(12, 7, -2).join(' '), '12 10 8', 'range with three arguments a & b & c, a > b, c < 0 generates an array of elements a,a-c,a-2c and ends with the number not less than b');
|
197
|
+
equal(_.range(0, -10, -1).join(' '), '0 -1 -2 -3 -4 -5 -6 -7 -8 -9', 'final example in the Python docs');
|
198
|
+
});
|
199
|
+
|
200
|
+
});
|
@@ -0,0 +1,59 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
|
3
|
+
module("Chaining");
|
4
|
+
|
5
|
+
test("map/flatten/reduce", function() {
|
6
|
+
var lyrics = [
|
7
|
+
"I'm a lumberjack and I'm okay",
|
8
|
+
"I sleep all night and I work all day",
|
9
|
+
"He's a lumberjack and he's okay",
|
10
|
+
"He sleeps all night and he works all day"
|
11
|
+
];
|
12
|
+
var counts = _(lyrics).chain()
|
13
|
+
.map(function(line) { return line.split(''); })
|
14
|
+
.flatten()
|
15
|
+
.reduce(function(hash, l) {
|
16
|
+
hash[l] = hash[l] || 0;
|
17
|
+
hash[l]++;
|
18
|
+
return hash;
|
19
|
+
}, {}).value();
|
20
|
+
ok(counts['a'] == 16 && counts['e'] == 10, 'counted all the letters in the song');
|
21
|
+
});
|
22
|
+
|
23
|
+
test("select/reject/sortBy", function() {
|
24
|
+
var numbers = [1,2,3,4,5,6,7,8,9,10];
|
25
|
+
numbers = _(numbers).chain().select(function(n) {
|
26
|
+
return n % 2 == 0;
|
27
|
+
}).reject(function(n) {
|
28
|
+
return n % 4 == 0;
|
29
|
+
}).sortBy(function(n) {
|
30
|
+
return -n;
|
31
|
+
}).value();
|
32
|
+
equal(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers");
|
33
|
+
});
|
34
|
+
|
35
|
+
test("select/reject/sortBy in functional style", function() {
|
36
|
+
var numbers = [1,2,3,4,5,6,7,8,9,10];
|
37
|
+
numbers = _.chain(numbers).select(function(n) {
|
38
|
+
return n % 2 == 0;
|
39
|
+
}).reject(function(n) {
|
40
|
+
return n % 4 == 0;
|
41
|
+
}).sortBy(function(n) {
|
42
|
+
return -n;
|
43
|
+
}).value();
|
44
|
+
equal(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers");
|
45
|
+
});
|
46
|
+
|
47
|
+
test("reverse/concat/unshift/pop/map", function() {
|
48
|
+
var numbers = [1,2,3,4,5];
|
49
|
+
numbers = _(numbers).chain()
|
50
|
+
.reverse()
|
51
|
+
.concat([5, 5, 5])
|
52
|
+
.unshift(17)
|
53
|
+
.pop()
|
54
|
+
.map(function(n){ return n * 2; })
|
55
|
+
.value();
|
56
|
+
equal(numbers.join(', '), "34, 10, 8, 6, 4, 2, 10, 10", 'can chain together array functions.');
|
57
|
+
});
|
58
|
+
|
59
|
+
});
|