mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
This commit is contained in:
parent
f22656b6f6
commit
6817fc1ce5
@ -133,6 +133,9 @@ type
|
|||||||
function GetOnGetValue: TTProCompiledTemplateGetValueEvent;
|
function GetOnGetValue: TTProCompiledTemplateGetValueEvent;
|
||||||
procedure SetOnGetValue(const Value: TTProCompiledTemplateGetValueEvent);
|
procedure SetOnGetValue(const Value: TTProCompiledTemplateGetValueEvent);
|
||||||
property OnGetValue: TTProCompiledTemplateGetValueEvent read GetOnGetValue write SetOnGetValue;
|
property OnGetValue: TTProCompiledTemplateGetValueEvent read GetOnGetValue write SetOnGetValue;
|
||||||
|
function GetFormatSettings: PFormatSettings;
|
||||||
|
procedure SetFormatSettings(const Value: PFormatSettings);
|
||||||
|
property FormatSettings: PFormatSettings read GetFormatSettings write SetFormatSettings;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TTProCompiledTemplateEvent = reference to procedure(const TemplateProCompiledTemplate: ITProCompiledTemplate);
|
TTProCompiledTemplateEvent = reference to procedure(const TemplateProCompiledTemplate: ITProCompiledTemplate);
|
||||||
@ -189,6 +192,8 @@ type
|
|||||||
function EvaluateValue(var Idx: Int64; out MustBeEncoded: Boolean): TValue;
|
function EvaluateValue(var Idx: Int64; out MustBeEncoded: Boolean): TValue;
|
||||||
procedure SetOnGetValue(const Value: TTProCompiledTemplateGetValueEvent);
|
procedure SetOnGetValue(const Value: TTProCompiledTemplateGetValueEvent);
|
||||||
procedure DoOnGetValue(const DataSource, Members: string; var Value: TValue; var Handled: Boolean);
|
procedure DoOnGetValue(const DataSource, Members: string; var Value: TValue; var Handled: Boolean);
|
||||||
|
function GetFormatSettings: PFormatSettings;
|
||||||
|
procedure SetFormatSettings(const Value: PFormatSettings);
|
||||||
class procedure InternalDumpToFile(const FileName: String; const aTokens: TList<TToken>);
|
class procedure InternalDumpToFile(const FileName: String; const aTokens: TList<TToken>);
|
||||||
public
|
public
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -201,6 +206,7 @@ type
|
|||||||
procedure AddFilter(const FunctionName: string; const FunctionImpl: TTProTemplateFunction); overload;
|
procedure AddFilter(const FunctionName: string; const FunctionImpl: TTProTemplateFunction); overload;
|
||||||
procedure AddFilter(const FunctionName: string; const AnonFunctionImpl: TTProTemplateAnonFunction); overload;
|
procedure AddFilter(const FunctionName: string; const AnonFunctionImpl: TTProTemplateAnonFunction); overload;
|
||||||
procedure DumpToFile(const FileName: String);
|
procedure DumpToFile(const FileName: String);
|
||||||
|
property FormatSettings: PFormatSettings read GetFormatSettings write SetFormatSettings;
|
||||||
property OnGetValue: TTProCompiledTemplateGetValueEvent read GetOnGetValue write SetOnGetValue;
|
property OnGetValue: TTProCompiledTemplateGetValueEvent read GetOnGetValue write SetOnGetValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -472,6 +478,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TTProCompiledTemplate.GetFormatSettings: PFormatSettings;
|
||||||
|
begin
|
||||||
|
Result := @fLocaleFormatSettings;
|
||||||
|
end;
|
||||||
|
|
||||||
function TTProCompiledTemplate.GetOnGetValue: TTProCompiledTemplateGetValueEvent;
|
function TTProCompiledTemplate.GetOnGetValue: TTProCompiledTemplateGetValueEvent;
|
||||||
begin
|
begin
|
||||||
Result := fOnGetValue;
|
Result := fOnGetValue;
|
||||||
@ -583,7 +594,17 @@ begin
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
Result := Value.ToString;
|
case Value.Kind of
|
||||||
|
tkInteger: Result := Value.AsInteger.ToString;
|
||||||
|
tkInt64: Result := Value.AsInt64.ToString;
|
||||||
|
tkString, tkUString, tkWString, tkLString: Result := Value.AsString;
|
||||||
|
tkWChar, tkChar: Result := Value.AsType<Char>;
|
||||||
|
tkFloat: Result := FloatToStr(Value.AsExtended, fLocaleFormatSettings);
|
||||||
|
tkEnumeration: Result := Value.ToString;
|
||||||
|
else
|
||||||
|
raise ETProException.Create('Unsupported type for variable "' + VarName + '"');
|
||||||
|
end;
|
||||||
|
//Result := Value.ToString;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1569,6 +1590,7 @@ var
|
|||||||
lFunc: TTProTemplateFunction;
|
lFunc: TTProTemplateFunction;
|
||||||
lAnonFunc: TTProTemplateAnonFunction;
|
lAnonFunc: TTProTemplateAnonFunction;
|
||||||
lIntegerPar1: Integer;
|
lIntegerPar1: Integer;
|
||||||
|
lDecimalMask: string;
|
||||||
begin
|
begin
|
||||||
aFunctionName := lowercase(aFunctionName);
|
aFunctionName := lowercase(aFunctionName);
|
||||||
if SameText(aFunctionName, 'gt') then
|
if SameText(aFunctionName, 'gt') then
|
||||||
@ -1671,6 +1693,16 @@ begin
|
|||||||
Result := lStrValue.PadLeft(aParameters[0].ToInteger, aParameters[1].Chars[0]);
|
Result := lStrValue.PadLeft(aParameters[0].ToInteger, aParameters[1].Chars[0]);
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
|
else if SameText(aFunctionName, 'round') then
|
||||||
|
begin
|
||||||
|
CheckParNumber(1, aParameters);
|
||||||
|
lDecimalMask := '';
|
||||||
|
if aParameters[0].ToInteger < 0 then
|
||||||
|
begin
|
||||||
|
lDecimalMask := '.' + StringOfChar('0', Abs(aParameters[0].ToInteger));
|
||||||
|
end;
|
||||||
|
Result := FormatFloat('0' + lDecimalMask, RoundTo(aValue.AsExtended, aParameters[0].ToInteger));
|
||||||
|
end
|
||||||
else if SameText(aFunctionName, 'datetostr') then
|
else if SameText(aFunctionName, 'datetostr') then
|
||||||
begin
|
begin
|
||||||
if aValue.IsEmpty then
|
if aValue.IsEmpty then
|
||||||
@ -1681,7 +1713,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
if Length(aParameters) = 0 then
|
if Length(aParameters) = 0 then
|
||||||
begin
|
begin
|
||||||
Result := DateToStr(lDateValue)
|
Result := DateToStr(lDateValue, fLocaleFormatSettings)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -1704,7 +1736,7 @@ begin
|
|||||||
else if aValue.TryAsType<TDateTime>(lDateValue) then
|
else if aValue.TryAsType<TDateTime>(lDateValue) then
|
||||||
begin
|
begin
|
||||||
if Length(aParameters) = 0 then
|
if Length(aParameters) = 0 then
|
||||||
Result := DateTimeToStr(lDateValue)
|
Result := DateTimeToStr(lDateValue, fLocaleFormatSettings)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
CheckParNumber(1, aParameters);
|
CheckParNumber(1, aParameters);
|
||||||
@ -2075,8 +2107,7 @@ begin
|
|||||||
fTemplateFunctions := TDictionary<string, TTProTemplateFunction>.Create(TTProEqualityComparer.Create);
|
fTemplateFunctions := TDictionary<string, TTProTemplateFunction>.Create(TTProEqualityComparer.Create);
|
||||||
fTemplateAnonFunctions := nil;
|
fTemplateAnonFunctions := nil;
|
||||||
TTProConfiguration.RegisterHandlers(self);
|
TTProConfiguration.RegisterHandlers(self);
|
||||||
fLocaleFormatSettings.DateSeparator := '-';
|
fLocaleFormatSettings := TFormatSettings.Invariant;
|
||||||
fLocaleFormatSettings.TimeSeparator := ':';
|
|
||||||
fLocaleFormatSettings.ShortDateFormat := 'yyyy-mm-dd';
|
fLocaleFormatSettings.ShortDateFormat := 'yyyy-mm-dd';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2584,6 +2615,26 @@ begin
|
|||||||
begin
|
begin
|
||||||
Result := lPJSONDataValue.ObjectValue.ToJSON();
|
Result := lPJSONDataValue.ObjectValue.ToJSON();
|
||||||
end;
|
end;
|
||||||
|
jdtFloat:
|
||||||
|
begin
|
||||||
|
Result := lPJSONDataValue.FloatValue;
|
||||||
|
end;
|
||||||
|
jdtInt:
|
||||||
|
begin
|
||||||
|
Result := lPJSONDataValue.IntValue;
|
||||||
|
end;
|
||||||
|
jdtLong:
|
||||||
|
begin
|
||||||
|
Result := lPJSONDataValue.LongValue;
|
||||||
|
end;
|
||||||
|
jdtULong:
|
||||||
|
begin
|
||||||
|
Result := lPJSONDataValue.ULongValue;
|
||||||
|
end;
|
||||||
|
jdtBool:
|
||||||
|
begin
|
||||||
|
Result := lPJSONDataValue.BoolValue;
|
||||||
|
end;
|
||||||
else
|
else
|
||||||
Result := lPJSONDataValue.Value;
|
Result := lPJSONDataValue.Value;
|
||||||
end;
|
end;
|
||||||
@ -3102,6 +3153,11 @@ begin
|
|||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTProCompiledTemplate.SetFormatSettings(const Value: PFormatSettings);
|
||||||
|
begin
|
||||||
|
fLocaleFormatSettings := Value^;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTProCompiledTemplate.SetOnGetValue(const Value: TTProCompiledTemplateGetValueEvent);
|
procedure TTProCompiledTemplate.SetOnGetValue(const Value: TTProCompiledTemplateGetValueEvent);
|
||||||
begin
|
begin
|
||||||
fOnGetValue := Value;
|
fOnGetValue := Value;
|
||||||
|
Loading…
Reference in New Issue
Block a user