Skip to content

Commit

Permalink
feat: Add Preview mailer command
Browse files Browse the repository at this point in the history
  • Loading branch information
tommasongr committed May 29, 2023
1 parent 3d8fa76 commit 458f7a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Scripts/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,5 +18,6 @@ module.exports = {
RailsMigrations,
RailsServer,
RailsStimulus,
RailsRelatedFiles
RailsRelatedFiles,
MailerPreview
}
9 changes: 9 additions & 0 deletions Scripts/commands/MailerPreview.js
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions Scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit 458f7a7

Please sign in to comment.