Skip to content

Commit 731e686

Browse files
authored
Add new properties to customize diagrams (#13)
* Add new properties to customize diagrams * showTitle * showDescription * footer * Update buildfile * Update doc * Fix phpstan complaints
1 parent e0b801c commit 731e686

File tree

7 files changed

+150
-10
lines changed

7 files changed

+150
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/custom.task.properties
55
/custom.type.properties
66
/docs/guide.html
7+
/build.puml

build.png

633 Bytes
Loading

build.xml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22

3-
<project name="VisualizerTask" default="help">
3+
<project name="VisualizerTask" description="Create a diagram from buildfile" default="help">
44

55
<target name="setup" depends="composer:install"
66
description="Prepare project for development"/>
77
<target name="qa" description="Check code quality"
88
depends="composer:normalize,composer:validate,phpstan:analyse"/>
99

1010
<target name="visualizer" description="Create buildfile diagram">
11-
<visualizer format="png"/>
11+
<uptodate property="visualizer.uptodate" srcfile="build.xml" targetfile="build.png"/>
12+
<if>
13+
<not>
14+
<isset property="visualizer.uptodate"/>
15+
</not>
16+
<then>
17+
<visualizer format="puml" showTitle="true" showDescription="true"
18+
footer="Visit https://www.phing.info/"/>
19+
<visualizer format="png" showTitle="true" showDescription="true"
20+
footer="Visit https://www.phing.info/"/>
21+
</then>
22+
</if>
1223
</target>
1324

1425
<target name="help" depends="visualizer">
@@ -23,11 +34,9 @@
2334

2435
<target name="composer:install" description="Install Composer dependencies">
2536
<composer command="install">
26-
<arg value="--dev"/>
2737
<arg value="--prefer-dist"/>
2838
<arg value="--no-interaction"/>
2939
<arg value="--no-progress"/>
30-
<arg value="--no-suggest"/>
3140
<arg value="--ansi"/>
3241
</composer>
3342
</target>
@@ -44,7 +53,9 @@
4453
</exec>
4554
</target>
4655

47-
<target name="guide:parse" description="Generate doc (dev only)">
56+
<target name="guide:preview" description="Generate doc (dev only)">
57+
<!-- http://tutoriels.meddeb.net/docbook-installation-utilisation-de-base/ -->
58+
<!-- apt install xsltproc docbook-xsl -->
4859
<!-- I use this Target to have a documentation preview -->
4960
<exec executable="xsltproc" passthru="true" checkreturn="true">
5061
<arg value="--output"/>
@@ -53,6 +64,9 @@
5364
<arg file="/usr/share/xml/docbook/stylesheet/nwalsh/xhtml/docbook.xsl"/>
5465
<arg file="docs/guide.xml"/>
5566
</exec>
67+
<exec executable="xdg-open" spawn="true">
68+
<arg value="docs/guide.html"/>
69+
</exec>
5670
</target>
5771

5872
</project>

docs/guide.xml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,39 @@
7979
</entry>
8080
<entry>no</entry>
8181
</row>
82+
<row>
83+
<entry>
84+
<literal>footer</literal>
85+
</entry>
86+
<entry>
87+
<literal role="type">String</literal>
88+
</entry>
89+
<entry>A text to display at the bottom right of the diagram.</entry>
90+
<entry>n/a</entry>
91+
<entry>no</entry>
92+
</row>
93+
<row>
94+
<entry>
95+
<literal>showTitle</literal>
96+
</entry>
97+
<entry>
98+
<literal role="type">Bool</literal>
99+
</entry>
100+
<entry>Should the buildfile's title be displayed in diagram?</entry>
101+
<entry><literal>true</literal></entry>
102+
<entry>no</entry>
103+
</row>
104+
<row>
105+
<entry>
106+
<literal>showDescription</literal>
107+
</entry>
108+
<entry>
109+
<literal role="type">Bool</literal>
110+
</entry>
111+
<entry>Should the buildfile's description be displayed in diagram?</entry>
112+
<entry><literal>false</literal></entry>
113+
<entry>no</entry>
114+
</row>
82115
<row>
83116
<entry>
84117
<literal>direction</literal>
@@ -128,6 +161,9 @@
128161
<para>Save diagram into <filename>resources/images/</filename> directory:
129162
</para>
130163
<programlisting language="xml">&lt;visualizer destination="resources/images/"/&gt;</programlisting>
164+
<para>Display buildfile's description and custom footer text:
165+
</para>
166+
<programlisting language="xml">&lt;visualizer showDescription="true" footer="© Copyright 2021"/&gt;</programlisting>
131167
</sect2>
132168
<sect2>
133169
<title>Limitations</title>
@@ -180,8 +216,8 @@
180216
</listitem>
181217
<listitem>
182218
<para>
183-
<link xlink:href="https://packagist.org/packages/jawira/plantuml-encoding" role="extern">
184-
jawira/plantuml-encoding
219+
<link xlink:href="https://packagist.org/packages/jawira/plantuml-client" role="extern">
220+
jawira/plantuml-client
185221
</link>
186222
</para>
187223
</listitem>

src/VisualizerTask.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use function filter_var;
3535
use function reset;
3636
use function simplexml_load_string;
37+
use function strval;
3738
use const FILTER_VALIDATE_URL;
3839

3940
/**
@@ -78,6 +79,21 @@ class VisualizerTask extends HttpTask
7879
*/
7980
protected $direction;
8081

82+
/**
83+
* @var bool Show title in diagram
84+
*/
85+
protected $showTitle;
86+
87+
/**
88+
* @var bool Show description in diagram
89+
*/
90+
protected $showDescription;
91+
92+
/**
93+
* @var string Text to display
94+
*/
95+
protected $footer;
96+
8197
/**
8298
* Setting some default values and checking requirements
8399
*/
@@ -100,6 +116,9 @@ public function init(): void
100116
$this->setFormat(VisualizerTask::FORMAT_PNG);
101117
$this->setServer(VisualizerTask::SERVER);
102118
$this->setDirection(VisualizerTask::ARROWS_VERTICAL);
119+
$this->setShowTitle(true);
120+
$this->setShowDescription(false);
121+
$this->setFooter('');
103122
}
104123

