Mange / roadie-rails

Making HTML emails comfortable for the Rails rockstars
MIT License
367 stars 66 forks source link

Deprecate `Automatic` #28

Open Mange opened 9 years ago

Mange commented 9 years ago

Deprecate Automatic in favor of something better.

Problems with Automatic:

Things I'd like to keep:


Since we're on semver, we cannot just drop Automatic just like that (and for good reason! People seem to actually use it.). I'll instead introduce a new module, which will be the successor, and then deprecate the Automatic module. We can then later drop it when we bump the next major release.

RSO commented 9 years ago

Pending your decision on this issue I decided not to use Automatic in our codebase. However, this raised some concerns for me, like: how do I make sure everybody uses Roadie for all the emails?

I think this is something all users of roadie with larger teams could run into, so I thought it might be interesting to share the custom Rubocop linter that I wrote:

module RuboCop
  module Cop
    module HackerOne
      class NoMailMethod < Cop
        MSG = 'Use `roadie_mail` instead of `mail`.'

        def on_send(node)
          return unless command?(:mail, node)

          add_offense(node, :selector)
        end
      end
    end
  end
end

You can include this in your rubocop.yml like this:

require: ./lib/rubocop/no_mail_method

Also: without the Automatic class I had to monkey patch devise a little to make sure the devise email-css was also inlined:

Devise::Mailer.class_eval do
  include Roadie::Rails::Mailer

  protected

  def devise_mail(record, action, opts = {})
    initialize_from_record(record)
    roadie_mail headers_for(action, opts)
  end

  private

  def roadie_options
    super unless Rails.env.test?
  end
end

I'm not really happy with that monkey patching, so I'm interested if you have other suggestions to solve this (from what I read in the roadie issues you're not a big monkey-patch fan ;-)).

Mange commented 9 years ago

Thank you for the input. I'll consider these use cases when I'm designing the replacement.

What license would you put your code under? Would you mind seeing it added to the README?

RSO commented 9 years ago

I don't mind! MIT I guess!