Skip to content

Commit 0574a3d

Browse files
committed
Merge pull request #23 from niess/master
Some tweaks and more love for callbacks
2 parents 5990e51 + 1bfdc4d commit 0574a3d

File tree

3 files changed

+64
-21
lines changed

3 files changed

+64
-21
lines changed

lib/docurium.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def generate_docs
167167

168168
# There's still some work we need to do serially
169169
tally_sigs!(version, data)
170+
force_utf8(data)
170171
sha = @repo.write(data.to_json, :blob)
171172

172173
print "Generating documentation [#{i}/#{nversions}]\r"
@@ -225,6 +226,21 @@ def generate_docs
225226
puts "\tupdated #{br}"
226227
end
227228

229+
def force_utf8(data)
230+
# Walk the data to force strings encoding to UTF-8.
231+
if data.instance_of? Hash
232+
data.each do |key, value|
233+
if [:comment, :comments, :description].include?(key)
234+
data[key] = value.force_encoding('UTF-8') unless value.nil?
235+
else
236+
force_utf8(value)
237+
end
238+
end
239+
elsif data.respond_to?(:each)
240+
data.each { |x| force_utf8(x) }
241+
end
242+
end
243+
228244
def show_warnings(data)
229245
out '* checking your api'
230246

@@ -362,17 +378,20 @@ def group_functions!(data)
362378
end
363379

364380
def find_type_usage!(data)
365-
# go through all the functions and see where types are used and returned
381+
# go through all the functions and callbacks and see where other types are used and returned
366382
# store them in the types data
367-
data[:functions].each do |func, fdata|
383+
h = {}
384+
h.merge!(data[:functions])
385+
h.merge!(data[:callbacks])
386+
h.each do |func, fdata|
368387
data[:types].each_with_index do |tdata, i|
369388
type, typeData = tdata
370389
data[:types][i][1][:used] ||= {:returns => [], :needs => []}
371-
if fdata[:return][:type].index(/#{type}[ ;\)\*]/)
390+
if fdata[:return][:type].index(/#{type}[ ;\)\*]?/)
372391
data[:types][i][1][:used][:returns] << func
373392
data[:types][i][1][:used][:returns].sort!
374393
end
375-
if fdata[:argline].index(/#{type}[ ;\)\*]/)
394+
if fdata[:argline].index(/#{type}[ ;\)\*]?/)
376395
data[:types][i][1][:used][:needs] << func
377396
data[:types][i][1][:used][:needs].sort!
378397
end

site/index.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ <h3><a href="#">Files</a></h3>
9292
<% }) %>
9393
</ul>
9494
</li>
95+
<% if (examples.length > 0) { %>
9596
<li>
9697
<h3><a href="#">Examples</a></h3>
9798
<ul>
@@ -102,6 +103,7 @@ <h3><a href="#">Examples</a></h3>
102103
<% }) %>
103104
</ul>
104105
</li>
106+
<% } %> <!-- if we have examples -->
105107
</script>
106108

107109
<!-- Listing of the details of a single function -->
@@ -162,14 +164,14 @@ <h3>versions</h3>
162164
</ul>
163165
</div>
164166
<% } %> <!-- if we have examples -->
165-
<% if (alsoLinks) { %>
167+
<% if (alsoLinks && (alsoLinks.length > 0)) { %>
166168
<div class="also">
167169
Also in <a href="<%= alsoGroup %>"><%= groupName %></a> group: <br/>
168170
<% _.each(_.initial(alsoLinks), function(link) { %>
169171
<a href="<%= link.url %>"><%= link.name %></a>,
170172
<% }) %>
171173
<% var link = _.last(alsoLinks) %>
172-
<a href="<%= link.url %>"><%= link.name %></a>
174+
<a href="<%= link.url %>"><%= link.name %></a>.
173175
</div>
174176
<% } %> <!-- if we have "also" links -->
175177
</script>
@@ -191,21 +193,21 @@ <h2 class="funcGroup"><%= group.name %></h2>
191193

192194
<script type="text/template" id="uses-template">
193195
<% if (returns.length > 0) { %>
194-
<h3>Returns</h3>
196+
<h3>Returned by</h3>
195197
<% _.each(_.initial(returns), function(fun) { %>
196-
<a href="<%= fun.url %>"><%= fun.name %></a>
198+
<a href="<%= fun.url %>"><%= fun.name %></a>,
197199
<% }) %> <!-- loop over each 'return' -->
198200
<% var fun = _.last(returns) %>
199-
<a href="<%= fun.url %>"><%= fun.name %></a>
201+
<a href="<%= fun.url %>"><%= fun.name %></a>.
200202
<% } %> <!-- if we have 'returns' -->
201203

202204
<% if (needs.length > 0) { %>
203-
<h3>Argument In</h3>
205+
<h3>Argument in</h3>
204206
<% _.each(_.initial(needs), function(fun) { %>
205-
<a href="<%= fun.url %>"><%= fun.name %></a>
207+
<a href="<%= fun.url %>"><%= fun.name %></a>,
206208
<% }) %> <!-- loop over each 'need' -->
207209
<% var fun = _.last(needs) %>
208-
<a href="<%= fun.url %>"><%= fun.name %></a>
210+
<a href="<%= fun.url %>"><%= fun.name %></a>.
209211
<% } %> <!-- if we have 'needs' -->
210212

211213
<div class="fileLink">

site/js/docurium.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ $(function() {
1717
return {name: name, link: link, num: group[1].length}
1818
})
1919

20+
// Callbacks
21+
var callbacks = _.map(_.keys(data['callbacks']), function(name) {
22+
var link = functionLink('callback', name, version)
23+
return {name: name, link: link}
24+
})
25+
2026
// Types
2127
var getName = function(type) {
2228
var name = type[0];
@@ -50,8 +56,8 @@ $(function() {
5056
})
5157
}
5258

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})
5561
},
5662
})
5763

@@ -78,12 +84,24 @@ $(function() {
7884
render: function() {
7985
var data = this.model.get('data')
8086

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})
8487
var menu = $(this.template({funs: data.funs, files: data.files, examples: data.examples}))
8588

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+
}
87105

88106
this.$el.html(menu)
89107
return this
@@ -223,7 +241,7 @@ $(function() {
223241
var cdata = docurium.get('data')['callbacks']
224242
ldata = cdata
225243
} else {
226-
var functions = group[1]
244+
var functions = _.filter(group[1], function(f){ return f != fname})
227245
}
228246

229247
// Function Arguments
@@ -391,6 +409,7 @@ $(function() {
391409
var cdata = o.callbacks
392410
var version = o.version
393411

412+
this.gname = gname.charAt(0).toUpperCase() + gname.substring(1).toLowerCase()
394413
this.functions = _.map(group[1], function(name) {
395414
var url = '#' + functionLink(gname, name, version)
396415
var d = fdata[name]
@@ -581,7 +600,7 @@ $(function() {
581600
})
582601
},
583602

584-
// look for structs and link them
603+
// look for structs and link them
585604
hotLink: function(text) {
586605
types = this.get('data')['types']
587606
var version = this.get('version')
@@ -606,7 +625,10 @@ $(function() {
606625
},
607626

608627
groupOf: function (func) {
609-
return this.get('data')['functions'][func]['group']
628+
if(func in this.get('data')['functions']) {
629+
return this.get('data')['functions'][func]['group']
630+
}
631+
return 'callback'
610632
},
611633

612634
github_file: function(file, line, lineto) {

0 commit comments

Comments
 (0)