Menu

[r660]: / trunk / Src / UCompResHTML.pas  Maximize  Restore  History

Download this file

423 lines (383 with data), 15.3 kB

  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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
{
* UCompResHTML.pas
*
* Static classes that generate HTML of parts of tables used to display compiler
* results.
*
* $Rev$
* $Date$
*
* ***** BEGIN LICENSE BLOCK *****
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is UCompResHTML.pas
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2006-2010 Peter
* Johnson. All Rights Reserved.
*
* Contributor(s)
* NONE
*
* ***** END LICENSE BLOCK *****
}
unit UCompResHTML;
interface
uses
// Project
IntfCompilers, UBaseObjects;
type
{
TCompResHTML:
Static class that provides information and HTML used in compiler tables that
is common to information and compilers check panes.
}
TCompResHTML = class(TNoConstructObject)
strict protected
class function ImageTag(const CompRes: TCompileResult;
const Id: string = ''): string;
{Provides HTML image tag used to represent a compilation result. Image has
title describing result.
@param CompRes [in] Required compilation result.
@param Id [in] Optional id attribute for image tag.
}
public
class function CompileResultDesc(const CompRes: TCompileResult): string;
{Provides description of a compiler result.
@param CompRes [in] Compiler result for which description wanted.
@return Required description.
}
class function ImageResURL(const CompRes: TCompileResult): string;
{Provides URL of image representing a compilation result.
@param CompRes [in] Compiler result for which URL is required.
@return Required URL.
}
end;
{
TInfoCompResHTML:
Static class that provides ids and HTML of table cells for the compiler
result table displayed in the routine view of the information pane.
}
TInfoCompResHTML = class(TCompResHTML)
public
class function NameCell(const Compiler: ICompiler): string;
{Generates HTML of a table cell containing the name of a compiler.
@param Compiler [in] Compiler whose name is to be displayed.
@result Required HTML code.
}
class function ResultCell(const CompRes: TCompileResult): string;
{Generates HTML of a table cell that displays an image that indicates a
compiler result.
@param CompRes [in] Compiler result to be displayed.
}
end;
{
TCompCheckResHTML:
Static class that provides ids, classes and HTML of table cells and links
for the compiler result table displayed in the routine view of the compiler
check pane.
}
TCompCheckResHTML = class(TCompResHTML)
strict private
class function NameSpanClass(const Compiler: ICompiler): string;
{Provides name of CSS class used to format a compiler name. This CSS class
is used in the span tag that surrounds the compiler name. The class is
used to indicates whether compiler is available or not.
@param Compiler [in] Compiler for which class is required.
@return Required class name (empty if compiler available).
}
class function NameSpanTitle(const Compiler: ICompiler): string;
{Provides a title attribute for span tag that surrounds a compiler name.
If compiler is note available title notes this. If compiler is availabele
title is blank.
@param Compiler [in] Compiler for which title is required.
@return Required title or empty string.
}
public
class function NameCell(const Compiler: ICompiler): string;
{Generates HTML of a table cell that displays a compiler name. If compiler
is not installed the name is greyed and has title indicating the case.
@param Compiler [in] Compiler whose name is to be displayed.
}
class function ResultCell(const CompRes: TCompileResult): string;
{Generates HTML of a table cell that displays an image that indicates a
compiler result.
@param CompRes [in] Compiler result to be displayed.
}
class function TestCellPlaceholder(const Compiler: ICompiler): string;
{Generates HTML of a placeholder table cell for a test compilation result.
The cell contains and image tag that displays an un-tested result and has
a unique id attribute.
@param Compiler [in] Compiler to be identified by the id attribute.
@result Required HTML code.
}
class function TestImgId(const Compiler: ICompiler): string;
{Provides a unique ID for an image used to a test display compilation
result for a specific compiler.
@param Compiler [in] Compiler for which id is required.
}
class function ErrCellPlaceholder(const Compiler: ICompiler): string;
{Generates HTML of an empty placeholder table cell for use in displaying
any error or warning links. The cell is given a unique id attribute.
@param Compiler [in] Compiler to be identified by the id attribute.
@result Required HTML code.
}
class function ErrCellId(const Compiler: ICompiler): string;
{Provides a unique ID for table cell used to display errors and warnings
from a test compilation for a specific compiler.
@param Compiler [in] Compiler for which id is required.
}
class function LogLink(const Compiler: ICompiler): string;
{Generates HTML of a link used to display error or warning logs created as
a result of a test compilation by a specific compiler. If there are no
errors or warnings no link is created.
@param Compiler [in] Compiler for which the link is required.
@param Required HTML.
}
end;
implementation
uses
// Delphi
SysUtils, StrUtils,
// Project
UConsts, UHTMLUtils, UHTMLDetailUtils, UIStringList, UJavaScriptUtils;
resourcestring
// Compiler image titles
sCompImgTitleOK = 'Compiles OK';
sCompImgTitleWarn = 'Compiles with warnings';
sCompImgTitleError = 'Does not compile';
sCompImgTitleQuery = 'Not tested';
const
// Compiler image sizes
cCompImgFileWidth = 18;
cCompImgFileHeight = 18;
// Table of compiler result images and associated titles
cLEDInfo: array[TCompileResult] of record
LED: string; // name of LED image "file" resource: ** do not localise
Title: string; // value of image tag title attribute
end =(
(LED: 'led-green.png'; Title: sCompImgTitleOK), // dcOK
(LED: 'led-yellow.png'; Title: sCompImgTitleWarn), // dcWarn
(LED: 'led-red.png'; Title: sCompImgTitleError), // dcError
(LED: 'led-off.png'; Title: sCompImgTitleQuery) // dcQuery
);
{ TCompResHTML }
class function TCompResHTML.CompileResultDesc(
const CompRes: TCompileResult): string;
{Provides description of a compiler result.
@param CompRes [in] Compiler result for which description wanted.
@return Required description.
}
begin
Result := cLEDInfo[CompRes].Title;
end;
class function TCompResHTML.ImageResURL(const CompRes: TCompileResult): string;
{Provides URL of image representing a compilation result.
@param CompRes [in] Compiler result for which URL is required.
@return Required URL.
}
begin
Result := MakeResourceURL(cLEDInfo[CompRes].LED);
end;
class function TCompResHTML.ImageTag(const CompRes: TCompileResult;
const Id: string): string;
{Provides HTML image tag used to represent a compilation result. Image has
title describing result.
@param CompRes [in] Required compilation result.
@param Id [in] Optional id attribute for image tag.
}
begin
Result := UHTMLUtils.ImageTag(
ImageResURL(CompRes),
CompileResultDesc(CompRes),
cCompImgFileWidth,
cCompImgFileHeight,
Id
);
end;
{ TInfoCompResHTML }
class function TInfoCompResHTML.NameCell(
const Compiler: ICompiler): string;
{Generates HTML of a table cell containing the name of a compiler.
@param Compiler [in] Compiler whose name is to be displayed.
@result Required HTML code.
}
var
CompilerNameHTML: string; // HTML containing compiler name
begin
// Any spaces in compiler name replaced by <br /> tags
CompilerNameHTML := ReplaceStr(
MakeSafeHTMLText(Compiler.GetName), ' ', MakeTag('br', ttSimple)
);
Result := MakeCompoundTag('th', CompilerNameHTML);
end;
class function TInfoCompResHTML.ResultCell(
const CompRes: TCompileResult): string;
{Generates HTML of a table cell that displays an image that indicates a
compiler result.
@param CompRes [in] Compiler result to be displayed.
}
begin
Result := MakeCompoundTag('td', ImageTag(CompRes));
end;
{ TCompCheckResHTML }
class function TCompCheckResHTML.ErrCellId(const Compiler: ICompiler): string;
{Provides a unique ID for table cell used to display errors and warnings from
a test compilation for a specific compiler.
@param Compiler [in] Compiler for which id is required.
}
begin
Result := Format('errcell%d', [Ord(Compiler.GetID)]);
end;
class function TCompCheckResHTML.ErrCellPlaceholder(
const Compiler: ICompiler): string;
{Generates HTML of an empty placeholder table cell for use in displaying any
error or warning links. The cell is given a unique id attribute.
@param Compiler [in] Compiler to be identified by the id attribute.
@result Required HTML code.
}
var
TableCellAttrs: IHTMLAttributes; // attributes of table cell tag
begin
TableCellAttrs := THTMLAttributes.Create;
TableCellAttrs.Add('class', 'testerr');
TableCellAttrs.Add('id', ErrCellId(Compiler));
Result := MakeCompoundTag('td', TableCellAttrs, '&nbsp;');
end;
class function TCompCheckResHTML.LogLink(const Compiler: ICompiler): string;
{Generates HTML of a link used to display error or warning logs created as
a result of a test compilation by a specific compiler. If there are no errors
or warnings no link is created.
@param Compiler [in] Compiler for which the link is required.
@param Required HTML.
}
resourcestring
// Compiler results strings
sWarningStatus = 'warnings';
sErrorStatus = 'errors';
sViewLinkText = 'View %s';
sHint = 'View the %0:s compilation %1:s';
var
LogStatus: string; // status text
begin
// Set up status and hints according to compilation result
case Compiler.GetLastCompileResult of
crWarning:
LogStatus := sWarningStatus;
crError:
LogStatus := sErrorStatus;
end;
// If we have some log text return HTML for link that accesses it
if Compiler.HasErrorsOrWarnings then
// We have warnings or errors: link causes dialog to be displayed
Result := '&nbsp;&raquo;&nbsp;' + JSLink(
JSLiteralFunc('viewCompilerLog', [Ord(Compiler.GetID)]),
'|' + Format(sHint, [Compiler.GetName, LogStatus]),
TIStringList.Create('command-link'),
Format(sViewLinkText, [LogStatus])
)
else
// No warnings or error: nothing to display
Result := '&nbsp';
end;
class function TCompCheckResHTML.NameCell(const Compiler: ICompiler): string;
{Generates HTML of a table cell that displays a compiler name. If compiler is
not installed the name is greyed and has title indicating the case.
@param Compiler [in] Compiler whose name is to be displayed.
}
var
TableCellAttrs: IHTMLAttributes; // attributes of table cell tag
SpanAttrs: IHTMLAttributes; // attributes of span tag
begin
TableCellAttrs := THTMLAttributes.Create;
TableCellAttrs.Add('class', 'compiler');
SpanAttrs := THTMLAttributes.Create;
SpanAttrs.Add('class', NameSpanClass(Compiler));
SpanAttrs.Add('title', NameSpanTitle(Compiler));
Result := MakeCompoundTag(
'td',
TableCellAttrs,
MakeCompoundTag('span', SpanAttrs, MakeSafeHTMLText(Compiler.GetName))
);
end;
class function TCompCheckResHTML.NameSpanClass(
const Compiler: ICompiler): string;
{Provides name of CSS class used to format a compiler name. This CSS class is
used in the span tag that surrounds the compiler name. The class is used to
indicates whether compiler is available or not.
@param Compiler [in] Compiler for which class is required.
@return Required class name (empty if compiler available).
}
const
// Map of compiler availability to span class
cSpanClass: array[Boolean] of string = ('disabled', '');
begin
Result := cSpanClass[Compiler.IsAvailable];
end;
class function TCompCheckResHTML.NameSpanTitle(
const Compiler: ICompiler): string;
{Provides a title attribute for span tag that surrounds a compiler name. If
compiler is note available title notes this. If compiler is availabele title
is blank.
@param Compiler [in] Compiler for which title is required.
@return Required title or empty string.
}
resourcestring
// Hint string for uninstalled compilers
sCompNotInstalled = '%s not installed';
begin
if Compiler.IsAvailable then
Result := ''
else
Result := MakeSafeHTMLText(Format(sCompNotInstalled, [Compiler.GetName]));
end;
class function TCompCheckResHTML.ResultCell(
const CompRes: TCompileResult): string;
{Generates HTML of a table cell that displays an image that indicates a
compiler result.
@param CompRes [in] Compiler result to be displayed.
}
var
TableCellAttrs: IHTMLAttributes; // attributes of table cell tag
begin
TableCellAttrs := THTMLAttributes.Create;
TableCellAttrs.Add('class', 'dbres');
Result := MakeCompoundTag('td', TableCellAttrs, ImageTag(CompRes));
end;
class function TCompCheckResHTML.TestCellPlaceholder(
const Compiler: ICompiler): string;
{Generates HTML of a placeholder table cell for a test compilation result. The
cell contains and image tag that displays an un-tested result and has a unique
id attribute.
@param Compiler [in] Compiler to be identified by the id attribute.
@result Required HTML code.
}
var
TableCellAttrs: IHTMLAttributes; // attributes of table cell tag
begin
TableCellAttrs := THTMLAttributes.Create;
TableCellAttrs.Add('class', 'testres');
Result := MakeCompoundTag(
'td', TableCellAttrs, ImageTag(crQuery, TestImgId(Compiler))
);
end;
class function TCompCheckResHTML.TestImgId(const Compiler: ICompiler): string;
{Provides a unique ID for an image used to a test display compilation result
for a specific compiler.
@param Compiler [in] Compiler for which id is required.
}
begin
Result := Format('testimg%d', [Ord(Compiler.GetID)]);
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.