Giter Site home page Giter Site logo

custom_emails's Introduction

CustomEmails

By Synbioz

Description

This gem contains some basic models that allows the end-user of your applications to customize the application email.

Example

This is a basic use case:

target = '[email protected]'
ctx = { 'name' => 'Luc' }

# Create default kinds
%w(request new_event).each do |kind_name|
  CustomEmails::EmailKind.find_or_create_by!(name: kind_name)
end

# Create an email
kind  = CustomEmails::EmailKind.find_by!(name: 'request')
email = CustomEmails::Email.create(
  locale:       :fr,
  kind:         kind,
  subject:      'Bonjour {{ name }} !',
  content_text: 'Bonne chance {{ name }}...'
)

# Send via the Email object
email.to(target, ctx).deliver

# Use the mailer to send an email if you don't have the Email objet
CustomEmails::Mailer.custom_email_to(target, 'request', nil, context: ctx).deliver

This is a basic use case with a scope object:

# Declare a class with customizable emails
class Account
  ...
  has_custom_emails
  ...
end

acc = Account.first

# Create some email related to the account
email = account.emails.create(
  locale:       :fr,
  kind:         kind,
  subject:      'Bonjour {{ name }} !',
  content_text: 'Bonne chance {{ name }}...',
  content_html: '<b>Bonne change...</b>' # Optional
)

# Deliver the email to somebody
email.to(target, ctx).deliver

# Or do it direclty with the mailer
CustomEmails::Mailer.custom_email_to(target, 'request', acc, ctx).deliver

This scope object allows you to have multiple email per kind.

Installation

Add this to your gemfile:

gem 'custom_emails'

Add the tables to your database with:

rake custom_emails:install:migrations
rake db:migrate

Add the initializer to configure the gem with:

rails generate custom_emails:install

That's all!

Limitations

  • Only active record is supported

Licence

This project uses the MIT licence.

custom_emails's People

Contributors

nicoolas25 avatar

Stargazers

 avatar Victor Darras avatar

Watchers

Nicolas Mérouze avatar Cedric Brancourt avatar Benoit Caccinolo avatar Martin Catty avatar Nicolas Cavigneaux avatar  avatar James Cloos avatar Alexandre Salaün avatar Théo Delaune avatar Numa Claudel avatar Jon avatar Victor Darras avatar Nicolas Le Chenic avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.