docurium 0.4.1 → 0.7.0

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/site/js/docurium.js CHANGED
@@ -12,46 +12,52 @@ $(function() {
12
12
 
13
13
  // Function groups
14
14
  var funs = _.map(data['groups'], function(group, i) {
15
- var name = group[0]
16
- var link = groupLink(name, version)
17
- return {name: name, link: link, num: group[1].length}
15
+ var name = group[0]
16
+ var link = groupLink(name, version)
17
+ return {name: name, link: link, num: group[1].length}
18
+ })
19
+
20
+ // Callbacks
21
+ var callbacks = _.map(_.keys(data['callbacks']), function(name) {
22
+ var link = functionLink('callback', name, version)
23
+ return {name: name, link: link}
18
24
  })
19
25
 
20
26
  // Types
21
27
  var getName = function(type) {
22
- var name = type[0];
23
- var link = typeLink(name, version);
24
- return {link: link, name: name};
28
+ var name = type[0];
29
+ var link = typeLink(name, version);
30
+ return {link: link, name: name};
25
31
  }
26
32
 
27
33
  var enums = _.filter(data['types'], function(type) {
28
- return type[1]['block'] && type[1]['type'] == 'enum';
34
+ return type[1]['block'] && type[1]['type'] == 'enum';
29
35
  }).map(getName)
30
36
 
31
37
  var structs = _.filter(data['types'], function(type) {
32
- return type[1]['block'] && type[1]['type'] != 'enum'
38
+ return type[1]['block'] && type[1]['type'] != 'enum'
33
39
  }).map(getName)
34
40
 
35
41
  var opaques = _.filter(data['types'], function(type) {
36
- return !type[1]['block']
42
+ return !type[1]['block']
37
43
  }).map(getName)
38
44
 
39
45
  // File Listing
40
46
  var files = _.map(data['files'], function(file) {
41
- var url = this.github_file(file['file'])
42
- return {url: url, name: file['file']}
47
+ var url = this.github_file(file['file'])
48
+ return {url: url, name: file['file']}
43
49
  }, docurium)
44
50
 
45
51
  // Examples List
46
52
  var examples = []
47
53
  if(data['examples'] && (data['examples'].length > 0)) {
48
- examples = _.map(data['examples'], function(file) {
49
- return {name: file[0], path: file[1]}
50
- })
54
+ examples = _.map(data['examples'], function(file) {
55
+ return {name: file[0], path: file[1]}
56
+ })
51
57
  }
52
58
 
53
- this.set('data', {funs: funs, enums: enums, structs: structs, opaques: opaques,
54
- files: files, examples: examples})
59
+ this.set('data', {funs: funs, callbacks: callbacks, enums: enums, structs: structs,
60
+ opaques: opaques, files: files, examples: examples})
55
61
  },
56
62
  })
57
63
 
