effective_resources 1.6.5 → 1.6.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 638c0fd7b0f6e8ad8cbcdfe19a1d10e3824a2767734371e7ee744687181eb773
4
- data.tar.gz: 25bf07d2126c62e65092cbeb4113a8df0017188fd5f17108b425cf8aa4ff09b0
3
+ metadata.gz: 323b70f4a0eb470c2e96edf3651c83493763ad203659f03bb25832cf487812a1
4
+ data.tar.gz: f997c5dcd62f4de1d49065c5fb3d5d882ea3eca30c47fe518bb6642dbd43e65a
5
5
  SHA512:
6
- metadata.gz: 86e11947ca25724dfb6255bd77129b92b87780f8199257634ebdd6841406165ba952d4ddad329608d15685102c5e216b9afeae6cffc51052c05b9564881ec749
7
- data.tar.gz: 70608699672fe60a576f96987224accdddeffeef6248d775c2f6f4481ef1b69c42edddc14e20cb953025098e041d9e354fdb354dfa0a6b99a25a18218f9a5d81
6
+ metadata.gz: 4d78587039acac7fa236913c588946277481a5df90933141db13a7d447491233452f8dd6c3c96ebf7bff8dfd95ba217e56c65e826128d9674532331d6971422c
7
+ data.tar.gz: daff8c0e7009dd67297f2e62a90744b7dcc67008f107543b53c53b24476ca8534284202aae98b0579e394fddbdbb498925b0294f47c95e70f9bbf8b551cab4a3
data/README.md CHANGED
@@ -256,6 +256,102 @@ end
256
256
 
257
257
  and include Effective::CrudController in your resource controller.
258
258
 
259
+ ### acts_as_wizard
260
+
261
+ Build up an object through a wizard.
262
+
263
+ Works with the [wicked](https://github.com/zombocom/wicked) gem to create wizard quickly.
264
+
265
+ Create a model and define `acts_as_wizard`:
266
+
267
+ ```ruby
268
+ class Thing < ApplicationRecord
269
+ acts_as_wizard(
270
+ start: 'Start',
271
+ select: 'Select',
272
+ finish: 'Finish'
273
+ )
274
+
275
+ effective_resource do
276
+ title :string
277
+ wizard_steps :text, permitted: false
278
+ end
279
+
280
+ validates :title, presence: true
281
+
282
+ def to_s
283
+ title.presence || 'New Thing'
284
+ end
285
+
286
+ # If you define a bang method matching the name of a step
287
+ # it will be called when that step is submitted.
288
+ # Otherwise save! is called.
289
+ def select!
290
+ ApplicationMailer.selected(self).deliver_later
291
+ save!
292
+ end
293
+
294
+ # An array of steps that the controller will use
295
+ # Default value is just all of them. But you can customize here
296
+ # def required_steps
297
+ # steps = WIZARD_STEPS.keys
298
+ # selectable? ? steps : steps - [:select]
299
+ # end
300
+
301
+ # Control whether the user has permission to visit this step
302
+ #
303
+ # This is the default, can go forward or back:
304
+ #
305
+ # def can_visit_step?(step)
306
+ # can_revisit_completed_steps(step)
307
+ # end
308
+ #
309
+ # Easy change if you only want to go forward:
310
+ #
311
+ # def can_visit_step?(step)
312
+ # cannot_revisit_completed_steps(step)
313
+ # end
314
+ #
315
+ # or custom algorithm:
316
+ #
317
+ # def can_visit_step?(step)
318
+ # return false unless has_completed_previous_step?(step)
319
+ # return false if has_completed_step?(:finish) && step != :finish
320
+ # end
321
+ end
322
+ ```
323
+
324
+ In your routes:
325
+
326
+ ```ruby
327
+ resources :things, only: [:index, :show, :new, :destroy] do
328
+ resources :build, controller: :things, only: [:show, :update]
329
+ end
330
+ ```
331
+
332
+ Make a controller:
333
+
334
+ ```ruby
335
+ class ThingsController < ApplicationController
336
+ include Effective::WizardController
337
+ end
338
+ ```
339
+
340
+ And then create one view per step.
341
+
342
+ Here's `views/things/start.html.haml`:
343
+
344
+ ```haml
345
+ = render_wizard_sidebar(resource) do
346
+ %h1= @page_title
347
+
348
+ = effective_form_with(model: resource, url: wizard_path(step), method: :put) do |f|
349
+ = f.text_field :title
350
+ = f.submit 'Save and Continue'
351
+ ```
352
+
353
+ You can also call `render_wizard_sidebar(resource)` without the block syntax.
354
+
259
355
  ## Testing
260
356
 
261
357
  Run tests by:
@@ -2,11 +2,7 @@ module Effective
2
2
  module WizardController
3
3
  extend ActiveSupport::Concern
4
4
 
5
- unless defined?(Wicked)
6
- raise("please install gem 'wicked' to use Effective::WizardController")
7
- end
8
-
9
- include Wicked::Wizard
5
+ include Wicked::Wizard if defined?(Wicked)
10
6
  include Effective::CrudController
11
7
 
12
8
  include Effective::WizardController::Actions
@@ -14,6 +10,8 @@ module Effective
14
10
  include Effective::WizardController::Save
15
11
 
16
12
  included do
13
+ raise("please install gem 'wicked' to use Effective::WizardController") unless defined?(Wicked)
14
+
17
15
  with_options(only: [:show, :update]) do
18
16
  before_action :redirect_if_blank_step
19
17
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.6.5'.freeze
2
+ VERSION = '1.6.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.5
4
+ version: 1.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-17 00:00:00.000000000 Z
11
+ date: 2020-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails