GithubHelp home page GithubHelp logo

markets / maily Goto Github PK

View Code? Open in Web Editor NEW
703.0 703.0 31.0 1020 KB

๐Ÿ“ซ Rails Engine to preview emails in the browser

Home Page: https://rubygems.org/gems/maily

License: MIT License

Ruby 70.92% HTML 29.03% Slim 0.05%
email-delivery email-preview hooks rails rails-engine ruby rubygem

maily's People

Contributors

alexlarra avatar araluce avatar arturminnullin avatar barrywoolgar avatar cenxky avatar djfpaagman avatar gnatok avatar krismichalski avatar markets avatar mtvillwock avatar seanhussey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

maily's Issues

Arrays in arguments of mailer.register_hook is not supported

Hi @markets,

Thanks for your Maily gem, it lets us easier to preview and test Emails. During working with it, I found mailer.register_hook doesn't support Array type arguments.

class Notifier < ActionMailer::Base
  def test_mail(to_mails, cc_mails)
     mail to: to_mails,  cc: cc_mails, subject: "Test"
  end
end

to_mails = %w([email protected] [email protected])
cc_mails = %w([email protected] [email protected])

Maily.hooks_for('Notifier') do |mailer|
  mailer.register_hook(:test_mail, to_mails, cc_mails)
end

The codes above will raise an error while running:

test_mail email requires at the most 2 arguments, passed 4

So I made a PR to fix it, pls have a look!

Merci!

Engine doesn't render

Not sure what I'm doing wrong.

NoMethodError in Maily::Emails#index

---

Showing /Users/kristiangerardsson/www/example.com/app/views/application/_account_popup_menu.html.erb where line #1 raised:

undefined method `employee_path' for #<#<Class:0x007f9a37a04cf8>:0x007f9a38076438>

---

app/views/application/_account_popup_menu.html.erb:1:in `_app_views_application__account_popup_menu_html_erb___2286500346444814438_70150160003460'
app/views/application/_app_bar.html.erb:6:in `_app_views_application__app_bar_html_erb__2941068856054159746_70150140576160'
app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___763355335627937910_70150166256700'

Seems it tried to render the apps normal layout. Just browsing localhost:3000/maily

I just used the generator to install the config and hooks file, and haven't changed them.

Any ideas?

Breaks if sass-rails is not present

Description

On an application i have, we are mainly not using the asset pipeline and we use the webpacker gem instead. (webpack)
So that's why we don't have sass-rails on our Gemfile.

Adding the gem fixes the issue but maybe this gem should require it?

Inherited methods dont show on ui

Give the following mailer and hooks:

# app/mailers/user_mailer.rb

class UserMailer < Devise::Mailer
  private

  # headers for devise mailers
  def headers_for(action, opts)
    super action, opts.merge(template_path: "/mailers/user_mailer")
  end
end
# lib/maily_hooks.rb

user = User.first
token = "token"

Maily.hooks_for("UserMailer") do |mailer|
  mailer.register_hook(:reset_password_instructions, user, token, template_path: "mailers/user_mailer")
  mailer.register_hook(:confirmation_instructions, user, token, template_path: "mailers/user_mailer")
  mailer.register_hook(:invitation_instructions, user, token, template_path: "mailers/user_mailer")
  mailer.register_hook(:unlock_instructions, user, token, template_path: "mailers/user_mailer")
  mailer.register_hook(:password_change, user, template_path: "mailers/user_mailer")
  mailer.register_hook(:email_changed, user, template_path: "mailers/user_mailer")
end

On the ui i get this: (text version for simplicity)

User mailer (0)

Edit mail fails with slim as a template engine

Description

Currently when you try to edit an email on an application using slim as a template engine you get the following error:

Errno::ENOENT in Maily::EmailsController#edit
No such file or directory @ rb_sysopen - /../email.text.erb

Lazy load hooks

Make hooks to load data only when using the engine (first hit to /maily), to avoid boot time penalty.

Allow to add multiple hooks/versions per mail

Possible APIs:

a) use register_hook multiple times, pass version name as a param:

Maily.hooks_for("Notifier") do |mailer|
  mailer.register_hook(:welcome, free_trial, version: "Free trial account")
  mailer.register_hook(:welcome, client, version: "Client account")
end

b.1) new method register_hooks (plural) with a different signature (passing hash):

Maily.hooks_for("Notifier") do |mailer|
  mailer.register_hooks(:welcome, versions: {
    "Free trial account": free_trial
    "Client account": client
  })
end

b.2) new method register_hooks (plural) with a different signature (passing array):

Maily.hooks_for("Notifier") do |mailer|
  mailer.register_hooks(:welcome, [
    ["Free trial account", free_trial],
    ["Client account", client]
  ])
end

c) new method register_version:

Maily.hooks_for("Notifier") do |mailer|
  mailer.register_hook(:welcome, free_trial)
        .register_version("Client account", client)
end

Email content rendered always as text

Suddenly emails content is only rendered as text. Any idea why this could be?

maily - account mailer email changed 2018-12-19 07-34-05

Also, is there anyway to update the emails without having to restart the rails server?

TIA!

Configured available locales not being picked up by maily

Description

With the following configuration options:

# config/application.rb
config.i18n.available_locales = %i[en nl]
config.i18n.default_locale = :nl

I get this:

maily - caregiver mailer new job offer notification 2018-06-23 11-40-47

Explicitly setting:

config.available_locales = I18n.available_locales

on config/initializers/maily.rb also doesn't fix the issue because at that point I18n.available_locales has all the locales.

App fails to boot because Maily expects the asset pipeline to be present

I don't know if this constitutes a bug, but my Rails 6 app is webpacker-only and after installing the gem it is not possible to enter the rails console (or run the generator). Consider this a half bug report, half workaround guide for anyone who needs it.

The bug part is because lib/maily/engine.rb attempts to modify config.assets.precompile, which does not exist without the asset pipeline and therefore raises an undefined method 'assets' for #<Rails::Engine::Configuration ...> error.

If I wrap that section in a config.respond_to?(:assets) then everything works, except the assets, as you would expect. I've just copied the SCSS out into a new pack file, and overridden the maily/application layout file in my app. Now everything except the images work, and I'm fine with that.

I'm not sure what the proper solution is. The first thing that comes to mind is maybe include a static version of the compiled assets in the gem and update the templates to source them out of /public using something like:

module Maily
  class Engine < ::Rails::Engine
    ...
    config.app_middleware.use(
      Rack::Static,
      urls: ["/maily-assets"], root: "maily/public"
    )
  end
end

Happy to do a PR with the respond_to? bit in, but that seems like only half the job.

Thanks

Remove sass and move to plain css

In the recents Rails releases they introduced a new pipeline via webpacker and some teams moved not only the js to webpack, but also their css too. Other people are using the Rails API mode, which doesn't include the sprockets railtie neither.

In summary, relying on the original "assets pipeline" and sass is harder nowadays, so would be nice to move our css out of sprockets and sass, and use just plain css3. Also, apps with node-sass or postcss (via webpacker) wont need to install sassc-rails (which contains native deps too).

Evidences: #46, #22

Exception when running the install generator

Description

When running bin/rails g maily:install

I get the following error (at the bottom of the error trace, let me know if you want the full trace)

lib/generators/maily/install_generator.rb:30:in `block in build_hooks': undefined method `name' for #<Array:0x00007fd52dd60f38> (NoMethodError)

