-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Misc doc changes Besides other documentation changes, this commit ensures the generated HTML doc for HexDocs.pm will become the main source doc for this Elixir library which leverage on latest ExDoc features. * Update .formatter.exs Co-authored-by: Po Chen <[email protected]>
- Loading branch information
1 parent
4c140a6
commit 23b79dc
Showing
9 changed files
with
138 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,26 @@ | ||
/_build | ||
/cover | ||
/deps | ||
/doc | ||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where third-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
phoenix_swoosh-*.tar | ||
|
||
# Temporary files for e.g. tests. | ||
/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Contributing | ||
|
||
## Running tests | ||
|
||
Clone the repo and fetch its dependencies: | ||
|
||
```bash | ||
$ git clone https://github.com/swoosh/phoenix_swoosh.git | ||
$ cd phoenix_swoosh | ||
$ mix deps.get | ||
$ mix test | ||
``` | ||
|
||
## Building docs | ||
|
||
Documentation is written into the library, you will find it in the source code, | ||
accessible from `iex` and of course, it all gets published to | ||
[hexdocs](http://hexdocs.pm/phoenix_swoosh). | ||
|
||
```bash | ||
$ mix docs | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,68 @@ | ||
# Phoenix.Swoosh | ||
|
||
[![Elixir CI](https://github.com/swoosh/phoenix_swoosh/actions/workflows/elixir.yml/badge.svg)](https://github.com/swoosh/phoenix_swoosh/actions/workflows/elixir.yml) | ||
[![Module Version](https://img.shields.io/hexpm/v/phoenix_swoosh.svg)](https://hex.pm/packages/phoenix_swoosh) | ||
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/phoenix_swoosh/) | ||
[![Total Download](https://img.shields.io/hexpm/dt/phoenix_swoosh.svg)](https://hex.pm/packages/phoenix_swoosh) | ||
[![License](https://img.shields.io/hexpm/l/phoenix_swoosh.svg)](https://github.com/swoosh/phoenix_swoosh/blob/master/LICENSE) | ||
[![Last Updated](https://img.shields.io/github/last-commit/swoosh/phoenix_swoosh.svg)](https://github.com/swoosh/phoenix_swoosh/commits/master) | ||
|
||
Use Swoosh to easily send emails in your Phoenix project. | ||
|
||
This module provides the ability to set the HTML and/or text body of an email by rendering templates. | ||
|
||
See the [docs](http://hexdocs.pm/phoenix_swoosh) for more information. | ||
|
||
## Installation | ||
|
||
Add phoenix_swoosh to your list of dependencies in `mix.exs`: | ||
Add `:phoenix_swoosh` to your list of dependencies in `mix.exs`: | ||
|
||
```elixir | ||
def deps do | ||
[{:phoenix_swoosh, "~> 0.3"}] | ||
[ | ||
{:phoenix_swoosh, "~> 0.3"} | ||
] | ||
end | ||
``` | ||
|
||
## Documentation | ||
|
||
Documentation is written into the library, you will find it in the source code, accessible from `iex` and of course, it | ||
all gets published to [hexdocs](http://hexdocs.pm/phoenix_swoosh). | ||
## Usage | ||
|
||
## Contributing | ||
Setting up the templates: | ||
|
||
### Running tests | ||
|
||
Clone the repo and fetch its dependencies: | ||
|
||
``` | ||
$ git clone https://github.com/swoosh/phoenix_swoosh.git | ||
$ cd phoenix_swoosh | ||
$ mix deps.get | ||
$ mix test | ||
```elixir | ||
# web/templates/layout/email.html.eex | ||
<html> | ||
<head> | ||
<title><%= @email.subject %></title> | ||
</head> | ||
<body> | ||
<%= @inner_content %> | ||
</body> | ||
</html> | ||
|
||
# web/templates/email/welcome.html.eex | ||
<div> | ||
<h1>Welcome to Sample, <%= @username %>!</h1> | ||
</div> | ||
``` | ||
|
||
### Building docs | ||
Passing values to templates: | ||
|
||
```elixir | ||
# web/emails/user_email.ex | ||
defmodule Sample.UserEmail do | ||
use Phoenix.Swoosh, view: Sample.EmailView, layout: {Sample.LayoutView, :email} | ||
|
||
def welcome(user) do | ||
new() | ||
|> from("[email protected]") | ||
|> to(user.email) | ||
|> subject("Hello, Avengers!") | ||
|> render_body("welcome.html", %{username: user.email}) | ||
end | ||
end | ||
``` | ||
$ MIX_ENV=docs mix docs | ||
``` | ||
|
||
## LICENSE | ||
## Copyright and License | ||
|
||
Copyright (c) 2016 Swoosh contributors | ||
|
||
See [LICENSE](https://github.com/swoosh/phoenix_swoosh/blob/main/LICENSE.txt) | ||
Released under the MIT License, which can be found in [LICENSE.md](./LICENSE.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,36 +4,6 @@ defmodule Phoenix.Swoosh do | |
text body of an email by rendering templates. | ||
It has been designed to integrate with Phoenix view, template and layout system. | ||
## Example | ||
# web/templates/layout/email.html.eex | ||
<html> | ||
<head> | ||
<title><%= @email.subject %></title> | ||
</head> | ||
<body> | ||
<%= @inner_content %> | ||
</body> | ||
</html> | ||
# web/templates/email/welcome.html.eex | ||
<div> | ||
<h1>Welcome to Sample, <%= @username %>!</h1> | ||
</div> | ||
# web/emails/user_email.ex | ||
defmodule Sample.UserEmail do | ||
use Phoenix.Swoosh, view: Sample.EmailView, layout: {Sample.LayoutView, :email} | ||
def welcome(user) do | ||
new() | ||
|> from("[email protected]") | ||
|> to(user.email) | ||
|> subject("Hello, Avengers!") | ||
|> render_body("welcome.html", %{username: user.email}) | ||
end | ||
end | ||
""" | ||
|
||
import Swoosh.Email | ||
|
@@ -63,13 +33,14 @@ defmodule Phoenix.Swoosh do | |
@doc """ | ||
Renders the given `template` and `assigns` based on the `email`. | ||
Once the template is rendered the resulting string is stored on the email fields `html_body` and `text_body` depending | ||
on the format of the template. | ||
`.html`, `.htm`, and `.xml` are stored in `html_body`; all other extensions, (e.g. `.txt` and `.text`), in `text_body`. | ||
Once the template is rendered the resulting string is stored on the email | ||
fields `html_body` and `text_body` depending on the format of the template. | ||
`.html`, `.htm`, and `.xml` are stored in `html_body`; all other extensions, | ||
(e.g. `.txt` and `.text`), in `text_body`. | ||
## Arguments | ||
* `email` - the `Swoosh.Email` struct | ||
* `email` - the `Swoosh.Email` struct. | ||
* `template` - may be an atom or a string. If an atom, like `:welcome`, it | ||
will render both the HTML and text template and stores them respectively on | ||
|
@@ -80,7 +51,7 @@ defmodule Phoenix.Swoosh do | |
assigns are merged and have higher order precedence than the email assigns. | ||
(`email.assigns`) | ||
## Example | ||
## Examples | ||
defmodule Sample.UserEmail do | ||
use Phoenix.Swoosh, view: Sample.EmailView | ||
|
@@ -191,6 +162,7 @@ defmodule Phoenix.Swoosh do | |
iex> email = put_layout email, :email | ||
iex> layout(email) | ||
{AppView, :email} | ||
""" | ||
def put_layout(email, layout) do | ||
do_put_layout(email, layout) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters