vines 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +1 -1
- data/Rakefile +33 -53
- data/conf/certs/README +10 -3
- data/conf/certs/ca-bundle.crt +55 -410
- data/lib/vines/cluster/connection.rb +1 -1
- data/lib/vines/command/ldap.rb +1 -1
- data/lib/vines/command/schema.rb +1 -1
- data/lib/vines/config.rb +11 -5
- data/lib/vines/jid.rb +3 -3
- data/lib/vines/stanza/iq/disco_items.rb +1 -1
- data/lib/vines/storage/local.rb +1 -0
- data/lib/vines/store.rb +50 -9
- data/lib/vines/stream.rb +5 -9
- data/lib/vines/stream/client/session.rb +1 -1
- data/lib/vines/stream/http.rb +3 -1
- data/lib/vines/stream/http/ready.rb +5 -1
- data/lib/vines/stream/http/request.rb +22 -0
- data/lib/vines/version.rb +1 -1
- data/test/config/host_test.rb +9 -9
- data/test/config/pubsub_test.rb +2 -2
- data/test/config_test.rb +5 -3
- data/test/jid_test.rb +9 -0
- data/test/rake_test_loader.rb +1 -1
- data/test/router_test.rb +7 -7
- data/test/stanza/iq/disco_info_test.rb +2 -2
- data/test/stanza/iq/private_storage_test.rb +1 -1
- data/test/stanza/iq_test.rb +1 -1
- data/test/stanza/presence/subscribe_test.rb +1 -1
- data/test/stanza/pubsub/subscribe_test.rb +3 -3
- data/test/stanza/pubsub/unsubscribe_test.rb +3 -3
- data/test/storage_test.rb +15 -8
- data/test/store_test.rb +131 -0
- data/test/stream/client/ready_test.rb +6 -6
- data/test/stream/component/ready_test.rb +1 -1
- data/test/stream/http/ready_test.rb +46 -11
- data/test/stream/http/request_test.rb +83 -11
- data/test/stream/http/sessions_test.rb +2 -2
- data/web/chat/coffeescripts/chat.coffee +1 -1
- data/web/chat/index.html +9 -10
- data/web/chat/javascripts/app.js +1 -1
- data/web/lib/coffeescripts/button.coffee +1 -1
- data/web/lib/coffeescripts/contact.coffee +2 -2
- data/web/lib/coffeescripts/filter.coffee +1 -1
- data/web/lib/coffeescripts/layout.coffee +2 -2
- data/web/lib/coffeescripts/login.coffee +1 -1
- data/web/lib/coffeescripts/logout.coffee +2 -2
- data/web/lib/coffeescripts/navbar.coffee +1 -1
- data/web/lib/coffeescripts/notification.coffee +1 -1
- data/web/lib/coffeescripts/router.coffee +1 -1
- data/web/lib/coffeescripts/session.coffee +1 -1
- data/web/lib/coffeescripts/transfer.coffee +1 -1
- data/web/lib/javascripts/base.js +10 -9
- metadata +65 -43
- data/web/chat/javascripts/chat.js +0 -390
- data/web/chat/javascripts/init.js +0 -21
- data/web/lib/javascripts/button.js +0 -39
- data/web/lib/javascripts/contact.js +0 -94
- data/web/lib/javascripts/filter.js +0 -88
- data/web/lib/javascripts/layout.js +0 -48
- data/web/lib/javascripts/login.js +0 -88
- data/web/lib/javascripts/logout.js +0 -11
- data/web/lib/javascripts/navbar.js +0 -69
- data/web/lib/javascripts/notification.js +0 -26
- data/web/lib/javascripts/router.js +0 -105
- data/web/lib/javascripts/session.js +0 -291
- data/web/lib/javascripts/transfer.js +0 -124
@@ -1,94 +0,0 @@
|
|
1
|
-
var Contact;
|
2
|
-
Contact = (function() {
|
3
|
-
function Contact(node) {
|
4
|
-
node = $(node);
|
5
|
-
this.jid = node.attr('jid');
|
6
|
-
this.name = node.attr('name');
|
7
|
-
this.ask = node.attr('ask');
|
8
|
-
this.subscription = node.attr('subscription');
|
9
|
-
this.groups = $('group', node).map(function() {
|
10
|
-
return $(this).text();
|
11
|
-
}).get();
|
12
|
-
this.presence = [];
|
13
|
-
}
|
14
|
-
Contact.prototype.online = function() {
|
15
|
-
return this.presence.length > 0;
|
16
|
-
};
|
17
|
-
Contact.prototype.offline = function() {
|
18
|
-
return this.presence.length === 0;
|
19
|
-
};
|
20
|
-
Contact.prototype.available = function() {
|
21
|
-
var p;
|
22
|
-
return this.online() && ((function() {
|
23
|
-
var _i, _len, _ref, _results;
|
24
|
-
_ref = this.presence;
|
25
|
-
_results = [];
|
26
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
27
|
-
p = _ref[_i];
|
28
|
-
if (!p.away) {
|
29
|
-
_results.push(p);
|
30
|
-
}
|
31
|
-
}
|
32
|
-
return _results;
|
33
|
-
}).call(this)).length > 0;
|
34
|
-
};
|
35
|
-
Contact.prototype.away = function() {
|
36
|
-
return !this.available();
|
37
|
-
};
|
38
|
-
Contact.prototype.status = function() {
|
39
|
-
var available, away, p;
|
40
|
-
available = ((function() {
|
41
|
-
var _i, _len, _ref, _results;
|
42
|
-
_ref = this.presence;
|
43
|
-
_results = [];
|
44
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
45
|
-
p = _ref[_i];
|
46
|
-
if (p.status && !p.away) {
|
47
|
-
_results.push(p.status);
|
48
|
-
}
|
49
|
-
}
|
50
|
-
return _results;
|
51
|
-
}).call(this))[0] || 'Available';
|
52
|
-
away = ((function() {
|
53
|
-
var _i, _len, _ref, _results;
|
54
|
-
_ref = this.presence;
|
55
|
-
_results = [];
|
56
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
57
|
-
p = _ref[_i];
|
58
|
-
if (p.status && p.away) {
|
59
|
-
_results.push(p.status);
|
60
|
-
}
|
61
|
-
}
|
62
|
-
return _results;
|
63
|
-
}).call(this))[0] || 'Away';
|
64
|
-
if (this.offline()) {
|
65
|
-
return 'Offline';
|
66
|
-
} else if (this.away()) {
|
67
|
-
return away;
|
68
|
-
} else {
|
69
|
-
return available;
|
70
|
-
}
|
71
|
-
};
|
72
|
-
Contact.prototype.update = function(presence) {
|
73
|
-
var p;
|
74
|
-
this.presence = (function() {
|
75
|
-
var _i, _len, _ref, _results;
|
76
|
-
_ref = this.presence;
|
77
|
-
_results = [];
|
78
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
79
|
-
p = _ref[_i];
|
80
|
-
if (p.from !== presence.from) {
|
81
|
-
_results.push(p);
|
82
|
-
}
|
83
|
-
}
|
84
|
-
return _results;
|
85
|
-
}).call(this);
|
86
|
-
if (!presence.type) {
|
87
|
-
this.presence.push(presence);
|
88
|
-
}
|
89
|
-
if (presence.type === 'unsubscribed') {
|
90
|
-
return this.presence = [];
|
91
|
-
}
|
92
|
-
};
|
93
|
-
return Contact;
|
94
|
-
})();
|
@@ -1,88 +0,0 @@
|
|
1
|
-
var Filter;
|
2
|
-
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
3
|
-
Filter = (function() {
|
4
|
-
function Filter(options) {
|
5
|
-
this.list = options.list;
|
6
|
-
this.icon = options.icon;
|
7
|
-
this.form = options.form;
|
8
|
-
this.attrs = options.attrs;
|
9
|
-
this.open = options.open;
|
10
|
-
this.close = options.close;
|
11
|
-
this.draw();
|
12
|
-
}
|
13
|
-
Filter.prototype.draw = function() {
|
14
|
-
var form, text;
|
15
|
-
$(this.icon).addClass('filter-button');
|
16
|
-
form = $('<form class="filter-form" style="display:none;"></form>').appendTo(this.form);
|
17
|
-
text = $('<input class="filter-text" type="search" placeholder="Filter" results="5"/>').appendTo(form);
|
18
|
-
if (this.icon) {
|
19
|
-
new Button(this.icon, ICONS.search, {
|
20
|
-
scale: 0.5,
|
21
|
-
translation: '-16,-16'
|
22
|
-
});
|
23
|
-
}
|
24
|
-
form.submit(function() {
|
25
|
-
return false;
|
26
|
-
});
|
27
|
-
text.keyup(__bind(function() {
|
28
|
-
return this.filter(text);
|
29
|
-
}, this));
|
30
|
-
text.change(__bind(function() {
|
31
|
-
return this.filter(text);
|
32
|
-
}, this));
|
33
|
-
text.click(__bind(function() {
|
34
|
-
return this.filter(text);
|
35
|
-
}, this));
|
36
|
-
return $(this.icon).click(__bind(function() {
|
37
|
-
if (form.is(':hidden')) {
|
38
|
-
this.filter(text);
|
39
|
-
form.show();
|
40
|
-
if (this.open) {
|
41
|
-
return this.open();
|
42
|
-
}
|
43
|
-
} else {
|
44
|
-
form.hide();
|
45
|
-
form[0].reset();
|
46
|
-
this.filter(text);
|
47
|
-
if (this.close) {
|
48
|
-
return this.close();
|
49
|
-
}
|
50
|
-
}
|
51
|
-
}, this));
|
52
|
-
};
|
53
|
-
Filter.prototype.filter = function(input) {
|
54
|
-
var test, text;
|
55
|
-
text = input.val().toLowerCase();
|
56
|
-
if (text === '') {
|
57
|
-
$('li', this.list).show();
|
58
|
-
return;
|
59
|
-
}
|
60
|
-
test = function(node, attr) {
|
61
|
-
var val;
|
62
|
-
val = (node.attr(attr) || '').toLowerCase();
|
63
|
-
return val.indexOf(text) !== -1;
|
64
|
-
};
|
65
|
-
return $('> li', this.list).each(__bind(function(ix, node) {
|
66
|
-
var attr, matches;
|
67
|
-
node = $(node);
|
68
|
-
matches = (function() {
|
69
|
-
var _i, _len, _ref, _results;
|
70
|
-
_ref = this.attrs;
|
71
|
-
_results = [];
|
72
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
73
|
-
attr = _ref[_i];
|
74
|
-
if (test(node, attr)) {
|
75
|
-
_results.push(true);
|
76
|
-
}
|
77
|
-
}
|
78
|
-
return _results;
|
79
|
-
}).call(this);
|
80
|
-
if (matches.length > 0) {
|
81
|
-
return node.show();
|
82
|
-
} else {
|
83
|
-
return node.hide();
|
84
|
-
}
|
85
|
-
}, this));
|
86
|
-
};
|
87
|
-
return Filter;
|
88
|
-
})();
|
@@ -1,48 +0,0 @@
|
|
1
|
-
var Layout;
|
2
|
-
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
3
|
-
Layout = (function() {
|
4
|
-
function Layout(fn) {
|
5
|
-
this.fn = fn;
|
6
|
-
this.resize();
|
7
|
-
this.listen();
|
8
|
-
setTimeout((__bind(function() {
|
9
|
-
return this.resize();
|
10
|
-
}, this)), 250);
|
11
|
-
}
|
12
|
-
Layout.prototype.resize = function() {
|
13
|
-
this.fill('.x-fill', 'outerWidth', 'width');
|
14
|
-
this.fill('.y-fill', 'outerHeight', 'height');
|
15
|
-
return this.fn();
|
16
|
-
};
|
17
|
-
Layout.prototype.fill = function(selector, get, set) {
|
18
|
-
return $(selector).each(__bind(function(ix, node) {
|
19
|
-
var fixed, getter, parent;
|
20
|
-
node = $(node);
|
21
|
-
getter = node[get];
|
22
|
-
parent = getter.call(node.parent(), true);
|
23
|
-
fixed = this.fixed(node, selector, function(n) {
|
24
|
-
return getter.call(n, true);
|
25
|
-
});
|
26
|
-
return node[set].call(node, parent - fixed);
|
27
|
-
}, this));
|
28
|
-
};
|
29
|
-
Layout.prototype.fixed = function(node, selector, fn) {
|
30
|
-
return node.siblings().not(selector).not('.float').filter(':visible').map(function() {
|
31
|
-
return fn($(this));
|
32
|
-
}).get().reduce((function(sum, num) {
|
33
|
-
return sum + num;
|
34
|
-
}), 0);
|
35
|
-
};
|
36
|
-
Layout.prototype.listen = function() {
|
37
|
-
var id;
|
38
|
-
id = null;
|
39
|
-
return $(window).resize(__bind(function() {
|
40
|
-
clearTimeout(id);
|
41
|
-
id = setTimeout((__bind(function() {
|
42
|
-
return this.resize();
|
43
|
-
}, this)), 10);
|
44
|
-
return this.resize();
|
45
|
-
}, this));
|
46
|
-
};
|
47
|
-
return Layout;
|
48
|
-
})();
|
@@ -1,88 +0,0 @@
|
|
1
|
-
var LoginPage;
|
2
|
-
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
3
|
-
LoginPage = (function() {
|
4
|
-
function LoginPage(session, startPage) {
|
5
|
-
this.session = session;
|
6
|
-
this.startPage = startPage;
|
7
|
-
}
|
8
|
-
LoginPage.prototype.start = function() {
|
9
|
-
var id, jid, password, _ref;
|
10
|
-
$('#error').hide();
|
11
|
-
_ref = (function() {
|
12
|
-
var _i, _len, _ref, _results;
|
13
|
-
_ref = ['#jid', '#password'];
|
14
|
-
_results = [];
|
15
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
16
|
-
id = _ref[_i];
|
17
|
-
_results.push($(id).val().trim());
|
18
|
-
}
|
19
|
-
return _results;
|
20
|
-
})(), jid = _ref[0], password = _ref[1];
|
21
|
-
if (jid.length === 0 || password.length === 0 || jid.indexOf('@') === -1) {
|
22
|
-
$('#error').show();
|
23
|
-
return;
|
24
|
-
}
|
25
|
-
return this.session.connect(jid, password, __bind(function(success) {
|
26
|
-
if (!success) {
|
27
|
-
this.session.disconnect();
|
28
|
-
$('#error').show();
|
29
|
-
$('#password').val('').focus();
|
30
|
-
return;
|
31
|
-
}
|
32
|
-
localStorage['jid'] = jid;
|
33
|
-
$('#current-user-name').text(this.session.bareJid());
|
34
|
-
$('#current-user-avatar').attr('src', this.session.avatar(this.session.jid()));
|
35
|
-
$('#current-user-avatar').attr('alt', this.session.bareJid());
|
36
|
-
return $('#container').fadeOut(200, __bind(function() {
|
37
|
-
$('#navbar').show();
|
38
|
-
return window.location.hash = this.startPage;
|
39
|
-
}, this));
|
40
|
-
}, this));
|
41
|
-
};
|
42
|
-
LoginPage.prototype.draw = function() {
|
43
|
-
var jid;
|
44
|
-
this.session.disconnect();
|
45
|
-
jid = localStorage['jid'] || '';
|
46
|
-
$('#navbar').hide();
|
47
|
-
$('body').attr('id', 'login-page');
|
48
|
-
$('#container').hide().empty();
|
49
|
-
$("<form id=\"login-form\">\n <div id=\"icon\"></div>\n <h1>vines</h1>\n <fieldset id=\"login-form-controls\">\n <input id=\"jid\" name=\"jid\" type=\"email\" maxlength=\"1024\" value=\"" + jid + "\" placeholder=\"Your user name\"/>\n <input id=\"password\" name=\"password\" type=\"password\" maxlength=\"1024\" placeholder=\"Your password\"/>\n <input id=\"start\" type=\"submit\" value=\"Sign in\"/>\n </fieldset>\n <p id=\"error\" style=\"display:none;\">User name and password not found.</p>\n</form>").appendTo('#container');
|
50
|
-
$('#container').fadeIn(1000);
|
51
|
-
$('#login-form').submit(__bind(function() {
|
52
|
-
this.start();
|
53
|
-
return false;
|
54
|
-
}, this));
|
55
|
-
$('#jid').keydown(function() {
|
56
|
-
return $('#error').fadeOut();
|
57
|
-
});
|
58
|
-
$('#password').keydown(function() {
|
59
|
-
return $('#error').fadeOut();
|
60
|
-
});
|
61
|
-
this.resize();
|
62
|
-
return this.icon();
|
63
|
-
};
|
64
|
-
LoginPage.prototype.icon = function() {
|
65
|
-
var opts;
|
66
|
-
opts = {
|
67
|
-
fill: '90-#ccc-#fff',
|
68
|
-
stroke: '#fff',
|
69
|
-
'stroke-width': 1.1,
|
70
|
-
opacity: 0.95,
|
71
|
-
scale: 3.0,
|
72
|
-
translation: '10,8',
|
73
|
-
animate: false
|
74
|
-
};
|
75
|
-
return new Button('#icon', ICONS.chat, opts);
|
76
|
-
};
|
77
|
-
LoginPage.prototype.resize = function() {
|
78
|
-
var form, sizer, win;
|
79
|
-
win = $(window);
|
80
|
-
form = $('#login-form');
|
81
|
-
sizer = function() {
|
82
|
-
return form.css('top', win.height() / 2 - form.height() / 2);
|
83
|
-
};
|
84
|
-
win.resize(sizer);
|
85
|
-
return sizer();
|
86
|
-
};
|
87
|
-
return LoginPage;
|
88
|
-
})();
|
@@ -1,69 +0,0 @@
|
|
1
|
-
var NavBar;
|
2
|
-
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
3
|
-
NavBar = (function() {
|
4
|
-
function NavBar(session) {
|
5
|
-
this.session = session;
|
6
|
-
this.session.onCard(__bind(function(card) {
|
7
|
-
if (card.jid === this.session.bareJid()) {
|
8
|
-
return $('#current-user-avatar').attr('src', this.session.avatar(card.jid));
|
9
|
-
}
|
10
|
-
}, this));
|
11
|
-
}
|
12
|
-
NavBar.prototype.draw = function() {
|
13
|
-
$("<header id=\"navbar\" class=\"x-fill\">\n <h1 id=\"logo\">vines></h1>\n <div id=\"current-user\">\n <img id=\"current-user-avatar\" alt=\"" + (this.session.bareJid()) + "\" src=\"" + (this.session.avatar(this.session.jid())) + "\"/>\n <div id=\"current-user-info\">\n <h1 id=\"current-user-name\">" + (this.session.bareJid()) + "</h1>\n <form id=\"current-user-presence-form\">\n <span class=\"select\">\n <span class=\"text\">Available</span>\n <select id=\"current-user-presence\">\n <optgroup label=\"Available\">\n <option>Available</option>\n <option>Surfing the web</option>\n <option>Reading email</option>\n </optgroup>\n <optgroup label=\"Away\">\n <option value=\"xa\">Away</option>\n <option value=\"xa\">Out to lunch</option>\n <option value=\"xa\">On the phone</option>\n <option value=\"xa\">In a meeting</option>\n </optgroup>\n </select>\n </span>\n </form>\n </div>\n </div>\n <nav id=\"app-nav\" class=\"x-fill\">\n <ul id=\"nav-links\"></ul>\n </nav>\n</header>").appendTo('body');
|
14
|
-
$('<div id="container" class="x-fill y-fill"></div>').appendTo('body');
|
15
|
-
return $('#current-user-presence').change(__bind(function(event) {
|
16
|
-
var selected;
|
17
|
-
selected = $('option:selected', event.currentTarget);
|
18
|
-
$('#current-user-presence-form .text').text(selected.text());
|
19
|
-
return this.session.sendPresence(selected.val() === 'xa', selected.text());
|
20
|
-
}, this));
|
21
|
-
};
|
22
|
-
NavBar.prototype.addButton = function(label, icon) {
|
23
|
-
var id, node;
|
24
|
-
id = "nav-link-" + (label.toLowerCase());
|
25
|
-
node = $("<li>\n <a id=\"" + id + "\" href=\"#/" + (label.toLowerCase()) + "\">\n <span>" + label + "</span>\n </a>\n</li>").appendTo('#nav-links');
|
26
|
-
this.button(id, icon);
|
27
|
-
return node.click(__bind(function(event) {
|
28
|
-
return this.select(event.currentTarget);
|
29
|
-
}, this));
|
30
|
-
};
|
31
|
-
NavBar.prototype.select = function(button) {
|
32
|
-
var dark, light;
|
33
|
-
button = $(button);
|
34
|
-
$('#nav-links li').removeClass('selected');
|
35
|
-
$('#nav-links li a').removeClass('selected');
|
36
|
-
button.addClass('selected');
|
37
|
-
$('a', button).addClass('selected');
|
38
|
-
dark = $('#nav-links svg path');
|
39
|
-
dark.attr('opacity', '0.6');
|
40
|
-
dark.css('opacity', '0.6');
|
41
|
-
light = $('svg path', button);
|
42
|
-
light.attr('opacity', '1.0');
|
43
|
-
return light.css('opacity', '1.0');
|
44
|
-
};
|
45
|
-
NavBar.prototype.button = function(id, path) {
|
46
|
-
var icon, node, paper;
|
47
|
-
paper = Raphael(id);
|
48
|
-
icon = paper.path(path).attr({
|
49
|
-
fill: '#fff',
|
50
|
-
stroke: '#000',
|
51
|
-
'stroke-width': 0.3,
|
52
|
-
opacity: 0.6
|
53
|
-
});
|
54
|
-
node = $('#' + id);
|
55
|
-
node.hover(function() {
|
56
|
-
return icon.animate({
|
57
|
-
opacity: 1.0
|
58
|
-
}, 200);
|
59
|
-
}, function() {
|
60
|
-
if (!node.hasClass('selected')) {
|
61
|
-
return icon.animate({
|
62
|
-
opacity: 0.6
|
63
|
-
}, 200);
|
64
|
-
}
|
65
|
-
});
|
66
|
-
return node.get(0);
|
67
|
-
};
|
68
|
-
return NavBar;
|
69
|
-
})();
|
@@ -1,26 +0,0 @@
|
|
1
|
-
var Notification;
|
2
|
-
Notification = (function() {
|
3
|
-
function Notification(text) {
|
4
|
-
this.text = text;
|
5
|
-
this.draw();
|
6
|
-
}
|
7
|
-
Notification.prototype.draw = function() {
|
8
|
-
var fn, left, node, top;
|
9
|
-
node = $('<div class="notification float" style="display:none;"></div>').appendTo('body');
|
10
|
-
node.text(this.text);
|
11
|
-
top = node.outerHeight() / 2;
|
12
|
-
left = node.outerWidth() / 2;
|
13
|
-
node.css({
|
14
|
-
marginTop: "-" + top + "px",
|
15
|
-
marginLeft: "-" + left + "px"
|
16
|
-
});
|
17
|
-
node.fadeIn(200);
|
18
|
-
fn = function() {
|
19
|
-
return node.fadeOut(200, function() {
|
20
|
-
return node.remove();
|
21
|
-
});
|
22
|
-
};
|
23
|
-
return setTimeout(fn, 1500);
|
24
|
-
};
|
25
|
-
return Notification;
|
26
|
-
})();
|
@@ -1,105 +0,0 @@
|
|
1
|
-
var Router;
|
2
|
-
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
3
|
-
Router = (function() {
|
4
|
-
function Router(pages) {
|
5
|
-
this.pages = pages;
|
6
|
-
this.routes = this.build();
|
7
|
-
$(window).bind('hashchange', __bind(function() {
|
8
|
-
return this.draw();
|
9
|
-
}, this));
|
10
|
-
}
|
11
|
-
Router.prototype.build = function() {
|
12
|
-
var f, fragments, map, page, pattern, route, routes, _ref;
|
13
|
-
routes = [];
|
14
|
-
_ref = this.pages;
|
15
|
-
for (pattern in _ref) {
|
16
|
-
page = _ref[pattern];
|
17
|
-
routes.push(route = {
|
18
|
-
args: [],
|
19
|
-
page: page,
|
20
|
-
re: null
|
21
|
-
});
|
22
|
-
if (pattern === 'default') {
|
23
|
-
route.re = pattern;
|
24
|
-
continue;
|
25
|
-
}
|
26
|
-
fragments = (function() {
|
27
|
-
var _i, _len, _ref2, _results;
|
28
|
-
_ref2 = pattern.split('/');
|
29
|
-
_results = [];
|
30
|
-
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
31
|
-
f = _ref2[_i];
|
32
|
-
if (f.length > 0) {
|
33
|
-
_results.push(f);
|
34
|
-
}
|
35
|
-
}
|
36
|
-
return _results;
|
37
|
-
})();
|
38
|
-
map = function(fragment) {
|
39
|
-
if (fragment[0] === ':') {
|
40
|
-
route.args.push(fragment.replace(':', ''));
|
41
|
-
return '(/[^/]+)?';
|
42
|
-
} else {
|
43
|
-
return '/' + fragment;
|
44
|
-
}
|
45
|
-
};
|
46
|
-
route.re = new RegExp('#' + ((function() {
|
47
|
-
var _i, _len, _results;
|
48
|
-
_results = [];
|
49
|
-
for (_i = 0, _len = fragments.length; _i < _len; _i++) {
|
50
|
-
f = fragments[_i];
|
51
|
-
_results.push(map(f));
|
52
|
-
}
|
53
|
-
return _results;
|
54
|
-
})()).join(''));
|
55
|
-
}
|
56
|
-
return routes;
|
57
|
-
};
|
58
|
-
Router.prototype.draw = function() {
|
59
|
-
var args, ix, name, opts, route, _i, _len, _ref, _ref2, _ref3;
|
60
|
-
_ref = this.match(), route = _ref[0], args = _ref[1];
|
61
|
-
route || (route = this.defaultRoute());
|
62
|
-
if (!route) {
|
63
|
-
return;
|
64
|
-
}
|
65
|
-
_ref2 = [{}, 0], opts = _ref2[0], ix = _ref2[1];
|
66
|
-
_ref3 = route.args;
|
67
|
-
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
68
|
-
name = _ref3[_i];
|
69
|
-
opts[name] = args[ix++];
|
70
|
-
}
|
71
|
-
return route.page.draw(opts);
|
72
|
-
};
|
73
|
-
Router.prototype.match = function() {
|
74
|
-
var arg, args, match, route, _i, _len, _ref;
|
75
|
-
_ref = this.routes;
|
76
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
77
|
-
route = _ref[_i];
|
78
|
-
if (match = window.location.hash.match(route.re)) {
|
79
|
-
args = (function() {
|
80
|
-
var _j, _len2, _ref2, _results;
|
81
|
-
_ref2 = match.slice(1);
|
82
|
-
_results = [];
|
83
|
-
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
84
|
-
arg = _ref2[_j];
|
85
|
-
_results.push(arg.replace('/', ''));
|
86
|
-
}
|
87
|
-
return _results;
|
88
|
-
})();
|
89
|
-
return [route, args];
|
90
|
-
}
|
91
|
-
}
|
92
|
-
return [];
|
93
|
-
};
|
94
|
-
Router.prototype.defaultRoute = function() {
|
95
|
-
var route, _i, _len, _ref;
|
96
|
-
_ref = this.routes;
|
97
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
98
|
-
route = _ref[_i];
|
99
|
-
if (route.re === 'default') {
|
100
|
-
return route;
|
101
|
-
}
|
102
|
-
}
|
103
|
-
};
|
104
|
-
return Router;
|
105
|
-
})();
|