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.NewWebModuleUnit;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
ToolsApi,
|
|
|
|
DMVC.Expert.CodeGen.NewUnit;
|
|
|
|
|
|
|
|
type
|
|
|
|
TNewWebModuleUnitEx = class(TNewUnit)
|
|
|
|
private
|
|
|
|
FUnitIdent, FFormName, FFileName : String;
|
2018-08-05 20:31:33 +02:00
|
|
|
FMiddlewares: TArray<String>;
|
2016-02-23 01:41:13 +01:00
|
|
|
protected
|
|
|
|
FWebModuleClassName : string;
|
|
|
|
FControllerClassName: string;
|
|
|
|
FControllerUnit: string;
|
2022-07-25 10:36:30 +02:00
|
|
|
FJSONRPCClassName: string;
|
|
|
|
FJSONRPCClassUnit: string;
|
2016-02-23 01:41:13 +01:00
|
|
|
function GetCreatorType: string; override;
|
|
|
|
function NewFormFile(const FormIdent, AncestorIdent: string): IOTAFile; override;
|
|
|
|
function NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile; override;
|
|
|
|
public
|
2022-07-25 10:36:30 +02:00
|
|
|
constructor Create(
|
|
|
|
const aWebModuleClassName: string;
|
|
|
|
const aControllerClassName: string;
|
|
|
|
const aControllerUnit: string;
|
|
|
|
const aMiddlewares: TArray<String>;
|
|
|
|
const aJSONRPCClassName: String;
|
|
|
|
const aJSONRPCClassUnit: String;
|
|
|
|
const aPersonality : String);
|
2016-02-23 01:41:13 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
Winapi.Windows,
|
|
|
|
System.SysUtils,
|
|
|
|
VCL.Dialogs,
|
|
|
|
DMVC.Expert.CodeGen.Templates,
|
|
|
|
DMVC.Expert.CodeGen.SourceFile;
|
|
|
|
|
2022-07-25 10:36:30 +02:00
|
|
|
constructor TNewWebModuleUnitEx.Create(
|
|
|
|
const aWebModuleClassName: string;
|
|
|
|
const aControllerClassName: string;
|
|
|
|
const aControllerUnit: string;
|
|
|
|
const aMiddlewares: TArray<String>;
|
|
|
|
const aJSONRPCClassName: String;
|
|
|
|
const aJSONRPCClassUnit: String;
|
|
|
|
const aPersonality : String);
|
2016-02-23 01:41:13 +01:00
|
|
|
begin
|
|
|
|
Assert(Length(aWebModuleClassName) > 0);
|
|
|
|
FAncestorName := '';
|
|
|
|
FFormName := '';
|
|
|
|
FImplFileName := '';
|
|
|
|
FIntfFileName := '';
|
2022-07-25 10:36:30 +02:00
|
|
|
FJSONRPCClassName := aJSONRPCClassName;
|
|
|
|
FJSONRPCClassUnit := aJSONRPCClassUnit;
|
2016-02-23 01:41:13 +01:00
|
|
|
FWebModuleClassName := aWebModuleClassName;
|
|
|
|
FControllerClassName := aControllerClassName;
|
|
|
|
FControllerUnit := aControllerUnit;
|
2018-08-05 20:31:33 +02:00
|
|
|
FMiddlewares := AMiddlewares;
|
2016-02-23 01:41:13 +01:00
|
|
|
Personality := APersonality;
|
2022-07-25 10:36:30 +02:00
|
|
|
(BorlandIDEServices as IOTAModuleServices).GetNewModuleAndClassName(
|
|
|
|
'', FUnitIdent, FFormName, FFileName);
|
2016-02-23 01:41:13 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TNewWebModuleUnitEx.GetCreatorType: string;
|
|
|
|
begin
|
|
|
|
Result := sForm;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TNewWebModuleUnitEx.NewFormFile(const FormIdent, AncestorIdent: string): IOTAFile;
|
|
|
|
begin
|
|
|
|
Result := TSourceFile.Create(sWebModuleDFM, [FormIdent, FWebModuleClassName]);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TNewWebModuleUnitEx.NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
|
2022-07-25 10:36:30 +02:00
|
|
|
var
|
|
|
|
lJSONRPCCode: string;
|
|
|
|
lMiddlewaresCode: String;
|
|
|
|
I: Integer;
|
2016-02-23 01:41:13 +01:00
|
|
|
begin
|
2022-08-13 00:21:00 +02:00
|
|
|
lMiddlewaresCode := sLineBreak;
|
2022-07-25 10:36:30 +02:00
|
|
|
for I := Low(FMiddlewares) to High(FMiddlewares) do
|
|
|
|
begin
|
2022-08-13 00:21:00 +02:00
|
|
|
lMiddlewaresCode := lMiddlewaresCode + ' ' + FMiddlewares[I] + sLineBreak;
|
2022-07-25 10:36:30 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
lJSONRPCCode := '';
|
|
|
|
if not FJSONRPCClassName.IsEmpty then
|
|
|
|
begin
|
|
|
|
lJSONRPCCode := 'FMVC.PublishObject( ' + sLineBreak +
|
|
|
|
' function : TObject ' + sLineBreak +
|
|
|
|
' begin ' + sLineBreak +
|
|
|
|
' Result := ' + FJSONRPCClassName + '.Create; ' + sLineBreak +
|
|
|
|
' end, ''/jsonrpc'');' + sLineBreak + sLineBreak;
|
|
|
|
end;
|
|
|
|
|
2016-02-23 01:41:13 +01:00
|
|
|
//ModuleIdent is blank for some reason.
|
|
|
|
// 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.
|
2022-07-25 10:36:30 +02:00
|
|
|
if not lJSONRPCCode.IsEmpty then
|
|
|
|
begin
|
|
|
|
if not FJSONRPCClassUnit.IsEmpty then
|
|
|
|
begin
|
|
|
|
FJSONRPCClassUnit := FJSONRPCClassUnit + ',';
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := TSourceFile.Create(sWebModuleUnit, [
|
|
|
|
FUnitIdent,
|
|
|
|
FWebModuleClassName,
|
|
|
|
FControllerUnit,
|
|
|
|
FControllerClassName,
|
|
|
|
lMiddlewaresCode,
|
|
|
|
lJSONRPCCode,
|
|
|
|
FJSONRPCClassUnit]);
|
2016-02-23 01:41:13 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end.
|