heya 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 125b5f898dd3d7841fd0e50ae05d424ec56d2818bb011a43a083f224d15aa3ea
4
- data.tar.gz: 23a1fd76278729817ab0317dff81ab816cabd9f09b323e8f723cb5c8f9186eff
3
+ metadata.gz: 91788b17940c18fd1196e0cc20f2892fb91233c714a5dc7c876833459ae867d3
4
+ data.tar.gz: 6f8694d2562802ff9102fd62e04349beaf464dee5043fd928e0403fd4deb6bab
5
5
  SHA512:
6
- metadata.gz: 22b4d72ffa9e69068ce5a77008b76047cf3f1379d330f233b0a4f174a6a89d3a91ab3353e1941b4b1262a4898316cdc1b14e3842468e4fd9bbffa301234c3e62
7
- data.tar.gz: bc5c5604c1e1d95adb14fe4435817431c4af2f471a5df7d6bfd4ec100d6a5607cbd4121a31d66660cde7e9a892b84126bf6b6e2d15676afbd36af2fad958910e
6
+ metadata.gz: 7315798099a708fa8bc0477e229672377634a29a97097139c2055ef09edd748edaf4a40a8685cfa015b87e766463ade73c3e10ea71ee41893184bea0ab7867ec
7
+ data.tar.gz: 3a437c995a6aaed616b75cce220c80bf28baf7d64364ac1956d11ce1e38c8bbf40d9a71bed97258e84d19d410970ae7ed48d07a6aaed92b92ebc3610ef9b654f
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.2.1] - 2020-04-23
10
+ ### Fixed
11
+ - Update the install and campaign generators.
12
+
9
13
  ## [0.2.0] - 2020-04-14
10
14
  ### Added
11
15
  - Added licensing.
data/README.md CHANGED
@@ -27,11 +27,12 @@ Getting started with Heya is easy:
27
27
  rails db:migrate
28
28
  ```
29
29
 
30
- This will do 3 things:
30
+ This will:
31
31
 
32
32
  1. Copy Heya's migration files to *db/migrate*
33
- 2. Copy Heya's default initializer to *config/initializers/heya.rb*
34
- 3. Run local migrations
33
+ 1. Copy Heya's default initializer to *config/initializers/heya.rb*
34
+ 1. Create the file *app/campaigns/application_campaign.rb*
35
+ 1. Run local migrations
35
36
 
36
37
  <details><summary>Note: Heya doesn't store a copy of your user data; instead, it reads from your existing <code>User</code> model (it never writes). If you have a different user model, change the <code>user_type</code> configuration option in <em>config/initializers/heya.rb</em>.</summary>
37
38
 
@@ -47,7 +48,7 @@ end
47
48
  1. Create a campaign:
48
49
 
49
50
  ```bash
50
- rails generate heya:campaign Onboarding welcome
51
+ rails generate heya:campaign Onboarding welcome:0
51
52
  ```
52
53
 
53
54
  2. Add a user to your campaign:
@@ -55,14 +56,99 @@ end
55
56
  ```ruby
56
57
  OnboardingCampaign.add(user)
57
58
  ```
59
+
60
+ Add the following to your `User` model to send them the campaign
61
+ when they first signup:
62
+
63
+ ```ruby
64
+ after_create_commit do
65
+ OnboardingCampaign.add(self)
66
+ end
67
+ ```
58
68
 
59
69
  ### Running the scheduler
60
- To start sending emails, run the scheduler periodically:
70
+ To start queuing emails, run the scheduler task periodically:
61
71
 
62
72
  ```bash
63
73
  rails heya:scheduler
64
74
  ```
65
75
 
76
+ Heya uses ActiveJob to send emails in the background. Make sure your
77
+ ActiveJob backend is configured to process the `heya` queue. For example,
78
+ here's how you might start Sidekiq:
79
+
80
+ ```sh
81
+ bundle exec sidekiq -q default -q heya
82
+ ```
83
+
84
+ You can change Heya's default queue using the `queue` option:
85
+
86
+ ```ruby
87
+ # app/campaigns/application_campaign.rb
88
+ class ApplicationCampaign < Heya::Campaigns::Base
89
+ default queue: "custom"
90
+ end
91
+ ```
92
+
93
+ ### Bonus: tips for working with email in Rails
94
+
95
+ <details><summary>Use <a href="http://mailcatcher.me">MailCatcher</a> to see emails sent from your dev environment</summary>
96
+
97
+ ```ruby
98
+ # config/environments/development.rb
99
+ Rails.application.configure do
100
+ # ..
101
+
102
+ # Use MailCatcher to inspect emails
103
+ # http://mailcatcher.me
104
+ # Usage:
105
+ # gem install mailcatcher
106
+ # mailcatcher
107
+ # # => Starting MailCatcher
108
+ # # => ==> smtp://127.0.0.1:1025
109
+ # # => ==> http://127.0.0.1:1080
110
+ config.action_mailer.delivery_method = :smtp
111
+ config.action_mailer.smtp_settings = {host: "localhost", port: 1025}
112
+ end
113
+ ```
114
+ </details>
115
+ <details><summary>Use <a href="https://github.com/codetriage/maildown">Maildown</a> to write your emails in Markdown</summary>
116
+
117
+ ```sh
118
+ $ bundle add maildown
119
+ $ rails generate heya:campaign Onboarding welcome
120
+ create app/campaigns/application_campaign.rb
121
+ create app/campaigns/onboarding_campaign.rb
122
+ create app/views/heya/campaign_mailer/onboarding_campaign/welcome.md.erb
123
+ ```
124
+
125
+ ☝️ Notice how only one template was generated; Maildown automatically builds
126
+ the HTML and text variants from the markdown file.
127
+ </details>
128
+ <details><summary>Use <a href="https://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails">ActionMailer::Preview</a> to preview emails as you write them</summary>
129
+
130
+ Heya's campaign generator generates previews for campaigns at
131
+ `(test|spec)/mailers/previews/*_campaign_preview.rb`. To see them, open
132
+ http://localhost:3000/rails/mailers/. If you didn't use the generator, you
133
+ can still build your own preview:
134
+
135
+ ```ruby
136
+ # test/mailers/previews/onboarding_campaign_preview.rb
137
+ class OnboardingCampaignPreview < ActionMailer::Preview
138
+ def welcome
139
+ OnboardingCampaign.welcome(user)
140
+ end
141
+
142
+ private
143
+
144
+ def user
145
+ User.where(id: params[:user_id]).first || User.first
146
+ end
147
+ end
148
+
149
+ ```
150
+ </details>
151
+
66
152
  ## Configuration
67
153
 
68
154
  You can use the following options to configure Heya (find this file in
@@ -96,11 +182,12 @@ Heya stores campaigns in *app/campaigns/*, similar to how Rails stores mailers i
96
182
  rails generate heya:campaign Onboarding first second third
97
183
  ```
98
184
 
99
- This will do three things:
185
+ This will:
100
186
 
101
- - Create the file *app/campaigns/onboarding_campaign.rb*
102
- - Create the directory *app/views/heya/campaign_mailer/onboarding_campaign/*
103
- - Create email templates inside of *app/views/heya/campaign_mailer/onboarding_campaign/*
187
+ 1. Create the file *app/campaigns/onboarding_campaign.rb*
188
+ 1. Create the directory *app/views/heya/campaign_mailer/onboarding_campaign/*
189
+ 1. Create email templates inside of *app/views/heya/campaign_mailer/onboarding_campaign/*
190
+ 1. Create an ActionMailer preview at *(test|spec)/mailers/previews/onboarding_campaign_preview.rb*
104
191
 
105
192
  Here's the campaign that the above command generates:
106
193
 
@@ -316,6 +403,27 @@ class ApplicationCampaign < Heya::Campaigns::Base
316
403
  end
317
404
  ```
318
405
 
406
+ ### Handling exceptions
407
+
408
+ Heya campaigns are [rescuable](https://api.rubyonrails.org/classes/ActiveSupport/Rescuable/ClassMethods.html).
409
+ Use the `rescue_from` method to handle exceptions in campaigns:
410
+
411
+ ```ruby
412
+ class OnboardingCampaign < ApplicationCampaign
413
+ rescue_from Postmark::InactiveRecipientError, with: :log_error
414
+
415
+ private
416
+
417
+ def log_error(error)
418
+ Rails.logger.error("Got Heya error: #{error}")
419
+ end
420
+ end
421
+ ```
422
+
423
+ See the
424
+ [Rails documentation](https://api.rubyonrails.org/classes/ActiveSupport/Rescuable/ClassMethods.html#method-i-rescue_from)
425
+ for additional details.
426
+
319
427
  ### Campaigns FAQ
320
428
  **What happens when:**
321
429
  <details><summary>I reorder messages in an active campaign?</summary>
@@ -2,7 +2,7 @@ Description:
2
2
  Generate a new campaign
3
3
 
4
4
  Example:
5
- rails generate heya:campaign Onboarding first second third
5
+ rails generate heya:campaign Onboarding first:0 second:2.days third
6
6
 
7
7
  This will create:
8
8
  app/campaigns/onboarding_campaign.rb
@@ -6,7 +6,10 @@ class Heya::CampaignGenerator < Rails::Generators::NamedBase
6
6
  argument :steps, type: :array, default: []
7
7
 
8
8
  def copy_campaign_template
9
- template "application_campaign.rb", "app/campaigns/application_campaign.rb"
9
+ application_campaign = "app/campaigns/application_campaign.rb"
10
+ unless File.exist?(application_campaign)
11
+ template File.expand_path("../install/templates/application_campaign.rb", __dir__), application_campaign
12
+ end
10
13
  template "campaign.rb", "app/campaigns/#{file_name.underscore}_campaign.rb"
11
14
  end
12
15
 
@@ -35,11 +38,18 @@ class Heya::CampaignGenerator < Rails::Generators::NamedBase
35
38
  end
36
39
 
37
40
  steps.each do |step|
41
+ step, _wait = step.split(":")
38
42
  @step = step
39
43
  template_method.call(step)
40
44
  end
41
45
  end
42
46
 
47
+ def copy_test_templates
48
+ if preview_path
49
+ template "preview.rb", preview_path.join("#{file_name.underscore}_campaign_preview.rb")
50
+ end
51
+ end
52
+
43
53
  private
44
54
 
45
55
  def action_mailer_template(step)
@@ -50,4 +60,10 @@ class Heya::CampaignGenerator < Rails::Generators::NamedBase
50
60
  def maildown_template(step)
51
61
  template "message.md.erb", "app/views/heya/campaign_mailer/#{file_name.underscore}_campaign/#{step.underscore.to_sym}.md.erb"
52
62
  end
63
+
64
+ def preview_path
65
+ @preview_path ||= if ActionMailer::Base.preview_path.present?
66
+ Pathname(ActionMailer::Base.preview_path).sub(Rails.root.to_s, ".")
67
+ end
68
+ end
53
69
  end
@@ -1,7 +1,4 @@
1
- class <%= file_name.camelcase %>Campaign < ApplicationCampaign
2
- <% steps.each do |step| %>
3
- step :<%= step.underscore.to_sym %>,
4
- subject: "<%= step.humanize %> Message"
5
-
6
- <% end -%>
7
- end
1
+ class <%= file_name.camelcase %>Campaign < ApplicationCampaign<% steps.each do |step| %><% step, wait = step.split(":") %>
2
+ step :<%= step.underscore.to_sym %>,<%= wait.presence ? "\n wait: #{wait}," : "" %>
3
+ subject: "<%= step.humanize %>"
4
+ <% end %>end
@@ -0,0 +1,12 @@
1
+ # Preview all emails at http://localhost:3000/rails/mailers/
2
+ class <%= file_name.camelcase %>CampaignPreview < ActionMailer::Preview<% steps.each do |step| %><% step, wait = step.split(":") %>
3
+ def <%= step %>
4
+ <%= file_name.camelcase %>Campaign.<%= step %>(user)
5
+ end
6
+ <% end %>
7
+ private
8
+
9
+ def user
10
+ <%= Heya.config.user_type %>.where(id: params[:user_id]).first || <%= Heya.config.user_type %>.first || <%= Heya.config.user_type %>.new(email: "user@example.com").freeze
11
+ end
12
+ end
@@ -13,6 +13,10 @@ class Heya::InstallGenerator < Rails::Generators::Base
13
13
  copy_file "initializer.rb", "config/initializers/heya.rb"
14
14
  end
15
15
 
16
+ def copy_application_campaign_template
17
+ template "application_campaign.rb", "app/campaigns/application_campaign.rb"
18
+ end
19
+
16
20
  def self.next_migration_number(dirname)
17
21
  next_migration_number = current_migration_number(dirname) + 1
18
22
  ActiveRecord::Migration.next_migration_number(next_migration_number)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Heya
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Wood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-14 00:00:00.000000000 Z
11
+ date: 2020-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -88,13 +88,14 @@ files:
88
88
  - config/routes.rb
89
89
  - lib/generators/heya/campaign/USAGE
90
90
  - lib/generators/heya/campaign/campaign_generator.rb
91
- - lib/generators/heya/campaign/templates/application_campaign.rb.tt
92
91
  - lib/generators/heya/campaign/templates/campaign.rb.tt
93
92
  - lib/generators/heya/campaign/templates/message.html.erb.tt
94
93
  - lib/generators/heya/campaign/templates/message.md.erb.tt
95
94
  - lib/generators/heya/campaign/templates/message.text.erb.tt
95
+ - lib/generators/heya/campaign/templates/preview.rb.tt
96
96
  - lib/generators/heya/install/USAGE
97
97
  - lib/generators/heya/install/install_generator.rb
98
+ - lib/generators/heya/install/templates/application_campaign.rb.tt
98
99
  - lib/generators/heya/install/templates/initializer.rb.tt
99
100
  - lib/generators/heya/install/templates/migration.rb.tt
100
101
  - lib/heya.rb