wicked-pipeline 0.1.1 → 0.1.2

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: c59b79336370d4dff4c11d14e81248c309a7621abffec1b4e07252047db97312
4
- data.tar.gz: 11bb3cbed87f59db523471ccaf24669b375b7122e46a2bbe2b7e91c1fd0c306d
3
+ metadata.gz: 0cb739756e551e6a258cc5740d86873e2f66953bded3b80c64feeca23d7c7ae6
4
+ data.tar.gz: 05c232626e1e34f79064bc51bcd4478f48fc7d2ffebec5642422c5f4ae2041ba
5
5
  SHA512:
6
- metadata.gz: 5416bd3edb4ecb54735249a6546cce437468c4cc33b925be995236bee843bb4ed054f639e592fdc01acba1f720a4c380a2ce2b16d23aa31d0970c40a65b59a3a
7
- data.tar.gz: daa012c32f06118c45c8983ad8a08fe12cc9f44f39e9437b46c43264f3524310d12dbc589512e7e004ae527ba2cec9c58395eac3dbadc2328ea48a10d4425501
6
+ metadata.gz: 158695e62113c19dcec9769c90487f811d39bb258b6eec3725194c4aee034f12e3015d7a735cadaa6de97422ffb867fe717716195952a07b25d980d9cce29c95
7
+ data.tar.gz: 7dfeeb9ca234a1fadc1d8fc410a54c180c4dbe224eac07bbc7da3b74ebf80de6b992262467aa30dee2aea6241be457283a3abdb2f8b889f390e26ae8ceb1d510
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  [Unreleased]
2
2
  ------------
3
3
 
4
+ [0.1.2] - 2022-04-18
5
+ --------------------
6
+
7
+ - Remove the pre-Rails 7 restriction
8
+ - Generate a locales file in the step generator
9
+ - Add a controller generator
10
+
4
11
  [0.1.1] - 2022-04-17
5
12
  --------------------
6
13
 
data/Gemfile CHANGED
@@ -7,8 +7,12 @@ gemspec
7
7
 
8
8
  gem "rails", ">= 6.1", "< 7"
9
9
  gem "rake", "~> 13.0"
10
- gem "standard", "~> 1.3"
11
- gem "yard", "~> 0.9"
10
+ gem "standard", "~> 1.3", require: false
11
+ gem "yard", "~> 0.9", require: false
12
+
13
+ group :development do
14
+ gem "solargraph", require: false
15
+ end
12
16
 
13
17
  group :development, :test do
14
18
  gem "rspec-rails", "~> 5.0"
data/README.md CHANGED
@@ -45,6 +45,10 @@ If bundler is not being used to manage dependencies, install the gem by executin
45
45
  $ gem install wicked-pipeline
46
46
  ```
47
47
 
48
+ ### Compatibility
49
+
50
+ Currently this gem requires Rails >= 6.1
51
+
48
52
  Usage
49
53
  -----
50
54
 
@@ -68,7 +72,7 @@ This will generate the `IdentificationStep` with the `email`, `subscribe_to_news
68
72
 
69
73
  A step object is very similar to a form object. It takes a "resource" (the `ActiveRecord` model) and optional params as arguments and will contain attribute definitions, validations for the step, a list of permitted params and a `#save` method. The validations are specific to the step but the resource will also be validated before being saved.
70
74
 
71
- Step objects are subclasses of the `BaseStep` class, and they live in the `app/steps` directory. Here are the rules that must be respected in a step object:
75
+ Step objects are subclasses of the `Wicked::Pipeline::BaseStep` class, and they live in the `app/steps` directory. Here are the rules that must be respected in a step object:
72
76
 
73
77
  - The name of a step class must end with `Step`
74
78
  - Attributes must be defined using the `ActiveModel::Attributes` API (more on that later)
@@ -81,7 +85,7 @@ The only method that needs to be implemented is the `permitted_params` private m
81
85
 
82
86
  ```ruby
83
87
  module Users
84
- class ProfileStep < ::BaseStep
88
+ class ProfileStep < ::Wicked::Pipeline::BaseStep
85
89
  private
86
90
 
87
91
  def permitted_params
@@ -107,7 +111,7 @@ To define a String attributes as an Array, the second argument must be `array: t
107
111
 
108
112
  ```ruby
109
113
  module Users
110
- class ProfileStep < ::BaseStep
114
+ class ProfileStep < ::Wicked::Pipeline::BaseStep
111
115
  attribute :email
112
116
  attribute :first_name
113
117
  attribute :last_name
@@ -133,7 +137,7 @@ _Hint: A custom validation method must be used for uniqueness validations, but u
133
137
 
134
138
  ```ruby
135
139
  module Users
136
- class ProfileStep < ::BaseStep
140
+ class ProfileStep < ::Wicked::Pipeline::BaseStep
137
141
  # ...
138
142
 
139
143
  validates_presence_of :email, :first_name, :last_name
@@ -163,7 +167,7 @@ A step can be marked as "blocking" by overriding the `blocking?` predicate metho
163
167
 
164
168
  ```ruby
165
169
  module Users
166
- class ProfileStep < ::BaseStep
170
+ class ProfileStep < ::Wicked::Pipeline::BaseStep
167
171
  attribute :first_name
168
172
  attribute :is_us_citizen, :boolean
169
173
 
@@ -184,7 +188,7 @@ To specify a reason why the step is marked as blocking, the `blocking_reason` me
184
188
 
185
189
  ```ruby
186
190
  module Users
187
- class ProfileStep < ::BaseStep
191
+ class ProfileStep < ::Wicked::Pipeline::BaseStep
188
192
  attribute :first_name
189
193
  attribute :is_us_citizen, :boolean
190
194
 
@@ -209,12 +213,12 @@ end
209
213
 
210
214
  ### Step pipelines
211
215
 
212
- A step pipeline class is a subclass of the `BasePipeline` class and live in `app/steps`. At the most basic level should contain a list of step classes.
216
+ A step pipeline class is a subclass of the `Wicked::Pipeline::BasePipeline` class and live in `app/steps`. At the most basic level should contain a list of step classes.
213
217
 
214
218
  **Note:** Step pipeline should only be used with step objects!
215
219
 
216
220
  ```ruby
217
- class UserAccountPipeline < BasePipeline
221
+ class UserAccountPipeline < Wicked::Pipeline::BasePipeline
218
222
  def steps
219
223
  [
220
224
  User::ProfileStep,
@@ -248,7 +252,7 @@ UserAccountPipeline.valid?(User.last)
248
252
 
249
253
  ### Steps controllers
250
254
 
251
- A steps controller is a subclass of `BaseStepsController`, it can have any name and can be placed anywhere under the `app/controllers` directory. Unlike a regular controller, the `:id` parameter references the current step **not** the ID of a resource. For this reason, the name of the resource ID parameter must be specified using the `#resource_param_name` private method.
255
+ A steps controller is a subclass of `Wicked::Pipeline::BaseStepsController`, it can have any name and can be placed anywhere under the `app/controllers` directory. Unlike a regular controller, the `:id` parameter references the current step **not** the ID of a resource. For this reason, the name of the resource ID parameter must be specified using the `#resource_param_name` private method.
252
256
 
253
257
  Steps controllers **must** implement the following private methods:
254
258
 
@@ -257,7 +261,7 @@ Steps controllers **must** implement the following private methods:
257
261
  - `#find_resource`: This method takes care of finding the resource object from the database.
258
262
 
259
263
  ```ruby
260
- class UsersController < BaseStepsController
264
+ class UsersController < Wicked::Pipeline::BaseStepsController
261
265
  # ...
262
266
 
263
267
  private
@@ -321,7 +325,7 @@ A step controller has the `show` and `update` actions. **It cannot have the `new
321
325
  Both action must call `super` with a block and set the `@step_processor` instance variable inside of that block:
322
326
 
323
327
  ```ruby
324
- class UsersController < BaseStepsController
328
+ class UsersController < Wicked::Pipeline::BaseStepsController
325
329
  def show
326
330
  super do
327
331
  @user = find_resource
@@ -361,7 +365,7 @@ end
361
365
  Flash messages can be set manually **after** calling `super`. Step objects have a `#saved?` method which can be used to verify that it was successfully saved. The method should be used before setting a flash messages:
362
366
 
363
367
  ```ruby
364
- class UsersController < BaseStepsController
368
+ class UsersController < Wicked::Pipeline::BaseStepsController
365
369
  # ...
366
370
 
367
371
  def update
data/Rakefile CHANGED
@@ -5,10 +5,24 @@ require "rspec/core/rake_task"
5
5
  require "standard/rake"
6
6
  require "yard"
7
7
 
8
+ # Taken from https://gist.github.com/AlexWayfer/d57f6fa0d69a8e352197ab83a82cff98
9
+ def alias_task(name, old_name)
10
+ t = Rake::Task[old_name]
11
+ desc t.full_comment if t.full_comment
12
+ task name, *t.arg_names do |_, args|
13
+ # values_at is broken on Rake::TaskArguments
14
+ args = t.arg_names.map { |a| args[a] }
15
+ t.invoke(*args)
16
+ end
17
+ end
18
+
8
19
  RSpec::Core::RakeTask.new(:spec)
9
20
 
10
21
  YARD::Rake::YardocTask.new do |t|
11
22
  t.files = ["lib/**/*.rb"]
12
23
  end
13
24
 
25
+ alias_task "lint", "standard"
26
+ alias_task "lint:fix", "standard:fix"
27
+
14
28
  task default: [:standard, :spec]
@@ -0,0 +1,7 @@
1
+ en:
2
+ wicked:
3
+ pipeline:
4
+ step:
5
+ next_step: "Next"
6
+ previous_step: "Previous"
7
+ finish: "Finish"
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/erb"
4
+ require_relative "../../../../wicked/pipeline/helpers"
5
+
6
+ module Erb
7
+ module Wicked
8
+ module Pipeline
9
+ class ControllerGenerator < Erb::Generators::Base
10
+ include ::Wicked::Pipeline::Generators::Helpers
11
+
12
+ hide!
13
+
14
+ argument :resource_name, required: true, desc: "The name of the resource associated with the pipeline"
15
+ argument :pipeline_name, required: true, desc: "The name of the pipeline"
16
+ argument :steps, type: :array, default: [], desc: "List of steps"
17
+
18
+ source_root File.expand_path("templates", __dir__)
19
+
20
+ def copy_step_partial_layout_view
21
+ empty_directory base_path
22
+
23
+ template "_step.html.erb", File.join(base_path, "_step.html.erb")
24
+ end
25
+
26
+ def create_step_view_files
27
+ steps.each do |step_name|
28
+ @step_name = step_name
29
+
30
+ template "view.html.erb", File.join(base_path, "#{step_name}.html.erb")
31
+ end
32
+
33
+ @step_name = nil
34
+ end
35
+
36
+ private
37
+
38
+ def base_path
39
+ @_base_path ||= File.join("app/views", class_path, file_name)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,41 @@
1
+ <nav aria-label="breadcrumb">
2
+ <ol>
3
+ <%% steps_metadata.each do |step_name, step_metadata| %>
4
+ <li class="<%%= "active-step" if step_metadata[:active] %> <%%= "valid-step" if step_metadata[:valid] %> <%%= "<%= pipeline_name.dasherize %>-#{step_name.dasherize}-step" %>">
5
+ <%%= link_to_if step_metadata[:accessible], t(".breadcrumbs.#{step_name}"), step_metadata[:url] %>
6
+ </li>
7
+ <%% end %>
8
+ </ol>
9
+ </nav>
10
+
11
+ <div>
12
+ <%% if I18n.exists?("#{step_i18n_scope}.subtitle", I18n.locale) %>
13
+ <h2>
14
+ <%%= t "subtitle", scope: step_i18n_scope %>
15
+ </h2>
16
+ <%% end %>
17
+
18
+ <%%= form_with model: <%= resource_name %>, url: step_path, method: :patch, html: { id: "<%= resource_name.dasherize %>-form" } do |f| %>
19
+ <%%= yield(f) %>
20
+
21
+ <%% unless local_assigns[:skip_form_buttons] %>
22
+ <div>
23
+ <%% unless steps_pipeline.first_step?(step_processor) %>
24
+ <%%= link_to step_path(step_name: steps_pipeline.previous_step(step_processor).step_name) do %>
25
+ <%%= t "previous_step", scope: step_i18n_scope, default: t("steps.previous_step", scope: Wicked::Pipeline::Engine.i18n_scope) %>
26
+ <%% end %>
27
+ <%% end %>
28
+
29
+ <%% if steps_metadata.keys.last == step %>
30
+ <%%= button_tag type: "submit" do %>
31
+ <%%= t "finish", scope: step_i18n_scope, default: t("steps.finish", scope: Wicked::Pipeline::Engine.i18n_scope) %>
32
+ <%% end %>
33
+ <%% else %>
34
+ <%%= button_tag type: "submit" do %>
35
+ <%%= t "next_step", scope: step_i18n_scope, default: t("steps.next_step", scope: Wicked::Pipeline::Engine.i18n_scope) %>
36
+ <%% end %>
37
+ <%% end %>
38
+ </div>
39
+ <%% end %>
40
+ <%% end %>
41
+ </div>
@@ -0,0 +1,4 @@
1
+ <%%= render layout: "#{controller.controller_path}/step", locals: { <%= resource_name %>: @<%= resource_name %> } do |f| %>
2
+ <%%# f.label :attribute %>
3
+ <%%# f.text_field :attribute %>
4
+ <%% end %>
@@ -2,6 +2,8 @@ Description:
2
2
  Generates a new pipeline. Pass the pipeline name, either CamelCased or
3
3
  under_scored, and an optional list of steps.
4
4
 
5
+ Duplicate steps will be ignored.
6
+
5
7
  To create a pipeline within a module, specify the pipeline name as a
6
8
  path like "parent_module/pipeline_name".
7
9
 
@@ -0,0 +1,30 @@
1
+ Description:
2
+ Generates a new steps controller. Pass the controller name, the resource name,
3
+ the pipeline name and a list of steps, either CamelCased or under_scored.
4
+
5
+ If either the resource name or the pipeline name are missing they will be
6
+ infered from the controller name.
7
+
8
+ Duplicate steps will be ignored.
9
+
10
+ To create a controller within a module, specify the controller name as a
11
+ path like 'parent_module/controller_name'.
12
+
13
+ This generates a controller class in app/controllers and invokes the
14
+ template engine generators. If no steps were provided then only the
15
+ partial step view will be created.
16
+
17
+ It will also create a locales file for the controller for each available locale.
18
+
19
+ Example:
20
+ `bin/rails generate wicked:pipeline:controller suitability User questionnaire identification experience objectives risks`
21
+
22
+ CreditCards controller with URLs like /credit_cards/debit.
23
+ Controller: app/controllers/suitability_steps_controller.rb
24
+ Views: app/views/suitability_steps/_step.html.erb
25
+ app/views/suitability/identification.html.erb
26
+ app/views/suitability/experience.html.erb
27
+ app/views/suitability/objectives.html.erb
28
+ app/views/suitability/risks.html.erb
29
+ I18n: config/locales/views/suitability_steps.en.yml
30
+ Route resources :suitability_steps, only: [:show, :update], param: :user_id
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/named_base"
4
+ require_relative "../helpers"
5
+
6
+ module Wicked
7
+ module Pipeline
8
+ class ControllerGenerator < Rails::Generators::NamedBase
9
+ include ::Wicked::Pipeline::Generators::Helpers
10
+
11
+ argument :resource, optional: true, desc: "The resource associated with the pipeline"
12
+ argument :pipeline, optional: true, desc: "The pipeline used in the controller"
13
+ argument :steps, optional: true, type: :array, default: [], desc: "The pipeline's steps"
14
+
15
+ class_option :generate_pipeline, type: :boolean, default: false, desc: "Generate the pipeline class"
16
+ class_option :generate_steps, type: :boolean, default: false, desc: "Generate the pipeline's step classes"
17
+ class_option :skip_locales, type: :boolean, default: false, desc: "Don't generate locale files"
18
+ class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
19
+
20
+ check_class_collision suffix: "StepsController"
21
+
22
+ source_root File.expand_path("templates", __dir__)
23
+
24
+ def create_controller_files
25
+ template "controller.rb", File.join("app/controllers", class_path, "#{file_name}_steps_controller.rb")
26
+ end
27
+
28
+ hook_for :template_engine, as: "wicked:pipeline:controller" do |generator|
29
+ invoke generator, [
30
+ remove_possible_suffix(name),
31
+ resource_name,
32
+ remove_possible_suffix(pipeline_name, "pipeline"),
33
+ step_names
34
+ ]
35
+ end
36
+
37
+ def create_locale_file
38
+ return if options[:skip_locales]
39
+
40
+ @structure = hashify_locale_keypath([*class_path, "#{file_name}_steps"].join("."))
41
+
42
+ available_locales.each do |locale|
43
+ @locale = locale
44
+ template "locale.yml", File.join("config/locales/views", class_path, "#{file_name}_steps.#{locale}.yml")
45
+ end
46
+ end
47
+
48
+ def add_routes
49
+ return if options[:skip_routes]
50
+
51
+ routing_code = "resources :#{file_name}_steps, only: [:show, :update], param: :#{resource_param_name}"
52
+
53
+ route routing_code, namespace: regular_class_path
54
+ end
55
+
56
+ def create_pipeline_file
57
+ return unless options[:generate_pipeline]
58
+
59
+ pipeline_args = [pipeline]
60
+ pipeline_args.concat(steps) if options[:generate_steps]
61
+ pipeline_args.concat(options_as_switches)
62
+
63
+ Rails::Generators.invoke "wicked:pipeline", pipeline_args, behavior: behavior
64
+ end
65
+
66
+ def create_step_files
67
+ return if options[:generate_pipeline] || !options[:generate_steps]
68
+
69
+ steps.each do |step|
70
+ Rails::Generators.invoke "wicked:pipeline:step", [step, *options_as_switches], behavior: behavior
71
+ end
72
+ end
73
+
74
+ private
75
+
76
+ def file_name
77
+ @_file_name ||= remove_possible_suffix(super)
78
+ end
79
+
80
+ def resource
81
+ @resource ||= file_name.singularize
82
+ end
83
+
84
+ def pipeline
85
+ @pipeline ||= file_name.singularize
86
+ end
87
+
88
+ def steps
89
+ @_steps ||= (@steps.presence || []).uniq
90
+ end
91
+
92
+ def resource_class_name
93
+ @_resource_class ||= resource.camelize
94
+ end
95
+
96
+ def resource_name
97
+ @_resource_name ||= resource_class_name.demodulize.underscore
98
+ end
99
+
100
+ def resource_param_name
101
+ @_resource_param_name ||= "#{resource_name}_id"
102
+ end
103
+
104
+ def pipeline_class_name
105
+ @_pipeline_class_name ||=
106
+ if pipeline.match?(/\/|::/)
107
+ String.new(remove_possible_suffix(pipeline).camelize) << "Pipeline"
108
+ else
109
+ String.new((class_path + [remove_possible_suffix(pipeline)]).map!(&:camelize).join("::")) << "Pipeline"
110
+ end
111
+ end
112
+
113
+ def pipeline_name
114
+ @_pipeline_name ||= pipeline_class_name.underscore.parameterize.underscore
115
+ end
116
+
117
+ def step_names
118
+ @_step_names ||= steps.map do |step_name|
119
+ remove_possible_suffix(step_name).camelize.demodulize.underscore
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ <% if namespaced? -%>
4
+ require_dependency "<%= namespaced_path %>/application_controller"
5
+
6
+ <% end -%>
7
+ <% module_namespacing do -%>
8
+ class <%= class_name %>StepsController < ::Wicked::Pipeline::BaseStepsController
9
+ def show
10
+ super do
11
+ @<%= resource_name %> = find_resource
12
+ @step_processor = step_class.new(@<%= resource_name %>)
13
+ end
14
+ end
15
+
16
+ def update
17
+ super do
18
+ @<%= resource_name %> = find_resource
19
+ @step_processor = step_class.new(@<%= resource_name %>, params.require(:<%= resource_name %>))
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def resource_param_name
26
+ :<%= resource_param_name %>
27
+ end
28
+
29
+ def steps_pipeline
30
+ <%= pipeline_class_name %>
31
+ end
32
+
33
+ def find_resource
34
+ <%= resource_class_name %>.find(params[resource_param_name])
35
+ end
36
+ end
37
+ <% end -%>
@@ -0,0 +1,15 @@
1
+ <%= @locale %>:
2
+ <%= indent(@structure.to_yaml.sub("---\n", ""), 2) -%>
3
+ <% indented(((file_path.count("/") + 1) * 2) + 2) do -%>
4
+ step:
5
+ breadcrumbs:
6
+ <% step_names.each do |step_name| -%>
7
+ <%= step_name %>: "<%= step_name.humanize %>"
8
+ <% end -%>
9
+
10
+ <% step_names.each do |step_name| -%>
11
+ <%= step_name %>:
12
+ subtitle: "<%= step_name.humanize %>"
13
+ <%= "\n" unless step_name == step_names.last -%>
14
+ <% end -%>
15
+ <% end -%>
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wicked
4
+ module Pipeline
5
+ module Generators
6
+ module Helpers
7
+ def available_locales
8
+ @_available_locales ||= I18n.available_locales.presence || [I18n.default_locale.presence || :en]
9
+ end
10
+
11
+ def hashify_locale_keypath(keypath)
12
+ keypath.split(".").reverse.inject(nil) { |assigned_value, key| {key.to_s => assigned_value} }
13
+ end
14
+
15
+ def indented(indentation = 2, &block)
16
+ concat(indent(capture(&block), indentation))
17
+ end
18
+
19
+ def remove_possible_suffix(name, *suffixes)
20
+ regex =
21
+ if suffixes.empty?
22
+ /_?(?:(:?steps_?)?controller|pipeline|step)\z/i
23
+ else
24
+ /_?(?:#{Regexp.union(*suffixes)})\z/i
25
+ end
26
+
27
+ name.sub(regex, "")
28
+ end
29
+
30
+ def options_as_switches
31
+ @options_as_switches ||= options.compact_blank.each_with_object([]) do |(option, value), obj|
32
+ next unless value
33
+
34
+ obj << "--#{option.to_s.dasherize}"
35
+ obj << value.presence unless value == true
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rails/generators/named_base"
4
+ require_relative "helpers"
4
5
 
5
6
  module Wicked
6
7
  class PipelineGenerator < Rails::Generators::NamedBase
8
+ include ::Wicked::Pipeline::Generators::Helpers
9
+
7
10
  check_class_collision suffix: "Pipeline"
8
11
 
9
12
  source_root File.expand_path("templates", __dir__)
@@ -25,11 +28,11 @@ module Wicked
25
28
  private
26
29
 
27
30
  def file_name
28
- @_file_name ||= remove_possible_suffix(super)
31
+ @_file_name ||= remove_possible_suffix(super, "pipeline")
29
32
  end
30
33
 
31
- def remove_possible_suffix(name)
32
- name.sub(/_?pipeline\z/i, "")
34
+ def steps
35
+ @_steps ||= (@steps.presence || []).uniq
33
36
  end
34
37
 
35
38
  def step_classes
@@ -41,14 +44,5 @@ module Wicked
41
44
  end
42
45
  end
43
46
  end
44
-
45
- def options_as_switches
46
- @options_as_switches ||= options.compact_blank.each_with_object([]) do |(option, value), obj|
47
- next unless value
48
-
49
- obj << "--#{option.to_s.dasherize}"
50
- obj << value.presence unless value == true
51
- end
52
- end
53
47
  end
54
48
  end
@@ -8,8 +8,11 @@ Description:
8
8
  To create a step within a module, specify the step name as a
9
9
  path like "parent_module/step_name".
10
10
 
11
+ It will also create locales files for the step for each available locale.
12
+
11
13
  Example:
12
14
  `bin/rails generate wicked:pipeline:step UserIdendification name is_active:boolean hobbies:array`
13
15
 
14
16
  UserIdentificationStep.
15
17
  Step: app/steps/user_identification_step.rb
18
+ I18n: config/locales/steps/user_identification_step.en.yml
@@ -1,30 +1,42 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rails/generators/named_base"
4
+ require_relative "../helpers"
4
5
 
5
6
  module Wicked
6
7
  module Pipeline
7
8
  class StepGenerator < Rails::Generators::NamedBase
9
+ include ::Wicked::Pipeline::Generators::Helpers
10
+
8
11
  check_class_collision suffix: "Step"
9
12
 
10
13
  source_root File.expand_path("templates", __dir__)
11
14
 
12
15
  argument :attributes, type: :array, default: [], banner: "attribute[:type] attribute[:type]"
13
16
 
17
+ class_option :skip_locales, type: :boolean, default: false, desc: "Don't generate locale files"
18
+
14
19
  def create_step_file
15
20
  template "step.rb", File.join("app/steps", class_path, "#{file_name}_step.rb")
16
21
  end
17
22
 
18
23
  hook_for :test_framework, as: "wicked:pipeline:step"
19
24
 
20
- private
25
+ def create_locale_file
26
+ return if options[:skip_locales]
21
27
 
22
- def file_name
23
- @_file_name ||= remove_possible_suffix(super)
28
+ @structure = hashify_locale_keypath([*class_path, "#{file_name}_step"].join("."))
29
+
30
+ available_locales.each do |locale|
31
+ @locale = locale
32
+ template "locale.yml", File.join("config/locales/steps", class_path, "#{file_name}_step.#{locale}.yml")
33
+ end
24
34
  end
25
35
 
26
- def remove_possible_suffix(name)
27
- name.sub(/_?step\z/i, "")
36
+ private
37
+
38
+ def file_name
39
+ @_file_name ||= remove_possible_suffix(super, "step")
28
40
  end
29
41
 
30
42
  def array_attributes
@@ -0,0 +1,17 @@
1
+ <%= @locale %>:
2
+ steps:
3
+ <%= indent(@structure.to_yaml.sub("---\n", ""), 4) -%>
4
+ <% indented(((file_path.count("/") + 1) * 2) + 4) do -%>
5
+ # blocking_reasons:
6
+ # blocking_reasons:
7
+ # not_compatible: "This answer is not compatible with our offer."
8
+ <% end -%>
9
+
10
+ activemodel:
11
+ errors:
12
+ models:
13
+ <%= file_path %>_step:
14
+ # required: "is required"
15
+ # attributes:
16
+ # total_percentage:
17
+ # total_percentage_must_equal_100_percent: "Total must be 100%"
@@ -18,7 +18,7 @@ module Wicked
18
18
  initializer :i18n_load_path do |app|
19
19
  ActiveSupport.on_load(:i18n) do
20
20
  # Prepend the engine i18n load path so that translations can be overriden in the main app
21
- engine_i18n_load_path = Dir[Engine.root.join("config", "locales", "**", "wicked", "pipeline", "**", "*.yml").to_s]
21
+ engine_i18n_load_path = Dir[Engine.root.join("config", "locales", "wicked", "pipeline", "*.yml").to_s]
22
22
  app.config.i18n.load_path = engine_i18n_load_path.concat(app.config.i18n.load_path)
23
23
  end
24
24
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Wicked
4
4
  module Pipeline
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
@@ -25,10 +25,10 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_dependency "railties", ">= 6.1", "< 7"
29
- spec.add_dependency "activesupport", ">= 6.1", "< 7"
30
- spec.add_dependency "activemodel", ">= 6.1", "< 7"
31
- spec.add_dependency "actionpack", ">= 6.1", "< 7"
28
+ spec.add_dependency "railties", ">= 6.1"
29
+ spec.add_dependency "activesupport", ">= 6.1"
30
+ spec.add_dependency "activemodel", ">= 6.1"
31
+ spec.add_dependency "actionpack", ">= 6.1"
32
32
 
33
33
  spec.add_dependency "wicked", "~> 1.3"
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wicked-pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Audi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-17 00:00:00.000000000 Z
11
+ date: 2022-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '6.1'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '7'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '6.1'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '7'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: activesupport
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -37,9 +31,6 @@ dependencies:
37
31
  - - ">="
38
32
  - !ruby/object:Gem::Version
39
33
  version: '6.1'
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '7'
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
@@ -47,9 +38,6 @@ dependencies:
47
38
  - - ">="
48
39
  - !ruby/object:Gem::Version
49
40
  version: '6.1'
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '7'
53
41
  - !ruby/object:Gem::Dependency
54
42
  name: activemodel
55
43
  requirement: !ruby/object:Gem::Requirement
@@ -57,9 +45,6 @@ dependencies:
57
45
  - - ">="
58
46
  - !ruby/object:Gem::Version
59
47
  version: '6.1'
60
- - - "<"
61
- - !ruby/object:Gem::Version
62
- version: '7'
63
48
  type: :runtime
64
49
  prerelease: false
65
50
  version_requirements: !ruby/object:Gem::Requirement
@@ -67,9 +52,6 @@ dependencies:
67
52
  - - ">="
68
53
  - !ruby/object:Gem::Version
69
54
  version: '6.1'
70
- - - "<"
71
- - !ruby/object:Gem::Version
72
- version: '7'
73
55
  - !ruby/object:Gem::Dependency
74
56
  name: actionpack
75
57
  requirement: !ruby/object:Gem::Requirement
@@ -77,9 +59,6 @@ dependencies:
77
59
  - - ">="
78
60
  - !ruby/object:Gem::Version
79
61
  version: '6.1'
80
- - - "<"
81
- - !ruby/object:Gem::Version
82
- version: '7'
83
62
  type: :runtime
84
63
  prerelease: false
85
64
  version_requirements: !ruby/object:Gem::Requirement
@@ -87,9 +66,6 @@ dependencies:
87
66
  - - ">="
88
67
  - !ruby/object:Gem::Version
89
68
  version: '6.1'
90
- - - "<"
91
- - !ruby/object:Gem::Version
92
- version: '7'
93
69
  - !ruby/object:Gem::Dependency
94
70
  name: wicked
95
71
  requirement: !ruby/object:Gem::Requirement
@@ -120,6 +96,10 @@ files:
120
96
  - README.md
121
97
  - Rakefile
122
98
  - app/controllers/wicked/pipeline/base_steps_controller.rb
99
+ - config/locales/wicked/pipeline/en.yml
100
+ - lib/generators/erb/wicked/pipeline/controller/controller_generator.rb
101
+ - lib/generators/erb/wicked/pipeline/controller/templates/_step.html.erb
102
+ - lib/generators/erb/wicked/pipeline/controller/templates/view.html.erb.tt
123
103
  - lib/generators/rspec/wicked/pipeline/USAGE
124
104
  - lib/generators/rspec/wicked/pipeline/pipeline_generator.rb
125
105
  - lib/generators/rspec/wicked/pipeline/step/USAGE
@@ -127,9 +107,15 @@ files:
127
107
  - lib/generators/rspec/wicked/pipeline/step/templates/step_spec.rb.tt
128
108
  - lib/generators/rspec/wicked/pipeline/templates/pipeline_spec.rb.tt
129
109
  - lib/generators/wicked/pipeline/USAGE
110
+ - lib/generators/wicked/pipeline/controller/USAGE
111
+ - lib/generators/wicked/pipeline/controller/controller_generator.rb
112
+ - lib/generators/wicked/pipeline/controller/templates/controller.rb.tt
113
+ - lib/generators/wicked/pipeline/controller/templates/locale.yml
114
+ - lib/generators/wicked/pipeline/helpers.rb
130
115
  - lib/generators/wicked/pipeline/pipeline_generator.rb
131
116
  - lib/generators/wicked/pipeline/step/USAGE
132
117
  - lib/generators/wicked/pipeline/step/step_generator.rb
118
+ - lib/generators/wicked/pipeline/step/templates/locale.yml
133
119
  - lib/generators/wicked/pipeline/step/templates/step.rb.tt
134
120
  - lib/generators/wicked/pipeline/templates/pipeline.rb.tt
135
121
  - lib/wicked/pipeline.rb