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

Cleaning up the README with some docs updates and typo fixes. #71

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ Templates go in the same folder the email is in:
- Text email: `<folder_email_class_is_in>/templates/<underscored_class_name>/text.ecr`
- HTML email: `<folder_email_class_is_in>/templates/<underscored_class_name>/html.ecr`

So if your email class is in `src/my_app/emails/welcome_email.cr`, then your
templates would go in `src/my_app/emails/welcome_email/text|html.ecr`.
So if your email class is in `src/emails/welcome_email.cr`, then your
templates would go in `src/emails/templates/welcome_email/text|html.ecr`.

```
# in <folder_of_email_class>/templates/welcome_email/text.ecr
Expand All @@ -90,6 +90,33 @@ Welcome, <%= @name %>!

For more information on what you can do with Embedded Crystal (ECR), see [the official Crystal documentation](https://crystal-lang.org/api/latest/ECR.html).

### Template layouts

Layouts are optional allowing you to specify how each email template looks individually.
If you'd like to have the same layout on each, you can create a layout template in
`<folder_email_class_is_in>/templates/<layout_name>/layout.ecr`

In this file, you'll yield the main email body with `<%= content %>`. Then in your `BaseEmail`, you can specify the name of the layout.

```crystal
abstract class BaseEmail < Carbon::Email
macro inherited
from default_from
layout :application_layout
end
end
```

```
# in src/emails/templates/application_layout/layout.ecr

<h1>Our Email</h1>

<%= content %>

<div>footer</div>
```

### Deliver the email

```
Expand Down Expand Up @@ -166,7 +193,7 @@ class SignUpUser

def run
sign_user_up
WelcomeEmail.new(name: @name, email_address: @email_address).deliver_now
WelcomeEmail.new(name: @name, email_address: @email_address).deliver
end
end

Expand All @@ -176,6 +203,13 @@ it "sends an email after the user signs up" do
# Test that this email was sent
WelcomeEmail.new(name: "Emily", email_address: "[email protected]").should be_delivered
end

# or we can just check that some emails were sent
it "sends some emails" do
SignUpUser.new(name: "Emily", email_address: "[email protected]").run

Carbon.should have_delivered_emails
end
```

### Unit testing
Expand All @@ -202,7 +236,8 @@ end

- `shards install`
- Make changes
- `crystal spec`
- `./script/test`
- `./bin/ameba`

## Contributing

Expand All @@ -216,4 +251,4 @@ end

## Contributors

- [paulcsmith](https://github.com/paulcsmith) Paul Smith - creator, maintainer
- [paulcsmith](https://github.com/paulcsmith) Paul Smith - creator