6
6
use Doctrine \RST \Builder ;
7
7
use Doctrine \RST \Event \PostNodeRenderEvent ;
8
8
use Doctrine \RST \Event \PostParseDocumentEvent ;
9
+ use Doctrine \RST \Event \PreBuildParseEvent ;
9
10
use Doctrine \RST \Event \PreBuildRenderEvent ;
10
11
use Symfony \Component \Console \Helper \ProgressBar ;
11
12
use Symfony \Component \Console \Input \InputInterface ;
@@ -126,10 +127,19 @@ private function getRealAbsolutePath(string $path, Filesystem $filesystem): stri
126
127
127
128
private function initializeProgressBarEventListeners (): void
128
129
{
130
+ // sets up the "parsing" progress bar
131
+ $ this ->eventManager ->addEventListener (
132
+ [PreBuildParseEvent::PRE_BUILD_PARSE ],
133
+ $ this
134
+ );
135
+
136
+ // advances "parsing" progress bar
129
137
$ this ->eventManager ->addEventListener (
130
138
[PostParseDocumentEvent::POST_PARSE_DOCUMENT ],
131
139
$ this
132
140
);
141
+
142
+ // tries to handle progress bar for "rendering"
133
143
$ this ->eventManager ->addEventListener (
134
144
[PreBuildRenderEvent::PRE_BUILD_RENDER ],
135
145
$ this
@@ -145,9 +155,6 @@ private function startBuild()
145
155
146
156
$ this ->sanitizeOutputDirs ($ this ->finder );
147
157
148
- $ this ->io ->note (sprintf ('Start parsing %d rst files ' , $ this ->finder ->count ()));
149
- $ this ->progressBar = new ProgressBar ($ this ->output , $ this ->finder ->count ());
150
-
151
158
$ this ->builder ->build (
152
159
$ this ->buildContext ->getSourceDir (),
153
160
$ this ->buildContext ->getHtmlOutputDir ()
@@ -205,6 +212,19 @@ private function isCacheDisabled(): bool
205
212
return $ this ->input ->hasOption ('disable-cache ' ) && (bool ) $ this ->input ->getOption ('disable-cache ' );
206
213
}
207
214
215
+ /**
216
+ * Called very early: used to initialize the "parsing" progress bar.
217
+ *
218
+ * @param PreBuildParseEvent $event
219
+ */
220
+ public function preBuildParse (PreBuildParseEvent $ event )
221
+ {
222
+ $ parseQueue = $ event ->getParseQueue ();
223
+ $ parseCount = count ($ parseQueue ->getAllFilesThatRequireParsing ());
224
+ $ this ->io ->note (sprintf ('Start parsing %d out-of-date rst files ' , $ parseCount ));
225
+ $ this ->progressBar = new ProgressBar ($ this ->output , $ parseCount );
226
+ }
227
+
208
228
public function postParseDocument (PostParseDocumentEvent $ postParseDocumentEvent ): void
209
229
{
210
230
$ file = $ postParseDocumentEvent ->getDocumentNode ()->getEnvironment ()->getCurrentFileName ();
@@ -216,25 +236,10 @@ public function postParseDocument(PostParseDocumentEvent $postParseDocumentEvent
216
236
217
237
public function doPreBuildRender ()
218
238
{
219
- $ this ->eventManager ->removeEventListener (
220
- [PostParseDocumentEvent::POST_PARSE_DOCUMENT ],
221
- $ this
222
- );
223
-
239
+ // finishes the "parse" progress bar
224
240
$ this ->progressBar ->finish ();
225
241
226
- $ this ->progressBar = new ProgressBar ($ this ->output );
227
-
228
- $ this ->eventManager ->addEventListener (
229
- [PostNodeRenderEvent::POST_NODE_RENDER ],
230
- $ this
231
- );
232
-
233
242
$ this ->io ->newLine (2 );
234
- }
235
-
236
- public function postNodeRender (): void
237
- {
238
- $ this ->progressBar ->advance ();
243
+ // TODO: create a proper progress bar for rendering
239
244
}
240
245
}
0 commit comments