Sha256: 5e74e26f1ec92095aaa27f39ebb4f9df541a5409e92be79f54abadcfaeeeb0f3
Contents?: true
Size: 1.81 KB
Versions: 6
Compression:
Stored size: 1.81 KB
Contents
module RailsEmailPreview # This class represents an email preview class Preview attr_accessor :id, :preview_class_name, :preview_method def initialize(attr = {}) attr.each { |k, v| self.send "#{k}=", v } end def locales I18n.available_locales end def formats %w(text/html text/plain raw) end def preview_mail(run_hooks = false) preview_class_name.constantize.new.send(preview_method).tap do |mail| RailsEmailPreview.run_before_render(mail, self) if run_hooks end end def name @name ||= "#{group_name}: #{method_name}" end def method_name @action_name ||= preview_method.to_s.humanize end def group_name @group_name ||= preview_class_name.to_s.underscore.sub(/(_mailer)?_preview$/, '').humanize end class << self def find(email_id) @by_id[email_id] end alias_method :[], :find attr_reader :all, :all_by_preview_class def mail_methods(mailer) mailer.public_instance_methods(false).map(&:to_s) end def load_all(class_names) @all = [] @by_id = {} class_names.each do |preview_class_name| preview_class = preview_class_name.constantize mail_methods(preview_class).sort.each do |preview_method| mailer_method = preview_method id = "#{preview_class_name.underscore}-#{mailer_method}" email = new( id: id, preview_class_name: preview_class_name, preview_method: preview_method ) @all << email @by_id[id] = email end end @all.sort_by!(&:name) @all_by_preview_class = @all.group_by(&:preview_class_name) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems