Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial multi-line expr implementation

  • Loading branch information...
commit cedcfcea0d526141ddd47c0d2077d8c7777b4847 1 parent c2ae738
@rf- authored
View
1  lib/pry-notebook/files/index.html
@@ -16,6 +16,7 @@
</div>
<div class="output"></div>
<div class="footer">
+ <div class="partial"></div>
<input type="text"></input>
</div>
</div>
View
5 lib/pry-notebook/files/main.js
@@ -1,7 +1,8 @@
$(function () {
var nb = new Notebook({
- input: $(".footer input"),
- output: $(".output")
+ output: $(".output"),
+ partial: $(".footer .partial"),
+ input: $(".footer input")
});
Notebook.openSocket(function (msg) {
View
26 lib/pry-notebook/files/notebook.js
@@ -1,6 +1,7 @@
function Notebook(options) {
- this.output = options.output;
- this.input = options.input;
+ this.output = options.output;
+ this.input = options.input;
+ this.partial = options.partial;
this.bindKeyup();
};
@@ -15,14 +16,29 @@ Notebook.prototype.handleMessage = function(data) {
var html = $('<div/>').text(data.value).html(),
div = $('<div/>').addClass("pry-" + data.type);
+ html = html.replace(/\n$/, "");
html = html.replace(/\n/g, "<br>");
html = html.replace(/ /g, "&nbsp; ");
- if (data.type == "result") {
- html = "=> " + html;
+ switch (data.type) {
+ case "continuation":
+ this.handleContinuation(html);
+ break;
+ case "result":
+ this.clearContinuationArea();
+ html = "=> " + html;
+ // fall through
+ default:
+ this.output.append(div.html(html));
}
+};
+
+Notebook.prototype.clearContinuationArea = function() {
+ this.partial.html("");
+};
- this.output.append(div.html(html));
+Notebook.prototype.handleContinuation = function(html) {
+ this.partial.html(html);
};
Notebook.prototype.sendLine = function(line) {
View
2  lib/pry-notebook/files/pry-notebook.css
@@ -5,7 +5,7 @@
padding: 16px;
}
-.output, input {
+.output, .partial, input {
font-family: Monaco, Consolas, monospace;
font-size: 16px;
}
View
54 lib/pry-notebook/files/test.js
@@ -2,9 +2,11 @@ describe("Pry Notebook", function() {
beforeEach(function() {
this.output = { append: jasmine.createSpy("append") };
this.input = { on: jasmine.createSpy("on") };
+ this.partial = { html: jasmine.createSpy("html") };
this.notebook = new Notebook({
- output: this.output,
- input: this.input
+ output: this.output,
+ input: this.input,
+ partial: this.partial
});
});
@@ -19,28 +21,38 @@ describe("Pry Notebook", function() {
this.el = call && call.args && call.args[0];
});
- it("appends them to the output div", function() {
- expect(this.output.append).toHaveBeenCalled();
- });
-
cb.call(this);
});
};
- describeMessageType("result", { value: "100" }, function() {
- it("uses the class 'pry-result'", function() {
- expect(this.el.hasClass("pry-result")).toBe(true);
+ var itAppends = function() {
+ it("appends them to the output div", function() {
+ expect(this.output.append).toHaveBeenCalled();
});
+ };
+
+ var itUsesClass = function(classname) {
+ it("uses the class '" + classname + "'", function() {
+ expect(this.el.hasClass(classname)).toBe(true);
+ });
+ };
+
+ describeMessageType("result", { value: "100" }, function() {
+ itAppends();
+ itUsesClass("pry-result");
it("prepends =>", function() {
expect(this.el.text()).toBe("=> 100");
});
+
+ it("clears the partial expr", function() {
+ expect(this.partial.html).toHaveBeenCalledWith("");
+ });
});
describeMessageType("output", { value: "hey\nb ab y" }, function() {
- it("uses the class 'pry-output'", function() {
- expect(this.el.hasClass("pry-output")).toBe(true);
- });
+ itAppends();
+ itUsesClass("pry-output");
it("preserves line breaks and whitespace", function() {
expect(this.el.html()).toBe("hey<br>b&nbsp; ab y");
@@ -49,11 +61,25 @@ describe("Pry Notebook", function() {
it("does not prepend =>", function() {
expect(this.el.html()).not.toMatch(/^=> /);
});
+
+ it("does not clear the partial expr", function() {
+ expect(this.partial.html).not.toHaveBeenCalled();
+ });
});
describeMessageType("error", { value: "Some Message" }, function() {
- it("uses the class 'pry-error'", function() {
- expect(this.el.hasClass("pry-error")).toBe(true);
+ itAppends();
+ itUsesClass("pry-error");
+ });
+
+ describeMessageType("continuation", { value: "def x\n 10\n" }, function () {
+ it("does not add it to the output area", function () {
+ expect(this.output.append).not.toHaveBeenCalled();
+ });
+
+ it("adds the partial expression above the input box", function () {
+ expect(this.partial.html)
+ .toHaveBeenCalledWith("def x<br>&nbsp; 10");
});
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.