Skip to content

Commit dbd20bf

Browse files
committed
added picture display for wiki asciidocs
1 parent 4228d58 commit dbd20bf

6 files changed

Lines changed: 44 additions & 11 deletions

File tree

documentation/Functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ createDevon4jProject("com.mycustomer.myapplication")
186186

187187
### buildJava <a name="buildJava"></a>
188188
#### parameter
189-
1. The project directory
189+
1. The project directory, relative to workspace.
190190
2. (Optional) Indicator whether tests should be run. Default is false.
191191
#### example
192192
buildJava("cobigenexample", true)
@@ -323,7 +323,7 @@ downloadFile("https://bit.ly/2BCkFa9", "file", "downloads")
323323

324324
### buildNg <a name="buildNg"></a>
325325
#### parameter
326-
1. Path to the angular project relative to workspace
326+
1. Path to the angular project, relative to workspace
327327
2. (Optional) Custom output directory.
328328
#### example
329329
buildNg("exampleAngularProject")

engine/parser.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export class Parser {
2020
let result = new Playbook();
2121
result.title = parseResult[0][2];
2222
result.subtitle = parseResult[1]? parseResult[1][3]: "";
23-
result.description = parseResult[2][2].descriptionlines;
24-
result.conclusion = parseResult[4]? parseResult[4][2].conclusionlines: "";
23+
result.description = this.insertNewlineIntoDescription(parseResult[2][2].descriptionlines);
24+
result.conclusion = this.insertNewlineIntoDescription(parseResult[4]? parseResult[4][2].conclusionlines: "");
2525
for(let index in parseResult[3]){
2626
let step = new Step();
2727
step.text = this.getText(parseResult, index);
@@ -81,4 +81,23 @@ export class Parser {
8181
return "";
8282
}
8383
}
84+
85+
insertNewlineIntoDescription(description: string): string{
86+
let result = description;
87+
let offset = 0;
88+
for(let i = 0; i < description.length-1; i++){
89+
if(description[i] == '#' && description[i+1] == '#'){
90+
let temp = result.slice(0,i+offset);
91+
result = temp +"\n"+result.slice(i+offset);
92+
offset++;
93+
}
94+
if(description[i] == '*'){
95+
let temp = result.slice(0,i+offset);
96+
result = temp +"\n"+result.slice(i+offset);
97+
offset++;
98+
}
99+
100+
}
101+
return result;
102+
}
84103
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<%= description; %>
1+
22

33
<% if(tutorialPath){ %>
44
The definition of each step of this tutorial can be found at https://github.com/devonfw-tutorials/tutorials/tree/main/<%= tutorialPath; %>. <% } %>
55

66
Feel free to report any errors to us or fix them yourself. Errors can be reported by creating an issue in the https://github.com/devonfw-tutorials/tutorials/issues[tutorials repository]. To fix the error fork the repository and create a pull request. Errors in the wiki can be reported and fixed in the https://github.com/devonfw-tutorials/tutorial-compiler[Tutorial-compiler repository].
77
You can find a description of what to look for when creating a pull request at the devonfw contribution guide: https://devonfw.com/website/pages/community/community.html#community.asciidoc_contributing-to-devonfw. If you want to create a tutorial you can start with the https://katacoda.com/devonfw/scenarios/create-your-own-tutorial[katacoda tutorial] and read the description for creating your own tutorials: https://github.com/devonfw-tutorials/tutorials/wiki/Development.
88

9+
<%= description; %>

runners/wikiConsole/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RunCommand } from "../../engine/run_command";
33
import { RunResult } from "../../engine/run_result";
44
import { WikiRunner } from "../../engine/wikiRunner";
55
import * as path from "path";
6-
import * as fs from "fs";
6+
import * as fs from "fs-extra";
77

88

99
export class WikiConsole extends WikiRunner {
@@ -158,22 +158,30 @@ export class WikiConsole extends WikiRunner {
158158
runDisplayContent(runCommand: RunCommand): RunResult {
159159
let tempFile = path.join(this.getTempDirectory(), runCommand.command.name + ".md");
160160
fs.writeFileSync(tempFile, "");
161+
let counter = 2;
161162
for(let i = 0; i < runCommand.command.parameters[1].length; i++) {
162163
let param = runCommand.command.parameters[1][i];
163164
if(param.content) {
164165
fs.appendFileSync(tempFile, param.content);
165166
} else if(param.file) {
166167
fs.appendFileSync(tempFile, fs.readFileSync(path.join(this.playbookPath, param.file), "utf-8"));
167168
} else if (param.image) {
168-
let image = path.join(this.playbookPath, param.image);
169-
fs.appendFileSync(tempFile, "![" + path.basename(image) + "](./assets/" + path.basename(image) + ")");
169+
this.createFolder(path.join(this.outputPathTutorial, "images"), false);
170+
let imageName = path.join(this.outputPathTutorial, "images",path.basename(param.image));
171+
while(fs.existsSync(imageName)){
172+
imageName = path.join(this.outputPathTutorial, "images",counter+"_"+path.basename(param.image));
173+
counter++;
174+
}
175+
fs.createFileSync(imageName);
176+
fs.copyFileSync(path.join(this.playbookPath, param.image),imageName);
177+
fs.appendFileSync(tempFile, "image::images/"+path.basename(imageName)+"[]");
178+
counter = 2;
170179
}
171180
fs.appendFileSync(tempFile, "\n\n");
172181
}
173182

174183
let content = fs.readFileSync(tempFile, "utf-8");
175-
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "displayContent.asciidoc"), { title: runCommand.command.parameters[0], content: content, path: runCommand.command.parameters[2]});
176-
184+
this.renderWiki(path.join(this.getRunnerDirectory(), "templates", "nextKatacodaStep.asciidoc"), { steptitle: runCommand.stepTitle, text: runCommand.text, textAfter: runCommand.textAfter, title: runCommand.command.parameters[0], content: content, path: runCommand.command.parameters[2]});
177185
return null;
178186
}
179187
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
== <%= title; %>
2+
=== <%= steptitle; %>
3+
4+
<%- text; %>
25

36
<%= content; %>
47

8+
<%- textAfter; %>
9+
510
<% if(path) {%>
611
After that, move to the target directory by executing `cd <%= path; %>` in the terminal.
712
<% } %>

runners/wikiConsole/templates/npmInstall.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can install the package <%= npmCommand.name; %><% if(!npmCommand.global){ %>
1616
You need to be located in the project directory where the package.json file lies.
1717
For this tutorial it is `<%= projectPath; %>`. You can either move there manually and open the terminal there or open the terminal and move there by executing `cd <%= projectPath; %>`.<% } %>
1818

19-
Now execute `npm install<% if(npmCommand.global){ %> -g<% } %> <%= npmCommand.args; %> <%= npmCommand.name; %>` in the terminal.
19+
Now execute `npm install<% if(npmCommand.global){ %> -g<% } %><% if(npmCommand.args){%> <%= npmCommand.args; %><% } %><%if(npmCommand.name){ %> <%= npmCommand.name; %><%}%>` in the terminal.
2020

2121
<% if(npmCommand.global){ %>Due to the argument '-g' the package will be installed globally.<% } %>
2222
This may take some time.

0 commit comments

Comments
 (0)