@@ -78,12 +84,24 @@ $(function() {
78
84
  render: function() {
79
85
  var data = this.model.get('data')
80
86
 
81
- var enumList = this.typeTemplate({title: 'Enums', elements: data.enums})
82
- var structList = this.typeTemplate({title: 'Structs', elements: data.structs})
83
- var opaquesList = this.typeTemplate({title: 'Opaque Structs', elements: data.opaques})
84
87
  var menu = $(this.template({funs: data.funs, files: data.files, examples: data.examples}))
85
88
 
86
- $('#types-list', menu).append(enumList, structList, opaquesList)
89
+ if (data.enums.length) {
90
+ var enumList = this.typeTemplate({title: 'Enums', elements: data.enums})
91
+ $('#types-list', menu).append(enumList)
92
+ }
93
+ if (data.structs.length) {
94
+ var structList = this.typeTemplate({title: 'Structs', elements: data.structs})
95
+ $('#types-list', menu).append(structList)
96
+ }
97
+ if (data.opaques.length) {
98
+ var opaquesList = this.typeTemplate({title: 'Opaque Structs', elements: data.opaques})
99
+ $('#types-list', menu).append(opaquesList)
100
+ }
101
+ if (data.callbacks.length) {
102
+ var callbacksList = this.typeTemplate({title: 'Callbacks', elements: data.callbacks})
103
+ $('#types-list', menu).append(callbacksList)
104
+ }
87
105
 
88
106
  this.$el.html(menu)
89
107
  return this
@@ -169,34 +187,34 @@ $(function() {
169
187
 
170
188
  // figure out the adds, deletes and changes
171
189
  _.forEach(sigHist, function(func, fname) {
172
- var lastv = _.last(func.exists)
173
- var firstv = _.first(func.exists)
174
- changelog[firstv]['adds'].push(fname)
175
-
176
- // figure out where it was deleted or changed
177
- if (lastv && (lastv != lastVer)) {
178
- var vi = _.indexOf(versions,lastv)
179
- var delv = versions[vi-1]
180
- changelog[delv]['deletes'].push(fname)
181
-
182
- _.forEach(func.changes, function(_, v) {
183
- changelog[v]['changes'].push(fname)
184
- })
185
- }
190
+ var lastv = _.last(func.exists)
191
+ var firstv = _.first(func.exists)
192
+ changelog[firstv]['adds'].push(fname)
193
+
194
+ // figure out where it was deleted or changed
195
+ if (lastv && (lastv != lastVer)) {
196
+ var vi = _.indexOf(versions,lastv)
197
+ var delv = versions[vi-1]
198
+ changelog[delv]['deletes'].push(fname)
199
+
200
+ _.forEach(func.changes, function(_, v) {
201
+ changelog[v]['changes'].push(fname)
202
+ })
203
+ }
186
204
  })
187
205
 
188
206
  var vers = _.map(versions, function(version) {
189
- var deletes = changelog[version]['deletes']
190
- deletes.sort()
207
+ var deletes = changelog[version]['deletes']
208
+ deletes.sort()
191
209
 
192
- var additions = changelog[version]['adds']
193
- additions.sort()
194
- var adds = _.map(additions, function(add) {
210
+ var additions = changelog[version]['adds']
211
+ additions.sort()
212
+ var adds = _.map(additions, function(add) {
195
213
  var gname = this.model.groupOf(add)
196
- return {link: functionLink(gname, add, version), text: add}
197
- }, this)
214
+ return {link: functionLink(gname, add, version), text: add}
215
+ }, this)
198
216
 
199
- return {title: version, listing: this.itemTemplate({dels: deletes, adds: adds})}
217
+ return {title: version, listing: this.itemTemplate({dels: deletes, adds: adds})}
200
218
  }, this)
201
219
 
202
220
  this.el = this.template({versions: vers})
@@ -220,15 +238,15 @@ $(function() {
220
238
 
221
239
  var ldata = fdata
222
240
  if (isCallback) {
223
- var cdata = docurium.get('data')['callbacks']
224
- ldata = cdata
241
+ var cdata = docurium.get('data')['callbacks']
242
+ ldata = cdata
225
243
  } else {
226
- var functions = group[1]
244
+ var functions = _.filter(group[1], function(f){ return f != fname})
227
245
  }
228
246
 
229
247
  // Function Arguments
230
248
  var args = _.map(ldata[fname]['args'], function(arg) {
231
- return {link: this.hotLink(arg.type), name: arg.name, comment: arg.comment}
249
+ return {link: this.hotLink(arg.type), name: arg.name, comment: arg.comment}
232
250
  }, docurium)
233
251
 
234
252
  var data = ldata[fname]
@@ -239,32 +257,32 @@ $(function() {
239
257
  var sig = docurium.hotLink(ret.type) + ' ' + fname + '(' + data['argline'] + ');'
240
258
  // version history
241
259
  if (!isCallback) {
242
- var sigHist = docurium.get('signatures')[fname]
243
- var version = docurium.get('version')
244
- var sigs = _.map(sigHist.exists, function(ver) {
245
- var klass = []
246
- if (sigHist.changes[ver])
247
- klass.push('changed')
248
- if (ver == version)
249
- klass.push('current')
250
-
251
- return {url: '#' + functionLink(gname, fname, ver), name: ver, klass: klass.join(' ')}
252
- })
260
+ var sigHist = docurium.get('signatures')[fname]
261
+ var version = docurium.get('version')
262
+ var sigs = _.map(sigHist.exists, function(ver) {
263
+ var klass = []
264
+ if (sigHist.changes[ver])
265
+ klass.push('changed')
266
+ if (ver == version)
267
+ klass.push('current')
268
+
269
+ return {url: '#' + functionLink(gname, fname, ver), name: ver, klass: klass.join(' ')}
270
+ })
253
271
  }
254
272
  // GitHub link
255
273
  var fileLink = docurium.github_file(data.file, data.line, data.lineto)
256
274
  // link to the group
257
275
  if (!isCallback) {
258
- var version = docurium.get('version')
259
- var alsoGroup = '#' + groupLink(group[0], version)
260
- var alsoLinks = _.map(functions, function(f) {
261
- return {url: '#' + functionLink(gname, f, version), name: f}
262
- })
276
+ var version = docurium.get('version')
277
+ var alsoGroup = '#' + groupLink(group[0], version)
278
+ var alsoLinks = _.map(functions, function(f) {
279
+ return {url: '#' + functionLink(gname, f, version), name: f}
280
+ })
263
281
  }
264
282
 
265
283
  this.set('data', {name: fname, data: data, args: args, returns: returns, sig: sig,
266
- sigs: sigs, fileLink: fileLink, groupName: gname,
267
- alsoGroup: alsoGroup, alsoLinks: alsoLinks})
284
+ sigs: sigs, fileLink: fileLink, groupName: gname,
285
+ alsoGroup: alsoGroup, alsoLinks: alsoLinks})
268
286
  }
269
287
  })
270
288
 
@@ -295,18 +313,18 @@ $(function() {
295
313
  var version = this.docurium.get('version')
296
314
 
297
315
  var groups = _.map(data.groups, function(group) {
298
- var gname = group[0]
299
- var funs = _.map(group[1], function(fun) {
300
- var klass = ''
301
- if (sigHist[fun].changes[version])
302
- klass = 'changed'
303
-
304
- if (version == _.first(sigHist[fun].exists))
305
- klass = 'introd'
306
-
307
- return {name: fun, url: '#' + functionLink(gname, fun, version), klass: klass}
308
- })
309
- return {name: gname, funs: funs}
316
+ var gname = group[0]
317
+ var funs = _.map(group[1], function(fun) {
318
+ var klass = ''
319
+ if (sigHist[fun].changes[version])
320
+ klass = 'changed'
321
+
322
+ if (version == _.first(sigHist[fun].exists))
323
+ klass = 'introd'
324
+
325
+ return {name: fun, url: '#' + functionLink(gname, fun, version), klass: klass}
326
+ })
327
+ return {name: gname, funs: funs}
310
328
  })
311
329
 
312
330
  this.reset(groups)
@@ -329,38 +347,33 @@ $(function() {
329
347
  var version = docurium.get('version')
330
348
  var types = docurium.get('data')['types']
331
349
  var tdata = _.find(types, function(g) {
332
- return g[0] == typename
350
+ return g[0] == typename
333
351
  })
334
352
  var tname = tdata[0]
335
353
  var data = tdata[1]
336
354
 
337
- var toPair = function(fun) {
338
- var gname = this.groupOf(fun)
339
- var url = '#' + functionLink(gname, fun, version)
340
- return {name: fun, url: url}
355
+ var toFuncPair = function(fun) {
356
+ var gname = this.groupOf(fun)
357
+ var url = '#' + functionLink(gname, fun, version)
358
+ return {name: fun, url: url}
359
+ }
360
+
361
+ var toTypePair = function(type) {
362
+ var url = '#' + typeLink(type, version)
363
+ return {name: type, url: url}
341
364
  }
342
365
 
343
- var returns = _.map(data.used.returns, toPair, docurium)
344
- var needs = _.map(data.used.needs, toPair, docurium)
366
+ var returns = _.map(data.used.returns, toFuncPair, docurium)
367
+ var needs = _.map(data.used.needs, toFuncPair, docurium)
368
+ var fields = _.map(data.used.fields, toTypePair, docurium)
345
369
  var fileLink = {name: data.file, url: docurium.github_file(data.file, data.line, data.lineto)}
346
370
 
347
- // so it doesn't look crap, we build up a block with fields
348
- // without a comment
349
- var had_comment = false
350
- var blocks = []
351
- var tmp = []
352
- _.each(data.fields, function(f) {
353
- if (had_comment) {
354
- blocks.push(tmp)
355
- tmp = []
356
- }
357
-
358
- tmp.push(f)
359
- had_comment = f.comments
360
- })
361
- blocks.push(tmp)
371
+ // Hot link our field types
372
+ data.fields = _.map(data.fields, function(field) {
373
+ return {type: this.hotLink(field.type), name: field.name, comments: field.comments}
374
+ }, docurium)
362
375
 
363
- this.set('data', {tname: tname, data: data, blocks: blocks, returns: returns, needs: needs, fileLink: fileLink})
376
+ this.set('data', {tname: tname, data: data, returns: returns, needs: needs, fields: fields, fileLink: fileLink})
364
377
  }
365
378
  })
366
379
 
@@ -391,11 +404,12 @@ $(function() {
391
404
  var cdata = o.callbacks
392
405
  var version = o.version
393
406
 
407
+ this.gname = gname.charAt(0).toUpperCase() + gname.substring(1).toLowerCase()
394
408
  this.functions = _.map(group[1], function(name) {
395
- var url = '#' + functionLink(gname, name, version)
396
- var d = fdata[name]
397
- return {name: name, url: url, returns: d['return']['type'], argline: d['argline'],
398
- description: d['description'], comments: d['comments'], args: d['args']}
409
+ var url = '#' + functionLink(gname, name, version)
410
+ var d = fdata[name]
411
+ return {name: name, url: url, returns: d['return']['type'], argline: d['argline'],
412
+ description: d['description'], comments: d['comments'], args: d['args']}
399
413
  })
400
414
  },
401
415
 
@@ -414,9 +428,9 @@ $(function() {
414
428
 
415
429
  events: {
416
430
  'keyup': function() {
417
- this.trigger('keyup')
418
- if (this.$el.val() == '')
419
- this.trigger('empty')
431
+ this.trigger('keyup')
432
+ if (this.$el.val() == '')
433
+ this.trigger('empty')
420
434
  }
421
435
  },
422
436
  })
@@ -436,7 +450,7 @@ $(function() {
436
450
  keyup: function() {
437
451
  var newValue = this.field.$el.val()
438
452
  if (this.value == newValue || newValue.length < 3)
439
- return
453
+ return
440
454
 
441
455
  this.value = newValue
442
456
  this.refreshSearch()
@@ -452,19 +466,19 @@ $(function() {
452
466
  var version = docurium.get('version')
453
467
  // look for functions (name, comment, argline)
454
468
  _.forEach(data.functions, function(f, name) {
455
- var gname = docurium.groupOf(name)
456
- // look in the function name first
469
+ var gname = docurium.groupOf(name)
470
+ // look in the function name first
457
471
  if (name.search(value) > -1) {
458
- var gl = functionLink(gname, name, version)
459
- var url = '#' + gl
460
- searchResults.push({url: url, name: name, match: 'function', navigate: gl})
461
- return
472
+ var gl = functionLink(gname, name, version)
473
+ var url = '#' + gl
474
+ searchResults.push({url: url, name: name, match: 'function', navigate: gl})
475
+ return
462
476
  }
463
477
 
464
- // if we didn't find it there, let's look in the argline
478
+ // if we didn't find it there, let's look in the argline
465
479
  if (f.argline && f.argline.search(value) > -1) {
466
- var gl = functionLink(gname, name, version)
467
- var url = '#' + gl
480
+ var gl = functionLink(gname, name, version)
481
+ var url = '#' + gl
468
482
  searchResults.push({url: url, name: name, match: f.argline, navigate: gl})
469
483
  }
470
484
  })
@@ -472,8 +486,8 @@ $(function() {
472
486
  // look for types
473
487
  data.types.forEach(function(type) {
474
488
  var name = type[0]
475
- var tl = typeLink(name, version)
476
- var url = '#' + tl
489
+ var tl = typeLink(name, version)
490
+ var url = '#' + tl
477
491
  if (name.search(value) > -1) {
478
492
  searchResults.push({url: url, name: name, match: type[1].type, navigate: tl})
479
493
  }
@@ -481,12 +495,12 @@ $(function() {
481
495
 
482
496
  // look for callbacks
483
497
  _.each(data.callbacks, function(f, name) {
484
- if (name.search(value) > -1) {
485
- var gl = functionLink('callback', name, version)
486
- var url = '#' + gl
487
- searchResults.push({url: url, name: name, match: 'callback', navigate: gl})
488
- return
489
- }
498
+ if (name.search(value) > -1) {
499
+ var gl = functionLink('callback', name, version)
500
+ var url = '#' + gl
501
+ searchResults.push({url: url, name: name, match: 'callback', navigate: gl})
502
+ return
503
+ }
490
504
  })
491
505
 
492
506
  this.reset(searchResults)
@@ -513,8 +527,8 @@ $(function() {
513
527
  view.render()
514
528
 
515
529
  if (this.activeView) {
516
- this.stopListening()
517
- this.activeView.remove()
530
+ this.stopListening()
531
+ this.activeView.remove()
518
532
  }
519
533
 
520
534
  this.activeView = view
@@ -556,15 +570,15 @@ $(function() {
556
570
 
557
571
  current = docurium.get('version')
558
572
  if (current == version) {
559
- if (success)
560
- success();
561
- return;
573
+ if (success)
574
+ success();
575
+ return;
562
576
  }
563
577
 
564
578
  docurium.set({version: version})
565
579
  p = this.loadDoc()
566
580
  if (success)
567
- p.then(success)
581
+ p.then(success)
568
582
  },
569
583
 
570
584
  loadDoc: function() {
@@ -577,27 +591,26 @@ $(function() {
577
591
  getGroup: function(gname) {
578
592
  var groups = docurium.get('data')['groups']
579
593
  return _.find(groups, function(g) {
580
- return g[0] == gname
594
+ return g[0] == gname
581
595
  })
582
596
  },
583
597
 
584
- // look for structs and link them
598
+ // look for structs and link them
585
599
  hotLink: function(text) {
586
600
  types = this.get('data')['types']
587
601
  var version = this.get('version')
588
602
 
589
- for(var i=0; i<types.length; i++) {
590
- type = types[i]
591
- typeName = type[0]
592
- typeData = type[1]
593
- re = new RegExp(typeName + '\\s', 'gi');
603
+ _.each(types, function(type) {
604
+ var typeName = type[0];
605
+ var typeData = type[1];
606
+ var re = new RegExp('\\b' + typeName + '\\b', 'gi');
594
607
  var link = $('<a>').attr('href', '#' + typeLink(typeName, version)).append(typeName)[0]
595
608
  text = text.replace(re, link.outerHTML + ' ')
596
- }
609
+ });
597
610
 
598
611
  var callbacks = this.get('data')['callbacks']
599
612
  _.each(callbacks, function(cb, typeName) {
600
- re = new RegExp(typeName + '$', 'gi');
613
+ var re = new RegExp(typeName + '$', 'gi');
601
614
  var link = $('<a>').attr('href', '#' + functionLink('callback', typeName, version)).append(typeName)[0]
602
615
  text = text.replace(re, link.outerHTML + ' ')
603
616
  });
@@ -606,17 +619,20 @@ $(function() {
606
619
  },
607
620
 
608
621
  groupOf: function (func) {
609
- return this.get('data')['functions'][func]['group']
622
+ if(func in this.get('data')['functions']) {
623
+ return this.get('data')['functions'][func]['group']
624
+ }
625
+ return 'callback'
610
626
  },
611
627
 
612
628
  github_file: function(file, line, lineto) {
613
629
  var data = this.get('data')
614
630
  url = ['https://github.com', docurium.get('github'),
615
- 'blob', docurium.get('version'), data.prefix, file].join('/')
631
+ 'blob', docurium.get('version'), data.prefix, file].join('/')
616
632
  if(line) {
617
633
  url += '#L' + line.toString()
618
634
  if(lineto) {
619
- url += '-' + lineto.toString()
635
+ url += '-L' + lineto.toString()
620
636
  }
621
637
  } else {
622
638
  url += '#files'
@@ -655,47 +671,47 @@ $(function() {
655
671
  main: function(version) {
656
672
  var self = this
657
673
  this.doc.setVersion(version, function() {
658
- var view = new MainListView({collection: self.groups})
659
- self.mainView.setActive(view)
674
+ var view = new MainListView({collection: self.groups})
675
+ self.mainView.setActive(view)
660
676
  })
661
677
  },
662
678
 
663
679
  group: function(version, gname) {
664
680
  var self = this
665
681
  this.doc.setVersion(version, function() {
666
- var group = self.doc.getGroup(gname)
667
- var fdata = self.doc.get('data')['functions']
668
- var cdata = self.doc.get('data')['callbacks']
669
- var version = self.doc.get('version')
670
- var view = new GroupView({group: group, functions: fdata, callbacks: cdata, version: version})
671
- self.mainView.setActive(view)
682
+ var group = self.doc.getGroup(gname)
683
+ var fdata = self.doc.get('data')['functions']
684
+ var cdata = self.doc.get('data')['callbacks']
685
+ var version = self.doc.get('version')
686
+ var view = new GroupView({group: group, functions: fdata, callbacks: cdata, version: version})
687
+ self.mainView.setActive(view)
672
688
  });
673
689
  },
674
690
 
675
691
  groupFun: function(version, gname, fname) {
676
692
  var self = this
677
693
  this.doc.setVersion(version, function() {
678
- var model = new FunctionModel({docurium: self.doc, gname: gname, fname: fname})
679
- var view = new FunctionView({model: model})
680
- self.mainView.setActive(view)
694
+ var model = new FunctionModel({docurium: self.doc, gname: gname, fname: fname})
695
+ var view = new FunctionView({model: model})
696
+ self.mainView.setActive(view)
681
697
  })
682
698
  },
683
699
 
684
700
  showtype: function(version, tname) {
685
701
  var self = this
686
702
  this.doc.setVersion(version, function() {
687
- var model = new TypeModel({docurium: self.doc, typename: tname})
688
- var view = new TypeView({model: model})
689
- self.mainView.setActive(view)
703
+ var model = new TypeModel({docurium: self.doc, typename: tname})
704
+ var view = new TypeView({model: model})
705
+ self.mainView.setActive(view)
690
706
  })
691
707
  },
692
708
 
693
709
  search: function(version, query) {
694
710
  var self = this
695
711
  this.doc.setVersion(version, function() {
696
- var view = new SearchView({collection: self.search})
697
- $('#search-field').val(query).keyup()
698
- self.mainView.setActive(view)
712
+ var view = new SearchView({collection: self.search})
713
+ $('#search-field').val(query).keyup()
714
+ self.mainView.setActive(view)
699
715
  })
700
716
  },
701
717
 
@@ -703,10 +719,10 @@ $(function() {
703
719
  // let's wait to process it until it's asked, and let's only do
704
720
  // it once
705
721
  if (this.changelogView == undefined) {
706
- this.changelogView = new ChangelogView({model: this.doc})
722
+ this.changelogView = new ChangelogView({model: this.doc})
707
723
  }
708
724
  this.doc.setVersion(undefined, function() {
709
- this.mainView.setActive(this.changelogView)
725
+ this.mainView.setActive(this.changelogView)
710
726
  })
711
727
  },
712
728
  });
@@ -738,7 +754,7 @@ $(function() {
738
754
  var mainView = new MainView()
739
755
 
740
756
  var router = new Workspace({docurium: docurium, search: searchCol, mainView: mainView,
741
- groups: groupCol})
757
+ groups: groupCol})
742
758
 
743
759
  searchField.on('empty', function() {
744
760
  router.navigate(docurium.get('version'), {trigger: true})