Class: NotifierGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- NotifierGenerator
- Defined in:
- lib/generators/notifier_generator.rb
Instance Method Summary collapse
- #create_ahoy_email_initializer ⇒ Object
- #create_html_view_file ⇒ Object
- #create_mailer_file ⇒ Object
- #create_text_view_file ⇒ Object
- #insert_association_user_model ⇒ Object
Instance Method Details
#create_ahoy_email_initializer ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/generators/notifier_generator.rb', line 112 def create_ahoy_email_initializer create_file "config/initializers/ahoy_email.rb", "class EmailSubscriber def open(event) # :message and :controller keys ahoy = event[:controller].ahoy ahoy.track \"Email opened\", message_id: event[:message].id end def click(event) # same keys as above, plus :url ahoy = event[:controller].ahoy ahoy.track \"Email clicked\", message_id: event[:message].id, url: event[:url] end end AhoyEmail.subscribers << EmailSubscriber.new" end |
#create_html_view_file ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/generators/notifier_generator.rb', line 11 def create_html_view_file create_file "app/views/notifier/new_notification.html.erb", "<!DOCTYPE html> <html> <head> <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' /> </head> <body> <h1>Hello!</h1> <p> If your account has new notifications, they will be lised below.<br><br> Please visit the course website at: <%= @url %><br> Or you can follow the links provided by the notifications.<br><br> Thanks!<br> <% if @recipient.notificationFrequency == 2 && @recipient.admin == false %> <h1>List of Notifications (past 24 hours):</h1> <% i = 0 %> <% @notifications.each do |x| %> <% if x.recipient_id == @recipient.id && x.created_at >= 1.day.ago %> <% i += 1 %> <%= i %>. <%= x.action %> -- <%= x.url %> <br> <% end %> <% end %> <% elsif @recipient.notificationFrequency == 1 && @recipient.admin == false %> <h1>New Notification:</h1> <% @notifications.reverse.each do |x| %> <% if x.recipient_id == @recipient.id %> <%= x.action %> -- <%= x.url %> <% break %> <% end %> <% end %> <% elsif @recipient.admin == true %> <h1>List of all Notifications (past 24 hours):</h1> <% i = 0 %> <% @notifications.each do |x| %> <% if x.created_at >= 1.day.ago %> <% i += 1 %> <%= i %>. User ID <%= x.recipient_id %> -- <%= x.action %> -- <%= x.url %> <br> <% end %> <% end %> <% end %> </p> </body> </html>" end |
#create_mailer_file ⇒ Object
7 8 9 |
# File 'lib/generators/notifier_generator.rb', line 7 def create_mailer_file create_file "app/mailers/notifier.rb", "require 'simply_notify'" end |
#create_text_view_file ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/generators/notifier_generator.rb', line 66 def create_text_view_file create_file "app/views/notifier/new_notification.text.erb", "Hello, If your account has new notifications, they will be lised below. Please visit the course website at: <%= @url %> Or you can follow the links provided by the notifications. Thanks! <% if @recipient.notificationFrequency == 2 && @recipient.admin == false %> List of Notifications (past 24 hours): <% i = 0 %> <% @notifications.each do |x| %> <% if x.recipient_id == @recipient.id && x.created_at >= 1.day.ago %> <% i += 1 %> <%= i %>. <%= x.action %> -- <%= x.url %> \r\n <% end %> <% end %> <% elsif @recipient.notificationFrequency == 1 && @recipient.admin == false %> New Notification: <% @notifications.reverse.each do |x| %> <% if x.recipient_id == @recipient.id %> <%= x.action %> -- <%= x.url %> <% break %> <% end %> <% end %> <% elsif @recipient.admin == true %> List of all Notifications (past 24 hours): <% i = 0 %> <% @notifications.each do |x| %> <% if x.created_at >= 1.day.ago %> <% i += 1 %> <%= i %>. User ID <%= x.recipient_id %> -- <%= x.action %> -- <%= x.url %> \r\n <% end %> <% end %> <% end %>" end |
#insert_association_user_model ⇒ Object
132 133 134 135 136 |
# File 'lib/generators/notifier_generator.rb', line 132 def insert_association_user_model insert_into_file "app/models/user.rb", "\n has_many :messages, class_name: \"Ahoy::Message\"", after: "class User < ActiveRecord::Base" end |