Skip to content

Commit 7a9a1cc

Browse files
author
delphidabbler
committed
Merge branch 'feature/update-license-info' into develop
2 parents 18fec20 + 8e740d1 commit 7a9a1cc

File tree

6 files changed

+122
-67
lines changed

6 files changed

+122
-67
lines changed

Src/DB.UMetaData.pas

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ TDBLicenseInfo = record
125125
property URL: string read fURL;
126126
/// <summary>Full text of license.</summary>
127127
property Text: string read fText;
128+
/// <summary>Returns a string containing license name followed by any URL
129+
/// in parentheses.</summary>
130+
/// <remarks>If no URL is available then only the license name is returned.
131+
/// </remarks>
132+
function NameWithURL: string;
128133
end;
129134

130135
/// <summary>Record providing informaton about the main database copyright.
@@ -938,6 +943,13 @@ constructor TDBLicenseInfo.Create(const AName, ASPDX, AURL, AText: string);
938943
fText := AText;
939944
end;
940945

946+
function TDBLicenseInfo.NameWithURL: string;
947+
begin
948+
Result := fName;
949+
if fURL <> '' then
950+
Result := Result + ' (' + fURL + ')';
951+
end;
952+
941953
{ TDBCopyrightInfo }
942954

943955
constructor TDBCopyrightInfo.Create(const ADate, AHolder, AHolderURL: string);

Src/SWAG.UImporter.pas

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* CodeSnip format and adds them to the database.
1010
}
1111

12-
// TODO -cDatabase: check BSD3URI const has valid license info
1312

1413
unit SWAG.UImporter;
1514

