|
2 | 2 | https://youtu.be/KLVq0IAzh1A
|
3 | 3 |
|
4 | 4 |
|
5 |
| -A collection of commonly used fields implemented as custom Ecto types with the necessary validation, encryption, and/or hashing. |
| 5 | +A collection of commonly used fields implemented as custom Ecto types with the necessary validation, encryption, and/or hashing. |
6 | 6 |
|
7 | 7 |
|
8 | 8 | ## Installation
|
@@ -41,27 +41,38 @@ Each field is defined as an [Ecto type](https://hexdocs.pm/ecto/Ecto.Type.html),
|
41 | 41 |
|
42 | 42 | When you load one of the fields into your database, the corresponding `dump/1` callback will be called, ensuring it is inserted into the database in the correct format. In the case of `Fields.EmailEncrypted`, it will encrypt the email address using a give encryption key (set in your config file) before inserting it.
|
43 | 43 |
|
44 |
| -Likewise, when you load a field from the database, the `load/1` callback will be called, giving you the data in the format you need. `Fields.EmailEncrypted` will be decrypted back to plaintext. |
| 44 | +Likewise, when you load a field from the database, the `load/1` callback will be called, giving you the data in the format you need. `Fields.EmailEncrypted` will be decrypted back to plaintext. |
45 | 45 |
|
46 | 46 | Each Field optionally defines an `input_type/0` function. This will return an atom representing the `Phoenix.HTML.Form` input type to use for the Field. For example, `Fields.DescriptionPlaintextUnlimited.input_type` returns `:textarea`.
|
47 | 47 |
|
| 48 | +The fields `DescriptionPlaintextUnlimited` and `HtmlBody` use html_sanitize_ex |
| 49 | +(https://github.com/rrrene/html_sanitize_ex) to remove scripts and help keep your |
| 50 | +project safe. `HtmlBody` is able to display basic html elements whilst |
| 51 | +`DescriptionPlaintextUnlimited` displays text. Remember to use `raw` when rendering |
| 52 | +the content of your `DescriptionPlaintextUnlimited` and `HtmlBody` fields so that |
| 53 | +symbols such as & (ampersand) and Html are rendered correctly. E.g. |
| 54 | +`<p><%= raw @product.description %></p>` |
| 55 | + |
48 | 56 | The currently existing fields are:
|
49 | 57 |
|
| 58 | +- [Address](lib/address.ex) |
| 59 | +- [AddressEncrypted](lib/address_encrypted.ex) |
| 60 | +- [DescriptionPlaintextUnlimited](lib/description_plaintext_unlimited.ex) |
50 | 61 | - [Encrypted](lib/encrypted.ex)
|
51 |
| -- [Hash](lib/hash.ex) |
52 | 62 | - [EmailPlaintext](lib/email_plaintext.ex)
|
53 | 63 | - [EmailHash](lib/email_hash.ex)
|
54 | 64 | - [EmailEncrypted](lib/email_encrypted.ex)
|
| 65 | +- [Hash](lib/hash.ex) |
| 66 | +- [HtmlBody](lib/html-body.ex) |
55 | 67 | - [Password](lib/password.ex)
|
56 |
| -- [Postcode](lib/postcode.ex) |
57 |
| -- [PostcodeEncrypted](lib/postcode_encrypted.ex) |
58 |
| -- [Address](lib/address.ex) |
59 |
| -- [AddressEncrypted](lib/address_encrypted.ex) |
60 | 68 | - [PhoneNumber](lib/phone_number.ex)
|
61 | 69 | - [PhoneNumberEncrypted](lib/phone_number_encrypted.ex)
|
62 |
| -- [DescriptionPlaintextUnlimited](lib/description_plaintext_unlimited.ex) |
| 70 | +- [Postcode](lib/postcode.ex) |
| 71 | +- [PostcodeEncrypted](lib/postcode_encrypted.ex) |
| 72 | +- [Url](lib/url.ex) |
| 73 | + |
63 | 74 |
|
64 |
| -## Config |
| 75 | +## Config |
65 | 76 |
|
66 | 77 | If you use any of the `Encrypted` fields, you will need to set a list of one or more encryption keys in your config:
|
67 | 78 |
|
|
0 commit comments