105124
/**
@@ -179,6 +198,10 @@ protected function transformToPuml(File $buildfile, string $xslFile): string
179198

180199
$processor = new XSLTProcessor();
181200
$processor->setParameter('', 'direction', $this->getDirection());
201+
$processor->setParameter('', 'description', strval($this->getProject()->getDescription()));
202+
$processor->setParameter('', 'showTitle', strval($this->isShowTitle()));
203+
$processor->setParameter('', 'showDescription', strval($this->isShowDescription()));
204+
$processor->setParameter('', 'footer', $this->getFooter());
182205
$processor->importStylesheet($xsl);
183206

184207
return $processor->transformToXml($xml) . PHP_EOL;
@@ -395,6 +418,38 @@ public function setDirection(string $direction): self
395418
return $this;
396419
}
397420

421+
/**
422+
* @return bool
423+
*/
424+
public function isShowTitle(): bool
425+
{
426+
return $this->showTitle;
427+
}
428+
429+
/**
430+
* @param bool $showTitle
431+
*/
432+
public function setShowTitle(bool $showTitle): void
433+
{
434+
$this->showTitle = $showTitle;
435+
}
436+
437+
/**
438+
* @return bool
439+
*/
440+
public function isShowDescription(): bool
441+
{
442+
return $this->showDescription;
443+
}
444+
445+
/**
446+
* @param bool $showDescription
447+
*/
448+
public function setShowDescription(bool $showDescription): void
449+
{
450+
$this->showDescription = $showDescription;
451+
}
452+
398453
/**
399454
* Receive server's response
400455
*
@@ -433,4 +488,20 @@ protected function saveToFile(string $content, File $destination): void
433488

434489
(new FileWriter($destination))->write($content);
435490
}
491+
492+
/**
493+
* @return string
494+
*/
495+
public function getFooter(): string
496+
{
497+
return $this->footer;
498+
}
499+
500+
/**
501+
* @param string $footer
502+
*/
503+
public function setFooter(string $footer): void
504+
{
505+
$this->footer = $footer;
506+
}
436507
}

src/header.xsl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4-
<xsl:param name="direction"/>
54
<xsl:output method="text" encoding="UTF-8" indent="no"/>
5+
<xsl:param name="direction"/>
6+
<xsl:param name="description"/>
7+
<xsl:param name="showTitle"/>
8+
<xsl:param name="showDescription"/>
9+
<xsl:param name="footer"/>
610
<xsl:template match="/project">@startuml
11+
<xsl:if test="$showTitle">
712
<xsl:variable name="name" select="@name"/>
8-
title <xsl:value-of select="$name"/>
13+
title
14+
<xsl:value-of select="$name"/>
15+
end title
16+
</xsl:if>
17+
<xsl:if test="$showDescription">
18+
caption
19+
<xsl:value-of select="$description"/>
20+
end caption
21+
</xsl:if>
22+
<xsl:if test="$footer">
23+
right footer
24+
<xsl:value-of select="$footer"/>
25+
end footer
26+
</xsl:if>
927
<xsl:choose>
1028
<xsl:when test="'horizontal' = $direction">
1129
left to right direction
@@ -14,6 +32,7 @@ left to right direction
1432
top to bottom direction
1533
</xsl:otherwise>
1634
</xsl:choose>
35+
skinparam Shadowing false
1736
skinparam ArrowFontColor Black
1837
skinparam ArrowThickness 2
1938
skinparam UseCaseBackgroundColor #FFFECC

src/targets.xsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
44
<xsl:output method="text" encoding="UTF-8" indent="no"/>
5-
<xsl:param name="color"/>
65
<xsl:template match="/project">
76
<xsl:for-each select="./target">(<xsl:value-of select="@name"/>)
87
</xsl:for-each>

0 commit comments

Comments
 (0)