@@ -161,27 +160,20 @@ function TSWAGImporter.ExtraBoilerplate: IActiveText;
161160
sStatementPrefix = 'This snippet was imported from the ';
162161
sStatementLinkText = 'SWAG Pascal Archive';
163162
sStatementPostfix = '. ';
164-
sLicensePrefix = 'Unless stated otherwise this snippet is licensed under '
165-
+ 'the ';
166-
sLicenseLinkText = 'BSD 3-Clause License';
167-
sLicensePostfix = '.';
168-
const
169-
// URLs of web pages referenced from links in boilerplate
163+
sLicense = 'The code snippets in the archive pages are generally freeware or '
164+
+ 'public domain as defined by any accompanying comments and copyright '
165+
+ 'statements. Contact the author if in doubt.';
166+
// URL of web page referenced from links in boilerplate
170167
SWAGDBURI = 'https://github.com/delphidabbler/swag';
171-
BSD3URI = 'http://opensource.org/licenses/BSD-3-Clause';
172168
var
173-
// Active text attributes for links included in boilerplate
169+
// Active text attributes for link included in boilerplate
174170
SWAGDBURIAttr: IActiveTextAttrs;
175-
BSD3URIAttr: IActiveTextAttrs;
176171
begin
177172
if not Assigned(fExtraBoilerplate) then
178173
begin
179174
SWAGDBURIAttr := TActiveTextFactory.CreateAttrs(
180175
TActiveTextAttr.Create('href', SWAGDBURI)
181176
);
182-
BSD3URIAttr := TActiveTextFactory.CreateAttrs(
183-
TActiveTextAttr.Create('href', BSD3URI)
184-
);
185177
fExtraBoilerplate := TActiveTextFactory.CreateActiveText;
186178
fExtraBoilerplate.AddElem(
187179
TActiveTextFactory.CreateActionElem(ekPara, fsOpen)
@@ -202,19 +194,7 @@ function TSWAGImporter.ExtraBoilerplate: IActiveText;
202194
TActiveTextFactory.CreateTextElem(sStatementPostfix)
203195
);
204196
fExtraBoilerplate.AddElem(
205-
TActiveTextFactory.CreateTextElem(sLicensePrefix)
206-
);
207-
fExtraBoilerplate.AddElem(
208-
TActiveTextFactory.CreateActionElem(ekLink, BSD3URIAttr, fsOpen)
209-
);
210-
fExtraBoilerplate.AddElem(
211-
TActiveTextFactory.CreateTextElem(sLicenseLinkText)
212-
);
213-
fExtraBoilerplate.AddElem(
214-
TActiveTextFactory.CreateActionElem(ekLink, BSD3URIAttr, fsClose)
215-
);
216-
fExtraBoilerplate.AddElem(
217-
TActiveTextFactory.CreateTextElem(sLicensePostfix)
197+
TActiveTextFactory.CreateTextElem(sLicense)
218198
);
219199
fExtraBoilerplate.AddElem(
220200
TActiveTextFactory.CreateActionElem(ekPara, fsClose)

Src/USaveUnitMgr.pas

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ implementation
9696
// Delphi
9797
SysUtils,
9898
// Project
99-
UAppInfo, UUrl, UUtils;
99+
DB.UMetaData,
100+
UAppInfo,
101+
UUrl,
102+
UUtils;
100103

101-
// TODO -cDatabase: get license info from database rather than use literal text.
102104

103105
resourcestring
104106
// Dialog box title
@@ -113,11 +115,9 @@ implementation
113115
// Error message
114116
sErrorMsg = 'Filename is not valid for a Pascal unit';
115117
// Unit header comments
116-
// TODO -cWeb: Change following to get license from database meta data
117-
sLicense = 'This unit is copyright © %0:s by the Peter Johnson and Code '
118-
+ 'Snippets Database contributors and is licensed under the MIT license '
119-
+ '(http://opensource.org/licenses/MIT).';
120-
sMainDescription = 'The unit was generated automatically and incorporates a '
118+
sLicense = 'The unit is copyright © %0:s by %1:s and is licensed under '
119+
+ 'the %2:s.';
120+
sMainDescription = 'This unit was generated automatically. It incorporates a '
121121
+ 'selection of source code taken from the Code Snippets Database at %0:s.';
122122
sGenerated = 'Generated on : %0:s.';
123123
sGenerator = 'Generated by : %0:s %1:s.';
@@ -144,14 +144,26 @@ procedure TSaveUnitMgr.CheckFileName(const FileName: string;
144144
end;
145145

146146
function TSaveUnitMgr.CreateHeaderComments: IStringList;
147+
var
148+
DBMetaData: IDBMetaData;
147149
begin
148150
Result := TIStringList.Create;
149151
if fContainsMainDBSnippets then
150152
begin
151-
// Result used for units that contain at snippet(s) from main database
152-
Result.Add(Format(sLicense, [FormatDateTime('YYYY', Now)]));
153+
// Result used for units that contain any snippet(s) from main database
154+
Result.Add(Format(sMainDescription, [TURL.CodeSnippetsDBRepo]));
153155
Result.Add('');
154-
Result.Add(Format(sMainDescription, [TURL.CodeSnipRepo]));
156+
DBMetaData := TMainDBMetaDataFactory.MainDBMetaDataInstance;
157+
Result.Add(
158+
Format(
159+
sLicense,
160+
[
161+
DBMetaData.GetCopyrightInfo.Date,
162+
DBMetaData.GetCopyrightInfo.Holder,
163+
DBMetaData.GetLicenseInfo.NameWithURL
164+
]
165+
)
166+
);
155167
Result.Add('');
156168
Result.Add(Format(sGenerated, [RFC1123DateStamp]));
157169
Result.Add(

Src/USnippetDoc.pas

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ TSnippetDoc = class(TObject)
5252
/// <summary>Creates and returns an array of compiler compatibility
5353
/// information for given snippet.</summary>
5454
function CompilerInfo(const Snippet: TSnippet): TCompileDocInfoArray;
55-
{Gets compiler compatibility information for a snippet.
56-
@param Snippet [in] Snippet for which compiler information is required.
57-
@return Array of compiler compatibility information.
58-
}
55+
/// <summary>Generates and returns a string containing information about
56+
/// the main database.</summary>
57+
function MainDBInfo: string;
5958
strict protected
6059
/// <summary>Initialise document.</summary>
6160
/// <remarks>Does nothing. Descendant classes should perform any required
@@ -111,7 +110,12 @@ implementation
111110
// Delphi
112111
SysUtils,
113112
// Project
114-
Compilers.UCompilers, DB.UMain, DB.USnippetKind, UStrUtils, UUrl;
113+
Compilers.UCompilers,
114+
DB.UMain,
115+
DB.UMetaData,
116+
DB.USnippetKind,
117+
UStrUtils,
118+
UUrl;
115119

116120

117121
{ TSnippetDoc }
@@ -155,10 +159,6 @@ function TSnippetDoc.Generate(const Snippet: TSnippet): TEncodedData;
155159
sDependListTitle = 'Required snippets:';
156160
sXRefListTitle = 'See also:';
157161
sCompilers = 'Supported compilers:';
158-
// TODO -cWeb: Change following to get license info from DB meta data
159-
sMainDatabaseInfo = 'A snippet from the DelphiDabbler CodeSnip Database '
160-
+ '(%s), licensed under the MIT License '
161-
+ '(http://opensource.org/licenses/MIT).';
162162
begin
163163
Assert(Assigned(Snippet), ClassName + '.Create: Snippet is nil');
164164
// generate document
@@ -181,7 +181,7 @@ function TSnippetDoc.Generate(const Snippet: TSnippet): TEncodedData;
181181
RenderExtra(Snippet.Extra);
182182
if not Snippet.UserDefined then
183183
// database info written only if snippet is from main database
184-
RenderDBInfo(Format(sMainDatabaseInfo, [TURL.CodeSnipRepo]));
184+
RenderDBInfo(MainDBInfo);
185185
Result := FinaliseDoc;
186186
end;
187187

@@ -190,6 +190,23 @@ procedure TSnippetDoc.InitialiseDoc;
190190
// Do nothing
191191
end;
192192

193+
function TSnippetDoc.MainDBInfo: string;
194+
resourcestring
195+
sMainDBInfo = 'A snippet from the DelphiDabbler Code Snippets Database '
196+
+ '(%0:s), licensed under the %1:s.';
197+
var
198+
DBMetaData: IDBMetaData;
199+
begin
200+
DBMetaData := TMainDBMetaDataFactory.MainDBMetaDataInstance;
201+
Result := Format(
202+
sMainDBInfo,
203+
[
204+
TURL.CodeSnipRepo,
205+
DBMetaData.GetLicenseInfo.NameWithURL
206+
]
207+
);
208+
end;
209+
193210
function TSnippetDoc.SnippetsToStrings(const SnippetList: TSnippetList):
194211
IStringList;
195212
var

Src/USnippetSourceGen.pas

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ implementation
8787
// Delphi
8888
SysUtils,
8989
// Project
90-
DB.USnippet, DB.USnippetKind, UAppInfo, UQuery, UUtils;
90+
DB.UMetaData,
91+
DB.USnippet,
92+
DB.USnippetKind,
93+
UAppInfo,
94+
UQuery,
95+
UUtils;
9196

9297

9398
{ TSnippetSourceGen }
@@ -97,31 +102,59 @@ function TSnippetSourceGen.BuildHeaderComments: IStringList;
97102
@return String list containing comments.
98103
}
99104
var
100-
Header: string; // format string for header comment
105+
DBMetaData: IDBMetaData;
101106
resourcestring
102107
// Comment to be included at top of snippet
103-
// header used if snippet includes code from main database
104-
sMainHeader = 'This code snippet was generated by %0:s %1:s on %2:s. It '
105-
+ 'includes code taken from the DelphiDabbler Code Snippets database that '
106-
+ 'is covered by the MIT license (http://opensource.org/licenses/MIT).';
107-
// header used if snippet contains only user defined snippets
108-
sUserHeader = 'This user defined code snippet was generated by '
108+
// when snippets include those from main database
109+
sMainDBGenerator = 'This code snippet was generated by %0:s %1:s on %2:s.';
110+
sMainDBLicense = 'It includes code taken from the DelphiDabbler Code '
111+
+ 'Snippets database that is copyright © %0:s by %1:s and is licensed '
112+
+ 'under the %2:s.';
113+
// when snippets are all from user defined database
114+
sUserGenerator = 'This user defined code snippet was generated by '
109115
+ '%0:s %1:s on %2:s.';
110116
begin
111117
// Header depends on whether snippets contain any from main database or are
112118
// all user defined
119+
Result := TIStringList.Create;
113120
if fContainsMainDBSnippets then
114-
Header := sMainHeader
121+
begin
122+
Result.Add(
123+
Format(
124+
sMainDBGenerator,
125+
[
126+
TAppInfo.FullProgramName,
127+
TAppInfo.ProgramReleaseInfo,
128+
RFC1123DateStamp
129+
]
130+
)
131+
);
132+
Result.Add('');
133+
DBMetaData := TMainDBMetaDataFactory.MainDBMetaDataInstance;
134+
Result.Add(
135+
Format(
136+
sMainDBLicense,
137+
[
138+
DBMetaData.GetCopyrightInfo.Date,
139+
DBMetaData.GetCopyrightInfo.Holder,
140+
DBMetaData.GetLicenseInfo.NameWithURL
141+
]
142+
)
143+
);
144+
end
115145
else
116-
Header := sUserHeader;
117-
// Add the comments
118-
Result := TIStringList.Create;
119-
Result.Add(
120-
Format(
121-
Header,
122-
[TAppInfo.FullProgramName, TAppInfo.ProgramReleaseInfo, RFC1123DateStamp]
123-
)
124-
);
146+
begin
147+
Result.Add(
148+
Format(
149+
sUserGenerator,
150+
[
151+
TAppInfo.FullProgramName,
152+
TAppInfo.ProgramReleaseInfo,
153+
RFC1123DateStamp
154+
]
155+
)
156+
);
157+
end;
125158
end;
126159

127160
class function TSnippetSourceGen.CanGenerate(View: IView): Boolean;

Src/UUrl.pas

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ TURL = record
2424
/// <summary>URL of DelphiDabbler's account on GitHub repository.
2525
/// </summary>
2626
DDabGitHub = 'https://github.com/delphidabbler';
27-
/// <summary>URL of the Code Snippet database's GitHub repository.
28-
/// </summary>
29-
CodeSnippetsDBRepo = DDabGitHub + '/code-snippets';
3027
/// <summary>URL of the SWAG database's GitHub repository.</summary>
3128
SWAGRepo = DDabGitHub + '/swag';
3229
/// <summary>URL of the CodeSnip FAQ's GitHub repository.</summary>
@@ -44,6 +41,10 @@ TURL = record
4441
/// <remarks>This is the CodeSnip FAQ project on GitHub.</remarks>
4542
CodeSnipFAQReadMe = CodeSnipFAQRepo + '/blob/master/README.md';
4643

44+
/// <summary>URL of the Code Snippet database's GitHub repository.
45+
/// </summary>
46+
CodeSnippetsDBRepo = DDabGitHub + '/code-snippets';
47+
4748
/// <summary>URL of the GitHub page where DelphiDabbler Code Snippets
4849
/// database releases are hosted.</summary>
4950
CodeSnippetsDBReleases = CodeSnippetsDBRepo + '/releases';

0 commit comments

Comments
 (0)