sun-sword 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -10
  3. data/lib/generators/sun_sword/frontend_generator.rb +43 -19
  4. data/lib/generators/sun_sword/init_generator.rb +15 -0
  5. data/lib/generators/sun_sword/scaffold_generator.rb +160 -9
  6. data/lib/generators/sun_sword/templates_frontend/config/devise.rb +313 -0
  7. data/lib/generators/sun_sword/templates_frontend/controllers/application_controller.rb.tt +7 -3
  8. data/lib/generators/sun_sword/templates_frontend/controllers/site_controller.rb +1 -0
  9. data/lib/generators/sun_sword/templates_frontend/db/migrate/20241117042039_devise_create_auths.rb +47 -0
  10. data/lib/generators/sun_sword/templates_frontend/db/migrate/20241117043154_create_models_accounts.rb +11 -0
  11. data/lib/generators/sun_sword/templates_frontend/db/migrate/20241117044142_create_models_users.rb +16 -0
  12. data/lib/generators/sun_sword/templates_frontend/db/seeds.rb +3 -0
  13. data/lib/generators/sun_sword/templates_frontend/db/structures/example.yaml.tt +106 -0
  14. data/lib/generators/sun_sword/templates_frontend/frontend/pages/web.js +2 -8
  15. data/lib/generators/sun_sword/templates_frontend/models/models/account.rb +4 -0
  16. data/lib/generators/sun_sword/templates_frontend/models/models/auth.rb +8 -0
  17. data/lib/generators/sun_sword/templates_frontend/models/models/user.rb +5 -0
  18. data/lib/generators/sun_sword/templates_frontend/views/layouts/dashboard/_sidebar.html.erb.tt +11 -1
  19. data/lib/generators/sun_sword/templates_frontend/views/layouts/dashboard/application.html.erb.tt +6 -9
  20. data/lib/generators/sun_sword/templates_init/config/initializers/sun_sword.rb +3 -0
  21. data/lib/generators/sun_sword/templates_scaffold/controllers/controller.rb.tt +31 -20
  22. data/lib/generators/sun_sword/templates_scaffold/views/_form.html.erb.tt +3 -8
  23. data/lib/generators/sun_sword/templates_scaffold/views/components/menu/link.html.erb.tt +1 -1
  24. data/lib/generators/sun_sword/templates_scaffold/views/index.html.erb.tt +4 -4
  25. data/lib/generators/sun_sword/templates_scaffold/views/show.html.erb.tt +2 -2
  26. data/lib/sun-sword.rb +4 -2
  27. data/lib/sun_sword/configuration.rb +29 -0
  28. data/lib/sun_sword/version.rb +1 -1
  29. metadata +28 -3
  30. data/lib/generators/sun_sword/templates_frontend/controllers/dashboard/site_controller.rb +0 -6
@@ -1,76 +1,83 @@
1
1
  # Template for the controller (controllers/controller.rb.tt)
2
- class <%= [@route_scope_class, @scope_class].join("::") %>Controller < ApplicationController
3
- before_action :set_<%= @variable_subject %>, only: %i[show edit update destroy]
2
+ class <%= [@route_scope_class, @scope_class].reject { |c| c.empty? }.join("::") %>Controller < ApplicationController
3
+ before_action :set_<%= @variable_subject %>, only: %i[edit update]
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
- @<%= @scope_path %> = Dry::Matcher::ResultMatcher.call(result) do |matcher|
11
+ @<%= @variable_subject %> = Dry::Matcher::ResultMatcher.call(result) do |matcher|
12
12
  matcher.success { |response| response }
13
13
  matcher.failure { |errors| errors }
14
14
  end
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
+ use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('fetch', '_by_id')].reject { |c| c.empty? }.join("::") %>
21
+ contract = use_case.contract!(build_contract({ id: params[:id] }))
22
+ result = use_case.new(contract).result
23
+ @<%= @scope_path %> = Dry::Matcher::ResultMatcher.call(result) do |matcher|
24
+ matcher.success { |response| response }
25
+ matcher.failure { |errors| errors }
26
+ end
20
27
  end
21
28
 
22
- # GET /<%= [@route_scope_path, @scope_path, "new"].join("/") %>
29
+ # GET /<%= [@route_scope_path, @scope_path, "new"].reject { |c| c.empty? }.join("/") %>
23
30
  def new
24
31
  @<%= @variable_subject %> = <%= @model_class %>.new
25
32
  end
26
33
 
27
- # GET /<%= [@route_scope_path, @scope_path, ":uuid", "edit"].join("/") %>
34
+ # GET /<%= [@route_scope_path, @scope_path, ":uuid", "edit"].reject { |c| c.empty? }.join("/") %>
28
35
  def edit
29
36
  end
30
37
 
31
38
  # POST /<%= @route_scope_path %>/<%= @scope_path %>
