Skip to content

Commit c593a7c

Browse files
author
Visnu Pitiyanuvath
committed
add coffee to compiler support for static public assets
1 parent cc4a61f commit c593a7c

File tree

6 files changed

+254
-4
lines changed

6 files changed

+254
-4
lines changed

lib/connect/lib/connect/middleware/compiler.js

+17
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ var compilers = exports.compilers = {
7373
}
7474
});
7575
}
76+
},
77+
coffee: {
78+
match: /\.js$/,
79+
ext: '.coffee',
80+
compile: function(str, fn){
81+
require.async('coffee-script', function(err, coffee){
82+
if (err) {
83+
fn(err);
84+
} else {
85+
try {
86+
fn(null, coffee.compile(str));
87+
} catch (err) {
88+
fn(err);
89+
}
90+
}
91+
});
92+
}
7693
}
7794
};
7895

nodeko.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ express = require 'express'
55
models = require './models/models'
66
[Team, Person, Vote] = [models.Team, models.Person, models.Vote]
77

8-
pub = __dirname + '/public';
8+
pub = __dirname + '/public'
99
app = express.createServer(
10-
connect.compiler({ src: pub, enable: ['sass'] }),
10+
connect.compiler({ src: pub, enable: ['sass', 'coffee'] }),
1111
connect.staticProvider(pub)
1212
)
1313

File renamed without changes.

public/javascripts/application.js

