Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from NikitaNaumenko/add_generators
add generators
- Loading branch information
Showing
4 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Description: | ||
Generates a form for a model with the given name. | ||
|
||
Example: | ||
rails generate active_form_model:form sign_up --model=user | ||
|
||
This will create: | ||
app/forms/user_form.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveFormModel | ||
module Generators | ||
class FormGenerator < ::Rails::Generators::NamedBase | ||
class_option :model, type: :string | ||
source_root File.expand_path('templates', __dir__) | ||
|
||
def create_form | ||
template 'form.rb', File.join('app/forms', class_path, "#{file_name}_form.rb") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% module_namespacing do -%> | ||
class <%= class_name %>Form < <%= options['model'].classify %> | ||
include ActiveFormModel | ||
end | ||
<% end -%> |