Skip to content

Commit e0b801c

Browse files
authored
Add direction to VisualizerTask (#12)
* Add direction to VisualizerTask * Update documentation * Rename constants
1 parent 864e8d1 commit e0b801c

File tree

7 files changed

+106
-30
lines changed

7 files changed

+106
-30
lines changed

.editorconfig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ insert_final_newline = true
99
trim_trailing_whitespace = true
1010

1111
[*.{php, xml, rng}]
12-
indent_size = 4
12+
indent_size = 4
13+
max_line_length = 120
1314

1415
[*.{md, txt}]
1516
trim_trailing_whitespace = false
17+
18+
[.editorconfig]
19+
ij_editorconfig_align_group_field_declarations = true
20+
ij_editorconfig_space_after_comma = true
21+
ij_editorconfig_spaces_around_assignment_operators = true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/composer.lock
44
/custom.task.properties
55
/custom.type.properties
6+
/docs/guide.html

build.png

2.88 KB
Loading

build.xml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
<target name="setup" depends="composer:install"
66
description="Prepare project for development"/>
77
<target name="qa" description="Check code quality"
8-
depends="composer:validate, composer:normalize, phpstan:analyse"/>
8+
depends="composer:normalize,composer:validate,phpstan:analyse"/>
9+
10+
<target name="visualizer" description="Create buildfile diagram">
11+
<visualizer format="png"/>
12+
</target>
913

1014
<target name="help" depends="visualizer">
1115
<exec executable="xdg-open" spawn="true">
1216
<arg path="build.png"/>
1317
</exec>
1418
</target>
1519

16-
<target name="visualizer" description="Create buildfile diagram">
17-
<visualizer format="png"/>
18-
</target>
19-
2020
<target name="composer:normalize" description="Normalize composer.json content">
2121
<composer command="normalize"/>
2222
</target>
@@ -44,4 +44,15 @@
4444
</exec>
4545
</target>
4646

47+
<target name="guide:parse" description="Generate doc (dev only)">
48+
<!-- I use this Target to have a documentation preview -->
49+
<exec executable="xsltproc" passthru="true" checkreturn="true">
50+
<arg value="--output"/>
51+
<arg value="docs/guide.html"/>
52+
<arg value="--xinclude"/>
53+
<arg file="/usr/share/xml/docbook/stylesheet/nwalsh/xhtml/docbook.xsl"/>
54+
<arg file="docs/guide.xml"/>
55+
</exec>
56+
</target>
57+
4758
</project>

docs/guide.xml

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<?xml-model xlink:href="http://www.oasis-open.org/docbook/xml/5.0/rng/docbookxi.rng"
3-
schematypens="http://relaxng.org/ns/structure/1.0"?>
1+
<?xml version="1.0" encoding="UTF-8"?><?xml-model xlink:href="http://www.oasis-open.org/docbook/xml/5.0/rng/docbookxi.rng"schematypens="http://relaxng.org/ns/structure/1.0"?>
42

53
<sect1 role="taskdef" xml:id="VisualizerTask" xmlns="http://docbook.org/ns/docbook"
64
xmlns:xlink="http://www.w3.org/1999/xlink">
75
<title>VisualizerTask</title>
8-
<para>The <literal>VisualizerTask</literal> generates a graphical representation of your current buildfile.
9-
This allows you to see all available targets but also the calls and dependencies among targets.
6+
<para>
7+
The <literal>VisualizerTask</literal> generates a graphical representation of your current buildfile. This
8+
allows you to see all available targets but also the calls and dependencies among targets.
109
</para>
1110
<para>
1211
<literal>VisualizerTask</literal> is able to represent:
@@ -80,31 +79,52 @@
8079
</entry>
8180
<entry>no</entry>
8281
</row>
82+
<row>
83+
<entry>
84+
<literal>direction</literal>
85+
</entry>
86+
<entry>
87+
<literal role="type">String</literal>
88+
</entry>
89+
<entry>
90+
Use this to change the diagram's layout. Valid values are:
91+
<literal>horizontal</literal>
92+
and <literal>vertical</literal>.
93+
</entry>
94+
<entry>
95+
<literal>vertical</literal>
96+
</entry>
97+
<entry>no</entry>
98+
</row>
8399
<row>
84100
<entry>
85101
<literal>server</literal>
86102
</entry>
87103
<entry>
88104
<literal role="type">String</literal>
89105
</entry>
90-
<entry>PlantUML server.</entry>
106+
<entry>
107+
PlantUML server. Needed by all formats except <literal>puml</literal>.
108+
</entry>
91109
<entry>http://www.plantuml.com/plantuml</entry>
92110
<entry>no</entry>
93111
</row>
94112
</tbody>
95113
</tgroup>
96114
</table>
97-
<para>If you have network connectivity issues, you should try <literal>puml</literal> format. This format
98-
doesn't needs Internet connection to generate a diagram.
115+
<para>
116+
If you have network connectivity issues, you should try <literal>puml</literal> format. This format doesn't
117+
require a PlantUML server (and therefore an internet connection) to generate a diagram.
99118
</para>
100119
<sect2>
101120
<title>Examples</title>
102121
<para>Using <literal>VisualizerTask</literal> with default values:
103122
</para>
104123
<programlisting language="xml">&lt;visualizer/&gt;</programlisting>
105-
<para>Setting diagram's format to <literal>svg</literal>:
124+
<para>
125+
Setting diagram's format to <literal>svg</literal> with <literal>horizontal</literal> arrows:
106126
</para>
107-
<programlisting language="xml">&lt;visualizer format="svg"/&gt;</programlisting>
127+
<programlisting language="xml">&lt;visualizer format="svg" direction="horizontal"/&gt;</programlisting>
108128
<para>Save diagram into <filename>resources/images/</filename> directory:
109129
</para>
110130
<programlisting language="xml">&lt;visualizer destination="resources/images/"/&gt;</programlisting>
@@ -246,8 +266,8 @@
246266
<literal>config</literal>
247267
</para>
248268
<para>Holds additional config data. See
249-
<link xlink:href="http://docs.guzzlephp.org/en/stable/request-options.html"
250-
role="extern">Guzzle documentation
269+
<link xlink:href="http://docs.guzzlephp.org/en/stable/request-options.html" role="extern">Guzzle
270+
documentation
251271
</link>
252272
for supported values.
253273
</para>

src/VisualizerTask.php

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,18 @@
4545
*/
4646
class VisualizerTask extends HttpTask
4747
{
48-
public const FORMAT_EPS = 'eps';
49-
public const FORMAT_PNG = 'png';
50-
public const FORMAT_PUML = 'puml';
51-
public const FORMAT_SVG = 'svg';
52-
public const SERVER = 'http://www.plantuml.com/plantuml';
53-
public const STATUS_OK = 200;
54-
public const XSL_CALLS = __DIR__ . '/calls.xsl';
55-
public const XSL_FOOTER = __DIR__ . '/footer.xsl';
56-
public const XSL_HEADER = __DIR__ . '/header.xsl';
57-
public const XSL_TARGETS = __DIR__ . '/targets.xsl';
48+
protected const ARROWS_HORIZONTAL = 'horizontal';
49+
protected const ARROWS_VERTICAL = 'vertical';
50+
protected const FORMAT_EPS = 'eps';
51+
protected const FORMAT_PNG = 'png';
52+
protected const FORMAT_PUML = 'puml';
53+
protected const FORMAT_SVG = 'svg';
54+
protected const SERVER = 'http://www.plantuml.com/plantuml';
55+
protected const STATUS_OK = 200;
56+
protected const XSL_CALLS = __DIR__ . '/calls.xsl';
57+
protected const XSL_FOOTER = __DIR__ . '/footer.xsl';
58+
protected const XSL_HEADER = __DIR__ . '/header.xsl';
59+
protected const XSL_TARGETS = __DIR__ . '/targets.xsl';
5860

5961
/**
6062
* @var string Diagram format
@@ -71,6 +73,11 @@ class VisualizerTask extends HttpTask
7173
*/
7274
protected $server;
7375

76+
/**
77+
* @var string Arrows' direction
78+
*/
79+
protected $direction;
80+
7481
/**
7582
* Setting some default values and checking requirements
7683
*/
@@ -92,6 +99,7 @@ public function init(): void
9299
}
93100
$this->setFormat(VisualizerTask::FORMAT_PNG);
94101
$this->setServer(VisualizerTask::SERVER);
102+
$this->setDirection(VisualizerTask::ARROWS_VERTICAL);
95103
}
96104