error | rails g maily:install

/home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/maily-0.10.1/app/controllers/maily/application_controller.rb:2:in <module:Maily>': undefined method constantize' for nil:NilClass (NoMethodError)
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/maily-0.10.1/app/controllers/maily/application_controller.rb:1:in <main>' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in load'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in load' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:476:in block in load_file'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:661:in new_constants_in' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:475:in load_file'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:373:in block in require_or_load' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:37:in block in load_interlock'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:14:in block in loading' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/concurrency/share_lock.rb:151:in exclusive'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:13:in loading' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:37:in load_interlock'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:356:in require_or_load' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:48:in block in require_or_load'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in allow_bootsnap_retry' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:47:in require_or_load'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:334:in depend_on' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:85:in depend_on'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:246:in require_dependency' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:478:in block (2 levels) in eager_load!'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:477:in each' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:477:in block in eager_load!'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:475:in each' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:475:in eager_load!'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:356:in eager_load!' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/application/finisher.rb:69:in each'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/application/finisher.rb:69:in block in <module:Finisher>' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in instance_exec'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:32:in run' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:61:in block in run_initializers'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:228:in block in tsort_each' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:350:in block (2 levels) in each_strongly_connected_component'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:431:in each_strongly_connected_component_from' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:349:in block in each_strongly_connected_component'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in each' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in call'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in each_strongly_connected_component' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:226:in tsort_each'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:205:in tsort_each' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/initializable.rb:60:in run_initializers'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:361:in initialize!' from /home/rafarosa92/Documentos/osmarapp/config/environment.rb:5:in

'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in require' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in block in require_with_bootsnap_lfi'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in register' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in require_with_bootsnap_lfi'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in require' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in block in require'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in load_dependency' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in require'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:106:in preload' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:157:in serve'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:145:in block in run' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:139:in loop'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:139:in run' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application/boot.rb:19:in <top (required)>'
from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in require'
from -e:1:in `'

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.