Skip to content

Commit fd1eb8a

Browse files
author
Friedrich
committed
Merge pull request #875 from kossebau/customLogRenderer
Remove HTML rendering of logging out of normal BrowserRuntime
2 parents 2d536ac + 963eabf commit fd1eb8a

10 files changed

Lines changed: 83 additions & 36 deletions

File tree

webodf/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ include(${CMAKE_BINARY_DIR}/jsfileslist.txt)
1313

1414
configure_file(webodfversion.js.in ${CMAKE_CURRENT_BINARY_DIR}/webodfversion.js)
1515

16-
set(TESTJSFILES tests/core/ZipTests.js
16+
set(TESTJSFILES
17+
tests/core/UnitTester.js
18+
tests/core/ZipTests.js
1719
tests/core/Base64Tests.js
1820
tests/core/CursorTests.js
1921
tests/core/DomUtilsTests.js

webodf/lib/manifest.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
"core.Task": [
5353
"core.ScheduledTask"
5454
],
55-
"core.UnitTester": [
56-
],
5755
"core.Utils": [
5856
],
5957
"core.Zip": [

webodf/lib/runtime.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,8 @@ Runtime.assert = function (condition, message) {
340340
* @constructor
341341
* @augments Runtime
342342
* @implements {Runtime}
343-
* @param {Element} logoutput
344343
*/
345-
function BrowserRuntime(logoutput) {
344+
function BrowserRuntime() {
346345
"use strict";
347346
var self = this;
348347

@@ -490,32 +489,13 @@ function BrowserRuntime(logoutput) {
490489
* @return {undefined}
491490
*/
492491
function log(msgOrCategory, msg) {
493-
var node, doc, category;
492+
var category;
494493
if (msg !== undefined) {
495494
category = msgOrCategory;
496495
} else {
497496
msg = msgOrCategory;
498497
}
499-
if (logoutput) {
500-
doc = logoutput.ownerDocument;
501-
if (category) {
502-
node = doc.createElement("span");
503-
node.className = category;
504-
node.appendChild(doc.createTextNode(category));
505-
logoutput.appendChild(node);
506-
logoutput.appendChild(doc.createTextNode(" "));
507-
}
508-
node = doc.createElement("span");
509-
if (msg.length > 0 && msg[0] === "<") {
510-
node.innerHTML = msg;
511-
} else {
512-
node.appendChild(doc.createTextNode(msg));
513-
}
514-
logoutput.appendChild(node);
515-
logoutput.appendChild(doc.createElement("br"));
516-
} else if (console) {
517-
console.log(msg);
518-
}
498+
console.log(msg);
519499
if (self.enableAlerts && category === "alert") {
520500
alert(msg);
521501
}
@@ -1492,7 +1472,7 @@ Runtime.create = function create() {
14921472
var /**@type{!Runtime}*/
14931473
result;
14941474
if (String(typeof window) !== "undefined") {
1495-
result = new BrowserRuntime(window.document.getElementById("logoutput"));
1475+
result = new BrowserRuntime();
14961476
} else if (String(typeof require) !== "undefined") {
14971477
result = new NodeJSRuntime();
14981478
} else {

webodf/tests/manifest.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"core.StepIterator",
3232
"core.UnitTester"
3333
],
34+
"core.UnitTester": [
35+
],
3436
"core.ZipTests": [
3537
"core.UnitTester",
3638
"core.Zip"
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Copyright (C) 2012-2015 KO GmbH <copyright@kogmbh.com>
3+
*
4+
* @licstart
5+
* This file is part of WebODF.
6+
*
7+
* WebODF is free software: you can redistribute it and/or modify it
8+
* under the terms of the GNU Affero General Public License (GNU AGPL)
9+
* as published by the Free Software Foundation, either version 3 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* WebODF is distributed in the hope that it will be useful, but
13+
* WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with WebODF. If not, see <http://www.gnu.org/licenses/>.
19+
* @licend
20+
*
21+
* @source: http://www.webodf.org/
22+
* @source: https://github.com/kogmbh/WebODF/
23+
*/
24+
25+
/*global window, runtime*/
26+
27+
runtime.libraryPaths = (function () {
28+
"use strict";
29+
30+
return function () {
31+
return ["../lib", "."];
32+
};
33+
}());
34+
35+
runtime.log = (function () {
36+
"use strict";
37+
38+
var normalLog = runtime.log,
39+
logoutput = window.document.getElementById("logoutput");
40+
41+
return function (msgOrCategory, msg) {
42+
var node, doc, category;
43+
44+
// do normal log first
45+
normalLog(msgOrCategory, msg);
46+
47+
// now output also
48+
if (msg !== undefined) {
49+
category = msgOrCategory;
50+
} else {
51+
msg = msgOrCategory;
52+
}
53+
54+
doc = logoutput.ownerDocument;
55+
if (category) {
56+
node = doc.createElement("span");
57+
node.className = category;
58+
node.appendChild(doc.createTextNode(category));
59+
logoutput.appendChild(node);
60+
logoutput.appendChild(doc.createTextNode(" "));
61+
}
62+
node = doc.createElement("span");
63+
if (msg.length > 0 && msg[0] === "<") {
64+
node.innerHTML = msg;
65+
} else {
66+
node.appendChild(doc.createTextNode(msg));
67+
}
68+
logoutput.appendChild(node);
69+
logoutput.appendChild(doc.createElement("br"));
70+
};
71+
}());

webodf/tests/tests.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@
1010
<div id="console"></div>
1111
<div id="logoutput"></div>
1212
<script src="../lib/runtime.js"></script>
13-
<script type="text/javascript">
14-
runtime.libraryPaths = (function () {
15-
return function () {
16-
return ["../lib", "."];
17-
};
18-
}());
19-
</script>
13+
<script src="testruntimeadaption.js"></script>
2014
<script src="tests.js"></script>
2115
</body>
2216
</html>

webodf/tests/tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

2525
/*global runtime, Runtime, core, gui, xmldom, RuntimeTests, odf, ops, webodf_css: true*/
2626

27+
runtime.loadClass("core.UnitTester");
2728
runtime.loadClass("core.Base64Tests");
2829
runtime.loadClass("core.CursorTests");
2930
runtime.loadClass("core.DomUtilsTests");
3031
runtime.loadClass("core.EventSubscriptionsTests");
3132
runtime.loadClass("core.PositionIteratorTests");
3233
runtime.loadClass("core.RuntimeTests");
3334
runtime.loadClass("core.StepIteratorTests");
34-
runtime.loadClass("core.UnitTester");
3535
runtime.loadClass("core.ZipTests");
3636
runtime.loadClass("gui.DirectFormattingControllerTests");
3737
runtime.loadClass("gui.GuiStepUtilsTests");

webodf/tools/karma.conf.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ module.exports = function (config) {
4242
'lib/core/RawInflate.js',
4343
'lib/core/enums.js',
4444
'lib/core/StepIterator.js',
45-
'lib/core/UnitTester.js',
4645
'lib/core/Utils.js',
4746
'lib/core/Zip.js',
4847
'lib/core/typedefs.js',

webodf/tools/updateJS.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ function main(f) {
650650
delete contents[pathModule.normalize("lib/runtime.js")];
651651
delete contents[pathModule.normalize("lib/core/JSLint.js")];
652652
delete contents[pathModule.normalize("tests/tests.js")];
653+
delete contents[pathModule.normalize("tests/testruntimeadaption.js")];
653654
Object.keys(contents).forEach(function (name) {
654655
if (typeof contents[name] === "string") {
655656
files[name] = contents[name];

0 commit comments

Comments
 (0)