Skip to content

Instantly share code, notes, and snippets.

@stepantubanov
Created March 9, 2012 13:26
Show Gist options
  • Save stepantubanov/2006496 to your computer and use it in GitHub Desktop.
Save stepantubanov/2006496 to your computer and use it in GitHub Desktop.

Revisions

  1. stepantubanov revised this gist May 12, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ module Email
    module Invitations
    class Base
    def subject
    "Join our cool website"
    "Join our cool website" # Options: return I18n key "join_website", or the value h.t("....join_website")
    end

    def template
  2. stepantubanov revised this gist Mar 19, 2012. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -70,5 +70,4 @@ module Views
    # And use them

    invitation = "Decorators::Email::#{invitation.class.name}".constantize.new
    mail(subject: invitation.subject)
    render invitation.template
    mail(to: invitation.recipient_email, subject: invitation.subject, template_name: invitation.template)
  3. stepantubanov revised this gist Mar 9, 2012. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,8 @@ class BecomeManager < JoinGroup

    module Decorators
    module Email
    # Can actually place any decorators for that are used specifically for emails here

    module Invitations
    class Base
    def subject
    @@ -58,4 +60,15 @@ def template
    end
    end
    end
    end

    # We can actually place our presenters in a module like this one:
    # removing word "Presenter" from the class name of course...
    module Views
    end
    end

    # And use them

    invitation = "Decorators::Email::#{invitation.class.name}".constantize.new
    mail(subject: invitation.subject)
    render invitation.template
  4. stepantubanov created this gist Mar 9, 2012.
    61 changes: 61 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    # Models

    module Invitations
    class Base
    belongs_to :sender
    belongs_to :recipient
    end

    class JoinGroup < Base
    ...
    end

    class BecomeManager < JoinGroup
    ...
    end
    end

    # Each has different email subject and body.
    # The problem: do not want to add "email_subject" and "email_template" fields to the models.
    # Solution: May be something like

    module Decorators
    module Email
    module Invitations
    class Base
    def subject
    "Join our cool website"
    end

    def template
    "invitation_base"
    end
    end

    class JoinGroup < Base
    def subject
    "You have been invited to join #{group.name}"
    end

    def template
    "invitation_join_group"
    end
    end

    class BecomeManager < Base
    def subject
    # Example of some logic that might be used
    if recipient.member_of?(group)
    "You have been invited to manage #{subordinate.name}"
    else
    "You have been invited to join #{group.name} and manage #{subordinate.name}"
    end
    end

    def template
    "invitation_become_manager"
    end
    end
    end
    end
    end