Skip to content

Commit

Permalink
Allow comments on interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkschulze committed Mar 12, 2013
1 parent d4b2718 commit e1a161d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
5 changes: 5 additions & 0 deletions js/core/css/webidl-oldschool.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ a.idlEnumItem {
color: #666;
}

/*.idlSectionComment*/
.idlSectionComment {
color: gray;
}

/*.idlConst*/
.idlConstType {
color: #005a9c;
Expand Down
2 changes: 2 additions & 0 deletions js/core/templates/webidl/comment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<span class='idlSectionComment'>{{extAttr obj indent true
}}{{idn indent}}// {{comment}}</span>
16 changes: 15 additions & 1 deletion js/core/webidl-oldschool.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ define(
, "tmpl!core/templates/webidl/method.html"
, "tmpl!core/templates/webidl/attribute.html"
, "tmpl!core/templates/webidl/serializer.html"
, "tmpl!core/templates/webidl/comment.html"
, "tmpl!core/templates/webidl/field.html"
, "tmpl!core/templates/webidl/exception.html"
, "tmpl!core/templates/webidl/interface.html"
],
function (hb, css, idlModuleTmpl, idlTypedefTmpl, idlImplementsTmpl, idlDictMemberTmpl, idlDictionaryTmpl,
idlEnumItemTmpl, idlEnumTmpl, idlConstTmpl, idlParamTmpl, idlCallbackTmpl, idlMethodTmpl,
idlAttributeTmpl, idlSerializerTmpl, idlFieldTmpl, idlExceptionTmpl, idlInterfaceTmpl) {
idlAttributeTmpl, idlSerializerTmpl, idlCommentTmpl, idlFieldTmpl, idlExceptionTmpl, idlInterfaceTmpl) {
var WebIDLProcessor = function (cfg) {
this.parent = { type: "module", id: "outermost", children: [] };
if (!cfg) cfg = {};
Expand Down Expand Up @@ -574,6 +575,14 @@ define(
return obj;
}

// COMMENT
match = /^\s*\/\/\s*(.*)\s*$/.exec(str);
if (match) {
obj.type = "comment";
obj.id = match[1];
return obj;
}

// NOTHING MATCHED
this.msg.pub("error", "Expected interface member, got: " + str);
},
Expand Down Expand Up @@ -1107,6 +1116,7 @@ define(
else if (ch.type == "method") return self.writeMethod(ch, maxMeth, indent + 1, curLnk);
else if (ch.type == "constant") return self.writeConst(ch, maxConst, indent + 1, curLnk);
else if (ch.type == "serializer") return self.writeSerializer(ch, indent + 1, curLnk);
else if (ch.type == "comment") return self.writeComment(ch, indent + 1);
})
.join("")
;
Expand Down Expand Up @@ -1258,6 +1268,10 @@ define(
return idlConstTmpl({ obj: cons, indent: indent, pad: pad, nullable: cons.nullable ? "?" : ""});
},

writeComment: function (comment, indent) {
return idlCommentTmpl({ obj: comment, indent: indent, comment: comment.id});
},


writeSerializer: function (serializer, indent) {
var values = "";
Expand Down
10 changes: 10 additions & 0 deletions tests/spec/core/webidl-oldschool-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ describe("Core - WebIDL", function () {
expect($serializer.find(".idlSerializerValues").text()).toEqual("{foo, bar}");
});

it("should handle comments", function () {
$target = $("#comments-basic", doc);
text = "interface SuperStar {\n" +
" // This is a comment\n" +
" // over two lines.\n" +
"};";
expect($target.text()).toEqual(text);
expect($target.find(".idlSectionComment").length).toEqual(2);
});


it("should handle dictionaries", function () {
$target = $("#dict-basic", doc);
Expand Down
9 changes: 9 additions & 0 deletions tests/spec/core/webidl.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ <h2>Serializer</h2>
<dt>serializer = { foo, bar }</dt>
</dl>
</section>
<section>
<h2>Comments</h2>
<dl id="comments-basic" class='idl' title='interface SuperStar'>
<dt>// This is a comment</dt>
<dd></dd>
<dt>// over two lines.</dt>
<dd></dd>
</dl>
</section>
<section>
<h2>Dictionaries</h2>
<p>
Expand Down

0 comments on commit e1a161d

Please sign in to comment.