32
39
  def create
33
- use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('create')].join("::") %>
40
+ use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('create')].reject { |c| c.empty? }.join("::") %>
34
41
  contract = use_case.contract!(build_contract(<%= @variable_subject %>_params))
35
42
  result = use_case.new(contract).result
36
43
  Dry::Matcher::ResultMatcher.call(result) do |matcher|
37
44
  matcher.success do |response|
38
- redirect_to <%= [@route_scope_path, @variable_subject].join("_") %>_url(id: response.id), success: '<%= @subject_class %> was successfully created.'
45
+ redirect_to <%= [@route_scope_path, @variable_subject].reject { |c| c.empty? }.join("_") %>_url(id: response.id), success: '<%= @subject_class %> was successfully created.'
39
46
  end
40
47
  matcher.failure do |errors|
41
48
  @<%= @variable_subject %> = build_form_errors(<%= @variable_subject %>_params, <%= @model_class %>.new, errors)
42
- render '<%= [@route_scope_path, @scope_path, "new"].join("/") %>', status: :unprocessable_entity
49
+ render '<%= [@route_scope_path, @scope_path, "new"].reject { |c| c.empty? }.join("/") %>', status: :unprocessable_entity
43
50
  end
44
51
  end
45
52
  end
46
53
 
47
- # PATCH/PUT /<%= [@route_scope_path, @scope_path, ":uuid"].join("/") %>
54
+ # PATCH/PUT /<%= [@route_scope_path, @scope_path, ":uuid"].reject { |c| c.empty? }.join("/") %>
48
55
  def update
49
- use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('update')].join("::") %>
56
+ use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('update')].reject { |c| c.empty? }.join("::") %>
50
57
  contract = use_case.contract!(build_contract(<%= @variable_subject %>_params).merge({ id: params[:id] }))
51
58
  result = use_case.new(contract).result
52
59
  Dry::Matcher::ResultMatcher.call(result) do |matcher|
53
60
  matcher.success do |response|
54
- redirect_to <%= [@route_scope_path, @variable_subject].join("_") %>_url(id: response.id), success: '<%= @subject_class %> was successfully updated.'
61
+ redirect_to <%= [@route_scope_path, @variable_subject].reject { |c| c.empty? }.join("_") %>_url(id: response.id), success: '<%= @subject_class %> was successfully updated.'
55
62
  end
56
63
  matcher.failure do |errors|
57
64
  @<%= @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
65
+ render '<%= [@route_scope_path, @scope_path, "edit"].reject { |c| c.empty? }.join("/") %>', status: :unprocessable_entity
59
66
  end
60
67
  end
61
68
  end
62
69
 
63
- # DELETE /<%= [@route_scope_path, @scope_path, ":uuid"].join("/") %>
70
+ # DELETE /<%= [@route_scope_path, @scope_path, ":uuid"].reject { |c| c.empty? }.join("/") %>
64
71
  def destroy
65
- use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('destroy')].join("::") %>
72
+ use_case = Core::UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('destroy')].reject { |c| c.empty? }.join("::") %>
66
73
  contract = use_case.contract!(build_contract({ id: params[:id] }))
67
74
  result = use_case.new(contract).result
68
75
  Dry::Matcher::ResultMatcher.call(result) do |matcher|
69
76
  matcher.success do |response|
70
- redirect_to <%= [@route_scope_path, @scope_path].join("_") %>_url, notice: '<%= @subject_class %> was successfully destroyed.'
77
+ redirect_to <%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_") %>_url, notice: '<%= @subject_class %> was successfully destroyed.'
71
78
  end
72
79
  matcher.failure do |errors|
73
- redirect_to <%= [@route_scope_path, @scope_path].join("_") %>_url, error: '<%= @subject_class %> could not be destroyed.'
80
+ redirect_to <%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_") %>_url, error: '<%= @subject_class %> could not be destroyed.'
74
81
  end
75
82
  end
76
83
  end
@@ -79,8 +86,12 @@ class <%= [@route_scope_class, @scope_class].join("::") %>Controller < Applicati
79
86
 
80
87
  # Use callbacks to share common setup or constraints between actions.
81
88
  def set_<%= @variable_subject %>
89
+ <% if SunSword.scope_owner_column.present? -%>
90
+ @<%= @variable_subject %> = <%= @model_class %>.find_by(id: params[:id], <%=SunSword.scope_owner_column%>: <%=SunSword.scope_owner_column%>)
91
+ <%else %>
82
92
  @<%= @variable_subject %> = <%= @model_class %>.find_by(id: params[:id])
83
- redirect_to <%= [@route_scope_path, @scope_path].join("_") %>_url, error: '<%= @subject_class %> not found.' if @<%= @variable_subject %>.nil?
93
+ <%end %>
94
+ redirect_to <%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_") %>_url, error: '<%= @subject_class %> not found.' if @<%= @variable_subject %>.nil?
84
95
  end
