Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add ability to use markdown templates #15

Closed
watzon opened this issue Nov 8, 2017 · 7 comments
Closed

[Feature] Add ability to use markdown templates #15

watzon opened this issue Nov 8, 2017 · 7 comments

Comments

@watzon
Copy link

watzon commented Nov 8, 2017

Laravel gives us the ability to have blade templates that take blade/markdown and turn it into an HTML email template. This saves some major headache when it comes to making emails beautiful and responsive. It would be awesome if Adonis had the same functionality.

Proposal

Add a markdown method to the Mailer and some built in components that get added to edge templates. Developers should ideally be able to use the markdown method to render an edge template, or send plain markdown which will be parsed into valid email HTML before being sent.

Example Code

<!-- resources/views/emails/shipped.edge -->

@component('mail.message')
# Order Shipped

Your order has been shipped!

@component('mail.button', url = {{ order.viewUrl }})
View Order
@endcomponent

Thanks,<br>
{{ Config('appName') }}
@endcomponent
// app/Controllers/Http/OrdersController.js

await Mail.markdown('emails.shipped', Order.toJSON(), (message) => {
  message.subject('Hello ...')
  message.from('foo@bar.com')
  message.to('baz@bar.com')
})

Reference

https://laravel.com/docs/5.5/mail#markdown-mailables
https://www.npmjs.com/package/markdown
https://www.npmjs.com/package/markdown-it

@RomainLanz
Copy link
Member

RomainLanz commented Nov 8, 2017

Hey @watzon! 👋

I don't think adding a built-in Markdown support is a great idea. This would mean we choose to use Markdown over other simple text engine (like Asciidoc - that we heavy use in our documentation).

Why not make the MailSender class Macroable so you could add methods to it and handle this with a community package? This will avoid Adonis to take a strong decision and let the developer choose the tool he wants to use.

Concerning the idea of having built-in components I also think it'd be better to have a community package that handles that.

Then you could simply install it and use it with a syntax like the code below.

@component('@myPackage::mail.button', url = {{ order.viewUrl }})
  View Order
@endcomponent

(A similar syntax was proposed on the 4.0 Roadmap - section adonis-translator (new))

@watzon
Copy link
Author

watzon commented Nov 8, 2017

@RomainLanz I think making the MailSender class Macroable would be a fine idea. If a community package could handle this then that would work as well.

@RomainLanz
Copy link
Member

Also, using community package instead of having built-in components will let the community create many packages with many designs (Material, Bootstrap, Foundation, Semantic-UI, etc.).

Same goes for MailSender that will be able to handle other templating like MJML or Foundation Email.

@watzon
Copy link
Author

watzon commented Nov 8, 2017

I like that idea

@RomainLanz
Copy link
Member

Cool, let's wait to see the opinion of @thetutlage on this.

@thetutlage
Copy link
Member

thetutlage commented Nov 10, 2017

So Adonis mail doesn't have any idea on how the view engine works, it just uses Edge. My plan is to let users add preprocessors to Edge, so it will be like this

Raw edge

const edge = require('edge.js')
edge.use('mail/*.edge', function (content) {
  // return parsed content
})

In Adonis

const View = use('View')
View.use('mail/*.edge', function (content) {
  // return parsed content
})

@thetutlage
Copy link
Member

This issue was moved to edge-js/edge#13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants