rails_onboarding 0.6.1 → 0.6.3

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: b5f1d40794e4959c807fd7fd7077c81c60821cbf8e1bd79fd69089543e718790
4
- data.tar.gz: 3ce1ebd746fc540b491460bf1c0c7e2dee36709182bee72beab9a6c5e4b56ec0
3
+ metadata.gz: 54c87e18cdea35b440ea3d1f9dcd93984da008e6690bbf0dba255e8b1b803266
4
+ data.tar.gz: 6675e0f3bf44029a6ee5d2b6c6d051edf877dd388e087b44925a716f51070a1b
5
5
  SHA512:
6
- metadata.gz: ac1a9a964c82891f05512236f1930c753082efa29e16f34621da582f962cabdd7761611c4538f4857a6ffc08f5388c123f8837b3923aba3d2392b6d72c178ce2
7
- data.tar.gz: ed7976e143fc227f068324ac48c6d93e01acad26a3fcd6a445599fd628411b0b22f8353a9f5c87085929cc07025b18e956391c6d7973cb9742aab6dd4e522cf3
6
+ metadata.gz: fd7a88c2058c5ea08bc5636990af96fd58775bfa98bf8f5a93849793564afe09bb51dcdf4983641dab499cd850213e6b24c2c867c44137b4ae30b7cc469697b0
7
+ data.tar.gz: 75827eaa49ba15a510ae5212be0ba4f6ea67739b32e1da632c9e9fd36eaa452a721d635f839e01f77922755ed15742e9d31f91618dcca0485f4c012b4e6088d3
@@ -231,7 +231,7 @@ module RailsOnboarding
231
231
  def advance_completed_steps
232
232
  awarded_milestones = []
233
233
  RailsOnboarding.configuration.total_steps.times do
234
- break unless @current_step && step_criteria_met?(@current_step)
234
+ break unless @current_step && onboarding_step_criteria_met?(@current_step)
235
235
 
236
236
  if defined?(RailsOnboarding::MilestoneService)
