Class: NotifyWith::NotificationGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/notify_with/notification/notification_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_notification_subjectObject



18
19
20
21
22
23
24
# File 'lib/generators/notify_with/notification/notification_generator.rb', line 18

def add_notification_subject
  inject_into_file "config/locales/#{I18n.locale.to_s}.yml", after: /send_mail_by:\n/ do
<<-CODE
    subject_#{file_name}: "#{file_name}"
CODE
  end
end

#add_notification_typeObject



2
3
4
5
6
7
8
# File 'lib/generators/notify_with/notification/notification_generator.rb', line 2

def add_notification_type
  inject_into_file 'app/models/notification_type.rb', before: /  \)/ do
<<-CODE
  #{file_name}
CODE
  end
end

#create_notification_json_template_fileObject



26
27
28
29
30
31
32
# File 'lib/generators/notify_with/notification/notification_generator.rb', line 26

def create_notification_json_template_file
  create_file "app/views/api/notifications/_#{file_name}.json.jbuilder", <<-FILE
json.title notification.notification_type
json.description 'a notification description'
json.url 'a url for redirect to attached_object'
  FILE
end

#create_notification_mail_template_fileObject



10
11
12
13
14
15
16
# File 'lib/generators/notify_with/notification/notification_generator.rb', line 10

def create_notification_mail_template_file
  create_file "app/views/notifications_mailer/#{file_name}.html.erb", <<-FILE
<%# this is a mail template of notifcation #{file_name} %>
<p><%= @recipient.name %></p>
<p><%= @attached_object.body %></p>
  FILE
end