2020-05-28 22:35:45 +02:00
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Delphi MVC Framework
|
|
|
|
//
|
2022-01-04 15:44:47 +01:00
|
|
|
// Copyright (c) 2010-2022 Daniele Teti and the DMVCFramework Team
|
2020-05-28 22:35:45 +02:00
|
|
|
//
|
|
|
|
// https://github.com/danieleteti/delphimvcframework
|
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// This IDE expert is based off of the one included with the DUnitX }
|
|
|
|
// project. Original source by Robert Love. Adapted by Nick Hodges. }
|
|
|
|
//
|
|
|
|
// The DUnitX project is run by Vincent Parrett and can be found at: }
|
|
|
|
//
|
|
|
|
// https://github.com/VSoftTechnologies/DUnitX }
|
|
|
|
// ***************************************************************************
|
2016-02-23 01:41:13 +01:00
|
|
|
|
|
|
|
unit DMVC.Expert.CodeGen.NewControllerUnit;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
ToolsApi,
|
2022-07-25 10:36:30 +02:00
|
|
|
System.IOUtils,
|
2016-02-23 01:41:13 +01:00
|
|
|
DMVC.Expert.CodeGen.NewUnit;
|
|
|
|
|
|
|
|
type
|
|
|
|
TNewControllerUnitEx = class(TNewUnit)
|
|
|
|
protected
|
2016-02-24 22:37:13 +01:00
|
|
|
FCreateIndexMethod: Boolean;
|
2017-05-17 22:32:45 +02:00
|
|
|
FCreateCRUDMethods: Boolean;
|
2016-02-24 22:37:13 +01:00
|
|
|
FCreateActionFiltersMethods: Boolean;
|
2017-05-17 22:32:45 +02:00
|
|
|
FControllerClassName: string;
|
2016-02-24 22:37:13 +01:00
|
|
|
function NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string)
|
|
|
|
: IOTAFile; override;
|
2016-02-23 01:41:13 +01:00
|
|
|
public
|
2022-07-25 10:36:30 +02:00
|
|
|
constructor Create(
|
|
|
|
const aCreateIndexMethod, aCreateCRUDMethods, aCreateActionFiltersMethods: Boolean;
|
|
|
|
const AControllerClassName: string;
|
|
|
|
const APersonality: string = '');
|
|
|
|
end;
|
|
|
|
|
|
|
|
TNewJSONRPCUnitEx = class(TNewUnit)
|
|
|
|
protected
|
|
|
|
fJSONRPCClassName: String;
|
|
|
|
function NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string)
|
|
|
|
: IOTAFile; override;
|
|
|
|
public
|
|
|
|
constructor Create(const aJSONRPCClassName: String;
|
2017-05-17 22:32:45 +02:00
|
|
|
const APersonality: string = '');
|
2016-02-23 01:41:13 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils,
|
|
|
|
VCL.Dialogs,
|
|
|
|
DMVC.Expert.CodeGen.Templates,
|
|
|
|
DMVC.Expert.CodeGen.SourceFile;
|
|
|
|
|
2022-07-25 10:36:30 +02:00
|
|
|
constructor TNewControllerUnitEx.Create(
|
|
|
|
const aCreateIndexMethod, aCreateCRUDMethods,
|
|
|
|
aCreateActionFiltersMethods: Boolean;
|
|
|
|
const AControllerClassName: string;
|
2017-05-17 22:32:45 +02:00
|
|
|
const APersonality: string = '');
|
2016-02-23 01:41:13 +01:00
|
|
|
begin
|
|
|
|
Assert(Length(AControllerClassName) > 0);
|
|
|
|
FAncestorName := '';
|
|
|
|
FFormName := '';
|
|
|
|
FImplFileName := '';
|
|
|
|
FIntfFileName := '';
|
|
|
|
FControllerClassName := AControllerClassName;
|
|
|
|
FCreateIndexMethod := aCreateIndexMethod;
|
2017-05-17 22:32:45 +02:00
|
|
|
FCreateCRUDMethods := aCreateCRUDMethods;
|
2016-02-24 22:37:13 +01:00
|
|
|
FCreateActionFiltersMethods := aCreateActionFiltersMethods;
|
2016-02-23 01:41:13 +01:00
|
|
|
Personality := APersonality;
|
|
|
|
end;
|
|
|
|
|
2016-02-24 22:37:13 +01:00
|
|
|
function TNewControllerUnitEx.NewImplSource(const ModuleIdent, FormIdent,
|
|
|
|
AncestorIdent: string): IOTAFile;
|
2016-02-23 01:41:13 +01:00
|
|
|
var
|
|
|
|
lUnitIdent: string;
|
|
|
|
lFormName: string;
|
|
|
|
lFileName: string;
|
|
|
|
lIndexMethodIntf: string;
|
|
|
|
lIndexMethodImpl: string;
|
|
|
|
lControllerUnit: string;
|
2016-02-24 22:37:13 +01:00
|
|
|
lActionFiltersMethodsIntf: string;
|
|
|
|
lActionFiltersMethodsImpl: string;
|
2017-05-17 22:32:45 +02:00
|
|
|
lCRUDMethodsIntf: string;
|
|
|
|
lCRUDMethodsImpl: string;
|
2016-02-24 22:37:13 +01:00
|
|
|
begin
|
|
|
|
lControllerUnit := sControllerUnit;
|
|
|
|
lIndexMethodIntf := sIndexMethodIntf;
|
|
|
|
lIndexMethodImpl := Format(sIndexMethodImpl, [FControllerClassName]);
|
2017-05-17 22:32:45 +02:00
|
|
|
lCRUDMethodsIntf := sCRUDMethodsIntf;
|
|
|
|
lCRUDMethodsImpl := Format(sCRUDMethodsImpl, [FControllerClassName]);
|
2016-02-23 01:41:13 +01:00
|
|
|
|
2016-02-24 22:37:13 +01:00
|
|
|
if not FCreateIndexMethod then
|
|
|
|
begin
|
|
|
|
lIndexMethodIntf := '';
|
|
|
|
lIndexMethodImpl := '';
|
|
|
|
end;
|
2016-02-23 01:41:13 +01:00
|
|
|
|
2017-05-17 22:32:45 +02:00
|
|
|
if not FCreateCRUDMethods then
|
|
|
|
begin
|
|
|
|
lCRUDMethodsIntf := '';
|
|
|
|
lCRUDMethodsImpl := '';
|
|
|
|
end;
|
|
|
|
|
2016-02-24 22:37:13 +01:00
|
|
|
lActionFiltersMethodsIntf := sActionFiltersIntf;
|
|
|
|
lActionFiltersMethodsImpl := Format(sActionFiltersImpl,
|
|
|
|
[FControllerClassName]);
|
|
|
|
|
|
|
|
if not FCreateActionFiltersMethods then
|
|
|
|
begin
|
|
|
|
lActionFiltersMethodsIntf := '';
|
|
|
|
lActionFiltersMethodsImpl := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
// http://stackoverflow.com/questions/4196412/how-do-you-retrieve-a-new-unit-name-from-delphis-open-tools-api
|
|
|
|
// So using method mentioned by Marco Cantu.
|
|
|
|
(BorlandIDEServices as IOTAModuleServices).GetNewModuleAndClassName('',
|
|
|
|
lUnitIdent, lFormName, lFileName);
|
|
|
|
Result := TSourceFile.Create(sControllerUnit,
|
2017-05-17 22:32:45 +02:00
|
|
|
[lUnitIdent, FControllerClassName, lIndexMethodIntf, lIndexMethodImpl, lActionFiltersMethodsIntf, lActionFiltersMethodsImpl, lCRUDMethodsIntf, lCRUDMethodsImpl]);
|
2016-02-24 22:37:13 +01:00
|
|
|
end;
|
2016-02-23 01:41:13 +01:00
|
|
|
|
2022-07-25 10:36:30 +02:00
|
|
|
{ TNewJSONRPCUnitEx }
|
|
|
|
|
|
|
|
constructor TNewJSONRPCUnitEx.Create(const aJSONRPCClassName,
|
|
|
|
APersonality: string);
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
fJSONRPCClassName := aJSONRPCClassName;
|
|
|
|
Personality := aPersonality;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TNewJSONRPCUnitEx.NewImplSource(const ModuleIdent, FormIdent,
|
|
|
|
AncestorIdent: string): IOTAFile;
|
|
|
|
var
|
|
|
|
lUnitIdent: string;
|
|
|
|
// lFormName: string;
|
|
|
|
lFileName: string;
|
|
|
|
lDummy: String;
|
|
|
|
begin
|
|
|
|
// http://stackoverflow.com/questions/4196412/how-do-you-retrieve-a-new-unit-name-from-delphis-open-tools-api
|
|
|
|
// So using method mentioned by Marco Cantu.
|
|
|
|
lFileName := ''; //fJSONRPCClassName + 'U';
|
|
|
|
(BorlandIDEServices as IOTAModuleServices).GetNewModuleAndClassName('',
|
|
|
|
lUnitIdent, lDummy, lFileName);
|
|
|
|
Result := TSourceFile.Create(sJSONRPCUnit,
|
|
|
|
[
|
|
|
|
lUnitIdent,
|
|
|
|
fJSONRPCClassName
|
|
|
|
]);
|
|
|
|
end;
|
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
end.
|