sun-sword 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -10
- data/lib/generators/sun_sword/frontend_generator.rb +43 -19
- data/lib/generators/sun_sword/init_generator.rb +15 -0
- data/lib/generators/sun_sword/scaffold_generator.rb +135 -9
- data/lib/generators/sun_sword/templates_frontend/config/devise.rb +313 -0
- data/lib/generators/sun_sword/templates_frontend/controllers/application_controller.rb.tt +7 -3
- data/lib/generators/sun_sword/templates_frontend/controllers/site_controller.rb +1 -0
- data/lib/generators/sun_sword/templates_frontend/db/migrate/20241117042039_devise_create_auths.rb +47 -0
- data/lib/generators/sun_sword/templates_frontend/db/migrate/20241117043154_create_models_accounts.rb +11 -0
- data/lib/generators/sun_sword/templates_frontend/db/migrate/20241117044142_create_models_users.rb +16 -0
- data/lib/generators/sun_sword/templates_frontend/db/seeds.rb +3 -0
- data/lib/generators/sun_sword/templates_frontend/db/structures/example.yaml.tt +106 -0
- data/lib/generators/sun_sword/templates_frontend/frontend/pages/web.js +2 -8
- data/lib/generators/sun_sword/templates_frontend/models/models/account.rb +4 -0
- data/lib/generators/sun_sword/templates_frontend/models/models/auth.rb +8 -0
- data/lib/generators/sun_sword/templates_frontend/models/models/user.rb +5 -0
- data/lib/generators/sun_sword/templates_frontend/views/layouts/dashboard/_sidebar.html.erb.tt +11 -1
- data/lib/generators/sun_sword/templates_frontend/views/layouts/dashboard/application.html.erb.tt +6 -9
- data/lib/generators/sun_sword/templates_init/config/initializers/sun_sword.rb +3 -0
- data/lib/generators/sun_sword/templates_scaffold/controllers/controller.rb.tt +22 -18
- data/lib/generators/sun_sword/templates_scaffold/views/_form.html.erb.tt +3 -8
- data/lib/generators/sun_sword/templates_scaffold/views/components/menu/link.html.erb.tt +1 -1
- data/lib/generators/sun_sword/templates_scaffold/views/index.html.erb.tt +4 -4
- data/lib/generators/sun_sword/templates_scaffold/views/show.html.erb.tt +2 -2
- data/lib/sun-sword.rb +4 -2
- data/lib/sun_sword/configuration.rb +29 -0
- data/lib/sun_sword/version.rb +1 -1
- metadata +14 -3
- data/lib/generators/sun_sword/templates_frontend/controllers/dashboard/site_controller.rb +0 -6
@@ -1,12 +1,16 @@
|
|
1
1
|
class ApplicationController < ActionController::Base
|
2
|
+
add_flash_types :error, :success, :notice
|
2
3
|
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
|
3
4
|
allow_browser versions: :modern
|
4
5
|
|
5
6
|
protected
|
6
7
|
|
8
|
+
def <%=SunSword.scope_owner_column%>
|
9
|
+
current_auth.account.id
|
10
|
+
end
|
11
|
+
|
7
12
|
def build_contract(params)
|
8
|
-
|
9
|
-
{ <%=RiderKick.scope_owner_column.to_s%>: SecureRandom.uuid }.merge(params)
|
13
|
+
{ <%=SunSword.scope_owner_column.to_s%>: <%=SunSword.scope_owner_column.to_s%> }.merge(params)
|
10
14
|
end
|
11
15
|
|
12
16
|
def build_form_errors(params, model, errors)
|
@@ -31,6 +35,6 @@ class ApplicationController < ActionController::Base
|
|
31
35
|
|
32
36
|
def set_layouts
|
33
37
|
# "#{current_auth.user.role}/application"
|
34
|
-
|
38
|
+
"owner/application"
|
35
39
|
end
|
36
40
|
end
|
data/lib/generators/sun_sword/templates_frontend/db/migrate/20241117042039_devise_create_auths.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DeviseCreateAuths < ActiveRecord::Migration[7.2]
|
4
|
+
def change
|
5
|
+
create_table :auths, id: :uuid do |t|
|
6
|
+
## Database authenticatable
|
7
|
+
t.string :email, null: false, default: ''
|
8
|
+
t.string :encrypted_password, null: false, default: ''
|
9
|
+
t.uuid :account_id, null: false
|
10
|
+
t.uuid :user_id, null: false
|
11
|
+
|
12
|
+
## Recoverable
|
13
|
+
t.string :reset_password_token
|
14
|
+
t.datetime :reset_password_sent_at
|
15
|
+
|
16
|
+
## Rememberable
|
17
|
+
t.datetime :remember_created_at
|
18
|
+
|
19
|
+
## Trackable
|
20
|
+
# t.integer :sign_in_count, default: 0, null: false
|
21
|
+
# t.datetime :current_sign_in_at
|
22
|
+
# t.datetime :last_sign_in_at
|
23
|
+
# t.string :current_sign_in_ip
|
24
|
+
# t.string :last_sign_in_ip
|
25
|
+
|
26
|
+
## Confirmable
|
27
|
+
# t.string :confirmation_token
|
28
|
+
# t.datetime :confirmed_at
|
29
|
+
# t.datetime :confirmation_sent_at
|
30
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
31
|
+
|
32
|
+
## Lockable
|
33
|
+
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
34
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
35
|
+
# t.datetime :locked_at
|
36
|
+
|
37
|
+
t.timestamps null: false
|
38
|
+
end
|
39
|
+
|
40
|
+
add_index :auths, :email, unique: true
|
41
|
+
add_index :auths, :user_id, unique: true
|
42
|
+
add_index :auths, :reset_password_token, unique: true
|
43
|
+
add_index :auths, :account_id
|
44
|
+
add_index :auths, :created_at
|
45
|
+
add_index :auths, :updated_at
|
46
|
+
end
|
47
|
+
end
|
data/lib/generators/sun_sword/templates_frontend/db/migrate/20241117044142_create_models_users.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateModelsUsers < ActiveRecord::Migration[7.2]
|
2
|
+
def change
|
3
|
+
create_table :users, id: :uuid do |t|
|
4
|
+
t.uuid :account_id, null: false
|
5
|
+
t.string :full_name, null: false
|
6
|
+
t.string :role, null: false
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
add_index :users, :full_name
|
11
|
+
add_index :users, :role
|
12
|
+
add_index :users, :account_id
|
13
|
+
add_index :users, :created_at
|
14
|
+
add_index :users, :updated_at
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,3 @@
|
|
1
|
+
account = Models::Account.first_or_create(name: 'KOTAROISME')
|
2
|
+
user = Models::User.create(full_name: 'Kotaro Minami', account_id: account.id, role: 'owner')
|
3
|
+
Models::Auth.create(email: 'kotaroisme@gmail.com', password: 'blankblank', password_confirmation: 'blankblank', account_id: account.id, user_id: user.id)
|
@@ -0,0 +1,106 @@
|
|
1
|
+
model: <%= @model_class %>
|
2
|
+
resource_name: <%= @scope_path %>
|
3
|
+
actor: <%= @actor %>
|
4
|
+
fields:
|
5
|
+
<% @model_class.columns.each do |field| -%>
|
6
|
+
- <%= field.name.to_s %>
|
7
|
+
<% end -%>
|
8
|
+
<% @uploaders.each do |field| -%>
|
9
|
+
- <%= field %>
|
10
|
+
<% end -%>
|
11
|
+
uploaders:
|
12
|
+
<% @uploaders.each do |field| -%>
|
13
|
+
- <%= field %>
|
14
|
+
<% end -%>
|
15
|
+
search_able:
|
16
|
+
<% contract_fields.each do |field| -%>
|
17
|
+
<% if ['title', 'name'].include?(field) -%>
|
18
|
+
- <%= field %>
|
19
|
+
<% end -%>
|
20
|
+
<% end -%>
|
21
|
+
controllers:
|
22
|
+
list_fields:
|
23
|
+
<% @fields.each do |field| -%>
|
24
|
+
- <%= field %>
|
25
|
+
<% end -%>
|
26
|
+
show_fields:
|
27
|
+
<% @model_class.columns.each do |field| -%>
|
28
|
+
- <%= field.name.to_s %>
|
29
|
+
<% end -%>
|
30
|
+
<% @uploaders.each do |field| -%>
|
31
|
+
- <%= field %>
|
32
|
+
<% end -%>
|
33
|
+
form_fields:
|
34
|
+
<% (@fields).each do |field| -%>
|
35
|
+
- name: <%= field %>
|
36
|
+
type: string
|
37
|
+
<% end -%>
|
38
|
+
<% (@uploaders).each do |field| -%>
|
39
|
+
- name: <%= field %>
|
40
|
+
type: file
|
41
|
+
<% end -%>
|
42
|
+
domains:
|
43
|
+
action_list:
|
44
|
+
endpoint:
|
45
|
+
is_auth: true
|
46
|
+
is_skip: false
|
47
|
+
parameters:
|
48
|
+
use_case:
|
49
|
+
contract:
|
50
|
+
action_fetch_by_id:
|
51
|
+
endpoint:
|
52
|
+
is_auth: true
|
53
|
+
is_skip: false
|
54
|
+
parameters:
|
55
|
+
use_case:
|
56
|
+
contract:
|
57
|
+
- required(:id).filled(:string)
|
58
|
+
action_create:
|
59
|
+
endpoint:
|
60
|
+
is_auth: true
|
61
|
+
is_skip: false
|
62
|
+
parameters:
|
63
|
+
use_case:
|
64
|
+
contract:
|
65
|
+
<% (@fields + @uploaders).each do |field| -%>
|
66
|
+
<% column_type = get_column_type(field) -%>
|
67
|
+
<% dry_type = @type_mapping[column_type.to_s] || ':string' -%>
|
68
|
+
<% if @uploaders.include?(field) -%>
|
69
|
+
- optional(:<%= field %>).maybe(<%= dry_type %>)
|
70
|
+
<% else -%>
|
71
|
+
- required(:<%= field %>).filled(<%= dry_type %>)
|
72
|
+
<% end -%>
|
73
|
+
<% end -%>
|
74
|
+
action_update:
|
75
|
+
endpoint:
|
76
|
+
is_auth: true
|
77
|
+
is_skip: false
|
78
|
+
parameters:
|
79
|
+
use_case:
|
80
|
+
contract:
|
81
|
+
- required(:id).filled(:string)
|
82
|
+
<% (@fields + @uploaders).each do |field| -%>
|
83
|
+
<% column_type = get_column_type(field) -%>
|
84
|
+
<% dry_type = @type_mapping[column_type.to_s] || ':string' -%>
|
85
|
+
<% if @uploaders.include?(field) -%>
|
86
|
+
- optional(:<%= field %>).maybe(<%= dry_type %>)
|
87
|
+
<% else -%>
|
88
|
+
- optional(:<%= field %>).maybe(<%= dry_type %>)
|
89
|
+
<% end -%>
|
90
|
+
<% end -%>
|
91
|
+
action_destroy:
|
92
|
+
endpoint:
|
93
|
+
is_auth: true
|
94
|
+
is_skip: false
|
95
|
+
parameters:
|
96
|
+
use_case:
|
97
|
+
contract:
|
98
|
+
- required(:id).filled(:string)
|
99
|
+
entity:
|
100
|
+
skipped_fields:
|
101
|
+
- id
|
102
|
+
- created_at
|
103
|
+
- updated_at
|
104
|
+
<% if @model_class.columns.map(&:name).include?(:type) -%>
|
105
|
+
- type
|
106
|
+
<% end -%>
|
@@ -37,19 +37,15 @@ export default class extends Controller {
|
|
37
37
|
}
|
38
38
|
|
39
39
|
sidebarToggle(event) {
|
40
|
-
const toggleClose = document.querySelector(".sidebar-toggle-close");
|
41
|
-
const toggeleOpen = document.querySelector(".sidebar-toggle-open");
|
42
40
|
const backdropActive = document.querySelector(".backdrop-active");
|
43
41
|
const sidebar = document.querySelector(".sidebar");
|
44
42
|
if (sidebar.classList.contains('side_hide')) {
|
45
|
-
toggleClose.classList.remove('hidden');
|
46
|
-
toggeleOpen.classList.add('hidden');
|
47
43
|
sidebar.classList.remove('side_hide');
|
48
44
|
backdropActive.classList.remove('hidden');
|
49
45
|
anime({
|
50
46
|
targets: ".backdrop-active",
|
51
47
|
translateX: 0,
|
52
|
-
opacity: [0, 0.
|
48
|
+
opacity: [0, 0.8],
|
53
49
|
easing: 'easeInOutSine',
|
54
50
|
complete: function (anim) {
|
55
51
|
console.log('Backdrop Active');
|
@@ -65,8 +61,6 @@ export default class extends Controller {
|
|
65
61
|
}
|
66
62
|
});
|
67
63
|
} else {
|
68
|
-
toggleClose.classList.add('hidden');
|
69
|
-
toggeleOpen.classList.remove('hidden');
|
70
64
|
sidebar.classList.add('side_hide');
|
71
65
|
anime({
|
72
66
|
targets: '.sidebar',
|
@@ -80,7 +74,7 @@ export default class extends Controller {
|
|
80
74
|
anime({
|
81
75
|
targets: ".backdrop-active",
|
82
76
|
translateX: 0,
|
83
|
-
opacity: [0.
|
77
|
+
opacity: [0.8, 0],
|
84
78
|
easing: 'easeInOutSine',
|
85
79
|
complete: function (anim) {
|
86
80
|
backdropActive.classList.add('hidden');
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class Models::Auth < ApplicationRecord
|
2
|
+
# Include default devise modules. Others available are:
|
3
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
4
|
+
devise :database_authenticatable, :registerable,
|
5
|
+
:recoverable, :rememberable, :validatable
|
6
|
+
belongs_to :account, class_name: 'Models::Account', foreign_key: 'account_id'
|
7
|
+
belongs_to :user, class_name: 'Models::User', foreign_key: 'user_id'
|
8
|
+
end
|
data/lib/generators/sun_sword/templates_frontend/views/layouts/dashboard/_sidebar.html.erb.tt
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
<!-- Sidebar component, swap this element with another sidebar if you like -->
|
2
|
+
<div class="flex items-center px-4 lg:hidden sidebar-toggle-close">
|
3
|
+
<div class="py-2.5">
|
4
|
+
<button type="button" class="hover:bg-gray-100 rounded-lg p-2.5 mt-2 m-1 text-gray-700 lg:hidden cursor-pointer" data-action="click->web#sidebarToggle">
|
5
|
+
<span class="sr-only">Open sidebar</span>
|
6
|
+
<svg class="w-6 h-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
7
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12"/>
|
8
|
+
</svg>
|
9
|
+
</button>
|
10
|
+
</div>
|
11
|
+
</div>
|
2
12
|
<div class="flex grow flex-col gap-y-5 overflow-y-auto px-6 pb-2">
|
3
13
|
<div class="flex h-16 shrink-0 items-center">
|
4
14
|
<%%= render 'components/layouts/sidebar_logo' %>
|
@@ -17,7 +27,7 @@
|
|
17
27
|
</button>
|
18
28
|
<!-- Expandable link section, show/hide based on state. -->
|
19
29
|
<ul class="mt-1 px-2" id="sub-menu-1">
|
20
|
-
|
30
|
+
<%%# generate_link %>
|
21
31
|
</ul>
|
22
32
|
</div>
|
23
33
|
</li>
|
data/lib/generators/sun_sword/templates_frontend/views/layouts/dashboard/application.html.erb.tt
CHANGED
@@ -29,26 +29,23 @@
|
|
29
29
|
<%%# mobile %>
|
30
30
|
<div class="fixed bg-white rounded-2xl m-2 inset-y-0 w-64 -left-[300px] lg:hidden sidebar side_hide z-50" data-action="click->web#onSidebarClick">
|
31
31
|
<nav class="flex h-full min-h-0 flex-col">
|
32
|
-
<%%= render "layouts/
|
32
|
+
<%%= render "components/layouts/sidebar", from: :mobile %>
|
33
33
|
</nav>
|
34
34
|
</div>
|
35
35
|
|
36
36
|
<%%# browser %>
|
37
37
|
<div class="fixed inset-y-0 w-64 max-lg:hidden">
|
38
38
|
<nav class="flex h-full min-h-0 flex-col">
|
39
|
-
<%%= render "layouts/
|
39
|
+
<%%= render "components/layouts/sidebar", from: :browser %>
|
40
40
|
</nav>
|
41
41
|
</div>
|
42
42
|
|
43
43
|
<%%# Sidebar Toggle %>
|
44
|
-
<div class="
|
44
|
+
<div class="flex items-center px-4 lg:hidden sidebar-toggle-open">
|
45
45
|
<div class="py-2.5">
|
46
|
-
<button type="button" class="-
|
46
|
+
<button type="button" class="hover:bg-gray-100 rounded-lg p-2.5 mt-2 m-1 text-gray-700 lg:hidden cursor-pointer" data-action="click->web#sidebarToggle">
|
47
47
|
<span class="sr-only">Open sidebar</span>
|
48
|
-
<svg class="
|
49
|
-
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12"/>
|
50
|
-
</svg>
|
51
|
-
<svg class="sidebar-toggle-open w-6 h-6" data-slot="icon" viewBox="0 0 20 20" aria-hidden="true">
|
48
|
+
<svg class="w-6 h-6" data-slot="icon" viewBox="0 0 20 20" aria-hidden="true">
|
52
49
|
<path d="M2 6.75C2 6.33579 2.33579 6 2.75 6H17.25C17.6642 6 18 6.33579 18 6.75C18 7.16421 17.6642 7.5 17.25 7.5H2.75C2.33579 7.5 2 7.16421 2 6.75ZM2 13.25C2 12.8358 2.33579 12.5 2.75 12.5H17.25C17.6642 12.5 18 12.8358 18 13.25C18 13.6642 17.6642 14 17.25 14H2.75C2.33579 14 2 13.6642 2 13.25Z"></path>
|
53
50
|
</svg>
|
54
51
|
</button>
|
@@ -56,7 +53,7 @@
|
|
56
53
|
</div>
|
57
54
|
|
58
55
|
<main class="flex flex-1 flex-col pb-2 lg:min-w-0 lg:pl-64 lg:pr-2 lg:pt-2">
|
59
|
-
<div class="fixed inset-0 bg-gray-900
|
56
|
+
<div class="fixed inset-0 bg-gray-900 backdrop-blur-lg backdrop-active opacity-0 hidden lg:hidden" aria-hidden="true"></div>
|
60
57
|
<div class="grow p-6 lg:rounded-lg lg:bg-white lg:p-10 lg:shadow-sm lg:ring-1 lg:ring-zinc-950/5 dark:lg:bg-zinc-900 dark:lg:ring-white/10">
|
61
58
|
<div class="mx-auto max-w-6xl">
|
62
59
|
<%%= yield %>
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# Template for the controller (controllers/controller.rb.tt)
|
2
|
-
class <%= [@route_scope_class, @scope_class].join("::") %>Controller < ApplicationController
|
2
|
+
class <%= [@route_scope_class, @scope_class].reject { |c| c.empty? }.join("::") %>Controller < ApplicationController
|
3
3
|
before_action :set_<%= @variable_subject %>, only: %i[show edit update destroy]
|
4
4
|
layout :set_layouts
|
5
5
|
|
6
|
-
# GET /<%= [@route_scope_path, @scope_path].join("/") %>
|
6
|
+
# GET /<%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("/") %>
|
7
7
|
def index
|
8
|
-
use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('list')].join("::") %>
|
8
|
+
use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('list')].reject { |c| c.empty? }.join("::") %>
|
9
9
|
contract = use_case.contract!(build_contract({}))
|
10
10
|
result = use_case.new(contract).result
|
11
11
|
@<%= @scope_path %> = Dry::Matcher::ResultMatcher.call(result) do |matcher|
|
@@ -15,62 +15,62 @@ class <%= [@route_scope_class, @scope_class].join("::") %>Controller < Applicati
|
|
15
15
|
render '<%= @route_scope_path %>/<%= @scope_path %>/index'
|
16
16
|
end
|
17
17
|
|
18
|
-
# GET /<%= [@route_scope_path, @scope_path, ":uuid"].join("/") %>
|
18
|
+
# GET /<%= [@route_scope_path, @scope_path, ":uuid"].reject { |c| c.empty? }.join("/") %>
|
19
19
|
def show
|
20
20
|
end
|
21
21
|
|
22
|
-
# GET /<%= [@route_scope_path, @scope_path, "new"].join("/") %>
|
22
|
+
# GET /<%= [@route_scope_path, @scope_path, "new"].reject { |c| c.empty? }.join("/") %>
|
23
23
|
def new
|
24
24
|
@<%= @variable_subject %> = <%= @model_class %>.new
|
25
25
|
end
|
26
26
|
|
27
|
-
# GET /<%= [@route_scope_path, @scope_path, ":uuid", "edit"].join("/") %>
|
27
|
+
# GET /<%= [@route_scope_path, @scope_path, ":uuid", "edit"].reject { |c| c.empty? }.join("/") %>
|
28
28
|
def edit
|
29
29
|
end
|
30
30
|
|
31
31
|
# POST /<%= @route_scope_path %>/<%= @scope_path %>
|
32
32
|
def create
|
33
|
-
use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('create')].join("::") %>
|
33
|
+
use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('create')].reject { |c| c.empty? }.join("::") %>
|
34
34
|
contract = use_case.contract!(build_contract(<%= @variable_subject %>_params))
|
35
35
|
result = use_case.new(contract).result
|
36
36
|
Dry::Matcher::ResultMatcher.call(result) do |matcher|
|
37
37
|
matcher.success do |response|
|
38
|
-
redirect_to <%= [@route_scope_path, @variable_subject].join("_") %>_url(id: response.id), success: '<%= @subject_class %> was successfully created.'
|
38
|
+
redirect_to <%= [@route_scope_path, @variable_subject].reject { |c| c.empty? }.join("_") %>_url(id: response.id), success: '<%= @subject_class %> was successfully created.'
|
39
39
|
end
|
40
40
|
matcher.failure do |errors|
|
41
41
|
@<%= @variable_subject %> = build_form_errors(<%= @variable_subject %>_params, <%= @model_class %>.new, errors)
|
42
|
-
render '<%= [@route_scope_path, @scope_path, "new"].join("/") %>', status: :unprocessable_entity
|
42
|
+
render '<%= [@route_scope_path, @scope_path, "new"].reject { |c| c.empty? }.join("/") %>', status: :unprocessable_entity
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
# PATCH/PUT /<%= [@route_scope_path, @scope_path, ":uuid"].join("/") %>
|
47
|
+
# PATCH/PUT /<%= [@route_scope_path, @scope_path, ":uuid"].reject { |c| c.empty? }.join("/") %>
|
48
48
|
def update
|
49
|
-
use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('update')].join("::") %>
|
49
|
+
use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('update')].reject { |c| c.empty? }.join("::") %>
|
50
50
|
contract = use_case.contract!(build_contract(<%= @variable_subject %>_params).merge({ id: params[:id] }))
|
51
51
|
result = use_case.new(contract).result
|
52
52
|
Dry::Matcher::ResultMatcher.call(result) do |matcher|
|
53
53
|
matcher.success do |response|
|
54
|
-
redirect_to <%= [@route_scope_path, @variable_subject].join("_") %>_url(id: response.id), success: '<%= @subject_class %> was successfully updated.'
|
54
|
+
redirect_to <%= [@route_scope_path, @variable_subject].reject { |c| c.empty? }.join("_") %>_url(id: response.id), success: '<%= @subject_class %> was successfully updated.'
|
55
55
|
end
|
56
56
|
matcher.failure do |errors|
|
57
57
|
@<%= @variable_subject %> = build_form_errors(<%= @variable_subject %>_params, <%= @model_class %>.find(params[:id]), errors)
|
58
|
-
render '<%= [@route_scope_path, @scope_path, "edit"].join("/") %>', status: :unprocessable_entity
|
58
|
+
render '<%= [@route_scope_path, @scope_path, "edit"].reject { |c| c.empty? }.join("/") %>', status: :unprocessable_entity
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
# DELETE /<%= [@route_scope_path, @scope_path, ":uuid"].join("/") %>
|
63
|
+
# DELETE /<%= [@route_scope_path, @scope_path, ":uuid"].reject { |c| c.empty? }.join("/") %>
|
64
64
|
def destroy
|
65
|
-
use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('destroy')].join("::") %>
|
65
|
+
use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('destroy')].reject { |c| c.empty? }.join("::") %>
|
66
66
|
contract = use_case.contract!(build_contract({ id: params[:id] }))
|
67
67
|
result = use_case.new(contract).result
|
68
68
|
Dry::Matcher::ResultMatcher.call(result) do |matcher|
|
69
69
|
matcher.success do |response|
|
70
|
-
redirect_to <%= [@route_scope_path, @scope_path].join("_") %>_url, notice: '<%= @subject_class %> was successfully destroyed.'
|
70
|
+
redirect_to <%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_") %>_url, notice: '<%= @subject_class %> was successfully destroyed.'
|
71
71
|
end
|
72
72
|
matcher.failure do |errors|
|
73
|
-
redirect_to <%= [@route_scope_path, @scope_path].join("_") %>_url, error: '<%= @subject_class %> could not be destroyed.'
|
73
|
+
redirect_to <%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_") %>_url, error: '<%= @subject_class %> could not be destroyed.'
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -79,8 +79,12 @@ class <%= [@route_scope_class, @scope_class].join("::") %>Controller < Applicati
|
|
79
79
|
|
80
80
|
# Use callbacks to share common setup or constraints between actions.
|
81
81
|
def set_<%= @variable_subject %>
|
82
|
+
<% if SunSword.scope_owner_column.present? -%>
|
83
|
+
@<%= @variable_subject %> = <%= @model_class %>.find_by(id: params[:id], <%=SunSword.scope_owner_column%>: <%=SunSword.scope_owner_column%>)
|
84
|
+
<%else %>
|
82
85
|
@<%= @variable_subject %> = <%= @model_class %>.find_by(id: params[:id])
|
83
|
-
|
86
|
+
<%end %>
|
87
|
+
redirect_to <%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_") %>_url, error: '<%= @subject_class %> not found.' if @<%= @variable_subject %>.nil?
|
84
88
|
end
|
85
89
|
|
86
90
|
# Only allow a list of trusted parameters through.
|
@@ -1,22 +1,17 @@
|
|
1
|
-
<%%= form_with(model: <%= @variable_subject %>, url: ((["new", "create"].include? action_name) ? <%= [@route_scope_path, @scope_path].join("_") %>_path : <%= [@route_scope_path, @scope_path.singularize].join("_") %>_path(<%= @variable_subject %>)), class: "contents") do |form| %>
|
1
|
+
<%%= form_with(model: <%= @variable_subject %>, url: ((["new", "create"].include? action_name) ? <%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_") %>_path : <%= [@route_scope_path, @scope_path.singularize].reject { |c| c.empty? }.join("_") %>_path(<%= @variable_subject %>)), class: "contents") do |form| %>
|
2
2
|
|
3
3
|
<%%= render "components/error_form_submit", resource: <%= @variable_subject %> if <%= @variable_subject %>.errors.any? %>
|
4
4
|
|
5
5
|
<div class="space-y-12 sm:space-y-16">
|
6
6
|
<div>
|
7
7
|
<div class="mt-10 space-y-8 pb-12 sm:space-y-0 sm:pb-0 p-4 class-card-container">
|
8
|
-
|
9
|
-
<%%= form.label :name, class: "class-label" %>
|
10
|
-
<div class="mt-2 sm:col-span-2 sm:mt-0">
|
11
|
-
<%%= form.text_field :name, class: "class-text-field" %>
|
12
|
-
</div>
|
13
|
-
</div>
|
8
|
+
<%= @form_fields_html %>
|
14
9
|
</div>
|
15
10
|
</div>
|
16
11
|
</div>
|
17
12
|
|
18
13
|
<div class="mt-6 flex items-center justify-end gap-x-6">
|
19
|
-
<%%= link_to "Back", <%= [@route_scope_path, @scope_path].join("_") %>_path, class: "inline-flex justify-center class-button" %>
|
14
|
+
<%%= link_to "Back", <%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_") %>_path, class: "inline-flex justify-center class-button" %>
|
20
15
|
<%%= form.submit class: "inline-flex justify-center class-button" %>
|
21
16
|
</div>
|
22
17
|
<%% end %>
|
@@ -1 +1 @@
|
|
1
|
-
<a data-remote="true" id="<%= [@route_scope_path, @scope_path].join("_")%>" href="<%%=<%= [@route_scope_path, @scope_path].join("_")%>_path %>#<%= [@route_scope_path, @scope_path].join("_")%>" class="<%%= ['<%= [@route_scope_path, @scope_path].join("_")%>_index'].include?("#{controller_name}_#{action_name}") ? "class-menu-active-link" : "class-menu-link" %>"><%= @variable_subject.titleize%></a>
|
1
|
+
<a data-remote="true" id="<%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_")%>" href="<%%=<%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_")%>_path %>#<%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_")%>" class="<%%= ['<%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_")%>_index'].include?("#{controller_name}_#{action_name}") ? "class-menu-active-link" : "class-menu-link" %>"><%= @variable_subject.titleize%></a>
|
@@ -9,7 +9,7 @@
|
|
9
9
|
<p class="mt-2 text-sm text-gray-700">A list of all the <%= @subject_class %>.</p>
|
10
10
|
</div>
|
11
11
|
<div class="mt-4 sm:ml-16 sm:mt-0 sm:flex-none">
|
12
|
-
<%%= link_to new_<%= [@route_scope_path, @scope_path.singularize].join("_") %>_path do %>
|
12
|
+
<%%= link_to new_<%= [@route_scope_path, @scope_path.singularize].reject { |c| c.empty? }.join("_") %>_path do %>
|
13
13
|
<button type="button" class="block class-button">Add user</button>
|
14
14
|
<%% end %>
|
15
15
|
</div>
|
@@ -28,17 +28,17 @@
|
|
28
28
|
<tbody class="divide-y bg-white">
|
29
29
|
<%% @<%= @scope_path %>.response.each do |<%= @variable_subject %>| %>
|
30
30
|
<tr>
|
31
|
-
<%@controllers.list_fields.each do |
|
31
|
+
<%@controllers.list_fields.each do |field| -%>
|
32
32
|
<td class="class-td">
|
33
33
|
<div class="flex items-center">
|
34
34
|
<div>
|
35
|
-
<div class="text-sm text-gray-900"><%%= <%= @variable_subject
|
35
|
+
<div class="text-sm text-gray-900"><%%= <%= @variable_subject %>.<%=field %> %></div>
|
36
36
|
</div>
|
37
37
|
</div>
|
38
38
|
</td>
|
39
39
|
<%end-%>
|
40
40
|
<td class="class-td text-center">
|
41
|
-
<%%= render "components/link_action", key: "<%= [@route_scope_path, @variable_subject].join("_") %>", value:
|
41
|
+
<%%= render "components/link_action", key: "<%= [@route_scope_path, @variable_subject].reject { |c| c.empty? }.join("_") %>", value: <%= @variable_subject %>, actions: [:show, :edit, :destroy] %>
|
42
42
|
</td>
|
43
43
|
</tr>
|
44
44
|
<%% end %>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<p class="mt-1 max-w-2xl text-sm leading-6 text-gray-500">Details info from <%= @subject_class %> .</p>
|
7
7
|
</div>
|
8
8
|
<div class="mt-4 sm:ml-16 sm:mt-0 sm:flex-none">
|
9
|
-
<%%= render "components/link_action", key: "<%= [@route_scope_path, @variable_subject].join("_") %>", value: @<%= @variable_subject %>, actions: [:edit, :destroy] %>
|
9
|
+
<%%= render "components/link_action", key: "<%= [@route_scope_path, @variable_subject].reject { |c| c.empty? }.join("_") %>", value: @<%= @variable_subject %>, actions: [:edit, :destroy] %>
|
10
10
|
</div>
|
11
11
|
</div>
|
12
12
|
<div class="border-t border-gray-100">
|
@@ -20,7 +20,7 @@
|
|
20
20
|
</dl>
|
21
21
|
</div>
|
22
22
|
<div class="mt-6 flex items-center justify-end gap-x-6">
|
23
|
-
<%%= link_to "Back", <%= [@route_scope_path, @scope_path].join("_") %>_path, class: "inline-flex justify-center class-button" %>
|
23
|
+
<%%= link_to "Back", <%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_") %>_path, class: "inline-flex justify-center class-button" %>
|
24
24
|
</div>
|
25
25
|
</div>
|
26
26
|
</div>
|
data/lib/sun-sword.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'sun_sword/version'
|
4
|
+
require 'sun_sword/configuration'
|
4
5
|
|
5
6
|
module SunSword
|
6
|
-
|
7
|
+
extend SunSword::Configuration
|
8
|
+
define_setting :scope_owner_column, ''
|
7
9
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SunSword
|
4
|
+
module Configuration
|
5
|
+
def setup
|
6
|
+
yield self
|
7
|
+
end
|
8
|
+
|
9
|
+
def define_setting(name, default = nil)
|
10
|
+
class_variable_set("@@#{name}", default)
|
11
|
+
|
12
|
+
define_class_method "#{name}=" do |value|
|
13
|
+
class_variable_set("@@#{name}", value)
|
14
|
+
end
|
15
|
+
|
16
|
+
define_class_method name do
|
17
|
+
class_variable_get("@@#{name}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def define_class_method(name, &block)
|
24
|
+
(class << self; self; end).instance_eval do
|
25
|
+
define_method name, &block
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|