This repository has been archived by the owner on May 8, 2021. It is now read-only.
/
main.php
executable file
·284 lines (255 loc) · 8.34 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
/*
--------------------------------------------------------------------
TypeFriendly
Copyright (c) 2008-2010 Invenzzia Team
http://www.invenzzia.org/
See README for more author details
--------------------------------------------------------------------
This file is part of TypeFriendly.
TypeFriendly is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TypeFriendly is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TypeFriendly. If not, see <http://www.gnu.org/licenses/>.
*/
class tfMain extends tfApplication
{
const VERSION = '0.1.4';
private $args;
/**
* Parses the application arguments.
*
* @param tfProgram $prg The program instance.
*/
public function parseArgs(tfProgram $prg)
{
$this->args = array(
'#operation' => array(0 => OPT_REQUIRED, TYPE_STRING),
'#path' => array(0 => OPT_OPTIONAL, TYPE_PATH),
'-l' => array(0 => OPT_OPTIONAL, TYPE_STRING),
'-o' => array(0 => OPT_OPTIONAL, TYPE_STRING),
);
try
{
$prg->console->testArgs($this->args);
switch($this->args['#operation'])
{
case 'create':
$this->action = 'create';
break;
case 'build':
$this->action = 'build';
break;
case 'compare':
$this->action = 'compare';
break;
case 'version':
$this->action = 'version';
break;
default:
$this->action = 'main';
}
}
catch(Exception $e)
{
$this->action = 'main';
}
} // end parseArgs();
/**
* The main action, executed if no parameters were provided.
* @param tfProgram $prg
*/
public function main(tfProgram $prg)
{
$out = $prg->console->stdout;
$out->writeHr('=', 80);
$out->space();
$out->center('TypeFriendly', 80);
$out->center('Documentation building tool', 80);
$out->center('(c) Invenzzia Group 2008-2010', 80);
$out->center('www.invenzzia.org', 80);
$out->space();
$out->center('This program is free software. You can use, redistribute and/or modify it', 80);
$out->center('under the terms of GNU General Public License 3 or later. The license', 80);
$out->center('should be provided within the sources. The program comes with', 80);
$out->center('ABSOLUTELY NO WARRANTY!', 80);
$out->space();
$out->writeHr('=', 80);
$out->writeln('Usage:');
$out->writeln(' typefriendly.php ACTION [DOC_PATH] [OPTIONS]');
$out->space();
$out->writeln('Actions:');
$out->writeln(' create - creates a new documentation from a template under the specified path.');
$out->writeln(' build - builds an existing documentation.');
$out->writeln(' compare - compares the translations in existing documentation. Use with -l option.');
$out->writeln(' version - version information.');
$out->space();
$out->writeln('Options:');
$out->writeln(' -l language - [build, compare] the rendered or compared language');
$out->writeln(' -o output - [build] render only the specified output. The output');
$out->writeln(' must be declared within the project.');
} // end main();
/**
* New publication wizard
* @param tfProgram $prg
*/
public function create(tfProgram $prg)
{
$out = $prg->console->stdout;
if(!isset($this->args['#path']))
{
return $this->main($prg);
}
if(!is_dir($this->args['#path']))
{
$err = $prg->console->stderr;
$err->writeln('Error: the specified directory does not exist.');
return;
}
$fs = new tfFilesystem();
if(!$fs->setMasterDirectory($this->args['#path'], TF_READ | TF_WRITE | TF_EXEC))
{
$err = $prg->console->stderr;
$err->writeln('Error: unable to switch to "'.$this->args['#path'].'" - permission denied.');
return;
}
if($fs->containsItems(''))
{
$err = $prg->console->stderr;
$err->writeln('Error: the specified directory is not empty.');
return;
}
$out->writeln('Enter the title:');
$title = $prg->console->stdin->read(40);
$out->space();
$out->writeln('Enter the version:');
$version = $prg->console->stdin->read(40);
$out->space();
$out->writeln('Enter the copyright information:');
$copyright = $prg->console->stdin->read(100);
$out->space();
$out->writeln('Enter the license information:');
$license = $prg->console->stdin->read(100);
$out->space();
$projectType = -1;
while($projectType < 1 || $projectType > 4)
{
$out->writeln('Select the project type:');
$out->writeln(' (1) Documentation');
$out->writeln(' (2) User manual');
$out->writeln(' (3) Book');
$out->writeln(' (4) Article');
$out->space();
$projectType = (int)trim($prg->console->stdin->read(1));
}
$projectTypes = array(1 => 'documentation', 'manual', 'book', 'article');
$out->writeln('Generating files...');
$settings = '; This file was auto-generated by TypeFriendly
title = "'.trim(strtr($title, '\"\r\n', ' ')).'"
version = "'.trim(strtr($version, '\"\r\n', ' ')).'"
copyright = "'.trim(strtr($copyright, '\"\r\n', ' ')).'"
copyrightLink = ""
license = "'.trim(strtr($license, '\"\r\n', ' ')).'"
licenseLink = ""
projectType = "'.$projectTypes[$projectType].'"
outputs = "xhtml, xhtml_single"
baseLanguage = "en"
navigation = "book"
showNumbers = true
versionControlInfo = false
';
$fs->write('settings.ini', $settings);
$fs->write('sort_hints.txt', 'preface'.PHP_EOL);
$fs->safeMkdir('input', TF_READ | TF_WRITE | TF_EXEC);
$fs->safeMkdir('input/en', TF_READ | TF_WRITE | TF_EXEC);
$fs->safeMkdir('output', TF_READ | TF_WRITE | TF_EXEC);
$fs->write('input/en/preface.txt', 'Title: Preface'.PHP_EOL.PHP_EOL.'---'.PHP_EOL.PHP_EOL.'This documentation was auto-generated by TypeFriendly. You can fill it with your content now.'.PHP_EOL);
$out->writeln('Generation completed.');
} // end create();
/**
* Builds an output document
* @param tfProgram $prg
*/
public function build(tfProgram $prg)
{
if(!isset($this->args['#path']))
{
return $this->main($prg);
}
$prg->loadLibrary('parsers');
$prg->loadLibrary('output');
$prg->loadLibrary('project');
$prg->loadLibrary('i18n');
$prg->loadLibrary('tags');
$project = new tfProject($this->args['#path']);
tfProject::set($project);
// Choose the language
if(isset($this->args['-l']))
{
$project->setLanguage($this->args['-l']);
}
else
{
$project->setLanguage($project->config['baseLanguage']);
}
tfTags::setProject($project);
try
{
if(isset($this->args['-o']))
{
$prg->console->stdout->writeln('Processing the files.');
$project->loadItems();
$prg->console->stdout->writeln('Starting '.$this->args['-o'].'.');
$project->setOutput($this->args['-o']);
$project->generate();
$prg->console->stdout->writeln('Generation completed.');
}
else
{
$prg->console->stdout->writeln('Processing the files.');
$project->loadItems();
foreach($project->config['outputs'] as $out)
{
$prg->console->stdout->writeln('Starting '.$out.'.');
$project->setOutput($out);
$project->generate();
}
$prg->console->stdout->writeln('Generation completed.');
}
}
catch(Exception $e)
{
$prg->console->stderr->writeln($e->getMessage());
}
} // end build();
/**
* Compares the language versions.
* @param tfProgram $prg
*/
public function compare(tfProgram $prg)
{
if(!isset($this->args['-l']))
{
return $this->main($prg);
}
$prg->loadLibrary('project');
$prg->loadLibrary('parsers');
$prg->loadLibrary('i18n');
$prg->loadLibrary('tags');
$project = new tfProject($this->args['#path']);
tfProject::set($project);
$project->versionCompare($this->args['-l']);
} // end compare();
public function version(tfProgram $prg)
{
$out = $prg->console->stdout;
$out->writeln('TypeFriendly '.self::VERSION);
$out->writeln('(c) Invenzzia Group 2008 - 2010');
} // end version();
} // end tfMain;