From 5934b160fe789bbd16c7314865dd64a2dcce58e7 Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 17 Feb 2024 23:24:13 -0500 Subject: [PATCH] feat: switch to scriban --- Command.cs | 12 +++++++++--- Configuration.cs | 2 +- Screenie.csproj | 2 +- Ui/PluginUi.cs | 14 ++++++++++---- packages.lock.json | 20 ++++++-------------- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/Command.cs b/Command.cs index 0cb848a..6a8c1eb 100644 --- a/Command.cs +++ b/Command.cs @@ -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}"; diff --git a/Configuration.cs b/Configuration.cs index 8ba78cb..2a371ab 100644 --- a/Configuration.cs +++ b/Configuration.cs @@ -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 { diff --git a/Screenie.csproj b/Screenie.csproj index 7dee6f4..abf8397 100644 --- a/Screenie.csproj +++ b/Screenie.csproj @@ -58,10 +58,10 @@ - all + diff --git a/Ui/PluginUi.cs b/Ui/PluginUi.cs index 50dcfc1..535f9d5 100644 --- a/Ui/PluginUi.cs +++ b/Ui/PluginUi.cs @@ -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? 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) { diff --git a/packages.lock.json b/packages.lock.json index 82b1a01..7a6f267 100644 --- a/packages.lock.json +++ b/packages.lock.json @@ -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",