Skip to content

Commit b4c83c9

Browse files
- Fixing interactive tests;
- Reorganizing `dist` folder; - Using rollup to generate the UMD.
1 parent b8dc25a commit b4c83c9

File tree

9 files changed

+154
-87
lines changed

9 files changed

+154
-87
lines changed

index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

interactive-tests/js/simplelog.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1+
// Copyright 2023 Design Liquido
12
// Copyright 2018 Johannes Wilm
23
// Copyright 2005-2006 Google
34
//
45
// Author: Steffen Meschkat <mesch@google.com>
56
//
67
// A very simple logging facility, used in test/xpath.html.
7-
import {
8-
xmlEscapeText
9-
} from "../../src/dom/util.js"
10-
118

129
export class Log {
1310

@@ -16,14 +13,14 @@ export class Log {
1613
}
1714

1815
static write(s) {
19-
this.lines.push(xmlEscapeText(s));
16+
this.lines.push(window.xmlEscapeText(s));
2017
this.show();
2118
}
2219

2320
// Writes the given XML with every tag on a new line.
2421
static writeXML(xml) {
2522
const s0 = xml.replace(/</g, '\n<');
26-
const s1 = xmlEscapeText(s0);
23+
const s1 = window.xmlEscapeText(s0);
2724
const s2 = s1.replace(/\s*\n(\s|\n)*/g, '<br/>');
2825
this.lines.push(s2);
2926
this.show();

interactive-tests/xpath.html

Lines changed: 110 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,120 @@
11
<html>
2-
<head>
3-
<script src="../test_dist/xpath_script.js" language="JavaScript"></script>
4-
</head>
5-
<body onload="load_expr()">
6-
<form onsubmit="xpath_test(this);return false" action="javascript:void(0)">
7-
<select id="s" multiple="1" size="30" name="cases"></select>
8-
<input type="submit" value="parse" align="top"/>
9-
</form>
10-
<script type="application/javascript" src="https://www.unpkg.com/xslt-processor@1.0.0/xslt-processor.js"></script>
11-
<script>
12-
// Copyright 2023 Design Liquido
13-
// Copyright 2018 Johannes Wilm
14-
// Copyright 2005 Google Inc.
15-
// All Rights Reserved
16-
//
17-
// Tests for the XPath parser. To run the test, open the file from the
18-
// file system. No server support is required.
19-
//
20-
//
21-
// Author: Steffen Meschkat <mesch@google.com>
22-
import {
23-
Log
24-
} from "./simplelog.js"
25-
import {
26-
xpathParse
27-
} from "../src/xpath.js"
28-
import {
29-
expr
30-
} from "../tests_src/xpath_unittest.js"
31-
import {
32-
parseTree
33-
} from "../src/xpathdebug.js"
2+
<head>
3+
<script type="application/javascript" src="js/xslt-processor.js"></script>
4+
<script>
5+
// Copyright 2023 Design Liquido
6+
// Copyright 2018 Johannes Wilm
7+
// Copyright 2005 Google Inc.
8+
// All Rights Reserved
9+
//
10+
// Tests for the XPath parser. To run the test, open the file from the
11+
// file system. No server support is required.
12+
//
13+
//
14+
// Author: Steffen Meschkat <mesch@google.com>
15+
window.logging = true;
16+
window.xpathdebug = true;
3417

35-
window.logging = true;
36-
window.xpathdebug = true;
18+
class Log {
19+
constructor() {
20+
this.lines = [];
21+
}
3722

38-
window.load_expr = () => {
39-
const s = document.getElementById('s');
40-
for (let i = 0; i < expr.length; ++i) {
41-
const o = new Option(expr[i].replace(/&gt;/, '>').replace(/&lt;/, '<'));
42-
s.options[s.options.length] = o;
43-
}
44-
s.selectedIndex = 0;
45-
}
23+
static write(s) {
24+
this.lines.push(globalThis.XsltProcessor.xmlEscapeText(s));
25+
this.show();
26+
}
4627

47-
let log = new Log()
28+
// Writes the given XML with every tag on a new line.
29+
static writeXML(xml) {
30+
const s0 = xml.replace(/</g, '\n<');
31+
const s1 = global.XsltProcessor.xmlEscapeText(s0);
32+
const s2 = s1.replace(/\s*\n(\s|\n)*/g, '<br/>');
33+
this.lines.push(s2);
34+
this.show();
35+
}
4836

49-
window.xpath_test = form => {
50-
log.clear();
51-
try {
52-
const i = form.cases.selectedIndex;
53-
const options = form.cases.options;
37+
// Writes without any escaping
38+
static writeRaw(s) {
39+
this.lines.push(s);
40+
this.show();
41+
}
5442

55-
const text = options[i].value;
56-
log.writeRaw(`<tt><b>${text}</b></tt>`);
43+
static clear() {
44+
const l = this.div();
45+
l.innerHTML = '';
46+
this.lines = [];
47+
}
5748

58-
const expr = xpathParse(text, message => log.write(message));
59-
log.writeRaw(`<tt><b>${text}</b></tt>`);
60-
log.writeRaw(`<pre>${parseTree(expr, '')}</pre>`);
49+
static show() {
50+
const l = this.div();
51+
l.innerHTML += `${this.lines.join('<br/>')}<br/>`;
52+
this.lines = [];
53+
l.scrollTop = l.scrollHeight;
54+
}
6155

62-
options[i].selected = false;
63-
if (i < options.length - 1) {
64-
options[i + 1].selected = true;
65-
} else {
66-
options[0].selected = true;
67-
}
56+
static div() {
57+
let l = document.getElementById('log');
58+
if (!l) {
59+
l = document.createElement('div');
60+
l.id = 'log';
61+
l.style.position = 'absolute';
62+
l.style.right = '5px';
63+
l.style.top = '5px';
64+
l.style.width = '250px';
65+
l.style.height = '150px';
66+
l.style.overflow = 'auto';
67+
l.style.backgroundColor = '#f0f0f0';
68+
l.style.border = '1px solid gray';
69+
l.style.fontSize = '10px';
70+
l.style.padding = '5px';
71+
document.body.appendChild(l);
72+
}
73+
return l;
74+
}
75+
}
6876

69-
} catch (e) {
70-
log.write(`EXCEPTION ${e}`);
71-
}
72-
}
73-
</script>
74-
</body>
77+
window.load_expr = () => {
78+
const s = document.getElementById('s');
79+
const expr = ['<xsl:stylesheet>'];
80+
for (let i = 0; i < expr.length; ++i) {
81+
const o = new Option(expr[i].replace(/&gt;/, '>').replace(/&lt;/, '<'));
82+
s.options[s.options.length] = o;
83+
}
84+
s.selectedIndex = 0;
85+
};
86+
87+
let log = new Log();
88+
89+
window.xpath_test = (form) => {
90+
log.clear();
91+
try {
92+
const i = form.cases.selectedIndex;
93+
const options = form.cases.options;
94+
95+
const text = options[i].value;
96+
log.writeRaw(`<tt><b>${text}</b></tt>`);
97+
98+
const expr = xpathParse(text, (message) => log.write(message));
99+
log.writeRaw(`<tt><b>${text}</b></tt>`);
100+
log.writeRaw(`<pre>${parseTree(expr, '')}</pre>`);
101+
102+
options[i].selected = false;
103+
if (i < options.length - 1) {
104+
options[i + 1].selected = true;
105+
} else {
106+
options[0].selected = true;
107+
}
108+
} catch (e) {
109+
log.write(`EXCEPTION ${e}`);
110+
}
111+
};
112+
</script>
113+
</head>
114+
<body onload="window.load_expr()">
115+
<form onsubmit="window.xpath_test(this);return false" action="javascript:void(0)">
116+
<select id="s" multiple="1" size="30" name="cases"></select>
117+
<input type="submit" value="parse" align="top" />
118+
</form>
119+
</body>
75120
</html>

interactive-tests/xslt.html

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,35 @@
22
<html>
33
<head>
44
<title>Simple XSLT test</title>
5-
<script src="../test_dist/xslt_script.js"></script>
5+
<!-- script src="../test_dist/xslt_script.js"></script -->
6+
<script type="application/javascript" src="js/xslt-processor.js"></script>
7+
<script>
8+
window.logging = true;
9+
window.xsltdebug = true;
10+
11+
window.el = function(id) {
12+
return document.getElementById(id);
13+
}
14+
15+
window.test_xslt = function() {
16+
const xml = globalThis.XsltProcessor.xmlParse(el('xml').value);
17+
const xslt = globalThis.XsltProcessor.xmlParse(el('xslt').value);
18+
const xsltClass = new globalThis.XsltProcessor.Xslt();
19+
const html = xsltClass.xsltProcess(xml, xslt);
20+
el('html').value = html;
21+
el('htmldisplay').innerHTML = html;
22+
}
23+
24+
window.cleanxml = function() {
25+
cleanvalue('xml');
26+
cleanvalue('xslt');
27+
}
28+
29+
window.cleanvalue = function(id) {
30+
const x = el(id);
31+
x.value = x.value.replace(/^\s*/, '').replace(/\n\s*/g, '\n');
32+
}
33+
</script>
634
</head>
735
<body onload="cleanxml()">
836
<form onsubmit="test_xslt();return false">

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
"scripts": {
1212
"test": "jest",
1313
"build": "tsc",
14-
"rollup-build": "rollup index.ts -c -f umd -o dist/xslt-processor.js",
15-
"build_test": "yarn build_tests && yarn build_xpath_script && yarn build_xslt_script",
16-
"build_xpath_script": "rollup test_src/xpath_script.js -c -f iife -o test_dist/xpath_script.js",
17-
"build_xslt_script": "rollup test_src/xslt_script.js -c -f iife -o test_dist/xslt_script.js",
14+
"rollup-build": "rollup src/index.ts -c -f umd -o dist/umd/xslt-processor.js",
1815
"lint": "eslint src/**/*"
1916
},
2017
"repository": {

rollup.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import commonjs from 'rollup-plugin-commonjs'
22
import resolve from 'rollup-plugin-node-resolve'
33
import buble from 'rollup-plugin-buble'
4-
import terser from '@rollup/plugin-terser';
4+
// import terser from '@rollup/plugin-terser';
55
import typescript from '@rollup/plugin-typescript';
66

77
export default {
@@ -18,8 +18,8 @@ export default {
1818
resolve(),
1919
buble({
2020
transforms: {dangerousForOf: true}
21-
}),
22-
terser()
21+
})
22+
// terser()
2323
],
2424
output: {
2525
format: 'umd',

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { XPath } from './xpath';
2+
export { Xslt } from './xslt';
3+
export { xmlParse } from './dom';
4+
export { xmlEscapeText } from './dom/util';
5+
export { ExprContext } from './xpath';

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"compilerOptions": {
33
"outDir": "dist",
44
"module": "CommonJS",
5-
"target": "ES2017",
6-
"rootDir": ".",
5+
"target": "ES5",
6+
"rootDir": "src",
77
"allowJs": true,
88
"sourceMap": true,
99
"declaration": true,

tsconfig.rollup.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"jsx": "preserve",
44
"outDir": "dist",
55
"target": "ES5",
6-
"rootDir": ".",
6+
"rootDir": "src",
77
"allowJs": true,
88
"sourceMap": true,
99
"declaration": true,

0 commit comments

Comments
 (0)