feature_pack 0.6.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +68 -71
- data/doc/changelog.md +2 -0
- data/lib/feature_pack/controller.rb +15 -13
- data/lib/feature_pack/feature_pack_routes.rb +6 -11
- data/lib/feature_pack/group_controller.rb +14 -13
- data/lib/generators/feature_pack/add_group/add_group_generator.rb +5 -4
- data/lib/generators/feature_pack/add_group/templates/_group_space/manifest.yaml.tt +0 -1
- data/lib/generators/feature_pack/add_group/templates/_group_space/routes.rb.tt +1 -0
- metadata +15 -13
- data/lib/generators/feature_pack/add_group/templates/_group_space/routes.rb.disabled.tt +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f70a5116de8367b0eecf7c72cbab4762b6c28ded77c2cfd7b0df4369e4d82431
|
4
|
+
data.tar.gz: ca02d7cc7f78755908a3adec71641b8740f423cf7eab65d5b2f92c0b1755e861
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b9ea87e71245fc6d56827d933b4ca32ebd6e1e1a8c144b1ba62ca4a005fce36244414a6c278b4f0ff5e263e73ebc0b71617b09f9fba16816804c4cad7ea3d79
|
7
|
+
data.tar.gz: d135218c290abdd63c24c13f5e8944854e4bb186bb1db9982164ac7f52fe19a93e6c6f67e0d07f58d95baeeaf553a32fa021d9053f9513e0a0f40526ac43050c
|
data/README.md
CHANGED
@@ -1,94 +1,91 @@
|
|
1
|
-
# Feature Pack
|
2
|
-
Organizes and sets up the architecture of micro-applications within a Rails application, enabling the segregation of code, management, and isolation of functionalities, which can be developed, tested, and maintained independently of each other.
|
1
|
+
# Feature Pack Gem
|
2
|
+
Organizes and sets up the architecture of micro-applications within a Ruby On Rails application, enabling the segregation of code, management, and isolation of functionalities, which can be developed, tested, and maintained independently of each other.
|
3
3
|
|
4
|
+
## Code and Folder Structure
|
4
5
|
|
5
|
-
|
6
|
-
`
|
6
|
+
### Group
|
7
|
+
A group is a collection of related features. Groups are represented as directories in the `app/feature_packs` folder. Each group contains a `_group_space` directory that holds group-level views and JavaScript files. Group directories follow this naming pattern:
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
#### Naming Convention
|
10
|
+
Sample: `group_departments-100100_human_resources`
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
```
|
12
|
+
`group_` prefix is followed by the group identification (required)
|
13
|
+
`departments-100100` between `group_` and class name, exists only for organization purposes. The bounds are `group_` and next underscore `_`
|
14
|
+
`human_resources` class name of the group (required)
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
#### Note worthy
|
17
|
+
Group name is the same as the class name. Its used internally in the backend code.
|
18
|
+
The 'Name' within the manifest file (Group.manifest[:name]) is the name to be shown in the user interface.
|
19
19
|
|
20
|
-
|
21
|
-
```ruby
|
22
|
-
# config/application.rb
|
20
|
+
The `_group_space` directory contains:
|
23
21
|
|
24
|
-
|
25
|
-
|
22
|
+
- `views/` - Views of the group
|
23
|
+
#### Common Files in _group_space/views
|
26
24
|
|
27
|
-
|
25
|
+
The `_group_space/views` directory typically contains these common files:
|
28
26
|
|
29
|
-
|
30
|
-
|
27
|
+
```
|
28
|
+
_group_space/views/
|
29
|
+
├── index.html.slim # Default view for the group
|
30
|
+
└── partials/
|
31
|
+
└── _header.html.slim # Base header template for the group
|
32
|
+
└── _footer.html.slim # Base footer template for the group
|
33
|
+
```
|
34
|
+
Can have more views and partials, depending on the defined on `controller.rb` but these are the most common ones.
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
- `javascript/` - Group-level JavaScript modules shared across features
|
37
|
+
- `controller.rb` - Base controller class for the group's features
|
38
|
+
- `routes.rb` - The routes files come with the default `index` action/view.
|
35
39
|
|
36
|
-
|
40
|
+
#### How implement a new Group
|
41
|
+
```
|
42
|
+
rails generate feature_pack:add_gruop <group_name>
|
43
|
+
```
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
load FeaturePack.path.join('feature_pack/controller.rb')
|
45
|
+
### Feature
|
46
|
+
A feature is a single feature that can be added to a group. Feature naming patter is the same of group, but without the `group_` prefix.
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
```
|
48
|
+
#### Feature Routes
|
49
|
+
Every feature has a default route, which is the `index` action/view. If the feature has more than the default `index` action/view, the routes are defined in the `routes.rb` file.
|
46
50
|
|
47
|
-
|
48
|
-
# initializers/feature_pack.rb
|
49
|
-
|
50
|
-
FeaturePack.groups.each do |group|
|
51
|
-
group_module = FeaturePack.const_set(group.name.name.camelize, Module.new)
|
52
|
-
|
53
|
-
%w[Lib AI Jobs].each do |submodule_name|
|
54
|
-
submodule_path = File.join(group.relative_path, '_group_space', submodule_name.downcase)
|
55
|
-
if Dir.exist?(submodule_path)
|
56
|
-
submodule = group_module.const_set(submodule_name, Module.new)
|
57
|
-
Rails.autoloaders.main.push_dir(submodule_path, namespace: submodule)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
group.features.each do |feature|
|
62
|
-
feature_module = group_module.const_set(feature.name.name.camelize, Module.new)
|
63
|
-
Rails.autoloaders.main.push_dir(feature.relative_path, namespace: feature_module)
|
64
|
-
end
|
65
|
-
end
|
51
|
+
#### How implement a new feature
|
66
52
|
```
|
53
|
+
rails generate feature_pack:add_feature <group_name>/<feature_name>
|
54
|
+
```
|
55
|
+
|
56
|
+
#### Helpers
|
67
57
|
|
68
58
|
```ruby
|
69
|
-
#
|
70
|
-
|
71
|
-
|
59
|
+
# Application Helper
|
60
|
+
def feature_pack_group_path(group_name, *params) = send("feature_pack_#{group_name}_path".to_sym, *params)
|
61
|
+
def feature_pack_path(group_name, feature_name, *params) = send("feature_pack_#{group_name}_#{feature_name}_path".to_sym, *params)
|
72
62
|
```
|
73
63
|
|
74
|
-
|
75
|
-
# config/initializers/assets.rb
|
64
|
+
## Helpers
|
76
65
|
|
77
|
-
|
78
|
-
```
|
66
|
+
### Using the `feature_pack_group_path` and `feature_pack_path` Helpers
|
79
67
|
|
80
|
-
|
81
|
-
# config/importmap.rb
|
68
|
+
The `feature_pack_group_path` and `feature_pack_path` helpers are used to generate URLs for specific groups and features within the feature package system.
|
82
69
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
70
|
+
- `feature_pack_group_path(group, *params)`: Generates the path for a specific group. The `group` parameter should be an object representing the desired group. Additional parameters can be passed to specify more details in the URL.
|
71
|
+
|
72
|
+
**Usage example:**
|
73
|
+
```ruby
|
74
|
+
# Assuming `group` is a valid group name in symbol
|
75
|
+
group_url = feature_pack_group_path(:group_name)
|
76
|
+
```
|
88
77
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
78
|
+
- `feature_pack_path(group, feature, *params)`: Generates the path for a specific feature within a group. The `group` and `feature` parameters should be symbols of group and feature name, respectively. Additional parameters can be passed to specify more details in the URL.
|
79
|
+
|
80
|
+
**Usage example:**
|
81
|
+
```ruby
|
82
|
+
# Assuming `group` and `feature` are valid objects
|
83
|
+
feature_url = feature_pack_path(:my_group, :my_feature)
|
84
|
+
```
|
85
|
+
|
86
|
+
These helpers are useful for maintaining consistency and clarity when generating URLs within the application, ensuring that routes are correctly constructed based on the provided group and feature names.
|
87
|
+
|
88
|
+
## Variables
|
89
|
+
Current group and feature are available in the controller (so as in the views too) as `@group` and `@feature` variables.
|
90
|
+
@feature variable is not available in the group controller.
|
91
|
+
@group variable is available in the group controller and in the its features controllers.
|
data/doc/changelog.md
ADDED
@@ -1,12 +1,16 @@
|
|
1
1
|
class FeaturePack::Controller < ApplicationController
|
2
|
-
|
3
|
-
before_action :set_view_lookup_context_prefix
|
4
|
-
before_action :set_layout_paths
|
2
|
+
prepend_before_action :setup_feature
|
5
3
|
|
6
4
|
def index; end
|
7
5
|
|
8
6
|
private
|
9
7
|
|
8
|
+
def setup_feature
|
9
|
+
set_group_and_feature
|
10
|
+
set_view_lookup_context_prefix
|
11
|
+
set_layout_paths
|
12
|
+
end
|
13
|
+
|
10
14
|
def set_group_and_feature
|
11
15
|
group_name, feature_name = params['controller'].delete_prefix('feature_pack/').split('/').map(&:to_sym)
|
12
16
|
@group = FeaturePack.group group_name
|
@@ -14,19 +18,17 @@ class FeaturePack::Controller < ApplicationController
|
|
14
18
|
end
|
15
19
|
|
16
20
|
def set_view_lookup_context_prefix
|
17
|
-
|
18
|
-
|
19
|
-
|
21
|
+
return if lookup_context.prefixes.include?(@feature.views_relative_path)
|
22
|
+
|
23
|
+
lookup_context.prefixes.prepend(@feature.views_relative_path)
|
20
24
|
end
|
21
25
|
|
22
26
|
def set_layout_paths
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
-
|
27
|
-
|
28
|
-
- Fallback to Application's default header/footer
|
29
|
-
=end
|
27
|
+
# Header/Footer Lookup order
|
28
|
+
#
|
29
|
+
# - Feature dir/_partials, if not exists
|
30
|
+
# - Fallback to Group, if not exists
|
31
|
+
# - Fallback to Application's default header/footer
|
30
32
|
|
31
33
|
feature_partials_path = @feature.views_relative_path.join('partials')
|
32
34
|
group_partials_path = @feature.group.views_path.concat('/partials')
|
@@ -1,20 +1,15 @@
|
|
1
1
|
FeaturePack.groups.each do |group|
|
2
|
-
|
3
|
-
|
4
|
-
get group.manifest[:url],
|
5
|
-
to: "#{group.name.name}#index",
|
6
|
-
as: group.name.name
|
2
|
+
scope group.manifest[:url], as: group.name do
|
3
|
+
raise "Group '#{group.name}' routes file not found in #{group.metadata_path}" if group.routes_file.nil?
|
7
4
|
|
8
|
-
|
9
|
-
scope group.manifest[:url] do
|
10
|
-
draw(group.routes_file)
|
11
|
-
end
|
12
|
-
end
|
5
|
+
draw(group.routes_file)
|
13
6
|
end
|
14
7
|
|
15
8
|
namespace group.name, path: group.manifest[:url] do
|
16
9
|
group.features.each do |feature|
|
17
|
-
scope feature.manifest[:url], as: feature.name
|
10
|
+
scope feature.manifest[:url], as: feature.name do
|
11
|
+
raise "Feature '#{feature.name}' routes file not found in #{feature.routes_file}" if feature.routes_file.nil?
|
12
|
+
|
18
13
|
draw(feature.routes_file)
|
19
14
|
end
|
20
15
|
end
|
@@ -1,32 +1,33 @@
|
|
1
1
|
class FeaturePack::GroupController < ApplicationController
|
2
|
-
|
3
|
-
before_action :set_view_lookup_context_prefix
|
4
|
-
before_action :set_layout_paths
|
5
|
-
|
2
|
+
prepend_before_action :setup_group
|
6
3
|
def index; end
|
7
4
|
|
8
5
|
private
|
9
6
|
|
7
|
+
def setup_group
|
8
|
+
set_group
|
9
|
+
set_view_lookup_context_prefix
|
10
|
+
set_layout_paths
|
11
|
+
end
|
12
|
+
|
10
13
|
def set_group
|
11
14
|
group_name = params[:controller].split('/')[1].to_sym
|
12
15
|
@group = FeaturePack.group(group_name)
|
13
16
|
end
|
14
17
|
|
15
18
|
def set_view_lookup_context_prefix
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
return if lookup_context.prefixes.include?(@group.views_path)
|
20
|
+
|
21
|
+
lookup_context.prefixes.prepend(@group.views_path)
|
19
22
|
end
|
20
23
|
|
21
24
|
def set_layout_paths
|
22
25
|
patials_path = @group.views_path.concat('/partials')
|
23
26
|
|
24
|
-
if template_exists?('header', patials_path, true)
|
25
|
-
|
26
|
-
|
27
|
+
@header_layout_path = @group.view('partials/header') if template_exists?('header', patials_path, true)
|
28
|
+
|
29
|
+
return unless template_exists?('footer', patials_path, true)
|
27
30
|
|
28
|
-
|
29
|
-
@footer_layout_path = @group.view('partials/footer')
|
30
|
-
end
|
31
|
+
@footer_layout_path = @group.view('partials/footer')
|
31
32
|
end
|
32
33
|
end
|
@@ -2,7 +2,6 @@ require 'rails/generators/base'
|
|
2
2
|
require 'rails/generators/named_base'
|
3
3
|
|
4
4
|
class FeaturePack::AddGroupGenerator < Rails::Generators::NamedBase
|
5
|
-
|
6
5
|
desc 'Adds a new Feature Group'
|
7
6
|
source_root File.expand_path('templates', __dir__)
|
8
7
|
|
@@ -20,9 +19,11 @@ class FeaturePack::AddGroupGenerator < Rails::Generators::NamedBase
|
|
20
19
|
|
21
20
|
template './_group_space/controller.rb.tt', group_dir.join('_group_space', 'controller.rb')
|
22
21
|
template './_group_space/manifest.yaml.tt', group_dir.join('_group_space', 'manifest.yaml')
|
23
|
-
template './_group_space/routes.rb.
|
22
|
+
template './_group_space/routes.rb.tt', group_dir.join('_group_space', 'routes.rb')
|
24
23
|
template './_group_space/views/index.html.slim.tt', group_dir.join('_group_space', 'views/index.html.slim')
|
25
|
-
template './_group_space/views/partials/_header.html.slim.tt',
|
26
|
-
|
24
|
+
template './_group_space/views/partials/_header.html.slim.tt',
|
25
|
+
group_dir.join('_group_space', 'views/partials/_header.html.slim')
|
26
|
+
template './_group_space/views/partials/_footer.html.slim.tt',
|
27
|
+
group_dir.join('_group_space', 'views/partials/_footer.html.slim')
|
27
28
|
end
|
28
29
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
get '/', to: '<%= name %>#index'
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feature_pack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gedean Dias
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-09 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activesupport
|
@@ -30,16 +29,17 @@ dependencies:
|
|
30
29
|
- - "<"
|
31
30
|
- !ruby/object:Gem::Version
|
32
31
|
version: '9.0'
|
33
|
-
description:
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
description: |
|
33
|
+
Organizes and sets up the architecture of micro-applications within a Rails application,
|
34
|
+
enabling segregation, management, and isolation of functionalities, thereby supporting
|
35
|
+
independent development, testing, and maintenance.
|
37
36
|
email: gedean.dias@gmail.com
|
38
37
|
executables: []
|
39
38
|
extensions: []
|
40
39
|
extra_rdoc_files: []
|
41
40
|
files:
|
42
41
|
- README.md
|
42
|
+
- doc/changelog.md
|
43
43
|
- doc/feature_pack.md
|
44
44
|
- lib/feature_pack.rb
|
45
45
|
- lib/feature_pack/api/controller.rb
|
@@ -60,15 +60,18 @@ files:
|
|
60
60
|
- lib/generators/feature_pack/add_group/add_group_generator.rb
|
61
61
|
- lib/generators/feature_pack/add_group/templates/_group_space/controller.rb.tt
|
62
62
|
- lib/generators/feature_pack/add_group/templates/_group_space/manifest.yaml.tt
|
63
|
-
- lib/generators/feature_pack/add_group/templates/_group_space/routes.rb.
|
63
|
+
- lib/generators/feature_pack/add_group/templates/_group_space/routes.rb.tt
|
64
64
|
- lib/generators/feature_pack/add_group/templates/_group_space/views/index.html.slim.tt
|
65
65
|
- lib/generators/feature_pack/add_group/templates/_group_space/views/partials/_footer.html.slim.tt
|
66
66
|
- lib/generators/feature_pack/add_group/templates/_group_space/views/partials/_header.html.slim.tt
|
67
67
|
homepage: https://github.com/gedean/feature_pack
|
68
68
|
licenses:
|
69
69
|
- MIT
|
70
|
-
metadata:
|
71
|
-
|
70
|
+
metadata:
|
71
|
+
bug_tracker_uri: https://github.com/gedean/feature_pack/issues
|
72
|
+
source_code_uri: https://github.com/gedean/feature_pack
|
73
|
+
changelog_uri: https://github.com/gedean/feature_pack/blob/main/CHANGELOG.MD
|
74
|
+
post_install_message: Please check the README file for use instructions.
|
72
75
|
rdoc_options: []
|
73
76
|
require_paths:
|
74
77
|
- lib
|
@@ -83,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
86
|
- !ruby/object:Gem::Version
|
84
87
|
version: '0'
|
85
88
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
-
signing_key:
|
89
|
+
rubygems_version: 3.6.3
|
88
90
|
specification_version: 4
|
89
|
-
summary: A different
|
91
|
+
summary: A different approach to organizing Rails app features.
|
90
92
|
test_files: []
|