sun-sword 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/sun_sword/frontend_generator.rb +2 -43
- data/lib/generators/sun_sword/scaffold_generator.rb +2 -12
- data/lib/generators/sun_sword/templates_frontend/controllers/application_controller.rb.tt +6 -7
- data/lib/generators/sun_sword/templates_scaffold/controllers/controller.rb.tt +21 -9
- data/lib/generators/sun_sword/templates_scaffold/views/show.html.erb.tt +21 -0
- data/lib/sun_sword/version.rb +1 -1
- metadata +3 -9
- data/lib/generators/sun_sword/templates_frontend/db/migrate/20241117042039_devise_create_auths.rb +0 -47
- data/lib/generators/sun_sword/templates_frontend/db/migrate/20241117043154_create_models_accounts.rb +0 -11
- data/lib/generators/sun_sword/templates_frontend/db/migrate/20241117044142_create_models_users.rb +0 -16
- data/lib/generators/sun_sword/templates_frontend/models/models/account.rb +0 -4
- data/lib/generators/sun_sword/templates_frontend/models/models/auth.rb +0 -8
- data/lib/generators/sun_sword/templates_frontend/models/models/user.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e876a062dad8a99dc15b8954c7bdf447f843de121bc578932068394cab917000
|
4
|
+
data.tar.gz: 67c9dc597e823267475da811830f40699496537467a0fb2ca0cf20395543addc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b81d13ef0544cb3aa9ec08fb89aaae894a6636e551aa8234653cd03ec55a1ca8a4df89616aad8266f81222320655f112d16b2a50c02bcfdcf5d9f417715f7f4
|
7
|
+
data.tar.gz: 2b2f61c502fed7615f2efbc868d4874c390261103d261364e893af9f4ff4233d66528557cb8a911e7bfc7d8837bfb0eb8d41cec2d4c501ab3dccb57f03614f66
|
@@ -10,11 +10,9 @@ module SunSword
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
desc 'This generator installs Vite with Rails
|
13
|
+
desc 'This generator installs Vite with Rails 8 configuration'
|
14
14
|
|
15
15
|
def setup
|
16
|
-
validation!
|
17
|
-
remove_assets_folder
|
18
16
|
copy_assets_from_template
|
19
17
|
|
20
18
|
add_vite_to_gemfile
|
@@ -26,50 +24,10 @@ module SunSword
|
|
26
24
|
generate_controllers_site
|
27
25
|
generate_components
|
28
26
|
modify_layout_for_vite
|
29
|
-
|
30
|
-
setup_migration
|
31
|
-
setup_models
|
32
|
-
gem_dependencies
|
33
27
|
end
|
34
28
|
|
35
29
|
private
|
36
30
|
|
37
|
-
def gem_dependencies
|
38
|
-
# auth
|
39
|
-
# rails generate devise:install
|
40
|
-
# config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
41
|
-
# devise_for :auths, class_name: "Models::Auth", controllers: {
|
42
|
-
# sessions: 'auths/sessions'
|
43
|
-
# }
|
44
|
-
gem 'devise', '~> 4.9'
|
45
|
-
|
46
|
-
say 'Menjalankan bundle install...'
|
47
|
-
run 'bundle install'
|
48
|
-
run 'rails generate devise:install'
|
49
|
-
inject_into_file 'config/routes.rb', " devise_for :auths, class_name: 'Models::Auth'\n", after: "Rails.application.routes.draw do\n"
|
50
|
-
end
|
51
|
-
|
52
|
-
def setup_migration
|
53
|
-
template 'db/migrate/20241117042039_devise_create_auths.rb', File.join('db/migrate/20241117042039_devise_create_auths.rb')
|
54
|
-
template 'db/migrate/20241117043154_create_models_accounts.rb', File.join('db/migrate/20241117043154_create_models_accounts.rb')
|
55
|
-
template 'db/migrate/20241117044142_create_models_users.rb', File.join('db/migrate/20241117044142_create_models_users.rb')
|
56
|
-
|
57
|
-
template 'db/seeds.rb', File.join('db/seeds.rb')
|
58
|
-
end
|
59
|
-
|
60
|
-
def setup_models
|
61
|
-
template 'models/models/account.rb', File.join('app/models/models/account.rb')
|
62
|
-
template 'models/models/auth.rb', File.join('app/models/models/auth.rb')
|
63
|
-
template 'models/models/user.rb', File.join('app/models/models/user.rb')
|
64
|
-
end
|
65
|
-
|
66
|
-
def validation!
|
67
|
-
unless File.exist?('config/initializers/sun_sword.rb')
|
68
|
-
say 'Error must create init configuration for sun_sword!'
|
69
|
-
raise Thor::Error, 'run: bin/rails generate sun_sword:init'
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
31
|
def remove_assets_folder
|
74
32
|
assets_path = "#{path_app}/assets"
|
75
33
|
if Dir.exist?(assets_path)
|
@@ -144,6 +102,7 @@ module SunSword
|
|
144
102
|
template 'controllers/application_controller.rb.tt', File.join('app/controllers/application_controller.rb')
|
145
103
|
site_route = <<-RUBY
|
146
104
|
|
105
|
+
default_url_options :host => "#{ENV['BASE_URL']}"
|
147
106
|
root "site#stimulus"
|
148
107
|
get "site/jadi_a"
|
149
108
|
get "site/jadi_b"
|
@@ -6,7 +6,6 @@ module SunSword
|
|
6
6
|
argument :arg_scope, type: :hash, default: '', banner: 'scope:dashboard'
|
7
7
|
|
8
8
|
def running
|
9
|
-
validation!
|
10
9
|
setup_variables
|
11
10
|
create_root_folder
|
12
11
|
create_controller_file
|
@@ -16,13 +15,6 @@ module SunSword
|
|
16
15
|
|
17
16
|
private
|
18
17
|
|
19
|
-
def validation!
|
20
|
-
unless File.exist?('config/initializers/sun_sword.rb')
|
21
|
-
say 'Error must create init configuration for sun_sword!'
|
22
|
-
raise Thor::Error, 'run: bin/rails generate sun_sword:init'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
18
|
def setup_variables
|
27
19
|
config = YAML.load_file("db/structures/#{arg_structure}_structure.yaml")
|
28
20
|
@structure = Hashie::Mash.new(config)
|
@@ -33,6 +25,7 @@ module SunSword
|
|
33
25
|
entity = @structure.entity || {}
|
34
26
|
|
35
27
|
@actor = @structure.actor
|
28
|
+
@resource_owner_id = @structure.resource_owner_id
|
36
29
|
@uploaders = @structure.uploaders || []
|
37
30
|
@search_able = @structure.search_able || []
|
38
31
|
@services = @structure.domains || {}
|
@@ -221,15 +214,12 @@ module SunSword
|
|
221
214
|
if @route_scope_path.present?
|
222
215
|
inject_into_file routes_file, " resources :#{@scope_path}\n", after: "namespace :#{@route_scope_path} do\n"
|
223
216
|
else
|
224
|
-
inject_into_file routes_file, "
|
217
|
+
inject_into_file routes_file, " resources :#{@scope_path}\n", after: "Rails.application.routes.draw do\n"
|
225
218
|
end
|
226
219
|
end
|
227
220
|
|
228
221
|
def contract_fields
|
229
222
|
skip_contract_fields = @skipped_fields.map(&:strip).uniq
|
230
|
-
if SunSword.scope_owner_column.present?
|
231
|
-
skip_contract_fields << SunSword.scope_owner_column.to_s
|
232
|
-
end
|
233
223
|
@model_class.columns.reject { |column| skip_contract_fields.include?(column.name.to_s) }.map(&:name).map(&:to_s)
|
234
224
|
end
|
235
225
|
|
@@ -5,13 +5,12 @@ class ApplicationController < ActionController::Base
|
|
5
5
|
|
6
6
|
protected
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
8
|
+
# Adjust the value of <resource_owner_id> in db/structures/<resource>_structure.yaml
|
9
|
+
# Ignore this comment if you haven't generated the structure yet
|
11
10
|
|
12
|
-
def
|
13
|
-
|
14
|
-
end
|
11
|
+
#def <resource_owner_id>
|
12
|
+
# current_auth.<resource_owner_id>
|
13
|
+
#end
|
15
14
|
|
16
15
|
def build_form_errors(params, model, errors)
|
17
16
|
params.keys.each do |key|
|
@@ -35,6 +34,6 @@ class ApplicationController < ActionController::Base
|
|
35
34
|
|
36
35
|
def set_layouts
|
37
36
|
# "#{current_auth.user.role}/application"
|
38
|
-
|
37
|
+
'owner/application'
|
39
38
|
end
|
40
39
|
end
|
@@ -8,11 +8,15 @@ class <%= [@route_scope_class, @scope_class].reject { |c| c.empty? }.join("::")
|
|
8
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
|
-
|
12
|
-
matcher.success
|
13
|
-
|
11
|
+
Dry::Matcher::ResultMatcher.call(result) do |matcher|
|
12
|
+
matcher.success do |response|
|
13
|
+
@<%= @scope_path %> = response
|
14
|
+
render '<%= @route_scope_path %>/<%= @scope_path %>/index'
|
15
|
+
end
|
16
|
+
matcher.failure do |errors|
|
17
|
+
redirect_to root_path, success: errors
|
18
|
+
end
|
14
19
|
end
|
15
|
-
render '<%= @route_scope_path %>/<%= @scope_path %>/index'
|
16
20
|
end
|
17
21
|
|
18
22
|
# GET /<%= [@route_scope_path, @scope_path, ":uuid"].reject { |c| c.empty? }.join("/") %>
|
@@ -20,9 +24,13 @@ class <%= [@route_scope_class, @scope_class].reject { |c| c.empty? }.join("::")
|
|
20
24
|
use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('fetch', '_by_id')].reject { |c| c.empty? }.join("::") %>
|
21
25
|
contract = use_case.contract!(build_contract({ id: params[:id] }))
|
22
26
|
result = use_case.new(contract).result
|
23
|
-
|
24
|
-
matcher.success
|
25
|
-
|
27
|
+
Dry::Matcher::ResultMatcher.call(result) do |matcher|
|
28
|
+
matcher.success do |response|
|
29
|
+
@<%= @variable_subject %> = response
|
30
|
+
end
|
31
|
+
matcher.failure do |errors|
|
32
|
+
redirect_to root_path, success: errors
|
33
|
+
end
|
26
34
|
end
|
27
35
|
end
|
28
36
|
|
@@ -84,10 +92,14 @@ class <%= [@route_scope_class, @scope_class].reject { |c| c.empty? }.join("::")
|
|
84
92
|
|
85
93
|
private
|
86
94
|
|
95
|
+
def build_contract(params)
|
96
|
+
{ <%=@resource_owner_id%>: <%=@resource_owner_id%> }.merge(params)
|
97
|
+
end
|
98
|
+
|
87
99
|
# Use callbacks to share common setup or constraints between actions.
|
88
100
|
def set_<%= @variable_subject %>
|
89
|
-
<% if
|
90
|
-
@<%= @variable_subject %> = <%= @model_class %>.find_by(id: params[:id],
|
101
|
+
<% if @resource_owner_id.present? -%>
|
102
|
+
@<%= @variable_subject %> = <%= @model_class %>.find_by(id: params[:id], <%=@resource_owner_id%>: <%=@resource_owner_id%>)
|
91
103
|
<%else %>
|
92
104
|
@<%= @variable_subject %> = <%= @model_class %>.find_by(id: params[:id])
|
93
105
|
<%end %>
|
@@ -12,10 +12,31 @@
|
|
12
12
|
<div class="border-t border-gray-100">
|
13
13
|
<dl class="divide-y divide-gray-100">
|
14
14
|
<%@controllers.show_fields.each do |col| -%>
|
15
|
+
<%if @uploaders.include?(col)-%>
|
16
|
+
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
17
|
+
<dt class="text-sm font-medium text-gray-900"><%=col.titleize%></dt>
|
18
|
+
<dd class="mt-1 text-sm leading-6 text-gray-700 sm:col-span-2 sm:mt-0">
|
19
|
+
<section class="overflow-hidden text-gray-700 ">
|
20
|
+
<div class="container px-5 py-2 mx-auto">
|
21
|
+
<div class="flex flex-wrap -m-1 md:-m-2">
|
22
|
+
<div class="flex flex-wrap w-1/1">
|
23
|
+
<%%= [@<%=@variable_subject%>.<%=col%>].flatten.each do |asset| %>
|
24
|
+
<div class="w-1/3 p-1 md:p-2">
|
25
|
+
<img alt="<%=col.titleize%>" class="block object-cover object-center w-100 rounded-lg" src="<%%= asset %>">
|
26
|
+
</div>
|
27
|
+
<%% end %>
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
</div>
|
31
|
+
</section>
|
32
|
+
</dd>
|
33
|
+
</div>
|
34
|
+
<%else-%>
|
15
35
|
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
16
36
|
<dt class="text-sm font-medium text-gray-900"><%=col.titleize%></dt>
|
17
37
|
<dd class="mt-1 text-sm leading-6 text-gray-700 sm:col-span-2 sm:mt-0"><%%= @<%=@variable_subject%>.<%=col%> %></dd>
|
18
38
|
</div>
|
39
|
+
<%end-%>
|
19
40
|
<%end-%>
|
20
41
|
</dl>
|
21
42
|
</div>
|
data/lib/sun_sword/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sun-sword
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kotarominami
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,9 +77,6 @@ files:
|
|
77
77
|
- lib/generators/sun_sword/templates_frontend/config/vite.json
|
78
78
|
- lib/generators/sun_sword/templates_frontend/controllers/application_controller.rb.tt
|
79
79
|
- lib/generators/sun_sword/templates_frontend/controllers/site_controller.rb
|
80
|
-
- lib/generators/sun_sword/templates_frontend/db/migrate/20241117042039_devise_create_auths.rb
|
81
|
-
- lib/generators/sun_sword/templates_frontend/db/migrate/20241117043154_create_models_accounts.rb
|
82
|
-
- lib/generators/sun_sword/templates_frontend/db/migrate/20241117044142_create_models_users.rb
|
83
80
|
- lib/generators/sun_sword/templates_frontend/db/seeds.rb
|
84
81
|
- lib/generators/sun_sword/templates_frontend/db/structures/example.yaml.tt
|
85
82
|
- lib/generators/sun_sword/templates_frontend/env.development
|
@@ -93,9 +90,6 @@ files:
|
|
93
90
|
- lib/generators/sun_sword/templates_frontend/frontend/pages/web.js
|
94
91
|
- lib/generators/sun_sword/templates_frontend/frontend/stylesheets/application.scss
|
95
92
|
- lib/generators/sun_sword/templates_frontend/helpers/application_helper.rb
|
96
|
-
- lib/generators/sun_sword/templates_frontend/models/models/account.rb
|
97
|
-
- lib/generators/sun_sword/templates_frontend/models/models/auth.rb
|
98
|
-
- lib/generators/sun_sword/templates_frontend/models/models/user.rb
|
99
93
|
- lib/generators/sun_sword/templates_frontend/package.json
|
100
94
|
- lib/generators/sun_sword/templates_frontend/postcss.config.js
|
101
95
|
- lib/generators/sun_sword/templates_frontend/rubocop.yml.tt
|
@@ -145,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
139
|
- !ruby/object:Gem::Version
|
146
140
|
version: '0'
|
147
141
|
requirements: []
|
148
|
-
rubygems_version: 3.5.
|
142
|
+
rubygems_version: 3.5.23
|
149
143
|
signing_key:
|
150
144
|
specification_version: 4
|
151
145
|
summary: Sun Sword is a Generator for Clean Architecture
|
data/lib/generators/sun_sword/templates_frontend/db/migrate/20241117042039_devise_create_auths.rb
DELETED
@@ -1,47 +0,0 @@
|
|
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
DELETED
@@ -1,16 +0,0 @@
|
|
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
|
@@ -1,8 +0,0 @@
|
|
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
|