feat: switch to scriban

This commit is contained in:
Anna 2024-02-17 23:24:13 -05:00
parent 5ea43ba1e2
commit 5934b160fe
Signed by: anna
GPG Key ID: D0943384CD9F87D1
5 changed files with 27 additions and 23 deletions

View File

@ -2,8 +2,9 @@ using System.Drawing;
using System.Drawing.Imaging;
using Blake3;
using Dalamud.Game.Command;
using HandlebarsDotNet;
using Newtonsoft.Json;
using Scriban;
using Scriban.Parsing;
using WebP.Net;
namespace Screenie;
@ -100,8 +101,13 @@ internal class Command : IDisposable {
private FileStream OpenFile(string ext, ScreenshotMetadata meta) {
Directory.CreateDirectory(this.Plugin.Config.SaveDirectory);
var template = Handlebars.Compile(this.Plugin.Config.SaveFileNameFormat);
var fileName = template(meta);
var template = Template.Parse(
this.Plugin.Config.SaveFileNameFormat,
parserOptions: new ParserOptions {
LiquidFunctionsToScriban = true,
}
);
var fileName = template.Render(meta);
var path = Path.Join(this.Plugin.Config.SaveDirectory, fileName);
path += $".{ext}";

View File

@ -10,7 +10,7 @@ public class Configuration : IPluginConfiguration {
public string SaveDirectory = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Screenie");
public Format SaveFormat = Format.Png;
public int SaveFormatData = 90;
public string SaveFileNameFormat = "{{ CapturedAtLocal.Year }}/{{ CapturedAtLocal.Month }}/{{ ActiveCharacter.Name }} - {{ Location }}";
public string SaveFileNameFormat = "{{ captured_at_local.year | string.pad_left 4 0 }}/{{ captured_at_local.month | string.pad_left 2 0 }}/[{{ captured_at_local.hour | string.pad_left 2 0 }}:{{ captured_at_local.minute | string.pad_left 2 0 }}:{{ captured_at_local.seconds | string.pad_left 2 0 }}] {{ active_character.name }} - {{ location }}";
}
public enum Format {

View File

@ -58,10 +58,10 @@
<ItemGroup>
<PackageReference Include="Blake3" Version="1.0.0" />
<PackageReference Include="DalamudPackager" Version="2.1.12"/>
<PackageReference Include="Handlebars.Net" Version="2.1.4" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Scriban" Version="5.9.1" />
<PackageReference Include="System.Drawing.Common" Version="8.0.2"/>
<PackageReference Include="WebP_Net" Version="1.1.1"/>
</ItemGroup>

View File

@ -4,9 +4,10 @@ using Dalamud.Interface;
using Dalamud.Interface.Components;
using Dalamud.Interface.ImGuiFileDialog;
using Dalamud.Interface.Utility;
using HandlebarsDotNet;
using ImGuiNET;
using Screenie.Util;
using Scriban;
using Scriban.Parsing;
namespace Screenie.Ui;
@ -14,7 +15,7 @@ internal class PluginUi : IDisposable {
private Plugin Plugin { get; }
private FileDialogManager FileDialogManager { get; }
private ScreenshotMetadata Metadata { get; set; }
private HandlebarsTemplate<object, object>? Template { get; set; }
private Template? Template { get; set; }
internal bool Visible;
@ -96,11 +97,16 @@ internal class PluginUi : IDisposable {
var templateChanged = ImGui.InputText("##filename-format", ref this.Plugin.Config.SaveFileNameFormat, 1024);
anyChanged |= templateChanged;
if (this.Template == null || templateChanged) {
this.Template = Handlebars.Compile(this.Plugin.Config.SaveFileNameFormat);
this.Template = Template.Parse(
this.Plugin.Config.SaveFileNameFormat,
parserOptions: new ParserOptions {
LiquidFunctionsToScriban = true,
}
);
}
if (this.Template != null) {
ImGui.TextUnformatted(this.Template(this.Metadata));
ImGui.TextUnformatted(this.Template.Render(this.Metadata));
}
if (anyChanged) {

View File

@ -14,15 +14,6 @@
"resolved": "2.1.12",
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
},
"Handlebars.Net": {
"type": "Direct",
"requested": "[2.1.4, )",
"resolved": "2.1.4",
"contentHash": "Od7MWDfGxYKRtxETFMlcvCrY8hAqyuXZDX4EsOfiI/jzh+PVBuVxazHBC1HmVqTKX1JnRtoxIMcH95K9UFlYog==",
"dependencies": {
"Microsoft.CSharp": "4.7.0"
}
},
"Microsoft.Windows.CsWin32": {
"type": "Direct",
"requested": "[0.3.49-beta, )",
@ -36,6 +27,12 @@
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
}
},
"Scriban": {
"type": "Direct",
"requested": "[5.9.1, )",
"resolved": "5.9.1",
"contentHash": "Er0jZCXrHXtk+nnzmHVEnmz1pjfU+VL3GppO0UjtCMoZ0Se1plyPe1OLb6gM7ToSRA7nu/QIcdRFr29x8w8rQQ=="
},
"System.Drawing.Common": {
"type": "Direct",
"requested": "[8.0.2, )",
@ -54,11 +51,6 @@
"System.Drawing.Common": "7.0.0"
}
},
"Microsoft.CSharp": {
"type": "Transitive",
"resolved": "4.7.0",
"contentHash": "pTj+D3uJWyN3My70i2Hqo+OXixq3Os2D1nJ2x92FFo6sk8fYS1m1WLNTs0Dc1uPaViH0YvEEwvzddQ7y4rhXmA=="
},
"Microsoft.Win32.SystemEvents": {
"type": "Transitive",
"resolved": "8.0.0",