Skip to content

Commit e0f22f1

Browse files
authored
Update examples (#61)
* Use npm package for examples * Add second diagram in asciidoc example * Add file suffix to fix multiple diagrams issue
1 parent 2be4381 commit e0f22f1

File tree

10 files changed

+35
-23
lines changed

10 files changed

+35
-23
lines changed

examples/01-basic/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<!-- Require cheerpj dependency -->
88
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
99
<!-- Require PlantUML.js -->
10-
<script src="node_modules/@plantuml/plantuml.js/plantuml.js"></script>
10+
<script src="node_modules/@sakirtemel/plantuml.js/plantuml.js"></script>
1111
</head>
1212
<body>
1313
<img src="loading.png" id="plantuml-diagram" />
1414
<script type="text/javascript">
15-
plantuml.initialize('/app/node_modules/@plantuml/plantuml.js').then(() => {
15+
plantuml.initialize('/app/node_modules/@sakirtemel/plantuml.js').then(() => {
1616
const element = document.getElementById('plantuml-diagram')
1717
const pumlContent = `
1818
@startuml

examples/01-basic/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/01-basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"author": "",
1111
"license": "MIT",
1212
"dependencies": {
13-
"@plantuml/plantuml.js": "file:../../plantuml-wasm"
13+
"@sakirtemel/plantuml.js": "^1.0.0"
1414
}
1515
}

examples/02-asciidoctor.js/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<!-- Require cheerpj dependency -->
1212
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
1313
<!-- Require PlantUML.js -->
14-
<script src="node_modules/@plantuml/plantuml.js/plantuml.js"></script>
14+
<script src="node_modules/@sakirtemel/plantuml.js/plantuml.js"></script>
1515
</head>
1616
<body>
1717
<div id="content"></div>
@@ -60,7 +60,7 @@
6060
})
6161

6262
// render marked plantuml diagrams
63-
plantuml.initialize('/app/node_modules/@plantuml/plantuml.js').then(() => {
63+
plantuml.initialize('/app/node_modules/@sakirtemel/plantuml.js').then(() => {
6464
for(const element of document.querySelectorAll('.plantuml-diagram')){
6565
const code = element.querySelector('*:is(code, pre)').innerText
6666
const url = plantuml.renderPng(code).then((blob) => {

examples/02-asciidoctor.js/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/02-asciidoctor.js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
"license": "MIT",
1212
"dependencies": {
1313
"asciidoctor": "^2.2.6",
14-
"@plantuml/plantuml.js": "file:../../plantuml-wasm"
14+
"@sakirtemel/plantuml.js": "^1.0.0"
1515
}
1616
}

examples/02-asciidoctor.js/sequence-diagram.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ Alice <-- Bob: Another authentication Response
1111
@enduml
1212
----
1313

14+
[source,plantuml]
15+
----
16+
@startuml
17+
Bob -> Alice: Hello!
18+
@enduml
19+
----
20+
1421
=== Without rendering
1522

1623
[source,plantuml,render=false]

plantuml-wasm/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plantuml-wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sakirtemel/plantuml.js",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "PlantUML that runs completely on javascript without needing java/servers",
55
"main": "plantuml.js",
66
"scripts": {

plantuml-wasm/plantuml.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ const plantuml = (() => {
1111

1212
const renderPng = (pumlContent) => {
1313
return new Promise((resolve, reject) => {
14-
const renderingStartedAt = new Date()
15-
cjCall("com.plantuml.wasm.v1.Png", "convert", "light", "/files/result.png", pumlContent).then((result) => {
16-
console.log(result);
14+
const renderingStartedAt = new Date()
15+
const resultFileSuffix = renderingStartedAt.getTime().toString()
16+
cjCall("com.plantuml.wasm.v1.Png", "convert", "light", `/files/result-${resultFileSuffix}.png`, pumlContent).then((result) => {
1717
const obj = JSON.parse(result);
1818
if (obj.status=='ok') {
19-
cjFileBlob("result.png").then((blob) => {
20-
console.log('Rendering finished in', (new Date()).getTime() - renderingStartedAt.getTime(), 'ms');
21-
resolve(blob)
19+
cjFileBlob(`result-${resultFileSuffix}.png`).then((blob) => {
20+
const transaction = cheerpjGetFSMountForPath('/files/').dbConnection.transaction('files', 'readwrite')
21+
transaction.objectStore('files').delete(`/result-${resultFileSuffix}.png`)
22+
23+
transaction.oncomplete = () => {
24+
console.log('Rendering finished in', (new Date()).getTime() - renderingStartedAt.getTime(), 'ms');
25+
resolve(blob)
26+
}
2227
})
2328
}
2429
})

0 commit comments

Comments
 (0)