-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #405 from platanus/feat/mjml
Feat/mjml
- Loading branch information
Showing
13 changed files
with
255 additions
and
46 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
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,3 @@ | ||
class ApplicationMailer < ActionMailer::Base | ||
layout 'mailer' | ||
layout 'default_mail' | ||
end |
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,6 @@ | ||
class ExampleMailer < ApplicationMailer | ||
def example_mail | ||
@email = params[:email] | ||
mail(from: '[email protected]', to: @email, subject: 'Welcome to Potassium') | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
lib/potassium/assets/app/views/example_mailer/example_mail.html.mjml
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,7 @@ | ||
<mj-section> | ||
<mj-column> | ||
<mj-text> | ||
Hello <%= @email %>, welcome to Potassium | ||
</mj-text> | ||
</mj-column> | ||
</mj-section> |
49 changes: 49 additions & 0 deletions
49
lib/potassium/assets/app/views/layouts/default_mail.html.mjml
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,49 @@ | ||
<mjml> | ||
<mj-head> | ||
<mj-attributes> | ||
<mj-all font-family="'Helvetica Neue', Helvetica, Arial, sans-serif"></mj-all> | ||
<mj-text font-weight="400" font-size="16px" color="#000000" line-height="24px" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif"></mj-text> | ||
</mj-attributes> | ||
<mj-style inline="inline"> | ||
.body-section { | ||
-webkit-box-shadow: 1px 4px 11px 0px rgba(0, 0, 0, 0.15); | ||
-moz-box-shadow: 1px 4px 11px 0px rgba(0, 0, 0, 0.15); | ||
box-shadow: 1px 4px 11px 0px rgba(0, 0, 0, 0.15); | ||
} | ||
</mj-style> | ||
<mj-style inline="inline"> | ||
.text-link { | ||
color: #5e6ebf | ||
} | ||
</mj-style> | ||
<mj-style inline="inline"> | ||
.footer-link { | ||
color: #888888 | ||
} | ||
</mj-style> | ||
|
||
</mj-head> | ||
<mj-body width="600px"> | ||
<mj-section full-width="full-width" background-color="#71717A" padding-bottom="0"> | ||
<mj-column width="100%" background-color="#A1A1AA"> | ||
<mj-spacer height="25px" /> | ||
</mj-column> | ||
</mj-section> | ||
<mj-section background-color="#A1A1AA" padding-bottom="0" padding-top="0"> | ||
<mj-column> | ||
<mj-image width="100px" src="<%= image_url('/mails/platanus-logo.png') %>" align="center"> | ||
</mj-column> | ||
<mj-column width="100%"> | ||
<mj-spacer height="25px" /> | ||
</mj-column> | ||
</mj-section> | ||
<mj-wrapper padding-top="0" padding-bottom="0" css-class="body-section" background-color="#ffffff" padding-left="15px" padding-right="15px"> | ||
<%= yield %> | ||
</mj-wrapper> | ||
<mj-section background-color="#A1A1AA" padding-bottom="0" padding-top="0"> | ||
<mj-column width="100%"> | ||
<mj-spacer height="25px" /> | ||
</mj-column> | ||
</mj-section> | ||
</mj-body> | ||
</mjml> |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,31 @@ | ||
class Recipes::Mjml < Rails::AppBuilder | ||
def create | ||
return if get(:email_service).to_s.downcase.to_sym == :none | ||
|
||
gather_gem 'mjml-rails' | ||
after(:gem_install) do | ||
run 'bin/yarn add mjml' | ||
mjml_config | ||
end | ||
end | ||
|
||
def installed? | ||
gem_exists?(/mjml-rails/) | ||
end | ||
|
||
def install | ||
create | ||
end | ||
end | ||
|
||
private | ||
|
||
def mjml_config | ||
copy_file '../assets/app/views/layouts/default_mail.html.mjml', | ||
'app/views/layouts/default_mail.html.mjml', force: true | ||
copy_file '../assets/app/mailers/example_mailer.rb', 'app/mailers/example_mailer.rb', force: true | ||
copy_file '../assets/app/views/example_mailer/example_mail.html.mjml', | ||
'app/views/example_mailer/example_mail.html.mjml', force: true | ||
copy_file '../assets/public/mails/platanus-logo.png', | ||
'public/mails/platanus-logo.png', force: true | ||
end |
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 |
---|---|---|
@@ -1,58 +1,104 @@ | ||
# rubocop:disable Rspec/MultipleMemoizedHelpers | ||
require "spec_helper" | ||
|
||
RSpec.describe "Mailer" do | ||
let(:gemfile) { IO.read("#{project_path}/Gemfile") } | ||
let(:mailer_config) { IO.read("#{project_path}/config/mailer.rb") } | ||
let(:env) { IO.read("#{project_path}/.env.development") } | ||
let(:dev_config) { IO.read("#{project_path}/config/environments/development.rb") } | ||
let(:sidekiq_config) { IO.read("#{project_path}/config/sidekiq.yml") } | ||
let(:prod_config) { IO.read("#{project_path}/config/environments/production.rb") } | ||
let(:asset_host_dev) do | ||
<<~RUBY | ||
config.action_mailer.asset_host = "http://\#{ENV.fetch('APPLICATION_HOST')}" | ||
RUBY | ||
end | ||
let(:asset_host_prod) do | ||
<<~RUBY | ||
config.action_mailer.asset_host = "https://\#{ENV.fetch('APPLICATION_HOST')}" | ||
RUBY | ||
end | ||
let(:mailer_config_text) do | ||
<<~RUBY | ||
require Rails.root.join("config", "mailer") | ||
RUBY | ||
end | ||
|
||
before(:all) { drop_dummy_database } | ||
|
||
context "when selecting sendgrid as mailer" do | ||
before(:all) do | ||
remove_project_directory | ||
create_dummy_project("email_service" => "sendgrid") | ||
end | ||
describe 'with mailer' do | ||
let(:mailer_config) { IO.read("#{project_path}/config/mailer.rb") } | ||
let(:sidekiq_config) { IO.read("#{project_path}/config/sidekiq.yml") } | ||
|
||
context "when selecting sendgrid as mailer" do | ||
before(:all) do | ||
remove_project_directory | ||
create_dummy_project("email_service" => "sendgrid") | ||
end | ||
|
||
it_behaves_like "name" | ||
it { expect(gemfile).to include("send_grid_mailer") } | ||
|
||
it { expect(gemfile).to include("send_grid_mailer") } | ||
it "adds configuration to mailer.rb" do | ||
expect(mailer_config).to include("delivery_method = :sendgrid") | ||
expect(mailer_config).to include("sendgrid_settings = {") | ||
expect(mailer_config).to include("api_key: ENV['SENDGRID_API_KEY']") | ||
end | ||
|
||
it "adds configuration to mailer.rb" do | ||
expect(mailer_config).to include("delivery_method = :sendgrid") | ||
expect(mailer_config).to include("sendgrid_settings = {") | ||
expect(mailer_config).to include("api_key: ENV['SENDGRID_API_KEY']") | ||
it "adds configuration to development.rb" do | ||
expect(dev_config).to include("delivery_method = :sendgrid_dev") | ||
expect(dev_config).to include("sendgrid_dev_settings = {") | ||
expect(dev_config).to include("api_key: ENV['SENDGRID_API_KEY']") | ||
end | ||
|
||
it "adds configuration to production" do | ||
expect(prod_config).to include(mailer_config_text) | ||
expect(prod_config).to include(asset_host_prod) | ||
end | ||
end | ||
|
||
it "adds configuration to development.rb" do | ||
expect(dev_config).to include("delivery_method = :sendgrid_dev") | ||
expect(dev_config).to include("sendgrid_dev_settings = {") | ||
expect(dev_config).to include("api_key: ENV['SENDGRID_API_KEY']") | ||
context "when selecting aws_ses as mailer" do | ||
before(:all) do | ||
remove_project_directory | ||
create_dummy_project("email_service" => "aws_ses") | ||
end | ||
|
||
it_behaves_like "name" | ||
it { expect(gemfile).to include("aws-sdk-rails") } | ||
it { expect(gemfile).to include("letter_opener") } | ||
it { expect(mailer_config).to include("delivery_method = :aws_sdk") } | ||
it { expect(dev_config).to include("delivery_method = :letter_opener") } | ||
end | ||
|
||
it { expect(sidekiq_config).to include("- mailers") } | ||
context "when selecting a mailer and sidekiq" do | ||
before :all do | ||
drop_dummy_database | ||
remove_project_directory | ||
create_dummy_project( | ||
"background_processor" => true, "email_service" => 'sendgrid' | ||
) | ||
end | ||
|
||
it { expect(sidekiq_config).to include("- mailers") } | ||
end | ||
end | ||
|
||
context "when selecting aws_ses as mailer" do | ||
context "when there is no mailer" do | ||
before(:all) do | ||
remove_project_directory | ||
create_dummy_project("email_service" => "aws_ses") | ||
create_dummy_project | ||
end | ||
|
||
it { expect(gemfile).to include("aws-sdk-rails") } | ||
it { expect(gemfile).to include("letter_opener") } | ||
it { expect(mailer_config).to include("delivery_method = :aws_sdk") } | ||
it { expect(dev_config).to include("delivery_method = :letter_opener") } | ||
it { expect(sidekiq_config).to include("- mailers") } | ||
end | ||
it { expect(gemfile).not_to include("letter_opener") } | ||
it { expect(File.exists?("#{project_path}/config/mailer.rb")).to eq(false) } | ||
it { expect(env).not_to include("EMAIL_RECIPIENTS") } | ||
|
||
context "when selecting a mailer and sidekiq" do | ||
before :all do | ||
drop_dummy_database | ||
remove_project_directory | ||
create_dummy_project( | ||
"background_processor" => true, "email_service" => 'sendgrid' | ||
) | ||
it "adds configuration to development" do | ||
expect(dev_config).not_to include(asset_host_dev) | ||
expect(dev_config).not_to include("delivery_method") | ||
end | ||
|
||
it { expect(sidekiq_config).to include("- mailers") } | ||
it "adds configuration to production" do | ||
expect(prod_config).not_to include(mailer_config_text) | ||
expect(prod_config).not_to include(asset_host_prod) | ||
end | ||
end | ||
end |
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,53 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe "Mjml" do | ||
let(:gemfile) { IO.read("#{project_path}/Gemfile") } | ||
let(:mailer_config) { IO.read("#{project_path}/config/mailer.rb") } | ||
let(:dev_config) { IO.read("#{project_path}/config/environments/development.rb") } | ||
let(:sidekiq_config) { IO.read("#{project_path}/config/sidekiq.yml") } | ||
let(:yarn_lock) { IO.read("#{project_path}/yarn.lock") } | ||
|
||
before(:all) { drop_dummy_database } | ||
|
||
context "when selecting a mailer" do | ||
before(:all) do | ||
remove_project_directory | ||
create_dummy_project("email_service" => "sendgrid") | ||
end | ||
|
||
it 'adds gems and packages' do | ||
expect(yarn_lock).to include("mjml") | ||
expect(gemfile).to include("mjml-rails") | ||
end | ||
|
||
it 'creates example mailer' do | ||
expect(File.exists?("#{project_path}/app/views/layouts/default_mail.html.mjml")).to eq(true) | ||
expect(File.exists?("#{project_path}/app/mailers/example_mailer.rb")).to eq(true) | ||
expect(File.exists?("#{project_path}/app/views/example_mailer/example_mail.html.mjml")) | ||
.to eq(true) | ||
expect(File.exists?("#{project_path}/public/mails/platanus-logo.png")).to eq(true) | ||
end | ||
end | ||
|
||
context "when there is no mailer selected" do | ||
before(:all) do | ||
remove_project_directory | ||
create_dummy_project | ||
end | ||
|
||
it 'adds gems and packages' do | ||
expect(yarn_lock).not_to include("mjml") | ||
expect(gemfile).not_to include("mjml-rails") | ||
end | ||
|
||
it 'creates example mailer' do | ||
expect(File.exists?("#{project_path}/app/views/layouts/default_mail.html.mjml")) | ||
.not_to eq(true) | ||
expect(File.exists?("#{project_path}/app/mailers/example_mailer.rb")) | ||
.not_to eq(true) | ||
expect(File.exists?("#{project_path}/app/views/example_mailer/example_mail.html.mjml")) | ||
.not_to eq(true) | ||
expect(File.exists?("#{project_path}/public/mails/platanus-logo.png")).not_to eq(true) | ||
end | ||
end | ||
end |
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,5 @@ | ||
RSpec.shared_examples "name" do | ||
it { expect(sidekiq_config).to include("- mailers") } | ||
it { expect(env).to include("EMAIL_RECIPIENTS") } | ||
it { expect(dev_config).to include(asset_host_dev) } | ||
end |