3
3
namespace SymfonyDocs \Command ;
4
4
5
5
use Doctrine \RST \Builder ;
6
- use Doctrine \RST \Event \PostBuildRenderEvent ;
7
6
use Doctrine \RST \Event \PostNodeRenderEvent ;
8
7
use Doctrine \RST \Event \PostParseDocumentEvent ;
9
- use Doctrine \RST \Event \PreBuildParseEvent ;
10
8
use Doctrine \RST \Event \PreBuildRenderEvent ;
11
- use Doctrine \RST \Event \ PreBuildScanEvent ;
9
+ use Doctrine \RST \Nodes \ DocumentNode ;
12
10
use Symfony \Component \Console \Command \Command ;
13
11
use Symfony \Component \Console \Helper \ProgressBar ;
14
12
use Symfony \Component \Console \Input \InputInterface ;
@@ -41,6 +39,7 @@ class ParseDoc extends Command
41
39
private $ htmlOutputDir ;
42
40
private $ jsonOutputDir ;
43
41
private $ parsedFiles = [];
42
+ private $ parseOnly ;
44
43
45
44
public function __construct ()
46
45
{
@@ -57,12 +56,14 @@ protected function configure()
57
56
$ this
58
57
->addOption ('source-dir ' , null , InputOption::VALUE_REQUIRED , 'RST files Source directory ' , __DIR__ .'/../../.. ' )
59
58
->addOption ('html-output-dir ' , null , InputOption::VALUE_REQUIRED , 'HTML files output directory ' , __DIR__ .'/../../html ' )
60
- ->addOption ('json-output-dir ' , null , InputOption::VALUE_REQUIRED , 'JSON files output directory ' , __DIR__ .'/../../json ' );
59
+ ->addOption ('json-output-dir ' , null , InputOption::VALUE_REQUIRED , 'JSON files output directory ' , __DIR__ .'/../../json ' )->addOption ('parse-only ' , null , InputOption::VALUE_OPTIONAL , 'Parse only given directory ' , null )
60
+ // ->addOption('for-pdf', null, InputOption::VALUE_NONE, 'Export for pdf')
61
+ ;
61
62
}
62
63
63
64
protected function initialize (InputInterface $ input , OutputInterface $ output )
64
65
{
65
- $ this ->io = new SymfonyStyle ($ input , $ output );
66
+ $ this ->io = new SymfonyStyle ($ input , $ output );
66
67
$ this ->output = $ output ;
67
68
68
69
$ this ->sourceDir = $ this ->getRealAbsolutePath ($ input ->getOption ('source-dir ' ));
@@ -80,6 +81,11 @@ protected function initialize(InputInterface $input, OutputInterface $output)
80
81
$ this ->filesystem ->remove ($ this ->jsonOutputDir );
81
82
}
82
83
84
+ // $this->parseOnly = $this->getRealAbsolutePath($input->getOption('parse-only'));
85
+ // if ($this->parseOnly && !$this->filesystem->exists($this->parseOnly)) {
86
+ // throw new \InvalidArgumentException(sprintf('Given "parse-only" directory "%s" does not exist', $this->parseOnly));
87
+ // }
88
+
83
89
$ this ->builder = new Builder (KernelFactory::createKernel ());
84
90
$ eventManager = $ this ->builder ->getConfiguration ()->getEventManager ();
85
91
$ eventManager ->addEventListener (
@@ -117,7 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
117
123
}
118
124
}
119
125
120
- $ this ->io ->note ('Start transforming doc into json files ' );
126
+ $ this ->io ->note ('Start exporting doc into json files ' );
121
127
$ this ->progressBar = new ProgressBar ($ output , $ this ->finder ->count ());
122
128
$ jsonGenerator = new JsonGenerator ($ this ->builder ->getDocuments ()->getAll ());
123
129
$ jsonGenerator ->generateJson ($ this ->htmlOutputDir , $ this ->jsonOutputDir , $ this ->progressBar );
@@ -152,15 +158,27 @@ public function postParseDocument(PostParseDocumentEvent $postParseDocumentEvent
152
158
153
159
public function preBuildRender ()
154
160
{
155
- $ eventManager = $ this ->builder ->getConfiguration ()->getEventManager ();
161
+ $ eventManager = $ this ->builder ->getConfiguration ()->getEventManager ();
156
162
$ eventManager ->removeEventListener (
157
163
[PostParseDocumentEvent::POST_PARSE_DOCUMENT ],
158
164
$ this
159
165
);
160
166
161
167
$ this ->progressBar ->finish ();
162
168
169
+ $ this ->progressBar = new ProgressBar ($ this ->output );
170
+
171
+ $ eventManager ->addEventListener (
172
+ [PostNodeRenderEvent::POST_NODE_RENDER ],
173
+ $ this
174
+ );
175
+
163
176
$ this ->io ->newLine (2 );
164
177
$ this ->io ->note ('Start rendering in HTML... ' );
165
178
}
179
+
180
+ public function postNodeRender ()
181
+ {
182
+ $ this ->progressBar ->advance ();
183
+ }
166
184
}
0 commit comments