Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow comments on interfaces #163

Merged
merged 1 commit into from
Mar 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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