ultra_light_wizard 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f6a677b2537b3df14e59d1d579862c4fa106e41
4
+ data.tar.gz: 64b413b744fe3da9527ad49cce13979a53023067
5
+ SHA512:
6
+ metadata.gz: fe2a44cc2140f924f60f37aba9bf76049652fecd1719de26a419a10f0e96218cb0fa7a1ba816794b70869e83f5c4d2922557d0cd2ac39699a9ac40aa0be9731b
7
+ data.tar.gz: d36a12dc2cac94d1e72a72f2490a904ab239f28689c897826c22e3a1e11d659d03dd86a0072ad0e6474bf6aa4d7a4e99f87e4a83a5f537271eddcc0e2cd8ebd8
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ ultra_light_wizard
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.3
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'jeweler'
5
+ end
6
+
7
+ group :test do
8
+ gem 'rspec'
9
+ gem 'coveralls'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ builder (3.2.2)
6
+ coveralls (0.7.0)
7
+ multi_json (~> 1.3)
8
+ rest-client
9
+ simplecov (>= 0.7)
10
+ term-ansicolor
11
+ thor
12
+ diff-lcs (1.2.5)
13
+ docile (1.1.1)
14
+ faraday (0.8.8)
15
+ multipart-post (~> 1.2.0)
16
+ git (1.2.6)
17
+ github_api (0.10.1)
18
+ addressable
19
+ faraday (~> 0.8.1)
20
+ hashie (>= 1.2)
21
+ multi_json (~> 1.4)
22
+ nokogiri (~> 1.5.2)
23
+ oauth2
24
+ hashie (2.0.5)
25
+ highline (1.6.20)
26
+ httpauth (0.2.0)
27
+ jeweler (1.8.8)
28
+ builder
29
+ bundler (~> 1.0)
30
+ git (>= 1.2.5)
31
+ github_api (= 0.10.1)
32
+ highline (>= 1.6.15)
33
+ nokogiri (= 1.5.10)
34
+ rake
35
+ rdoc
36
+ json (1.8.1)
37
+ jwt (0.1.8)
38
+ multi_json (>= 1.5)
39
+ mime-types (2.0)
40
+ multi_json (1.8.2)
41
+ multi_xml (0.5.5)
42
+ multipart-post (1.2.0)
43
+ nokogiri (1.5.10)
44
+ oauth2 (0.9.2)
45
+ faraday (~> 0.8)
46
+ httpauth (~> 0.2)
47
+ jwt (~> 0.1.4)
48
+ multi_json (~> 1.0)
49
+ multi_xml (~> 0.5)
50
+ rack (~> 1.2)
51
+ rack (1.5.2)
52
+ rake (10.1.0)
53
+ rdoc (4.0.1)
54
+ json (~> 1.4)
55
+ rest-client (1.6.7)
56
+ mime-types (>= 1.16)
57
+ rspec (2.14.1)
58
+ rspec-core (~> 2.14.0)
59
+ rspec-expectations (~> 2.14.0)
60
+ rspec-mocks (~> 2.14.0)
61
+ rspec-core (2.14.7)
62
+ rspec-expectations (2.14.4)
63
+ diff-lcs (>= 1.1.3, < 2.0)
64
+ rspec-mocks (2.14.4)
65
+ simplecov (0.8.2)
66
+ docile (~> 1.1.0)
67
+ multi_json
68
+ simplecov-html (~> 0.8.0)
69
+ simplecov-html (0.8.0)
70
+ term-ansicolor (1.2.2)
71
+ tins (~> 0.8)
72
+ thor (0.18.1)
73
+ tins (0.13.1)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ coveralls
80
+ jeweler
81
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Andy Maleh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ Ultra Light Wizard
2
+ ==================
3
+
4
+ No time to manage a wizard state machine, session variables, or complicated controllers? Use Ultra Light Wizard!! A RESTful session-less validation-friendly simple wizard approach in Rails.
5
+
6
+ Watching this video explains it all:
7
+ https://www.youtube.com/watch?v=muyfoiKHMMA
8
+
9
+ Instructions
10
+ ============
11
+
12
+ rails generate ultra_light_wizard:wizard (resource) steps=(step1),(step2),(step3),...
13
+
14
+ This will generate wizard step routes, controller, models, and views
15
+
16
+ Example:
17
+
18
+ rails generate ultra_light_wizard:wizard Project steps:basic_info,project_detail,file_uploads,preview
19
+
20
+ Output:
21
+
22
+ ```
23
+ create app/controllers/project_steps_controller.rb
24
+ create app/models/project/basic_info.rb
25
+ create app/views/project_steps/basic_info.html.erb
26
+ create app/models/project/project_detail.rb
27
+ create app/views/project_steps/project_detail.html.erb
28
+ create app/models/project/file_uploads.rb
29
+ create app/views/project_steps/file_uploads.html.erb
30
+ create app/models/project/preview.rb
31
+ create app/views/project_steps/preview.html.erb
32
+ route resources :projects, only: [:create, :show] do
33
+ resources :project_steps, only: [:edit, :update]
34
+ end
35
+ ```
36
+
37
+ If you'd like to customize the term "step", you can add a step_alias:(alias) option as in the following:
38
+
39
+ Example:
40
+
41
+ rails generate ultra_light_wizard:wizard Project steps:basic_info,project_detail,file_uploads,preview step_alias:part
42
+
43
+ Output:
44
+
45
+ ```
46
+ create app/controllers/project_parts_controller.rb
47
+ create app/models/project/basic_info.rb
48
+ create app/views/project_parts/basic_info.html.erb
49
+ create app/models/project/project_detail.rb
50
+ create app/views/project_parts/project_detail.html.erb
51
+ create app/models/project/file_uploads.rb
52
+ create app/views/project_parts/file_uploads.html.erb
53
+ create app/models/project/preview.rb
54
+ create app/views/project_parts/preview.html.erb
55
+ route resources :projects, only: [:create, :show] do
56
+ resources :project_parts, only: [:edit, :update]
57
+ end
58
+ ```
59
+
60
+ Once the files are generated, you can proceed to place your own code customizations in the wizard step models and views.
61
+
62
+ To learn more about the Ultra Light Wizard philosophy and function, please read this [Code Painter](http://www.codepainter.ca) blog post: [Ultra Light & Maintainable Wizard in Rails] (http://www.codepainter.ca/2013/10/ultra-light-maintainable-wizards-in.html)
63
+
64
+ TODO
65
+ ====
66
+
67
+ - Wizard step generator (model part builder MVC components)
68
+ + Routes
69
+ + Controller steps
70
+ + Model parts
71
+ + View parts
72
+ - Helper (or Controller SuperModule trait) for ultra light wizard support
73
+ - Support for nested resources
74
+ - Modularize (perhaps extracting sub-generators)
75
+ + Customize name conventions
76
+
77
+ License
78
+ =======
79
+
80
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "ultra_light_wizard"
18
+ gem.homepage = "http://github.com/AndyObtiva/ultra_light_wizard"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Ultra Light & Maintainable Wizards In Rails}
21
+ gem.description = %Q{Ultra light & maintainble wizards in Rails that honor REST, MVC, and OO with minimal writing of code involved and maximum flexibility}
22
+ gem.email = "andy.am@gmail.com"
23
+ gem.authors = ["Andy Maleh"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core/rake_task'
29
+
30
+ RSpec::Core::RakeTask.new(:spec)
31
+
32
+ task :default => :spec
33
+
34
+ require 'rdoc/task'
35
+ Rake::RDocTask.new do |rdoc|
36
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
37
+
38
+ rdoc.rdoc_dir = 'rdoc'
39
+ rdoc.title = "ultra_light_wizard #{version}"
40
+ rdoc.rdoc_files.include('README*')
41
+ rdoc.rdoc_files.include('lib/**/*.rb')
42
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,53 @@
1
+ class <%= class_name %><%= step_alias.pluralize.camelize %>Controller < ApplicationController
2
+ before_action :authorize_<%= file_path %>
3
+
4
+ <%= step_alias.pluralize.upcase %> = %w(<%= steps.to_a.join(' ') %>)
5
+
6
+ def edit
7
+ if <%= file_path %>_<%= step_alias %>_model.editable?
8
+ if <%= step_alias %>.present?
9
+ render <%= step_alias %>
10
+ else
11
+ render "#{Rails.root.to_s}/public/404.html", :layout => false, :status => 404
12
+ end
13
+ else
14
+ redirect_to :back, :alert => I18n.t("<%= file_path %>.#{@<%= file_path %>.status}_editable_error")
15
+ end
16
+ end
17
+
18
+ def update
19
+ if <%= file_path %>_<%= step_alias %>_model.update_attributes(params[:<%= file_path %>])
20
+ if next_<%= step_alias %> && params[:commit].downcase.include?('continue')
21
+ redirect_to edit_<%= file_path %>_<%= file_path %>_<%= step_alias %>_path(<%= file_path %>_<%= step_alias %>_model, next_<%= step_alias %>)
22
+ else
23
+ redirect_to <%= file_path %>_path(@<%= file_path %>)
24
+ end
25
+ else
26
+ render <%= step_alias %>, :error => "Please complete all required fields"
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def authorize_<%= file_path %>
33
+ @<%= file_path %> = <%= file_path %>_<%= step_alias %>_model
34
+ if @<%= file_path %>.user_id != current_user.id && !current_user.is_admin?
35
+ render(:file => "#{Rails.root.to_s}/public/403.html", :layout => false, :status => 403)
36
+ end
37
+ end
38
+
39
+ def <%= file_path %>_<%= step_alias %>_model
40
+ <%= file_path %>_class = "<%= class_name %>::#{<%= step_alias %>.camelcase}".constantize rescue <%= class_name %>
41
+ <%= file_path %>_class.find(params[:<%= file_path %>_id])
42
+ end
43
+
44
+ def <%= step_alias %>
45
+ <%= step_alias.pluralize.upcase %>.find {|a_<%= step_alias %>| a_<%= step_alias %> == params[:id].to_s.downcase}
46
+ end
47
+
48
+ def next_<%= step_alias %>
49
+ current_<%= step_alias %>_index = <%= step_alias.pluralize.upcase %>.index(<%= step_alias %>)
50
+ next_<%= step_alias %> = <%= step_alias.pluralize.upcase %>[current_<%= step_alias %>_index+1]
51
+ end
52
+
53
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name %>::<%= @wizard_step.camelize %> < <%= class_name %>
2
+ end
@@ -0,0 +1,2 @@
1
+ <h1><%= file_path.humanize %> wizard</h1>
2
+ <h2><%= step_alias.titleize %>: <%= @wizard_step.humanize %></h2>
@@ -0,0 +1,38 @@
1
+ module UltraLightWizard
2
+ module Generators
3
+ class WizardGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path("../../templates", __FILE__)
5
+ def arguments
6
+ args.inject({}) do |output, arg|
7
+ arg_parts = arg.split(':')
8
+ output.merge(arg_parts.first => arg_parts.last)
9
+ end
10
+ end
11
+
12
+ def step_alias
13
+ arguments['step_alias'] || 'step'
14
+ end
15
+
16
+ def steps
17
+ arguments['steps'].to_s.split(',').map(&:strip)
18
+ end
19
+
20
+ desc "Creates a configuration file for a specific application context (e.g. admin). Takes context path as argument (e.g. admin or internal/wiki) to create config/features/[context_path].yml"
21
+ def copy_config
22
+ template "app/controllers/wizard_steps_controller.rb.erb", "app/controllers/#{file_path}_#{step_alias.pluralize}_controller.rb"
23
+ steps.each do |step|
24
+ @wizard_step = step
25
+ template "app/models/wizard_step_model.rb.erb", "app/models/#{file_path}/#{step}.rb"
26
+ template "app/views/wizard_step_view.html.erb", "app/views/#{file_path}_#{step_alias.pluralize}/#{step}.html.erb"
27
+ end
28
+ wizard_route_content = <<-CONTENT
29
+ resources :#{plural_file_name}, only: [:create, :show] do
30
+ resources :#{file_path}_#{step_alias.pluralize}, only: [:edit, :update]
31
+ end
32
+ CONTENT
33
+ routes_content = File.new(Rails.root.join('config', 'routes.rb')).read
34
+ route wizard_route_content unless routes_content.include?(wizard_route_content)
35
+ end
36
+ end
37
+ end
38
+ end
File without changes
data/ruby187.Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'jeweler'
5
+ end
6
+
7
+ group :test do
8
+ gem 'rspec'
9
+ end
@@ -0,0 +1,19 @@
1
+ ENV['APP_ENV'] = 'test'
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :test)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ if RUBY_VERSION >= '1.9'
12
+ begin
13
+ require 'coveralls'
14
+ Coveralls.wear!
15
+ rescue LoadError, StandardError
16
+ #no op to support Ruby 1.8.7, ree and Rubinius which do not support Coveralls
17
+ end
18
+ end
19
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ultra_light_wizard')
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: ultra_light_wizard 0.0.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "ultra_light_wizard"
9
+ s.version = "0.0.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Andy Maleh"]
14
+ s.date = "2016-01-26"
15
+ s.description = "Ultra light & maintainble wizards in Rails that honor REST, MVC, and OO with minimal writing of code involved and maximum flexibility"
16
+ s.email = "andy.am@gmail.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".ruby-gemset",
23
+ ".ruby-version",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.md",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "lib/generators/templates/app/controllers/wizard_steps_controller.rb.erb",
31
+ "lib/generators/templates/app/models/wizard_step_model.rb.erb",
32
+ "lib/generators/templates/app/views/wizard_step_view.html.erb",
33
+ "lib/generators/ultra_light_wizard/wizard_generator.rb",
34
+ "lib/ultra_light_wizard.rb",
35
+ "ruby187.Gemfile",
36
+ "spec/spec_helper.rb",
37
+ "spec/ultra_light_wizard/ultra_light_wizard_spec.rb",
38
+ "ultra_light_wizard.gemspec"
39
+ ]
40
+ s.homepage = "http://github.com/AndyObtiva/ultra_light_wizard"
41
+ s.licenses = ["MIT"]
42
+ s.rubygems_version = "2.4.5.1"
43
+ s.summary = "Ultra Light & Maintainable Wizards In Rails"
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 4
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<jeweler>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<jeweler>, [">= 0"])
55
+ end
56
+ end
57
+
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ultra_light_wizard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andy Maleh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jeweler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Ultra light & maintainble wizards in Rails that honor REST, MVC, and
28
+ OO with minimal writing of code involved and maximum flexibility
29
+ email: andy.am@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - LICENSE.txt
34
+ - README.md
35
+ files:
36
+ - ".ruby-gemset"
37
+ - ".ruby-version"
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - VERSION
44
+ - lib/generators/templates/app/controllers/wizard_steps_controller.rb.erb
45
+ - lib/generators/templates/app/models/wizard_step_model.rb.erb
46
+ - lib/generators/templates/app/views/wizard_step_view.html.erb
47
+ - lib/generators/ultra_light_wizard/wizard_generator.rb
48
+ - lib/ultra_light_wizard.rb
49
+ - ruby187.Gemfile
50
+ - spec/spec_helper.rb
51
+ - spec/ultra_light_wizard/ultra_light_wizard_spec.rb
52
+ - ultra_light_wizard.gemspec
53
+ homepage: http://github.com/AndyObtiva/ultra_light_wizard
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.4.5.1
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Ultra Light & Maintainable Wizards In Rails
77
+ test_files: []