From 458f7a734fe65759c8820fc506ca28452d2132a6 Mon Sep 17 00:00:00 2001 From: Tommaso Negri Date: Tue, 30 May 2023 00:10:27 +0200 Subject: [PATCH] feat: Add Preview mailer command --- Scripts/commands.js | 4 +++- Scripts/commands/MailerPreview.js | 9 +++++++++ Scripts/main.js | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Scripts/commands/MailerPreview.js diff --git a/Scripts/commands.js b/Scripts/commands.js index e47e46b..62eca73 100644 --- a/Scripts/commands.js +++ b/Scripts/commands.js @@ -7,6 +7,7 @@ const { RailsMigrations } = require("./commands/RailsMigrations") const { RailsServer } = require("./commands/RailsServer") const { RailsStimulus } = require("./commands/RailsStimulus") const RailsRelatedFiles = require("./commands/RailsRelatedFiles") +const MailerPreview = require("./commands/MailerPreview") module.exports = { erbTagSwitcher, @@ -17,5 +18,6 @@ module.exports = { RailsMigrations, RailsServer, RailsStimulus, - RailsRelatedFiles + RailsRelatedFiles, + MailerPreview } diff --git a/Scripts/commands/MailerPreview.js b/Scripts/commands/MailerPreview.js new file mode 100644 index 0000000..74df430 --- /dev/null +++ b/Scripts/commands/MailerPreview.js @@ -0,0 +1,9 @@ +class MailerPreview { + preview(path) { + const match = path.match(/.+\/views\/([^\.]*).+/) + + nova.openURL(`http://localhost:3000/rails/mailers/${match[1]}`) + } +} + +module.exports = MailerPreview diff --git a/Scripts/main.js b/Scripts/main.js index f0d0622..4d7a94d 100644 --- a/Scripts/main.js +++ b/Scripts/main.js @@ -150,3 +150,9 @@ nova.commands.register("tommasonegri.rails.commands.showRelatedFiles", (editor) const relatedFiles = new COMMANDS.RailsRelatedFiles() relatedFiles.run(editor.document.path) }) + +// Register Nova command for previewing mailers +nova.commands.register("tommasonegri.rails.commands.previewMailer", (editor) => { + const mailerPreview = new COMMANDS.MailerPreview() + mailerPreview.preview(editor.document.path) +})