organism-generators 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +92 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rspec +8 -0
- data/bin/setup +8 -0
- data/lib/organism/generators.rb +22 -0
- data/lib/organism/generators/base.rb +10 -0
- data/lib/organism/generators/cells/USAGE +8 -0
- data/lib/organism/generators/cells/cells_generator.rb +101 -0
- data/lib/organism/generators/cells/templates/cell/cell.rb.tt +18 -0
- data/lib/organism/generators/cells/templates/cell/list.rb.tt +2 -0
- data/lib/organism/generators/cells/templates/cell/show.rb.tt +2 -0
- data/lib/organism/generators/cells/templates/form/cell.rb.tt +8 -0
- data/lib/organism/generators/cells/templates/form/show.rb.tt +7 -0
- data/lib/organism/generators/cells/templates/list/cell.rb.tt +32 -0
- data/lib/organism/generators/cells/templates/table/cell.rb.tt +32 -0
- data/lib/organism/generators/concept/USAGE +8 -0
- data/lib/organism/generators/concept/concept_generator.rb +75 -0
- data/lib/organism/generators/concept/templates/contracts/create.rb.tt +11 -0
- data/lib/organism/generators/concept/templates/contracts/update.rb.tt +6 -0
- data/lib/organism/generators/concept/templates/create.rb.tt +6 -0
- data/lib/organism/generators/concept/templates/present.rb.tt +12 -0
- data/lib/organism/generators/concept/templates/spec/create.rb.tt +15 -0
- data/lib/organism/generators/concept/templates/spec/update.rb.tt +17 -0
- data/lib/organism/generators/concept/templates/update.rb.tt +3 -0
- data/lib/organism/generators/controller/USAGE +8 -0
- data/lib/organism/generators/controller/controller_generator.rb +44 -0
- data/lib/organism/generators/controller/templates/controller.rb.tt +72 -0
- data/lib/organism/generators/generator_helper.rb +106 -0
- data/lib/organism/generators/scaffold/USAGE +8 -0
- data/lib/organism/generators/scaffold/scaffold_generator.rb +12 -0
- data/lib/organism/generators/version.rb +5 -0
- data/lib/organism/generators/views/USAGE +8 -0
- data/lib/organism/generators/views/templates/edit.rb.tt +8 -0
- data/lib/organism/generators/views/templates/index.rb.tt +4 -0
- data/lib/organism/generators/views/templates/new.rb.tt +8 -0
- data/lib/organism/generators/views/templates/show.rb.tt +4 -0
- data/lib/organism/generators/views/views_generator.rb +34 -0
- data/organism-generators.gemspec +35 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2c2ab838d78d3a2b059712f53e60a61947b8c49b0ea70f7b380cedf87b8b6767
|
4
|
+
data.tar.gz: c9bc7b056f4f6b2865aa51511680b4ba1d5abc4ee621451eaac8dd86a675696d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 38f8811f1f517286b15f5afc156459cc937a96b0710c6da2f65e3619642f42ef2fb33ca098df1db3f3fa538119c5fabff02b00e7c092ff15fb9d8d5919b2227f
|
7
|
+
data.tar.gz: 9b1f94d49da3c3538b1771081c75d0eb42637f1f7ee9b714d3f72d19d36dacecb5b8f165ed3c0e5ea869464ca8edba8322fb8a983e9f2a65815cdf123a19157d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
organism-generators (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionpack (6.1.3.1)
|
10
|
+
actionview (= 6.1.3.1)
|
11
|
+
activesupport (= 6.1.3.1)
|
12
|
+
rack (~> 2.0, >= 2.0.9)
|
13
|
+
rack-test (>= 0.6.3)
|
14
|
+
rails-dom-testing (~> 2.0)
|
15
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
16
|
+
actionview (6.1.3.1)
|
17
|
+
activesupport (= 6.1.3.1)
|
18
|
+
builder (~> 3.1)
|
19
|
+
erubi (~> 1.4)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
22
|
+
activesupport (6.1.3.1)
|
23
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
24
|
+
i18n (>= 1.6, < 2)
|
25
|
+
minitest (>= 5.1)
|
26
|
+
tzinfo (~> 2.0)
|
27
|
+
zeitwerk (~> 2.3)
|
28
|
+
builder (3.2.4)
|
29
|
+
byebug (11.1.3)
|
30
|
+
concurrent-ruby (1.1.8)
|
31
|
+
crass (1.0.6)
|
32
|
+
diff-lcs (1.4.4)
|
33
|
+
erubi (1.10.0)
|
34
|
+
generator_spec (0.9.4)
|
35
|
+
activesupport (>= 3.0.0)
|
36
|
+
railties (>= 3.0.0)
|
37
|
+
i18n (1.8.10)
|
38
|
+
concurrent-ruby (~> 1.0)
|
39
|
+
loofah (2.9.1)
|
40
|
+
crass (~> 1.0.2)
|
41
|
+
nokogiri (>= 1.5.9)
|
42
|
+
method_source (1.0.0)
|
43
|
+
mini_portile2 (2.5.0)
|
44
|
+
minitest (5.14.4)
|
45
|
+
nokogiri (1.11.3)
|
46
|
+
mini_portile2 (~> 2.5.0)
|
47
|
+
racc (~> 1.4)
|
48
|
+
racc (1.5.2)
|
49
|
+
rack (2.2.3)
|
50
|
+
rack-test (1.1.0)
|
51
|
+
rack (>= 1.0, < 3)
|
52
|
+
rails-dom-testing (2.0.3)
|
53
|
+
activesupport (>= 4.2.0)
|
54
|
+
nokogiri (>= 1.6)
|
55
|
+
rails-html-sanitizer (1.3.0)
|
56
|
+
loofah (~> 2.3)
|
57
|
+
railties (6.1.3.1)
|
58
|
+
actionpack (= 6.1.3.1)
|
59
|
+
activesupport (= 6.1.3.1)
|
60
|
+
method_source
|
61
|
+
rake (>= 0.8.7)
|
62
|
+
thor (~> 1.0)
|
63
|
+
rake (13.0.3)
|
64
|
+
rspec (3.10.0)
|
65
|
+
rspec-core (~> 3.10.0)
|
66
|
+
rspec-expectations (~> 3.10.0)
|
67
|
+
rspec-mocks (~> 3.10.0)
|
68
|
+
rspec-core (3.10.1)
|
69
|
+
rspec-support (~> 3.10.0)
|
70
|
+
rspec-expectations (3.10.1)
|
71
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
72
|
+
rspec-support (~> 3.10.0)
|
73
|
+
rspec-mocks (3.10.2)
|
74
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
75
|
+
rspec-support (~> 3.10.0)
|
76
|
+
rspec-support (3.10.2)
|
77
|
+
thor (1.1.0)
|
78
|
+
tzinfo (2.0.4)
|
79
|
+
concurrent-ruby (~> 1.0)
|
80
|
+
zeitwerk (2.4.2)
|
81
|
+
|
82
|
+
PLATFORMS
|
83
|
+
ruby
|
84
|
+
|
85
|
+
DEPENDENCIES
|
86
|
+
byebug (~> 11.1.3)
|
87
|
+
generator_spec (~> 0.9.4)
|
88
|
+
organism-generators!
|
89
|
+
rspec (~> 3.10.0)
|
90
|
+
|
91
|
+
BUNDLED WITH
|
92
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Nolan Tait
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Organism::Generators
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/organism/generators`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'organism-generators'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install organism-generators
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/organism-generators.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "organism/generators"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/rspec
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'organism/generators/version'
|
2
|
+
require 'organism/generators/base'
|
3
|
+
require 'organism/generators/cells/cells_generator'
|
4
|
+
require 'organism/generators/concept/concept_generator'
|
5
|
+
require 'organism/generators/controller/controller_generator'
|
6
|
+
require 'organism/generators/views/views_generator'
|
7
|
+
require 'organism/generators/scaffold/scaffold_generator'
|
8
|
+
|
9
|
+
module Organism
|
10
|
+
module Generators
|
11
|
+
class Error < StandardError; end
|
12
|
+
# Your code goes here...
|
13
|
+
|
14
|
+
def self.root
|
15
|
+
File.expand_path(__dir__)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.tmp
|
19
|
+
File.join(root, '..', '..', 'tmp')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Organism
|
2
|
+
class CellsGenerator < Generators::Base
|
3
|
+
source_root File.expand_path('templates', __dir__)
|
4
|
+
|
5
|
+
argument :actions, type: :array, default: [], banner: 'action action'
|
6
|
+
class_option :model, type: :string, default: ''
|
7
|
+
class_option :collections, type: :array, default: ['list']
|
8
|
+
|
9
|
+
def create_cells
|
10
|
+
cells.each do |cell|
|
11
|
+
create_cell(cell)
|
12
|
+
|
13
|
+
next if cell == 'list'
|
14
|
+
next if cell == 'table'
|
15
|
+
|
16
|
+
create_cell_view(cell)
|
17
|
+
|
18
|
+
next unless cell == 'cell'
|
19
|
+
next unless cells.include?('list')
|
20
|
+
|
21
|
+
create_cell_view(cell, 'list')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def create_cell_view(type, view = 'show')
|
28
|
+
template(
|
29
|
+
"#{type}/#{view}.rb",
|
30
|
+
File.join('app/cells', singular_file_path, "#{type}/#{view}.erb")
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_cell(type)
|
35
|
+
template(
|
36
|
+
"#{type}/cell.rb",
|
37
|
+
File.join('app/cells', singular_file_path, "#{type}.rb")
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def singular_file_path
|
42
|
+
model_class_path.join('/')
|
43
|
+
end
|
44
|
+
|
45
|
+
def cells
|
46
|
+
[].tap do |array|
|
47
|
+
array << 'form' if form?
|
48
|
+
array << 'cell' if cell?
|
49
|
+
array << 'list' if list?
|
50
|
+
array << 'table' if table?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def form?
|
55
|
+
new? || edit?
|
56
|
+
end
|
57
|
+
|
58
|
+
def list?
|
59
|
+
collections.include?('list')
|
60
|
+
end
|
61
|
+
|
62
|
+
def table?
|
63
|
+
collections.include?('table')
|
64
|
+
end
|
65
|
+
|
66
|
+
def cell?
|
67
|
+
list? || table? || show?
|
68
|
+
end
|
69
|
+
|
70
|
+
def base_cell_class
|
71
|
+
'ApplicationCell'
|
72
|
+
end
|
73
|
+
|
74
|
+
def form_helper_class
|
75
|
+
'Forms'
|
76
|
+
end
|
77
|
+
|
78
|
+
def collections
|
79
|
+
options[:collections]
|
80
|
+
end
|
81
|
+
|
82
|
+
def nested_namespace(&block)
|
83
|
+
content = capture(&block)
|
84
|
+
content = wrap_model(indent(content))
|
85
|
+
content = nest_content(content)
|
86
|
+
concat("#{content}\n")
|
87
|
+
end
|
88
|
+
|
89
|
+
def cell_component_style
|
90
|
+
singular_table_name.gsub('_', '-')
|
91
|
+
end
|
92
|
+
|
93
|
+
def list_component_style
|
94
|
+
"#{cell_component_style}--list"
|
95
|
+
end
|
96
|
+
|
97
|
+
def table_component_style
|
98
|
+
"#{cell_component_style}--table"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% nested_namespace do -%>
|
2
|
+
class Cell < <%= base_cell_class %>
|
3
|
+
def show
|
4
|
+
render
|
5
|
+
end
|
6
|
+
<% if list? -%>
|
7
|
+
|
8
|
+
def list
|
9
|
+
render
|
10
|
+
end
|
11
|
+
<% end -%>
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def component_style
|
16
|
+
'<%= cell_component_style %>'
|
17
|
+
end
|
18
|
+
end<% end -%>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<% nested_namespace do -%>
|
2
|
+
class List < <%= base_cell_class %>
|
3
|
+
def show
|
4
|
+
cell(
|
5
|
+
Ui::List,
|
6
|
+
<%= table_name %>,
|
7
|
+
**list_options
|
8
|
+
).()
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def list_options
|
14
|
+
{
|
15
|
+
actions: actions_list,
|
16
|
+
header: header,
|
17
|
+
style: style
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def header
|
22
|
+
content_tag(:h5, '<%= human_name.pluralize %>')
|
23
|
+
end
|
24
|
+
|
25
|
+
def component_style
|
26
|
+
'<%= list_component_style %>'
|
27
|
+
end
|
28
|
+
|
29
|
+
def <%= table_name %>
|
30
|
+
model
|
31
|
+
end
|
32
|
+
end<% end -%>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<% nested_namespace do -%>
|
2
|
+
class Table < <%= base_cell_class %>
|
3
|
+
def show
|
4
|
+
cell(
|
5
|
+
Ui::Table,
|
6
|
+
<%= table_name %>,
|
7
|
+
**table_options
|
8
|
+
).()
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def table_options
|
14
|
+
{
|
15
|
+
actions: actions_list,
|
16
|
+
header: header,
|
17
|
+
style: style
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def header
|
22
|
+
content_tag(:h5, '<%= human_name.pluralize %>')
|
23
|
+
end
|
24
|
+
|
25
|
+
def component_style
|
26
|
+
'<%= table_component_style %>'
|
27
|
+
end
|
28
|
+
|
29
|
+
def <%= table_name %>
|
30
|
+
model
|
31
|
+
end
|
32
|
+
end<% end -%>
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Organism
|
2
|
+
class ConceptGenerator < Generators::Base
|
3
|
+
source_root File.expand_path('templates', __dir__)
|
4
|
+
|
5
|
+
argument :actions, type: :array, default: [], banner: 'action action'
|
6
|
+
|
7
|
+
def create_concept_files
|
8
|
+
create_present_concept
|
9
|
+
create_create_concept
|
10
|
+
create_update_concept
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def create_present_concept
|
16
|
+
create_concept_file('present')
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_create_concept
|
20
|
+
create_concept_file('create')
|
21
|
+
create_concept_spec('create')
|
22
|
+
create_contract_file('create')
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_update_concept
|
26
|
+
create_concept_file('update')
|
27
|
+
create_concept_spec('update')
|
28
|
+
create_contract_file('update')
|
29
|
+
end
|
30
|
+
|
31
|
+
def singular_file_path
|
32
|
+
model_class_path.join('/')
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_concept_file(type)
|
36
|
+
template(
|
37
|
+
"#{type}.rb",
|
38
|
+
File.join('app/concepts', singular_file_path, "#{type}.rb")
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_concept_spec(type)
|
43
|
+
template(
|
44
|
+
"spec/#{type}.rb",
|
45
|
+
File.join('spec/concepts', singular_file_path, "#{type}_spec.rb")
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_contract_file(type)
|
50
|
+
template(
|
51
|
+
"contracts/#{type}.rb",
|
52
|
+
File.join('app/concepts', singular_file_path, 'contracts', "#{type}.rb")
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def base_operation_class
|
57
|
+
'ApplicationOperation'
|
58
|
+
end
|
59
|
+
|
60
|
+
def base_contract_class
|
61
|
+
'ApplicationContract'
|
62
|
+
end
|
63
|
+
|
64
|
+
def contract_class(action)
|
65
|
+
model_class_path.concat(['contracts', action]).map(&:camelize).join('::')
|
66
|
+
end
|
67
|
+
|
68
|
+
def nested_namespace(&block)
|
69
|
+
content = capture(&block)
|
70
|
+
content = wrap_model(indent(content))
|
71
|
+
content = nest_content(content)
|
72
|
+
concat("#{content}\n")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<% nested_namespace do -%>
|
2
|
+
class Present < <%= base_operation_class %>
|
3
|
+
step Model(<%= namespaced_model_class %>, :find_by)
|
4
|
+
step Contract::Build(constant: <%= contract_class('update')%>),
|
5
|
+
Output(:success) => End(:success)
|
6
|
+
|
7
|
+
fail Model(<%= namespaced_model_class %>, :new),
|
8
|
+
id: :build_new,
|
9
|
+
Output(:success) => Track(:success)
|
10
|
+
step Contract::Build(constant: <%= contract_class('create') %>),
|
11
|
+
id: :build_new_contract
|
12
|
+
end<% end -%>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe <%= namespaced_model_class %>::Create do
|
4
|
+
let(:result) { described_class.trace(params: params) }
|
5
|
+
let(:params) do
|
6
|
+
{
|
7
|
+
<%= singular_table_name %>: attributes_for(:<%= singular_table_name %>)
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'persists when valid' do
|
12
|
+
expect(result.success?).to eq true
|
13
|
+
expect(result[:model].persisted?).to eq true
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe <%= namespaced_model_class %>::Update do
|
4
|
+
let(:result) { described_class.trace(params: params) }
|
5
|
+
let(:model) { <%= model_class %>::Factory.call }
|
6
|
+
let(:params) do
|
7
|
+
{
|
8
|
+
id: model.id,
|
9
|
+
<%= singular_table_name %>: attributes_for(:<%= singular_table_name %>)
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'persists when valid' do
|
14
|
+
expect(result.success?).to eq true
|
15
|
+
expect(result[:model].updated_at).to be > result[:model].created_at
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Organism
|
2
|
+
class ControllerGenerator < Generators::Base
|
3
|
+
source_root File.expand_path('templates', __dir__)
|
4
|
+
|
5
|
+
argument :actions, type: :array, default: [], banner: 'action action'
|
6
|
+
class_option :model, type: :string, default: ''
|
7
|
+
|
8
|
+
check_class_collision suffix: 'Controller'
|
9
|
+
|
10
|
+
def create_controller_files
|
11
|
+
template(
|
12
|
+
'controller.rb',
|
13
|
+
File.join('app/controllers', class_path, "#{file_name}_controller.rb")
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_routes
|
18
|
+
return if actions.empty?
|
19
|
+
|
20
|
+
route(
|
21
|
+
"resources :#{file_name}, only: %i[#{actions.join(' ')}]",
|
22
|
+
namespace: regular_class_path
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def after_create_path
|
29
|
+
redirect_to_resource
|
30
|
+
end
|
31
|
+
|
32
|
+
def after_update_path
|
33
|
+
redirect_to_resource
|
34
|
+
end
|
35
|
+
|
36
|
+
def after_destroy_path
|
37
|
+
"#{index_helper}_path"
|
38
|
+
end
|
39
|
+
|
40
|
+
def redirect_to_resource
|
41
|
+
show? ? "#{singular_route_name}_path(result[:model])" : "#{index_helper}_path"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
<% nested_namespace do -%>
|
2
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
3
|
+
<% if singular_actions? -%>
|
4
|
+
before_action :set_<%= singular_file_name %>, only: %i[<%= singular_actions.sort.join(' ') %>]
|
5
|
+
<% end -%>
|
6
|
+
<% if index? -%>
|
7
|
+
|
8
|
+
def index
|
9
|
+
@<%= file_name %> = <%= namespaced_model_class %>.all
|
10
|
+
end
|
11
|
+
<% end -%>
|
12
|
+
<% if show? -%>
|
13
|
+
|
14
|
+
def show; end
|
15
|
+
<% end -%>
|
16
|
+
<% if new? -%>
|
17
|
+
|
18
|
+
def new
|
19
|
+
run <%= namespaced_model_class %>::Present
|
20
|
+
end
|
21
|
+
<% end -%>
|
22
|
+
<% if create? -%>
|
23
|
+
|
24
|
+
def create
|
25
|
+
run <%= namespaced_model_class %>::Create do |result|
|
26
|
+
return redirect_to(
|
27
|
+
<%= after_create_path %>,
|
28
|
+
notice: t('<%= notice_namespace %>.create.success')
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
render :new
|
33
|
+
end
|
34
|
+
<% end -%>
|
35
|
+
<% if edit? -%>
|
36
|
+
|
37
|
+
def edit
|
38
|
+
run <%= namespaced_model_class %>::Present
|
39
|
+
end
|
40
|
+
<% end -%>
|
41
|
+
<% if update? -%>
|
42
|
+
|
43
|
+
def update
|
44
|
+
run <%= namespaced_model_class %>::Update do |result|
|
45
|
+
return redirect_to(
|
46
|
+
<%= after_update_path %>,
|
47
|
+
notice: t('<%= notice_namespace %>.update.success')
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
render :edit
|
52
|
+
end
|
53
|
+
<% end -%>
|
54
|
+
<% if destroy? -%>
|
55
|
+
|
56
|
+
def destroy
|
57
|
+
@<%= singular_file_name %>.destroy
|
58
|
+
redirect_to(
|
59
|
+
<%= after_destroy_path %>,
|
60
|
+
notice: t('<%= notice_namespace %>.destroy.success')
|
61
|
+
)
|
62
|
+
end
|
63
|
+
<% end -%>
|
64
|
+
<% if singular_actions? -%>
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def set_<%= singular_file_name %>
|
69
|
+
@<%= singular_file_name %> = <%= namespaced_model_class %>.find(params[:id])
|
70
|
+
end
|
71
|
+
<% end -%>
|
72
|
+
end<% end -%>
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module Organism
|
2
|
+
module GeneratorHelper
|
3
|
+
private
|
4
|
+
|
5
|
+
def controller_class_name
|
6
|
+
human_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def notice_namespace
|
10
|
+
model_class_path.map(&:underscore).join('.')
|
11
|
+
end
|
12
|
+
|
13
|
+
def nested_namespace(&block)
|
14
|
+
content = capture(&block)
|
15
|
+
content = nest_content(content)
|
16
|
+
concat(content)
|
17
|
+
end
|
18
|
+
|
19
|
+
def nest_content(content)
|
20
|
+
class_path.each do |namespace|
|
21
|
+
constant = namespace.camelize
|
22
|
+
begin
|
23
|
+
content = wrap_namespace(indent(content), constant.constantize)
|
24
|
+
rescue NameError
|
25
|
+
content = wrap_namespace(indent(content), constant)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
content
|
30
|
+
end
|
31
|
+
|
32
|
+
def wrap_model(content)
|
33
|
+
"class #{model_class} < ApplicationRecord\n#{content}\nend"
|
34
|
+
end
|
35
|
+
|
36
|
+
def wrap_namespace(content, namespace)
|
37
|
+
return "module #{namespace}\n#{content}\nend" if namespace.is_a? String
|
38
|
+
|
39
|
+
superclass = namespace.superclass
|
40
|
+
case superclass
|
41
|
+
when Object
|
42
|
+
"class #{key}\n#{content}\nend"
|
43
|
+
else
|
44
|
+
"class #{key} < #{superclass}\n#{content}\nend"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def namespaced_model_class
|
49
|
+
model_class_path.map!(&:camelize).join('::')
|
50
|
+
end
|
51
|
+
|
52
|
+
def model_class_path
|
53
|
+
class_path + [file_name.singularize]
|
54
|
+
end
|
55
|
+
|
56
|
+
def singular_file_name
|
57
|
+
file_name.singularize
|
58
|
+
end
|
59
|
+
|
60
|
+
def model_class
|
61
|
+
options[:model].blank? ? human_name.singularize : options[:model]
|
62
|
+
end
|
63
|
+
|
64
|
+
def singular_actions
|
65
|
+
actions.select do |action|
|
66
|
+
%w[show destroy edit update].include?(action)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def singular_actions?
|
71
|
+
singular_actions.any?
|
72
|
+
end
|
73
|
+
|
74
|
+
def new?
|
75
|
+
action?('new')
|
76
|
+
end
|
77
|
+
|
78
|
+
def create?
|
79
|
+
action?('new') || action?('create')
|
80
|
+
end
|
81
|
+
|
82
|
+
def show?
|
83
|
+
action?('show')
|
84
|
+
end
|
85
|
+
|
86
|
+
def index?
|
87
|
+
action?('index')
|
88
|
+
end
|
89
|
+
|
90
|
+
def edit?
|
91
|
+
action?('edit')
|
92
|
+
end
|
93
|
+
|
94
|
+
def update?
|
95
|
+
action?('edit') || action?('update')
|
96
|
+
end
|
97
|
+
|
98
|
+
def destroy?
|
99
|
+
action?('destroy')
|
100
|
+
end
|
101
|
+
|
102
|
+
def action?(action)
|
103
|
+
actions.include?(action)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Organism
|
2
|
+
class ScaffoldGenerator < Generators::Base
|
3
|
+
source_root File.expand_path('templates', __dir__)
|
4
|
+
|
5
|
+
def create_scaffold
|
6
|
+
generate 'organism:controller', file_name, *args
|
7
|
+
generate 'organism:cells', file_name, *args
|
8
|
+
generate 'organism:views', file_name, *args
|
9
|
+
generate 'organism:concept', file_name, *args
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Organism
|
2
|
+
class ViewsGenerator < Generators::Base
|
3
|
+
source_root File.expand_path('templates', __dir__)
|
4
|
+
|
5
|
+
argument :actions, type: :array, default: [], banner: 'action action'
|
6
|
+
class_option :model, type: :string, default: ''
|
7
|
+
class_option :collections, type: :array, default: ['list']
|
8
|
+
|
9
|
+
def create_views
|
10
|
+
viewable_actions.each do |action|
|
11
|
+
create_view(action)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def create_view(action)
|
18
|
+
template(
|
19
|
+
"#{action}.rb",
|
20
|
+
File.join('app/views', file_path, "#{action}.html.erb")
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def viewable_actions
|
25
|
+
actions.select do |action|
|
26
|
+
%w[new show index edit].include?(action)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def collection_renderer_class
|
31
|
+
options[:collections].first.camelize
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'lib/organism/generators/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'organism-generators'
|
5
|
+
spec.version = Organism::Generators::VERSION
|
6
|
+
spec.authors = ['Nolan Tait']
|
7
|
+
spec.email = ['nolanjtait@gmail.com']
|
8
|
+
|
9
|
+
spec.summary = <<~SUMMARY
|
10
|
+
Rails generators for quickly prototyping organisms.
|
11
|
+
SUMMARY
|
12
|
+
spec.description = <<~DESCRIPTION
|
13
|
+
Rails generators for quickly prototyping organisms.
|
14
|
+
DESCRIPTION
|
15
|
+
spec.homepage = 'https://github.com/nolantait/organism-generators'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
18
|
+
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
21
|
+
spec.metadata['changelog_uri'] = spec.homepage
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_development_dependency 'byebug', '~> 11.1.3'
|
33
|
+
spec.add_development_dependency 'generator_spec', '~> 0.9.4'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.10.0'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: organism-generators
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nolan Tait
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 11.1.3
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 11.1.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: generator_spec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.4
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.10.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.10.0
|
55
|
+
description: 'Rails generators for quickly prototyping organisms.
|
56
|
+
|
57
|
+
'
|
58
|
+
email:
|
59
|
+
- nolanjtait@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/rspec
|
74
|
+
- bin/setup
|
75
|
+
- lib/organism/generators.rb
|
76
|
+
- lib/organism/generators/base.rb
|
77
|
+
- lib/organism/generators/cells/USAGE
|
78
|
+
- lib/organism/generators/cells/cells_generator.rb
|
79
|
+
- lib/organism/generators/cells/templates/cell/cell.rb.tt
|
80
|
+
- lib/organism/generators/cells/templates/cell/list.rb.tt
|
81
|
+
- lib/organism/generators/cells/templates/cell/show.rb.tt
|
82
|
+
- lib/organism/generators/cells/templates/form/cell.rb.tt
|
83
|
+
- lib/organism/generators/cells/templates/form/show.rb.tt
|
84
|
+
- lib/organism/generators/cells/templates/list/cell.rb.tt
|
85
|
+
- lib/organism/generators/cells/templates/table/cell.rb.tt
|
86
|
+
- lib/organism/generators/concept/USAGE
|
87
|
+
- lib/organism/generators/concept/concept_generator.rb
|
88
|
+
- lib/organism/generators/concept/templates/contracts/create.rb.tt
|
89
|
+
- lib/organism/generators/concept/templates/contracts/update.rb.tt
|
90
|
+
- lib/organism/generators/concept/templates/create.rb.tt
|
91
|
+
- lib/organism/generators/concept/templates/present.rb.tt
|
92
|
+
- lib/organism/generators/concept/templates/spec/create.rb.tt
|
93
|
+
- lib/organism/generators/concept/templates/spec/update.rb.tt
|
94
|
+
- lib/organism/generators/concept/templates/update.rb.tt
|
95
|
+
- lib/organism/generators/controller/USAGE
|
96
|
+
- lib/organism/generators/controller/controller_generator.rb
|
97
|
+
- lib/organism/generators/controller/templates/controller.rb.tt
|
98
|
+
- lib/organism/generators/generator_helper.rb
|
99
|
+
- lib/organism/generators/scaffold/USAGE
|
100
|
+
- lib/organism/generators/scaffold/scaffold_generator.rb
|
101
|
+
- lib/organism/generators/version.rb
|
102
|
+
- lib/organism/generators/views/USAGE
|
103
|
+
- lib/organism/generators/views/templates/edit.rb.tt
|
104
|
+
- lib/organism/generators/views/templates/index.rb.tt
|
105
|
+
- lib/organism/generators/views/templates/new.rb.tt
|
106
|
+
- lib/organism/generators/views/templates/show.rb.tt
|
107
|
+
- lib/organism/generators/views/views_generator.rb
|
108
|
+
- organism-generators.gemspec
|
109
|
+
homepage: https://github.com/nolantait/organism-generators
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata:
|
113
|
+
homepage_uri: https://github.com/nolantait/organism-generators
|
114
|
+
source_code_uri: https://github.com/nolantait/organism-generators
|
115
|
+
changelog_uri: https://github.com/nolantait/organism-generators
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.3.0
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubygems_version: 3.1.4
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Rails generators for quickly prototyping organisms.
|
135
|
+
test_files: []
|