237
237
  milestones = RailsOnboarding::MilestoneService.check_onboarding_step_milestones(
@@ -258,19 +258,6 @@ module RailsOnboarding
258
258
  set_step
259
259
  end
260
260
 
261
- # A buggy :complete_if must not brick onboarding - if it raises, treat the
262
- # step as not yet complete instead of letting the shared StandardError
263
- # handler redirect back to /onboarding (which would re-raise on arrival,
264
- # redirecting again in an endless browser loop).
265
- def step_criteria_met?(step)
266
- return false unless step[:complete_if].is_a?(Proc)
267
-
268
- step[:complete_if].call(current_user)
269
- rescue StandardError => e
270
- Rails.logger.error("RailsOnboarding: complete_if for step '#{step[:name]}' raised #{e.class} - #{e.message}")
271
- false
272
- end
273
-
274
261
  # Redirect to the host-app page that owns the current step. Returns false
275
262
  # (without redirecting) when the configured path can't be resolved, so
276
263
  # show can fall back to rendering a gem template instead of stranding the
@@ -34,11 +34,15 @@
34
34
  </span>
35
35
  </div>
36
36
  <div class="onboarding-banner-actions">
37
- <%# For :path steps, /onboarding re-checks complete_if and either
38
- advances or routes back to the step's page - so "Continue" is
39
- always the right link. %>
40
- <%= link_to "Continue setup →", onboarding_root,
41
- class: "onboarding-banner-continue" %>
37
+ <%# /onboarding re-checks complete_if and either advances or routes back
38
+ to the step's page. That makes "Continue" the right link from
39
+ anywhere else in the app - but on the step's own page, with the
40
+ criteria not yet met, it redirects straight back here and the click
41
+ does nothing visible. Offer it only when it leads somewhere. %>
42
+ <% if !defined?(onboarding_continue_available?) || onboarding_continue_available? %>
43
+ <%= link_to "Continue setup →", onboarding_root,
44
+ class: "onboarding-banner-continue" %>
45
+ <% end %>
42
46
  <% if step[:skippable] %>
43
47
  <%= button_to "Skip this step", rails_onboarding.skip_onboarding_path,
44
48
  method: :post, class: "onboarding-banner-skip" %>
@@ -4,7 +4,7 @@ module RailsOnboarding
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- helper_method :needs_onboarding?, :onboarding_path
7
+ helper_method :needs_onboarding?, :onboarding_path, :onboarding_continue_available?
8
8
  end
9
9
 
10
10
  # Configuration at the controller level
@@ -105,6 +105,59 @@ module RailsOnboarding
105
105
  path.is_a?(Proc) ? instance_exec(&path) : main_app.public_send(path)
106
106
  end
107
107
 
108
+ # Has this step's :complete_if been satisfied?
109
+ #
110
+ # A buggy :complete_if must not brick onboarding - if it raises, treat the
111
+ # step as not yet complete instead of letting the engine's shared
112
+ # StandardError handler redirect back to /onboarding (which would re-raise
113
+ # on arrival, redirecting again in an endless browser loop).
114
+ def onboarding_step_criteria_met?(step)
115
+ return false unless step.is_a?(Hash) && step[:complete_if].is_a?(Proc)
116
+
117
+ step[:complete_if].call(current_user)
118
+ rescue StandardError => e
119
+ Rails.logger.error("RailsOnboarding: complete_if for step '#{step[:name]}' raised #{e.class} - #{e.message}")
120
+ false
121
+ end
122
+
123
+ # Would following the banner's "Continue" link actually move the user?
124
+ #
125
+ # Anywhere else in the app, yes: /onboarding routes them to the current
126
+ # step. Standing on the step's own page it depends - /onboarding re-checks
127
+ # :complete_if and only advances once it passes. Until then it resolves the
128
+ # step's path and redirects straight back to the page the user is already
129
+ # on, so the link renders but the click does nothing visible. The banner
130
+ # asks this before offering it.
131
+ #
132
+ # The comparison is deliberately an exact path match rather than
133
+ # on_current_step_page?, which also treats any other action on the same
134
+ # controller as "on the step page". That breadth is right for the loop
135
+ # guard - it keeps the guard off the PATCH that completes the step - but
136
+ # wrong here: /profiles/123 is a different page from a step pointing at
137
+ # /profiles/123/edit, and Continue really does move the user between them.
138
+ def onboarding_continue_available?
139
+ return false unless user_signed_in?
140
+ return false unless current_user.respond_to?(:current_onboarding_step)
141
+
142
+ step = current_user.current_onboarding_step
143
+ # No :path means the step renders a gem template at /onboarding, which is
144
+ # always somewhere other than the host page showing this banner.
145
+ return true unless step.is_a?(Hash) && step[:path]
146
+
147
+ # The resolved route may carry a query string or be a full URL;
148
+ # request.path never does.
149
+ resolved_path = URI.parse(resolve_onboarding_step_path(step[:path]).to_s).path
150
+ return true unless request.path == resolved_path
151
+
152
+ onboarding_step_criteria_met?(step)
153
+ rescue StandardError => e
154
+ # An unresolvable :path means the engine can't redirect to it either - it
155
+ # falls back to rendering a gem template, so Continue still goes
156
+ # somewhere. Offer it.
157
+ Rails.logger.warn("RailsOnboarding: could not resolve step path for the banner link: #{e.class} - #{e.message}")
158
+ true
159
+ end
160
+
108
161
  private
109
162
 
110
163
  # True when the current request is for the page a :path-based step points
@@ -1,3 +1,3 @@
1
1
  module RailsOnboarding
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_onboarding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Lewis
@@ -281,7 +281,7 @@ licenses:
281
281
  metadata:
282
282
  allowed_push_host: https://rubygems.org
283
283
  homepage_uri: https://github.com/bunnahabhain/rails_onboarding
284
- source_code_uri: https://github.com/bunnahabhain/rails_onboarding/tree/v0.6.1
284
+ source_code_uri: https://github.com/bunnahabhain/rails_onboarding/tree/v0.6.3
285
285
  changelog_uri: https://github.com/bunnahabhain/rails_onboarding/blob/master/docs/CHANGELOG.md
286
286
  rdoc_options: []
287
287
  require_paths: