Skip to content

Commit e6b9dfd

Browse files
authored
Merge pull request #38 from tiennou/fix/struct-style
Restyle structs
2 parents b22246b + 30715b4 commit e6b9dfd

File tree

7 files changed

+101
-53
lines changed

7 files changed

+101
-53
lines changed

lib/docurium.rb

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,13 +502,24 @@ def update_globals!(data, recs)
502502

503503
when :struct, :fnptr
504504
data[:types][r[:name]] ||= {}
505+
known = data[:types][r[:name]]
505506
r[:value] ||= r[:name]
506-
wanted[:types].each do |k|
507-
next unless r.has_key? k
508-
if k == :comments
509-
data[:types][r[:name]][k] = md.render r[k]
510-
else
511-
data[:types][r[:name]][k] = r[k]
507+
# we don't want to override "opaque" structs with typedefs or
508+
# "public" documentation
509+
unless r[:tdef].nil? and known[:fields] and known[:comments] and known[:description]
510+
wanted[:types].each do |k|
511+
next unless r.has_key? k
512+
if k == :comments
513+
data[:types][r[:name]][k] = md.render r[k]
514+
else
515+
data[:types][r[:name]][k] = r[k]
516+
end
517+
end
518+
else
519+
# We're about to skip that type. Just make sure we preserve the
520+
# :fields comment
521+
if r[:fields] and known[:fields].empty?
522+
data[:types][r[:name]][:fields] = r[:fields]
512523
end
513524
end
514525
if r[:type] == :fnptr

lib/docurium/docparser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def extract_function_args(cursor, cmt)
147147

148148
def extract_subject_desc(comment)
149149
subject = comment.child.text
150-
paras = comment.find_all { |cmt| cmt.kind == :comment_paragraph }.drop(1).map { |p| p.map(&:text).join() }
150+
paras = comment.find_all { |cmt| cmt.kind == :comment_paragraph }.drop(1).map { |p| p.text }
151151
desc = paras.join("\n\n")
152152
return subject, desc
153153
end

site/css/style.css

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,25 @@ table.methods tr td.methodName a {
117117
font-weight: bold;
118118
}
119119

