sun-sword 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac608a5b50200fae69d551c25b6abddc5355da222a1a8da739a7aba7c27fac03
4
- data.tar.gz: 2d9fab48ea8cc5560198a23801e3424683b7a0c236df9b3b13a12bdde468cc29
3
+ metadata.gz: d07154e1285345a247e59933071b6c40906ed2e4fa3c61f95274cec3bbacebfe
4
+ data.tar.gz: 95b7cee97b1bb5b4505e5cbe39e4f756ca5b9f65eab6b560df067f74645e75df
5
5
  SHA512:
6
- metadata.gz: 1ad02d8c6f6f1f92e2244754dc4fee44d2073af1f071dcb96b67ced1625a432aa4e142b8f06139aef3f491b5b48fee1b7bb3d3f064827e5998b6cae54211958c
7
- data.tar.gz: 400165a8e6d7df364e0ea8ab835cef59cdcdf4ed2b1e707d6084605f2c17df99c5e93b948b47668ee48264bf90ef979ee8e203e8ab3494a0d268722df1057a7f
6
+ metadata.gz: 47fb75a4bd69a876903071cf4521d9332f3ac727ff7a839eefd81a939d5576768396786bc5d9176118bc63e90c5a7137063aa059b52640f17fef80c199d5535e
7
+ data.tar.gz: b1129c75fe08c8d8aaeb75f774dc828273653c648a6facb1e59b7899cc5b4e8e78898dbf58e475e44779fff6e29b9bc6e555e730ba7c04b01fd2897bf4a6b382
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in sun-sword.gemspec
6
+ gemspec
7
+
8
+ group :development, :test do
9
+ gem 'byebug'
10
+ gem 'rubocop-performance'
11
+ gem 'rubocop-rails-omakase', require: false
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,193 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sun-sword (0.0.11)
5
+ activesupport (>= 7.1, < 8.1)
6
+ railties (>= 7.1, < 8.1)
7
+ thor (>= 1.2, < 2.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionpack (8.0.2.1)
13
+ actionview (= 8.0.2.1)
14
+ activesupport (= 8.0.2.1)
15
+ nokogiri (>= 1.8.5)
16
+ rack (>= 2.2.4)
17
+ rack-session (>= 1.0.1)
18
+ rack-test (>= 0.6.3)
19
+ rails-dom-testing (~> 2.2)
20
+ rails-html-sanitizer (~> 1.6)
21
+ useragent (~> 0.16)
22
+ actionview (8.0.2.1)
23
+ activesupport (= 8.0.2.1)
24
+ builder (~> 3.1)
25
+ erubi (~> 1.11)
26
+ rails-dom-testing (~> 2.2)
27
+ rails-html-sanitizer (~> 1.6)
28
+ activesupport (8.0.2.1)
29
+ base64
30
+ benchmark (>= 0.3)
31
+ bigdecimal
32
+ concurrent-ruby (~> 1.0, >= 1.3.1)
33
+ connection_pool (>= 2.2.5)
34
+ drb
35
+ i18n (>= 1.6, < 2)
36
+ logger (>= 1.4.2)
37
+ minitest (>= 5.1)
38
+ securerandom (>= 0.3)
39
+ tzinfo (~> 2.0, >= 2.0.5)
40
+ uri (>= 0.13.1)
41
+ appraisal (2.5.0)
42
+ bundler
43
+ rake
44
+ thor (>= 0.14.0)
45
+ ast (2.4.2)
46
+ base64 (0.3.0)
47
+ benchmark (0.4.1)
48
+ bigdecimal (3.2.3)
49
+ builder (3.3.0)
50
+ byebug (11.1.3)
51
+ concurrent-ruby (1.3.5)
52
+ connection_pool (2.5.4)
53
+ crass (1.0.6)
54
+ date (3.4.1)
55
+ diff-lcs (1.5.1)
56
+ drb (2.2.3)
57
+ erb (5.0.2)
58
+ erubi (1.13.1)
59
+ i18n (1.14.7)
60
+ concurrent-ruby (~> 1.0)
61
+ io-console (0.8.1)
62
+ irb (1.15.2)
63
+ pp (>= 0.6.0)
64
+ rdoc (>= 4.0.0)
65
+ reline (>= 0.4.2)
66
+ json (2.13.2)
67
+ language_server-protocol (3.17.0.5)
68
+ lint_roller (1.1.0)
69
+ logger (1.7.0)
70
+ loofah (2.24.1)
71
+ crass (~> 1.0.2)
72
+ nokogiri (>= 1.12.0)
73
+ mini_portile2 (2.8.9)
74
+ minitest (5.25.5)
75
+ nokogiri (1.18.10)
76
+ mini_portile2 (~> 2.8.2)
77
+ racc (~> 1.4)
78
+ nokogiri (1.18.10-arm64-darwin)
79
+ racc (~> 1.4)
80
+ parallel (1.27.0)
81
+ parser (3.3.9.0)
82
+ ast (~> 2.4.1)
83
+ racc
84
+ pp (0.6.2)
85
+ prettyprint
86
+ prettyprint (0.2.0)
87
+ prism (1.5.0)
88
+ psych (5.2.6)
89
+ date
90
+ stringio
91
+ racc (1.8.1)
92
+ rack (3.2.1)
93
+ rack-session (2.1.1)
94
+ base64 (>= 0.1.0)
95
+ rack (>= 3.0.0)
96
+ rack-test (2.2.0)
97
+ rack (>= 1.3)
98
+ rackup (2.2.1)
99
+ rack (>= 3)
100
+ rails-dom-testing (2.3.0)
101
+ activesupport (>= 5.0.0)
102
+ minitest
103
+ nokogiri (>= 1.6)
104
+ rails-html-sanitizer (1.6.2)
105
+ loofah (~> 2.21)
106
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
107
+ railties (8.0.2.1)
108
+ actionpack (= 8.0.2.1)
109
+ activesupport (= 8.0.2.1)
110
+ irb (~> 1.13)
111
+ rackup (>= 1.0.0)
112
+ rake (>= 12.2)
113
+ thor (~> 1.0, >= 1.2.2)
114
+ zeitwerk (~> 2.6)
115
+ rainbow (3.1.1)
116
+ rake (13.2.1)
117
+ rdoc (6.14.2)
118
+ erb
119
+ psych (>= 4.0.0)
120
+ regexp_parser (2.11.2)
121
+ reline (0.6.2)
122
+ io-console (~> 0.5)
123
+ rspec (3.13.0)
124
+ rspec-core (~> 3.13.0)
125
+ rspec-expectations (~> 3.13.0)
126
+ rspec-mocks (~> 3.13.0)
127
+ rspec-core (3.13.2)
128
+ rspec-support (~> 3.13.0)
129
+ rspec-expectations (3.13.3)
130
+ diff-lcs (>= 1.2.0, < 2.0)
131
+ rspec-support (~> 3.13.0)
132
+ rspec-mocks (3.13.2)
133
+ diff-lcs (>= 1.2.0, < 2.0)
134
+ rspec-support (~> 3.13.0)
135
+ rspec-support (3.13.1)
136
+ rubocop (1.80.2)
137
+ json (~> 2.3)
138
+ language_server-protocol (~> 3.17.0.2)
139
+ lint_roller (~> 1.1.0)
140
+ parallel (~> 1.10)
141
+ parser (>= 3.3.0.2)
142
+ rainbow (>= 2.2.2, < 4.0)
143
+ regexp_parser (>= 2.9.3, < 3.0)
144
+ rubocop-ast (>= 1.46.0, < 2.0)
145
+ ruby-progressbar (~> 1.7)
146
+ unicode-display_width (>= 2.4.0, < 4.0)
147
+ rubocop-ast (1.46.0)
148
+ parser (>= 3.3.7.2)
149
+ prism (~> 1.4)
150
+ rubocop-performance (1.26.0)
151
+ lint_roller (~> 1.1)
152
+ rubocop (>= 1.75.0, < 2.0)
153
+ rubocop-ast (>= 1.44.0, < 2.0)
154
+ rubocop-rails (2.33.3)
155
+ activesupport (>= 4.2.0)
156
+ lint_roller (~> 1.1)
157
+ rack (>= 1.1)
158
+ rubocop (>= 1.75.0, < 2.0)
159
+ rubocop-ast (>= 1.44.0, < 2.0)
160
+ rubocop-rails-omakase (1.1.0)
161
+ rubocop (>= 1.72)
162
+ rubocop-performance (>= 1.24)
163
+ rubocop-rails (>= 2.30)
164
+ ruby-progressbar (1.13.0)
165
+ securerandom (0.4.1)
166
+ stringio (3.1.7)
167
+ thor (1.4.0)
168
+ tzinfo (2.0.6)
169
+ concurrent-ruby (~> 1.0)
170
+ unicode-display_width (3.2.0)
171
+ unicode-emoji (~> 4.1)
172
+ unicode-emoji (4.1.0)
173
+ uri (1.0.3)
174
+ useragent (0.16.11)
175
+ zeitwerk (2.7.3)
176
+
177
+ PLATFORMS
178
+ arm64-darwin-23
179
+ ruby
180
+
181
+ DEPENDENCIES
182
+ appraisal (~> 2.5)
183
+ bundler (~> 2.4)
184
+ byebug
185
+ rake (~> 13.0)
186
+ rspec (~> 3.12)
187
+ rubocop (~> 1.65)
188
+ rubocop-performance
189
+ rubocop-rails-omakase
190
+ sun-sword!
191
+
192
+ BUNDLED WITH
193
+ 2.5.18
data/README.md CHANGED
@@ -1,8 +1,20 @@
1
1
  # SunSword
2
+ Rails generators for a **modern frontend stack**: Vite, Tailwind (v4), Hotwire (Turbo + Stimulus), plus view scaffolds aligned with your domain.
3
+
2
4
  This gem provides helper interfaces and classes to assist in the construction of application with
3
5
  Clean Architecture, as described in [Robert Martin's seminal book](https://www.amazon.com/gp/product/0134494164).
4
6
 
7
+ ---
8
+ ## ✨ Features
9
+
10
+ - **One-shot frontend setup**
11
+ Installs and wires **Vite**, **Tailwind v4**, **Turbo**, **Stimulus**, HMR, and sensible defaults.
12
+ - **Scaffolded views & components**
13
+ Opinionated but flexible ERB views, partials, and Stimulus controllers.
14
+ - **Clean integration with Rails 8 + Vite Ruby**
15
+ Ships `vite.config.ts`, `config/vite.json`, `Procfile.dev`, `bin/watch`, and entrypoints.
5
16
 
17
+ ---
6
18
  ## Installation
7
19
 
8
20
  Add this line to your application's Gemfile:
@@ -15,40 +27,45 @@ gem 'sun-sword'
15
27
 
16
28
  And then execute:
17
29
  ```bash
18
- $ rails new kotaro_minami -d=postgresql -T --skip-javascript --skip-asset-pipeline
19
- $ bundle install
20
- $ rails generate rider_kick:init
21
- $ rails generate rider_kick:clean_arch --setup
22
- $ rails db:drop db:create db:migrate db:seed
23
30
  $ rails generate sun_sword:frontend
24
- $ rubocop -a
31
+ $ rubocop -A
25
32
  ```
33
+ ---
26
34
  ## Usage
27
35
  ```bash
28
36
  Description:
29
37
  Clean Architecture CRUD generator
30
- rails new kotaro_minami -d=postgresql -T --skip-javascript --skip-asset-pipeline
31
38
 
32
39
  Example:
33
- To Generate Init:
34
- bin/rails generate rider_kick:init
35
-
36
- To Generate Pattern:
37
- bin/rails generate rider_kick:clean_arch --setup
38
-
39
40
  To Generate Frontend:
41
+ bin/rails generate sun_sword:init
40
42
  bin/rails generate sun_sword:frontend --setup
41
43
 
42
44
  To Generate scaffold:
43
45
  bin/rails generate sun_sword:scaffold Models::Contact actor:user
44
46
  ```
45
-
47
+ ---
48
+ ## Generated structure
49
+ ```text
50
+ app/
51
+ frontend/
52
+ entrypoints/
53
+ application.js
54
+ stimulus.js
55
+ pages/
56
+ web.js
57
+ stimulus.js
58
+ stylesheets/
59
+ application.css # Tailwind v4 style (@import, @plugin, @source)
60
+ assets/
61
+ ```
62
+ ---
46
63
  ## Philosophy
47
64
 
48
65
  The intention of this gem is to help you build applications that are built from the use case down,
49
66
  and decisions about I/O can be deferred until the last possible moment.
50
67
 
51
- ## Clean Architecture
68
+ ### Clean Architecture
52
69
  This structure provides helper interfaces and classes to assist in the construction of application with Clean Architecture, as described in Robert Martin's seminal book.
53
70
 
54
71
  ```
@@ -65,7 +82,7 @@ This structure provides helper interfaces and classes to assist in the construct
65
82
  - use_cases (Just Usecase)
66
83
  - utils (Class Reusable)
67
84
  ```
68
- ## Screaming architecture - use cases as an organisational principle
85
+ ### Screaming architecture - use cases as an organisational principle
69
86
  Uncle Bob suggests that your source code organisation should allow developers to easily find a listing of all use cases your application provides. Here's an example of how this might look in a this application.
70
87
  ```
71
88
  - app
@@ -93,4 +110,13 @@ Note that the use case name contains:
93
110
  # admin_fetch_info.rb [specific usecase]
94
111
  # fetch_info.rb [generic usecase] every role can access it
95
112
  ```
113
+ ---
114
+ ## Contributing
115
+
116
+ - Fork & bundle install
117
+ - ```bin/rails generate sun_sword:frontend --setup``` in a throwaway app to test changes
118
+ - Add/adjust generator tests where possible
119
+ - ```bundle exec rspec```
120
+ - Open a PR 🎉
96
121
 
122
+ See CONTRIBUTING.md for more.
@@ -3,6 +3,7 @@ Description:
3
3
  rails new jendral_jack -d=postgresql -T --skip-javascript --skip-asset-pipeline
4
4
 
5
5
  Example:
6
+ bin/rails generate sun_sword:init
6
7
  bin/rails generate sun_sword:frontend --setup
7
8
  bin/rails generate sun_sword:scaffold contacts<check in db/structure>
8
9
 
@@ -49,6 +49,10 @@ module SunSword
49
49
  gem "turbo-rails"
50
50
  gem "stimulus-rails"
51
51
  gem "vite_rails"
52
+
53
+ group :development do
54
+ gem "listen"
55
+ end
52
56
  RUBY
53
57
  append_to_file('Gemfile', gem_dependencies)
54
58
  say 'Vite Rails gem added and bundle installed', :green
@@ -57,10 +61,9 @@ module SunSword
57
61
  def install_vite
58
62
  template 'package.json', 'package.json'
59
63
  run 'bundle exec vite install'
60
- run 'yarn add -D sass vite-plugin-full-reload vite-plugin-ruby vite-plugin-stimulus-hmr'
61
- run 'yarn add -D tailwindcss @tailwindcss/forms @tailwindcss/typography @tailwindcss/aspect-ratio @tailwindcss/forms @tailwindcss/line-clamp autoprefixer'
62
- run 'yarn add -D eslint prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-tailwindcss path'
63
- run 'yarn add @hotwired/stimulus @hotwired/turbo-rails stimulus-vite-helpers vite animejs stimulus-use'
64
+ run 'yarn add -D vite vite-plugin-full-reload vite-plugin-ruby vite-plugin-stimulus-hmr'
65
+ run 'yarn add path stimulus-vite-helpers @hotwired/stimulus @hotwired/turbo-rails @tailwindcss/aspect-ratio @tailwindcss/forms @tailwindcss/line-clamp @tailwindcss/typography @tailwindcss/vite tailwindcss vite-plugin-rails autoprefixer'
66
+ run 'yarn add -D eslint prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-tailwindcss'
64
67
  say 'Vite installed successfully', :green
65
68
  end
66
69
 
@@ -68,8 +71,6 @@ module SunSword
68
71
  say 'Configuring Vite...'
69
72
 
70
73
  # Add a basic Vite configuration file to your Rails app
71
- template 'tailwind.config.js', 'tailwind.config.js'
72
- template 'postcss.config.js', 'postcss.config.js'
73
74
  template 'vite.config.ts.tt', 'vite.config.ts'
74
75
  template 'Procfile.dev', 'Procfile.dev'
75
76
  template 'bin/watch', 'bin/watch'
@@ -201,21 +201,25 @@ module SunSword
201
201
  end
202
202
 
203
203
  def create_link_file
204
- template 'views/components/menu/link.html.erb.tt', File.join('app/views/components/menu', "_link_to_#{@scope_path}.html.erb")
204
+ partial_path = File.join('app/views/components/menu', "_link_to_#{@scope_path}.html.erb")
205
+ template 'views/components/menu/link.html.erb.tt', partial_path unless File.exist?(partial_path)
206
+
207
+ sidebar = 'app/views/components/layouts/_sidebar.html.erb'
208
+ marker = " <%# generate_link %>\n"
205
209
  link_to = " <li><%= render 'components/menu/#{"link_to_#{@scope_path}"}' %></li>\n"
206
- inject_into_file 'app/views/components/layouts/_sidebar.html.erb', link_to, before: " <%# generate_link %>\n"
210
+ inject_into_file(sidebar, link_to, before: marker) unless File.read(sidebar).include?(link_to)
211
+
207
212
  routes_file = 'config/routes.rb'
208
- if !namespace_exists? && @route_scope_path.present?
209
- scope_code = <<-RUBY
210
- namespace :#{@route_scope_path} do
211
- end
212
- RUBY
213
- insert_into_file routes_file, scope_code, after: "Rails.application.routes.draw do\n"
214
- end
215
213
  if @route_scope_path.present?
216
- inject_into_file routes_file, " resources :#{@scope_path}\n", after: "namespace :#{@route_scope_path} do\n"
214
+ unless namespace_exists?
215
+ scope_code = " namespace :#{@route_scope_path} do\n end\n"
216
+ insert_into_file routes_file, scope_code, after: "Rails.application.routes.draw do\n" unless File.read(routes_file).include?(scope_code)
217
+ end
218
+ resource_line = " resources :#{@scope_path}\n"
219
+ inject_into_file routes_file, resource_line, after: "namespace :#{@route_scope_path} do\n" unless File.read(routes_file).include?(resource_line)
217
220
  else
218
- inject_into_file routes_file, " resources :#{@scope_path}\n", after: "Rails.application.routes.draw do\n"
221
+ resource_line = " resources :#{@scope_path}\n"
222
+ inject_into_file routes_file, resource_line, after: "Rails.application.routes.draw do\n" unless File.read(routes_file).include?(resource_line)
219
223
  end
220
224
  end
221
225
 
@@ -225,15 +229,29 @@ module SunSword
225
229
  end
226
230
 
227
231
  def strong_params
228
- results = ''
229
- @controllers.form_fields.each do |field|
230
- if field.type.to_s.eql?('files')
231
- results << "{ #{field.name}: [] }, "
232
+ # pakai controllers.form_fields kalau ada, kalau tidak jatuh ke kolom model (contract_fields)
233
+ raw_fields = @controllers&.form_fields || contract_fields
234
+
235
+ # normalisasi jadi pasangan [name, type]
236
+ pairs = raw_fields.map do |f|
237
+ if f.respond_to?(:name)
238
+ [f.name.to_s, f.type.to_s]
232
239
  else
233
- results << ":#{field.name}, "
240
+ column_type = @model_class.columns_hash[f.to_s]&.type.to_s
241
+ [f.to_s, column_type.presence || 'string']
234
242
  end
235
243
  end
236
- results[0..-2]
244
+
245
+ permitted = pairs.map do |name, type|
246
+ case type
247
+ when 'files' then "{ #{name}: [] }" # multiple
248
+ when 'json', 'jsonb', 'hash' then "{ #{name}: {} }"
249
+ when 'array' then "{ #{name}: [] }"
250
+ else ":#{name}"
251
+ end
252
+ end
253
+
254
+ permitted.join(', ')
237
255
  end
238
256
  end
239
257
  end
@@ -34,6 +34,10 @@ class ApplicationController < ActionController::Base
34
34
 
35
35
  def set_layouts
36
36
  # "#{current_auth.user.role}/application"
37
- 'owner/application'
37
+ 'application'
38
38
  end
39
+
40
+ def ensure_turbo_frame!
41
+ turbo_frame_request? || turbo_native_app?
42
+ end
39
43
  end
@@ -5,7 +5,7 @@ import {stimulus} from "./stimulus"
5
5
  import WebController from "../pages/web"
6
6
  import SiteStimulusController from "../pages/stimulus.js"
7
7
 
8
- import "../stylesheets/application.scss"
8
+ import "../stylesheets/application.css"
9
9
  console.log("Kotaro is here")
10
10
  console.log(window.location.hash.slice(1))
11
11