markets / maily Goto Github PK
View Code? Open in Web Editor NEW๐ซ Rails Engine to preview emails in the browser
Home Page: https://rubygems.org/gems/maily
License: MIT License
๐ซ Rails Engine to preview emails in the browser
Home Page: https://rubygems.org/gems/maily
License: MIT License
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!
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?
https://github.com/banister/method_source
Example:
Set.instance_method(:merge).comment.display
Or alternatively, add a new attribute on the hooks side:
mailer.register_hook(:welcome, description: "sent on new sign-ups")
Test repo
https://github.com/Frexuz/maily-test
Go to
http://localhost:3000/maily/application_mailer/hello
Error
def correct_number_of_arguments?
required_arguments.size == arguments.size
end
Related to #5.
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?
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)
Maily.hooks_for('Notifier') do |mailer|
mailer.hide_email(:welcome)
end
Everything is working fine locally, but in heroku environment does not, do you know why?
Allow to call emails with different parameters instead of those defined in hooks, via interface.
Seems like <div class="maily_mail_preview">
ignoring height: 100%
. Could you take a look @gnatok? Thanks.
Looks good in Chrome and Safari.
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
Make hooks to load data only when using the engine (first hit to /maily), to avoid boot time penalty.
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
When I set allow_delivery
to false, I'm still able to see the form for sending an email. I think It should be hidden because it doesn't work anyway, what do you think?
With the following configuration options:
# config/application.rb
config.i18n.available_locales = %i[en nl]
config.i18n.default_locale = :nl
I get this:
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.
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
Useful to edit emails with a custom template_path or template_name.
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).
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)
/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
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'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'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'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'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'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'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)>'require' from /home/rafarosa92/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in
require'A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.