85
96
 
86
97
  # 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
- <div class="class-input">
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 |col| -%>
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 %>.name %></div>
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: user, actions: [:show, :edit, :destroy] %>
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
- require_relative 'sun_sword/version'
3
+ require 'sun_sword/version'
4
+ require 'sun_sword/configuration'
4
5
 
5
6
  module SunSword
6
- # Your code goes here...
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SunSword
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.3'
5
5
  public_constant :VERSION
6
6
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sun-sword
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
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-20 00:00:00.000000000 Z
11
+ date: 2024-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rider-kick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.5
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,15 +81,21 @@ files:
67
81
  - Rakefile
68
82
  - lib/generators/sun_sword/USAGE
69
83
  - lib/generators/sun_sword/frontend_generator.rb
84
+ - lib/generators/sun_sword/init_generator.rb
70
85
  - lib/generators/sun_sword/scaffold_generator.rb
71
86
  - lib/generators/sun_sword/templates_frontend/Procfile.dev
72
87
  - lib/generators/sun_sword/templates_frontend/assets/config/manifest.js
73
88
  - lib/generators/sun_sword/templates_frontend/bin/watch
74
89
  - lib/generators/sun_sword/templates_frontend/config/database.yml
90
+ - lib/generators/sun_sword/templates_frontend/config/devise.rb
75
91
  - lib/generators/sun_sword/templates_frontend/config/vite.json
76
92
  - lib/generators/sun_sword/templates_frontend/controllers/application_controller.rb.tt
77
- - lib/generators/sun_sword/templates_frontend/controllers/dashboard/site_controller.rb
78
93
  - lib/generators/sun_sword/templates_frontend/controllers/site_controller.rb
94
+ - lib/generators/sun_sword/templates_frontend/db/migrate/20241117042039_devise_create_auths.rb
95
+ - lib/generators/sun_sword/templates_frontend/db/migrate/20241117043154_create_models_accounts.rb
96
+ - lib/generators/sun_sword/templates_frontend/db/migrate/20241117044142_create_models_users.rb
97
+ - lib/generators/sun_sword/templates_frontend/db/seeds.rb
98
+ - lib/generators/sun_sword/templates_frontend/db/structures/example.yaml.tt
79
99
  - lib/generators/sun_sword/templates_frontend/env.development
80
100
  - lib/generators/sun_sword/templates_frontend/frontend/assets/images/.keep
81
101
  - lib/generators/sun_sword/templates_frontend/frontend/assets/images/kotaro.ico
@@ -87,6 +107,9 @@ files:
87
107
  - lib/generators/sun_sword/templates_frontend/frontend/pages/web.js
88
108
  - lib/generators/sun_sword/templates_frontend/frontend/stylesheets/application.scss
89
109
  - lib/generators/sun_sword/templates_frontend/helpers/application_helper.rb
110
+ - lib/generators/sun_sword/templates_frontend/models/models/account.rb
111
+ - lib/generators/sun_sword/templates_frontend/models/models/auth.rb
112
+ - lib/generators/sun_sword/templates_frontend/models/models/user.rb
90
113
  - lib/generators/sun_sword/templates_frontend/package.json
91
114
  - lib/generators/sun_sword/templates_frontend/postcss.config.js
92
115
  - lib/generators/sun_sword/templates_frontend/rubocop.yml.tt
@@ -104,6 +127,7 @@ files:
104
127
  - lib/generators/sun_sword/templates_frontend/views/site/_comment.html.erb.tt
105
128
  - lib/generators/sun_sword/templates_frontend/views/site/stimulus.html.erb.tt
106
129
  - lib/generators/sun_sword/templates_frontend/vite.config.ts.tt
130
+ - lib/generators/sun_sword/templates_init/config/initializers/sun_sword.rb
107
131
  - lib/generators/sun_sword/templates_scaffold/controllers/controller.rb.tt
108
132
  - lib/generators/sun_sword/templates_scaffold/example.rb.tt
109
133
  - lib/generators/sun_sword/templates_scaffold/views/_form.html.erb.tt
@@ -113,6 +137,7 @@ files:
113
137
  - lib/generators/sun_sword/templates_scaffold/views/new.html.erb.tt
114
138
  - lib/generators/sun_sword/templates_scaffold/views/show.html.erb.tt
115
139
  - lib/sun-sword.rb
140
+ - lib/sun_sword/configuration.rb
116
141
  - lib/sun_sword/version.rb
117
142
  homepage: https://github.com/kotaroisme/sun-sword
118
143
  licenses:
@@ -1,6 +0,0 @@
1
- class Dashboard::SiteController < ApplicationController
2
- layout :set_layouts
3
- def index
4
- render 'site/stimulus'
5
- end
6
- end