97105
/**
@@ -170,6 +178,7 @@ protected function transformToPuml(File $buildfile, string $xslFile): string
170178
$xsl = $this->loadXmlFile($xslFile);
171179

172180
$processor = new XSLTProcessor();
181+
$processor->setParameter('', 'direction', $this->getDirection());
173182
$processor->importStylesheet($xsl);
174183

175184
return $processor->transformToXml($xml) . PHP_EOL;
@@ -259,7 +268,7 @@ public function getDestination(): ?string
259268
*
260269
* @return \Phing\Task\Ext\VisualizerTask
261270
*/
262-
public function setDestination(?string $destination): VisualizerTask
271+
public function setDestination(?string $destination): self
263272
{
264273
$this->destination = $destination;
265274

@@ -354,7 +363,7 @@ public function getServer(): string
354363
*
355364
* @return \Phing\Task\Ext\VisualizerTask
356365
*/
357-
public function setServer(string $server): VisualizerTask
366+
public function setServer(string $server): self
358367
{
359368
if (!filter_var($server, FILTER_VALIDATE_URL)) {
360369
$exceptionMessage = 'Invalid PlantUml server';
@@ -366,6 +375,26 @@ public function setServer(string $server): VisualizerTask
366375
return $this;
367376
}
368377

378+
/**
379+
* @return string
380+
*/
381+
public function getDirection(): string
382+
{
383+
return $this->direction;
384+
}
385+
386+
/**
387+
* @param string $direction
388+
*
389+
* @return \Phing\Task\Ext\VisualizerTask
390+
*/
391+
public function setDirection(string $direction): self
392+
{
393+
$this->direction = $direction === self::ARROWS_HORIZONTAL ? self::ARROWS_HORIZONTAL : self::ARROWS_VERTICAL;
394+
395+
return $this;
396+
}
397+
369398
/**
370399
* Receive server's response
371400
*

src/header.xsl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
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"/>
45
<xsl:output method="text" encoding="UTF-8" indent="no"/>
56
<xsl:template match="/project">@startuml
67
<xsl:variable name="name" select="@name"/>
78
title <xsl:value-of select="$name"/>
9+
<xsl:choose>
10+
<xsl:when test="'horizontal' = $direction">
11+
left to right direction
12+
</xsl:when>
13+
<xsl:otherwise>
14+
top to bottom direction
15+
</xsl:otherwise>
16+
</xsl:choose>
817
skinparam ArrowFontColor Black
918
skinparam ArrowThickness 2
1019
skinparam UseCaseBackgroundColor #FFFECC

0 commit comments

Comments
 (0)