120-
table.funcTable tr td {
120+
table.funcTable tr td,
121+
table.structTable tr td {
121122
padding: 5px 10px;
122123
border-bottom: 1px solid #eee;
123124
}
124-
table.funcTable tr td.comment {
125-
color: #999;
126-
}
127-
table.funcTable tr td.var {
125+
126+
.enumTable .var,
127+
.funcTable .var,
128+
.structTable .var {
128129
font-weight: bold;
129130
color: #833;
130131
}
131132

133+
.enumTable .type,
134+
.funcTable .type,
135+
.structTable .type {
136+
text-align: right;
137+
}
138+
132139
code.params {
133140
white-space: pre-wrap; /* css-3 */
134141
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
@@ -152,7 +159,9 @@ code.params {
152159

153160
.returns { margin-bottom: 15px; }
154161

155-
h1.funcTitle {
162+
h1.funcTitle,
163+
h1.enumTitle,
164+
h1.structTitle {
156165
font-size: 1.6em;
157166
}
158167
h3.funcDesc {
@@ -255,6 +264,3 @@ p.functionList a.introd {
255264
color: #933;
256265
}
257266

258-
.type-comment {
259-
padding-left: 3em;
260-
}

site/index.html

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ <h3><a href="#">Examples</a></h3>
111111
<table class="funcTable">
112112
<% _.each(args, function(arg) { %>
113113
<tr>
114-
<td valign="top" nowrap="true"><%= arg.link %></td>
114+
<td valign="top" class="type" nowrap="true" rowspan="<%= (arg.comment ? 2 : 1) %>"><%= arg.link %></td>
115115
<td valign="top" class="var"><%= arg.name %></td>
116+
</tr>
117+
<tr>
116118
<td class="comment"><%= arg.comment %></td>
117119
</tr>
118120
<% }) %>
@@ -218,7 +220,7 @@ <h3>Argument in</h3>
218220

219221
<!-- listing for an enum -->
220222
<script type="text/template" id="enum-template">
221-
<h1 class="funcTitle"><%= type.tname %><small><%= type.type %></small></h1>
223+
<h1 class="enumTitle"><%= type.tname %><small><%= type.type %></small></h1>
222224
<p><%= type.value %></p>
223225

224226
<% if (type.data.description) { %>
@@ -228,24 +230,20 @@ <h1 class="funcTitle"><%= type.tname %><small><%= type.type %></small></h1>
228230
<p><%= type.data.comments %></p>
229231
<% } %>
230232

231-
<table>
233+
<table class="enumTable">
232234
<% _.each(type.data.fields, function(field) { %>
233235
<tr>
234-
<td><code><%= field.name %></code></td>
236+
<td class="type"><code><%= field.name %></code></td>
237+
<td class="comment"><%= field.comments %></td>
235238
</tr>
236-
<% if (field.comments) { %>
237-
<tr>
238-
<td class="type-comment"><%= field.comments %></td>
239-
</tr>
240-
<% } %>
241239
<% }) %>
242240
</table>
243241
<%= uses %>
244242
</script>
245243

246244
<!-- listing for a struct -->
247245
<script type="text/template" id="struct-template">
248-
<h1 class="funcTitle"><%= type.tname %><small><%= type.type %></small></h1>
246+
<h1 class="structTitle"><%= type.tname %><small><%= type.type %></small></h1>
249247
<p><%= type.value %></p>
250248

251249
<% if (type.data.description) { %>
@@ -255,17 +253,17 @@ <h1 class="funcTitle"><%= type.tname %><small><%= type.type %></small></h1>
255253
<p><%= type.data.comments %></p>
256254
<% } %>
257255

258-
<table>
256+
<table class="structTable">
259257
<% _.each(type.data.fields, function(field) { %>
260258
<tr>
261-
<td><code><%= field.type %></code></td>
262-
<td><code><%= field.name %></code></td>
263-
<tr>
264-
<% if (field.comments) { %>
259+
<td class="type" valign="top" rowspan="<%= (field.comments ? 2 : 1) %>"><%= field.type %></td>
260+
<td class="var"><%= field.name %></td>
261+
<% if (field.comments) { %>
262+
</tr>
265263
<tr>
266-
<td colspan="2" class="type-comment"><%= field.comments %></td>
264+
<td><span class="comment"><%= field.comments %></td>
265+
<% } %>
267266
</tr>
268-
<% } %>
269267
<% }) %>
270268
</table>
271269

site/js/docurium.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -362,23 +362,12 @@ $(function() {
362362
var needs = _.map(data.used.needs, toPair, docurium)
363363
var fileLink = {name: data.file, url: docurium.github_file(data.file, data.line, data.lineto)}
364364

365-
// so it doesn't look crap, we build up a block with fields
366-
// without a comment
367-
var had_comment = false
368-
var blocks = []
369-
var tmp = []
370-
_.each(data.fields, function(f) {
371-
if (had_comment) {
372-
blocks.push(tmp)
373-
tmp = []
374-
}
375-
376-
tmp.push(f)
377-
had_comment = f.comments
378-
})
379-
blocks.push(tmp)
365+
// Hot link our field types
366+
data.fields = _.map(data.fields, function(field) {
367+
return {type: this.hotLink(field.type), name: field.name, comments: field.comments}
368+
}, docurium)
380369

381-
this.set('data', {tname: tname, data: data, blocks: blocks, returns: returns, needs: needs, fileLink: fileLink})
370+
this.set('data', {tname: tname, data: data, returns: returns, needs: needs, fileLink: fileLink})
382371
}
383372
})
384373

test/docurium_test.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,16 @@ def test_can_parse_function_cast_args
152152
assert_equal 'int (*)(const char *, void *)', func[:args][2][:type]
153153
assert_equal 'Function which will be called for every listed ref', func[:args][2][:comment]
154154
expect_comment =<<-EOF
155-
<p>The listed references may be filtered by type, or using a bitwise OR of several types. Use the magic value <code>GIT_REF_LISTALL</code> to obtain all references, including packed ones.</p>
156-
157-
<p>The <code>callback</code> function will be called for each of the references in the repository, and will receive the name of the reference and the <code>payload</code> value passed to this method.</p>
155+
<p>The listed references may be filtered by type, or using
156+
a bitwise OR of several types. Use the magic value
157+
<code>GIT_REF_LISTALL</code> to obtain all references, including
158+
packed ones.</p>
159+
160+
<p>The <code>callback</code> function will be called for each of the references
161+
in the repository, and will receive the name of the reference and
162+
the <code>payload</code> value passed to this method.</p>
158163
EOF
159-
assert_equal expect_comment.split("\n").map(&:strip), func[:comments].split("\n")
164+
assert_equal expect_comment.split("\n"), func[:comments].split("\n")
160165
end
161166

162167
def test_can_get_the_full_description_from_multi_liners

test/fixtures/git2/repository.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,45 @@ GIT_EXTERN(const char *) git_repository_path(git_repository *repo);
212212
*/
213213
GIT_EXTERN(const char *) git_repository_workdir(git_repository *repo);
214214

215+
/**
216+
* Extended options structure for `git_repository_init_ext`.
217+
*
218+
* This contains extra options for `git_repository_init_ext` that enable
219+
* additional initialization features. The fields are:
220+
*
221+
* * flags - Combination of GIT_REPOSITORY_INIT flags above.
222+
* * mode - Set to one of the standard GIT_REPOSITORY_INIT_SHARED_...
223+
* constants above, or to a custom value that you would like.
224+
* * workdir_path - The path to the working dir or NULL for default (i.e.
225+
* repo_path parent on non-bare repos). IF THIS IS RELATIVE PATH,
226+
* IT WILL BE EVALUATED RELATIVE TO THE REPO_PATH. If this is not
227+
* the "natural" working directory, a .git gitlink file will be
228+
* created here linking to the repo_path.
229+
* * description - If set, this will be used to initialize the "description"
230+
* file in the repository, instead of using the template content.
231+
* * template_path - When GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE is set,
232+
* this contains the path to use for the template directory. If
233+
* this is NULL, the config or default directory options will be
234+
* used instead.
235+
* * initial_head - The name of the head to point HEAD at. If NULL, then
236+
* this will be treated as "master" and the HEAD ref will be set
237+
* to "refs/heads/master". If this begins with "refs/" it will be
238+
* used verbatim; otherwise "refs/heads/" will be prefixed.
239+
* * origin_url - If this is non-NULL, then after the rest of the
240+
* repository initialization is completed, an "origin" remote
241+
* will be added pointing to this URL.
242+
*/
243+
typedef struct {
244+
unsigned int version;
245+
uint32_t flags;
246+
uint32_t mode;
247+
const char *workdir_path;
248+
const char *description;
249+
const char *template_path;
250+
const char *initial_head;
251+
const char *origin_url;
252+
} git_repository_init_options;
253+
215254
/** @} */
216255
GIT_END_DECL
217256
#endif

0 commit comments

Comments
 (0)