-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathGruntfile.coffee
289 lines (236 loc) · 6.15 KB
/
Gruntfile.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
moment = require "moment"
ical = require "ical-generator"
LIVERELOAD_PORT = 35729;
lrSnippet = require("connect-livereload") { port: LIVERELOAD_PORT }
mountFolder = (connect, dir) ->
return connect.static require("path").resolve dir
{J} = require "./jamhub"
module.exports = (grunt) ->
require("load-grunt-tasks")(grunt)
jam_files = [
"jams/2011.json"
"jams/2012.json"
"jams/2013.json"
"jams/2014.json"
"jams/2015.json"
]
assemble = {
options: {
cache_buster: "#{+new Date}"
layout: "templates/layout.hbs"
root: "../../.." # path to index from jam page
}
all_jams: {
options: {
root: ".."
page_title: "All game jams"
}
src: "templates/all_jams.hbs"
dest: "jams/index.html"
}
}
for file in jam_files
build_jam_pages assemble, grunt.file.readJSON file
build_tag_pages assemble
build_jam_root_page assemble
grunt.initConfig {
pkg: grunt.file.readJSON "package.json"
watch: {
coffee: {
files: ['jamhub.coffee']
tasks: ['coffee']
options: {
spawn: false
interrupt: false,
debounceDelay: 250
}
}
sass: {
files: ['jamhub.scss']
tasks: ['sass']
options: {
spawn: false
interrupt: false,
debounceDelay: 250
}
}
# BUG-LR-JSCSS: Livereload doesn't always refresh browser for jamhub.css and jamhub.js. index.html seems fine.
livereload: {
options: {
livereload: LIVERELOAD_PORT
spawn: false
interrupt: false,
debounceDelay: 250
}
files: [
"jamhub.js"
"jamhub.css"
"index.html"
]
}
}
coffee: {
compile: {
files: {
"jamhub.js": "jamhub.coffee"
}
}
}
sass: {
compile: {
files: {
"jamhub.css": "jamhub.scss"
}
}
}
connect: {
options: {
port: 9000
hostname: "localhost"
}
livereload: {
options: {
middleware: (connect) ->
return [
lrSnippet
mountFolder(connect, './')
]
}
}
}
open: {
server: {
path: "http://<%= connect.options.hostname %>:<%= connect.options.port %>"
}
}
assemble: assemble
}
grunt.loadNpmTasks "assemble"
grunt.loadNpmTasks "grunt-contrib-sass"
grunt.loadNpmTasks "grunt-contrib-coffee"
grunt.registerTask "ical", "create ical feed", ->
build_ical_feed assemble
grunt.registerTask "default", ["coffee", "sass"]
grunt.registerTask "serve", [
"coffee"
"sass"
"connect:livereload"
"open"
"watch"
]
build_ical_feed = (params) ->
calendar = ical()
calendar.setDomain('compohub.net')
calendar.setName('Compohub Game Jams')
#Get a list of jams in sorted order
jams = []
for slug, jam of params.options.jams_by_slug
jams.push(jam)
jams.sort (a, b) ->
b.start_date - a.start_date
#iCal library does not propery escape carriage returns
escape_carriage_return = (str) ->
str.replace(/\r/g, (match) -> "" )
#Iterate through jams, adding it to ical builder
for jam in jams
#Parse dates
[start_date] = J.parse_jam_timestamp jam.start_date
[end_date] = J.parse_jam_timestamp jam.end_date
#Escape Summary and Description
summary = if jam.name? then escape_carriage_return(jam.name) else ""
description = if jam.description? then escape_carriage_return(jam.description) else ""
#Ensure that there is both a start_date and end_date for this event
continue unless start_date
continue unless end_date
calendar.addEvent {
start: start_date,
end: end_date,
summary: summary,
description: description,
url: jam.url,
uid: jam.slug
}
calendar.saveSync("feed.ics")
build_jam_pages = (params, jam_data) ->
params.options ||= {}
# images is reserved name
params.options.jams_by_slug ||= {
images: true
}
J.Jams.slugify_jams jam_data.jams, params.options.jams_by_slug
for jam in jam_data.jams
params["jam_#{jam.slug}"] = {
options: {
jam: jam
jam_json: JSON.stringify(jam)
page_title: jam.name
}
src: "templates/jam.hbs"
dest: "#{jam.local_url}/index.html"
}
params
format_jam_for_list = (jam, start_date) ->
{
start_date: +start_date.toDate()
simple_date: start_date.format("MMM D")
url: "#{jam.local_url}"
jam: jam
}
build_tag_pages = (params) ->
jams = params.options.jams_by_slug
jams_by_tag = {}
for slug of jams
jam = jams[slug]
[start_date] = J.parse_jam_timestamp jam.start_date
continue unless start_date
start_date = moment start_date
wrapped = {
start_date: +start_date.toDate()
simple_date: start_date.format("YYYY-MM-DD")
url: "#{jam.local_url}"
jam: jam
}
if jam.tags
for tag in jam.tags
jams_by_tag[tag] ||= []
jams_by_tag[tag].push wrapped
for tag of jams_by_tag
jams = jams_by_tag[tag]
jams.sort (a, b) ->
b.start_date - a.start_date
params["tag_#{tag}"] = {
options: {
tag: tag
jams: jams
page_title: "Jams taged '#{tag}'"
root: "../.."
}
src: "templates/tag.hbs"
dest: "tags/#{tag}/index.html"
}
build_jam_root_page = (params) ->
jams = params.options.jams_by_slug
jams_by_year = {}
for slug of jams
jam = jams[slug]
[start_date] = J.parse_jam_timestamp jam.start_date
continue unless start_date
start_date = moment start_date
year = start_date.year()
wrapped = {
start_date: +start_date.toDate()
simple_date: start_date.format("MMM D")
url: "#{jam.local_url}"
jam: jam
}
unless jams_by_year[year]
jams_by_year[year] = []
jams_by_year[year].push wrapped
year_tuples = for year of jams_by_year
list = jams_by_year[year]
list.sort (a, b) ->
a.start_date - b.start_date
{ year: year, jams: list }
year_tuples.sort (a, b) ->
b.year - a.year
params.all_jams.options.jams_by_year = year_tuples