sun-sword 0.0.10 → 0.0.12

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +57 -2
  3. data/Gemfile +20 -0
  4. data/Gemfile.lock +252 -0
  5. data/README.md +74 -15
  6. data/Rakefile +6 -10
  7. data/lib/generators/sun_sword/USAGE +22 -3
  8. data/lib/generators/sun_sword/frontend_generator.rb +77 -39
  9. data/lib/generators/sun_sword/frontend_generator_spec.rb +539 -0
  10. data/lib/generators/sun_sword/init_generator.rb +2 -0
  11. data/lib/generators/sun_sword/init_generator_spec.rb +82 -0
  12. data/lib/generators/sun_sword/scaffold_generator.rb +212 -29
  13. data/lib/generators/sun_sword/scaffold_generator_spec.rb +1414 -0
  14. data/lib/generators/sun_sword/templates_frontend/{Procfile.dev → Procfile.dev.tt} +1 -0
  15. data/lib/generators/sun_sword/templates_frontend/bin/{watch → watch.tt} +2 -1
  16. data/lib/generators/sun_sword/templates_frontend/config/{vite.json → vite.json.tt} +2 -1
  17. data/lib/generators/sun_sword/templates_frontend/controllers/application_controller.rb.tt +2 -2
  18. data/lib/generators/sun_sword/templates_frontend/controllers/tests_controller.rb +36 -0
  19. data/lib/generators/sun_sword/templates_frontend/controllers/tests_controller_spec.rb +62 -0
  20. data/lib/generators/sun_sword/templates_frontend/env.development +1 -1
  21. data/lib/generators/sun_sword/templates_frontend/frontend/entrypoints/application.js +2 -2
  22. data/lib/generators/sun_sword/templates_frontend/frontend/pages/tests-stimulus.js +31 -0
  23. data/lib/generators/sun_sword/templates_frontend/frontend/pages/web.js +12 -0
  24. data/lib/generators/sun_sword/templates_frontend/frontend/stylesheets/application.css +1 -3
  25. data/lib/generators/sun_sword/templates_frontend/helpers/application_helper.rb +17 -0
  26. data/lib/generators/sun_sword/templates_frontend/helpers/application_helper_spec.rb +30 -0
  27. data/lib/generators/sun_sword/templates_frontend/package.json.tt +14 -0
  28. data/lib/generators/sun_sword/templates_frontend/views/components/_action_destroy.html.erb.tt +1 -1
  29. data/lib/generators/sun_sword/templates_frontend/views/components/_alert.html.erb.tt +1 -1
  30. data/lib/generators/sun_sword/templates_frontend/views/layouts/application.html.erb.tt +3 -3
  31. data/lib/generators/sun_sword/templates_frontend/views/tests/_frame_content.html.erb +9 -0
  32. data/lib/generators/sun_sword/templates_frontend/views/tests/_log_entry.html.erb +4 -0
  33. data/lib/generators/sun_sword/templates_frontend/views/tests/_updated_content.html.erb +6 -0
  34. data/lib/generators/sun_sword/templates_frontend/views/tests/stimulus.html.erb +45 -0
  35. data/lib/generators/sun_sword/templates_frontend/views/tests/turbo_drive.html.erb +55 -0
  36. data/lib/generators/sun_sword/templates_frontend/views/tests/turbo_frame.html.erb +87 -0
  37. data/lib/generators/sun_sword/templates_frontend/vite.config.ts.tt +1 -1
  38. data/lib/generators/sun_sword/templates_init/config/initializers/sun_sword.rb +1 -0
  39. data/lib/generators/sun_sword/templates_scaffold/controllers/controller.rb.tt +24 -24
  40. data/lib/generators/sun_sword/templates_scaffold/controllers/controller_spec.rb.tt +398 -0
  41. data/lib/generators/sun_sword/templates_scaffold/views/index.html.erb.tt +5 -5
  42. data/lib/generators/sun_sword/templates_scaffold/views/show.html.erb.tt +3 -0
  43. data/lib/generators/tmp/db/structures/test_structure.yaml +42 -0
  44. data/lib/sun-sword.rb +1 -0
  45. data/lib/sun_sword/configuration_spec.rb +77 -0
  46. data/lib/sun_sword/version.rb +1 -1
  47. metadata +177 -29
  48. data/.rspec +0 -3
  49. data/.rubocop.yml +0 -1146
  50. data/lib/generators/sun_sword/templates_frontend/controllers/site_controller.rb +0 -16
  51. data/lib/generators/sun_sword/templates_frontend/db/seeds.rb +0 -3
  52. data/lib/generators/sun_sword/templates_frontend/db/structures/example.yaml.tt +0 -106
  53. data/lib/generators/sun_sword/templates_frontend/frontend/pages/stimulus.js +0 -10
  54. data/lib/generators/sun_sword/templates_frontend/package.json +0 -7
  55. data/lib/generators/sun_sword/templates_frontend/views/site/_comment.html.erb.tt +0 -3
  56. data/lib/generators/sun_sword/templates_frontend/views/site/stimulus.html.erb.tt +0 -26
@@ -1,8 +1,11 @@
1
+ require 'rails/generators'
2
+
1
3
  module SunSword
2
4
  class FrontendGenerator < Rails::Generators::Base
3
5
  source_root File.expand_path('templates_frontend', __dir__)
4
6
 
5
7
  class_option :setup, type: :boolean, default: false, desc: 'Setup domain structure'
8
+ class_option :engine, type: :string, default: nil, desc: 'Engine option is not supported for frontend generator'
6
9
 
7
10
  def validate_setup_option
8
11
  unless options.setup
@@ -10,18 +13,25 @@ module SunSword
10
13
  end
11
14
  end
12
15
 
16
+ def validate_no_engine
17
+ if options[:engine]
18
+ raise Thor::Error, 'Frontend generator does not support --engine option. Frontend setup must be done in the main app only. Use "rails generate sun_sword:frontend --setup" without engine option.'
19
+ end
20
+ end
21
+
13
22
  desc 'This generator installs Vite with Rails 8 configuration'
14
23
 
15
24
  def setup
25
+ validate_no_engine
16
26
  copy_assets_from_template
17
27
 
18
- add_vite_to_gemfile
28
+ add_to_gemfile
19
29
  install_vite
20
30
  configure_vite
21
31
 
22
32
  modify_application_js
23
33
  generate_default_frontend
24
- generate_controllers_site
34
+ generate_controllers_tests
25
35
  generate_components
26
36
  modify_layout_for_vite
27
37
  end
@@ -43,28 +53,29 @@ module SunSword
43
53
  say "File '#{path_app}/assets' has been copied from template.", :green
44
54
  end
45
55
 
46
- def add_vite_to_gemfile
56
+ def add_to_gemfile
47
57
  gem_dependencies = <<~RUBY
48
58
  # --- SunSword Package frontend
49
- gem "turbo-rails"
50
- gem "stimulus-rails"
51
- gem "vite_rails"
52
-
53
59
  group :development do
54
60
  gem "listen"
55
61
  end
62
+ group :test do
63
+ gem "rails-controller-testing"
64
+ end
65
+ gem 'turbo-rails'
66
+ gem 'vite_rails'
56
67
  RUBY
57
68
  append_to_file('Gemfile', gem_dependencies)
58
- say 'Vite Rails gem added and bundle installed', :green
69
+ say 'Rails gem added and bundle installed', :green
59
70
  end
60
71
 
61
72
  def install_vite
62
- template 'package.json', 'package.json'
63
- run 'bundle exec vite install'
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'
67
- say 'Vite installed successfully', :green
73
+ template 'package.json.tt', 'package.json'
74
+ run 'bun install'
75
+ run 'bun add -D vite vite-plugin-full-reload vite-plugin-ruby vite-plugin-stimulus-hmr'
76
+ run 'bun 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'
77
+ run 'bun add -D eslint prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-tailwindcss'
78
+ say 'Vite installed successfully with Bun', :green
68
79
  end
69
80
 
70
81
  def configure_vite
@@ -72,10 +83,10 @@ module SunSword
72
83
 
73
84
  # Add a basic Vite configuration file to your Rails app
74
85
  template 'vite.config.ts.tt', 'vite.config.ts'
75
- template 'Procfile.dev', 'Procfile.dev'
76
- template 'bin/watch', 'bin/watch'
86
+ template 'Procfile.dev.tt', 'Procfile.dev'
87
+ template 'bin/watch.tt', 'bin/watch'
77
88
  run 'chmod +x bin/watch'
78
- template 'config/vite.json', 'config/vite.json'
89
+ template 'config/vite.json.tt', 'config/vite.json'
79
90
 
80
91
  say 'Vite configuration completed', :green
81
92
  end
@@ -88,44 +99,71 @@ module SunSword
88
99
  end
89
100
 
90
101
  def generate_default_frontend
91
- directory('frontend', 'app/frontend')
92
- say 'Generate default controller', :green
102
+ directory('frontend', File.join(path_app, 'frontend'))
103
+ say 'Generated default frontend files', :green
93
104
  end
94
105
 
95
106
  def generate_components
