multistep_form 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +51 -0
  2. data/lib/multistep_form.rb +46 -0
  3. data/lib/version.rb +3 -0
  4. metadata +64 -0
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ multistep_form
2
+ ==============
3
+
4
+
5
+ controller
6
+ ````
7
+ class AccountsController < ApplicationController
8
+ include MultistepForm
9
+
10
+ def update
11
+ @account = Account.find(params[:id])
12
+ if params[:back_button]
13
+ previous_step
14
+ else
15
+ next_step { @account.update_attributes(params[:account]) }
16
+ end
17
+ end
18
+
19
+ private
20
+ def steps
21
+ [:personal, :professional, :others]
22
+ end
23
+ end
24
+ ````
25
+
26
+ view
27
+ ````
28
+ - if @current_step == :personal
29
+ render :form_personal
30
+ - elsif @current_step == :professional
31
+ render :form_professional
32
+ - else
33
+ render :form_others
34
+ ````
35
+
36
+
37
+ ## Authorship
38
+
39
+ Written by [Adriano Bacha](http://github.com/abacha)
40
+
41
+ ## License
42
+
43
+ Copyright (c) 2013 Adriano Bacha
44
+
45
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
50
+
51
+ ---
@@ -0,0 +1,46 @@
1
+ require "active_support/inflector"
2
+
3
+ module MultistepForm
4
+ extend ActiveSupport::Inflector
5
+ StepsNotDefined = Class.new(StandardError)
6
+
7
+ def initialize(*args)
8
+ raise StepsNotDefined unless defined?(steps)
9
+ super(*args)
10
+ end
11
+
12
+ def first_step?
13
+ current_step == steps.first
14
+ end
15
+
16
+ def last_step?
17
+ current_step == steps.last
18
+ end
19
+
20
+ def force_step(step, as_index = false)
21
+ if as_index
22
+ @current_step = steps[step]
23
+ else
24
+ @current_step = step
25
+ end
26
+ @current_step ||= steps.first
27
+ session["#{self.class.name.underscore}_current_step"] = @current_step
28
+ end
29
+
30
+ def current_step
31
+ @current_step || steps.first
32
+ end
33
+
34
+ def next_step(&block)
35
+ step(1, &block)
36
+ end
37
+
38
+ def previous_step(&block)
39
+ step(-1, &block)
40
+ end
41
+
42
+ def step(index, &block)
43
+ return if block_given? && block.call == false
44
+ force_step(steps.index(current_step) + index, true)
45
+ end
46
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module MultistepForm
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multistep_form
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adriano Bacha
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: active_support
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ description: build form on many steps using only one controller method
31
+ email:
32
+ - abacha@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/version.rb
38
+ - lib/multistep_form.rb
39
+ - README.md
40
+ homepage: http://github.com/abacha/multistep_form
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: 1.9.3
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: 1.3.6
58
+ requirements: []
59
+ rubyforge_project: multistep_form
60
+ rubygems_version: 1.8.25
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: build form on many steps using only one controller method
64
+ test_files: []