+233
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
(function() {
2+
var Stars;
3+
$(function() {
4+
var _a, countdown, d, h, i, m, ms, s, tick, y;
5+
$('a.resend').click(function() {
6+
var a;
7+
a = $(this);
8+
a.hide().after('<span>Resending&hellip;</span>');
9+
$.get(this.href, function() {
10+
return a.next('span').html('Sent!').fadeOut('slow', function() {
11+
a.next('span').remove();
12+
return a.fadeIn();
13+
});
14+
});
15+
return false;
16+
});
17+
$('a.delete').click(function() {
18+
return confirm('Are you sure?');
19+
});
20+
$('a.reveal').click(function() {
21+
$(this).hide().next('.hidden').slideDown(function() {
22+
return $(this).find('input').select();
23+
});
24+
return false;
25+
});
26+
$(':input:visible:first:not([rel=nofollow])').focus();
27+
$('input.url').click(function() {
28+
if (this.value === this.defaultValue) {
29+
return this.select();
30+
}
31+
});
32+
$('form.reset_password').submit(function() {
33+
var email, form;
34+
form = $(this);
35+
email = form.find('input.email').val();
36+
$.ajax({
37+
type: form.attr('method'),
38+
url: form.attr('action'),
39+
data: form.serialize(),
40+
success: function(data) {
41+
return form.replaceWith("<h2>" + email + " has been sent a new password</h2>\n<p>It should arrive shortly.</p>");
42+
},
43+
error: function(xhr) {
44+
return $('#errors').append("<li>" + xhr.responseText + "</li>");
45+
}
46+
});
47+
return false;
48+
});
49+
$('form').submit(function(evt) {
50+
var errors, form, hasError, highlightError;
51+
form = $(this).closest('form');
52+
errors = $('#errors').html('');
53+
form.find('input').removeClass('error');
54+
hasError = false;
55+
highlightError = function(selector, message, fn) {
56+
var invalid;
57+
invalid = form.find(selector).filter(fn);
58+
if (invalid.length) {
59+
errors.append(("<li>" + (message) + "</li>"));
60+
invalid.addClass('error');
61+
invalid.blur();
62+
return (hasError = true);
63+
}
64+
};
65+
highlightError('input.email', 'Invalid email address', function() {
66+
var val;
67+
val = $(this).val();
68+
return val && !/^[a-zA-Z0-9+._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(val);
69+
});
70+
highlightError('input[name=name]', 'Name is required', function() {
71+
return !$(this).val();
72+
});
73+
highlightError('input#github', 'GitHub username is required', function() {
74+
return !$(this).val();
75+
});
76+
highlightError('input.email:first', 'Email is required', function() {
77+
return !$(this).val();
78+
});
79+
highlightError('input[type=password]:visible', 'Password required', function() {
80+
return !$(this).val();
81+
});
82+
highlightError('input.url', 'Invalid link', function() {
83+
var val;
84+
val = $(this).val();
85+
return val && val !== this.defaultValue && !/^https?:\/\/.*\./.test(val);
86+
});
87+
!(hasError) ? $('input.url').each(function() {
88+
if (this.value === this.defaultValue) {
89+
return (this.value = '');
90+
}
91+
}) : null;
92+
return !hasError;
93+
});
94+
if ($('.body.index time').length > 0) {
95+
_a = $('time').attr('datetime').split(/[-:TZ]/);
96+
y = _a[0];
97+
m = _a[1];
98+
d = _a[2];
99+
h = _a[3];
100+
i = _a[4];
101+
s = _a[5];
102+
ms = Date.UTC(y, m - 1, d, h, i, s);
103+
countdown = $('#date .about');
104+
tick = function() {
105+
var days, diff, hours, minutes, secs;
106+
diff = (ms - new Date().getTime()) / 1000;
107+
days = Math.floor(diff % 604800 / 86400);
108+
hours = Math.floor(diff % 86400 / 3600);
109+
minutes = Math.floor(diff % 3600 / 60);
110+
secs = Math.floor(diff % 60);
111+
countdown.html(days + ' days ' + hours + ' hours ' + minutes + ' minutes ' + secs + ' seconds');
112+
return setTimeout(tick, 1000);
113+
};
114+
tick();
115+
}
116+
return $('time').live('hover', function(e) {
117+
var $this, _b, dt;
118+
if (e.type === 'mouseout') {
119+
return $('.localtime').remove();
120+
}
121+
$this = $(this);
122+
_b = $this.attr('datetime').split(/[-:TZ]/);
123+
y = _b[0];
124+
m = _b[1];
125+
d = _b[2];
126+
h = _b[3];
127+
i = _b[4];
128+
s = _b[5];
129+
ms = Date.UTC(y, m - 1, d, h, i, s);
130+
dt = new Date(ms);
131+
return $('<div class="localtime blue">').css({
132+
left: e.pageX,
133+
top: $(this).position().top + 25
134+
}).html((" \
135+
" + (dt.strftime('%a %b %d, %I:%M%P %Z').replace(/\b0/, '')) + " \
136+
")).appendTo(document.body);
137+
});
138+
});
139+
$('.judge img').each(function() {
140+
var r;
141+
r = 'rotate(' + new String(Math.random() * 6 - 3) + 'deg)';
142+
return $(this).css('-webkit-transform', r).css('-moz-transform', r);
143+
});
144+
Stars = {
145+
value: function(elem) {
146+
return elem.attr('data-value');
147+
},
148+
input: function(elem) {
149+
return elem.closest('.stars').prev('input[type=hidden]');
150+
},
151+
set: function(elem) {
152+
var newVal, oldVal;
153+
newVal = this.value(elem);
154+
oldVal = this.input(elem).val();
155+
return this.input(elem).val(newVal === oldVal ? 0 : newVal);
156+
},
157+
highlight: function(elem, hover) {
158+
var score;
159+
score = parseInt(hover ? this.value(elem) : this.input(elem).val());
160+
return elem.closest('.stars').children().each(function(i, star) {
161+
var $star, fill;
162+
$star = $(star);
163+
fill = $star.attr('data-value') <= score;
164+
$star.find('.filled').toggle(fill);
165+
return $star.find('.empty').toggle(!fill);
166+
});
167+
}
168+
};
169+
$('.votes-new, #your_vote').delegate('.star', 'hover', function(e) {
170+
return Stars.highlight($(this), e.type === 'mouseover');
171+
}).delegate('.star', 'click', function(e) {
172+
return Stars.set($(this));
173+
});
174+
(function() {
175+
$('.votes time').each(function() {
176+
var _a, d, h, i, m, ms, s, y;
177+
_a = $(this).attr('datetime').split(/[-:TZ]/);
178+
y = _a[0];
179+
m = _a[1];
180+
d = _a[2];
181+
h = _a[3];
182+
i = _a[4];
183+
s = _a[5];
184+
ms = Date.UTC(y, m - 1, d, h, i, s);
185+
return $(this).text(prettyDate(new Date(ms)));
186+
});
187+
return setTimeout(arguments.callee, 10 * 1000);
188+
})();
189+
$('.votes .more').each(function() {
190+
var $more, loadMoreNow, page;
191+
$more = $(this);
192+
loadMoreNow = $more.position().top - $(window).height() + 10;
193+
page = 1;
194+
return $(window).scroll(function(e) {
195+
if (loadMoreNow && this.scrollY > loadMoreNow) {
196+
loadMoreNow = null;
197+
return $.get(window.location.pathname + ("/votes.js?page=" + (++page)), function(html) {
198+
var moreVotes;
199+
moreVotes = $('<div class="page">').html(html);
200+
$more.remove();
201+
$('.votes').append(moreVotes);
202+
if (moreVotes.find('li').length === 51) {
203+
$('.votes').append($more);
204+
return (loadMoreNow = $more.position().top - $(window).height() + 10);
205+
}
206+
});
207+
}
208+
});
209+
});
210+
$('#your_vote a[href$=draft]').click(function() {
211+
var _a;
212+
return (typeof (_a = window.localStorage) !== "undefined" && _a !== null) ? (localStorage['draft'] = JSON.stringify($(this).closest('form').serializeArray())) : null;
213+
});
214+
$('.teams-show #your_vote').each(function() {
215+
var _a, _b, _c, _d, _e, el;
216+
if (!((typeof (_a = window.localStorage == undefined ? undefined : window.localStorage.draft) !== "undefined" && _a !== null) && window.location.hash === '#draft')) {
217+
return null;
218+
}
219+
try {
220+
_b = []; _d = JSON.parse(localStorage.draft);
221+
for (_c = 0, _e = _d.length; _c < _e; _c++) {
222+
el = _d[_c];
223+
_b.push($(this[el.name]).val(el.value));
224+
}
225+
return _b;
226+
} finally {
227+
delete localStorage.draft;
228+
}
229+
});
230+
$('.votes-new .stars, #your_vote .stars').each(function() {
231+
return Stars.highlight($(this));
232+
});
233+
})();

support.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// bootstrap server config
2-
require.paths.unshift('./lib/connect/lib', './lib/express/lib', './lib/coffee/lib');
2+
require.paths.unshift('./lib/connect/lib', './lib/express/lib', './lib/coffee/lib', './lib/coffee/lib/coffee-script/lib');
33
require.paths.unshift('lib/express/lib/support/haml/lib/', 'lib/express/lib/support/sass/lib/', 'lib/express/support/jade/lib/', 'lib/express/support/jade/support/markdown/lib');
44
require('./public/javascripts/strftime');
55
require('coffee'); // coffeescript!

views/layout.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
%script{ src: '/javascripts/strftime.js', type: 'text/javascript' }
143143
%script{ src: '/javascripts/pretty_date.js', type: 'text/javascript' }
144144
%script{ src: '/javascripts/json2.js' }
145-
%script{ src: '/application.js', type: 'text/javascript' }
145+
%script{ src: '/javascripts/application.js', type: 'text/javascript' }
146146
%script{ src: 'http://hoptoadapp.com/javascripts/notifier.js', type: 'text/javascript'}
147147
:javascript
148148
$(function() {

0 commit comments

Comments
 (0)