96
- directory('views/components', 'app/views/components')
107
+ directory('views/components', File.join(path_app, 'views/components'))
97
108
  say 'Generate default controller', :green
98
109
  end
99
110
 
100
- def generate_controllers_site
101
- run 'rails g controller site stimulus'
102
- template 'controllers/site_controller.rb', File.join('app/controllers/site_controller.rb')
103
- template 'controllers/application_controller.rb.tt', File.join('app/controllers/application_controller.rb')
104
- site_route = <<-RUBY
105
-
106
- default_url_options :host => "ENV['BASE_URL']"
107
- root "site#stimulus"
108
- get "site/jadi_a"
109
- get "site/jadi_b"
111
+ def generate_controllers_tests
112
+ run 'rails g controller tests stimulus turbo_drive turbo_frame frame_content update_content'
113
+ template 'controllers/tests_controller.rb', File.join(path_app, 'controllers/tests_controller.rb')
114
+ template 'controllers/tests_controller_spec.rb', File.join(path_app, 'controllers/tests_controller_spec.rb')
115
+ template 'controllers/application_controller.rb.tt', File.join(path_app, 'controllers/application_controller.rb')
116
+ tests_route = <<-RUBY
117
+
118
+ default_url_options :host => "\#{ENV['BASE_URL']}"
119
+ root "tests#stimulus"
120
+ # Frontend feature tests
121
+ get "tests/stimulus"
122
+ get "tests/turbo_drive"
123
+ get "tests/turbo_frame"
124
+ get "tests/frame_content"
125
+ post "tests/update_content"
110
126
 
111
127
  RUBY
112
- inject_into_file 'config/routes.rb', site_route, after: "Rails.application.routes.draw do\n"
113
-
114
- say 'Generate default controller', :green
128
+ # Check if routes already exist before injecting
129
+ routes_file = 'config/routes.rb'
130
+ if File.exist?(routes_file) && !File.read(routes_file).include?('tests/stimulus')
131
+ inject_into_file routes_file, tests_route, after: "Rails.application.routes.draw do\n"
132
+ end
133
+ # Generate views for tests
134
+ # Copy non-template files from views/tests directory
135
+ copy_file 'views/tests/stimulus.html.erb', File.join(path_app, 'views/tests/stimulus.html.erb')
136
+ copy_file 'views/tests/turbo_drive.html.erb', File.join(path_app, 'views/tests/turbo_drive.html.erb')
137
+ copy_file 'views/tests/turbo_frame.html.erb', File.join(path_app, 'views/tests/turbo_frame.html.erb')
138
+ copy_file 'views/tests/_frame_content.html.erb', File.join(path_app, 'views/tests/_frame_content.html.erb')
139
+ copy_file 'views/tests/_updated_content.html.erb', File.join(path_app, 'views/tests/_updated_content.html.erb')
140
+ copy_file 'views/tests/_log_entry.html.erb', File.join(path_app, 'views/tests/_log_entry.html.erb')
141
+
142
+ say 'Generate tests controller for frontend feature testing', :green
115
143
  end
116
144
 
117
145
  def path_app
118
146
  'app'
119
147
  end
120
148
 
149
+ def app_name
150
+ @app_name ||= begin
151
+ Rails.application.class.module_parent_name.underscore
152
+ rescue
153
+ 'app'
154
+ end
155
+ end
156
+
157
+ def source_code_dir
158
+ @source_code_dir ||= 'app/frontend'
159
+ end
160
+
121
161
  def modify_layout_for_vite
122
- template 'views/site/stimulus.html.erb.tt', 'app/views/site/stimulus.html.erb'
123
- template 'views/site/_comment.html.erb.tt', 'app/views/site/_comment.html.erb'
124
- template 'views/layouts/application.html.erb.tt', 'app/views/layouts/application.html.erb'
162
+ template 'views/layouts/application.html.erb.tt', File.join(path_app, 'views/layouts/application.html.erb')
125
163
 
126
- template 'views/layouts/dashboard/application.html.erb.tt', 'app/views/layouts/owner/application.html.erb'
127
- template 'views/layouts/dashboard/_sidebar.html.erb.tt', 'app/views/components/layouts/_sidebar.html.erb'
128
- directory('helpers', 'app/helpers')
164
+ template 'views/layouts/dashboard/application.html.erb.tt', File.join(path_app, 'views/layouts/owner/application.html.erb')
165
+ template 'views/layouts/dashboard/_sidebar.html.erb.tt', File.join(path_app, 'views/components/layouts/_sidebar.html.erb')
166
+ directory('helpers', File.join(path_app, 'helpers'))
129
167
  say 'Updated application layout for Vite integration', :green
130
168
  end
131
169
  end