2017-05-17 22:32:45 +02:00
|
|
|
{ *************************************************************************** }
|
2018-08-05 20:31:33 +02:00
|
|
|
{ }
|
|
|
|
{ Delphi MVC Framework }
|
|
|
|
{ }
|
|
|
|
{ Copyright (c) 2010-2018 Daniele Teti and the DMVCFramework Team }
|
|
|
|
{ }
|
|
|
|
{ https://github.com/danieleteti/delphimvcframework }
|
|
|
|
{ }
|
2017-05-17 22:32:45 +02:00
|
|
|
{ *************************************************************************** }
|
|
|
|
{ }
|
|
|
|
{ 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,
|
|
|
|
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
|
2017-05-17 22:32:45 +02:00
|
|
|
constructor Create(const aCreateIndexMethod, aCreateCRUDMethods, aCreateActionFiltersMethods
|
|
|
|
: Boolean; const AControllerClassName: string;
|
|
|
|
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;
|
|
|
|
|
2017-05-17 22:32:45 +02:00
|
|
|
constructor TNewControllerUnitEx.Create(const aCreateIndexMethod, aCreateCRUDMethods, aCreateActionFiltersMethods
|
|
|
|
: Boolean; const AControllerClassName: string;
|
|
|
|
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
|
|
|
|
|
|
|
end.
|