Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/buckybox/email_templator
https://github.com/buckybox/email_templator
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/buckybox/email_templator
- Owner: buckybox
- License: mit
- Created: 2014-03-10T10:38:16.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-03-10T10:55:00.000Z (almost 11 years ago)
- Last Synced: 2024-03-27T11:25:48.620Z (10 months ago)
- Language: Ruby
- Homepage:
- Size: 117 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# EmailTemplator
Sanitize and parse an user-generated email template for sending.
## Usage
```ruby
# 1. Define an email template class which can be personalized for a given resource (e.g. a customer)
class CustomerEmailTemplate < EmailTemplator# white-list mapping of keywords to be replaced
KEYWORDS = {
first_name: :first_name,
account_balance: :account_balance_with_currency,
email_address: :email,
}end
# 2. Create the template
template = CustomerEmailTemplate.new "Hi {first_name}", <<-BODY
Hey {first_name}!Here's your email: {email_address}
BODYtemplate.valid? #=> true
# 3. Create a personalized email from the template
customer = OpenStruct.new(first_name: "Joe", email: "[email protected]") # typically a model
personalized_email = template.personalize(customer)
personalized_email.subject #=> "Hi Joe"
personalized_email.body #=> "Hey Joe!\n\nHere's your email: [email protected]\n"# 4. Send emails!
```