hotwire_crud 1.0.0 → 1.1.0

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: 3e28611e36f142b7cbc686342aa46add0584de857664561cb12da7c3ac9e9b7f
4
- data.tar.gz: 7ce6fa2c4d1245df5231a4f70ad177049681e1aa9df714ef4da2f5b36a5e6492
3
+ metadata.gz: 7440b0ff951cbd011abf2479b8842efeb4d57c42ec7533ec596f494da015d777
4
+ data.tar.gz: 07d704e527c643a27991621454a34650ae64f53aee1e25104f2fc3425c4bf64d
5
5
  SHA512:
6
- metadata.gz: 1e37b02588f1d5cfd9d974efa90858711c481451e59922648deba621e2cbf6d36c265bd81c59b7712cb6e66769f55e08dc2283aefad1ba965d507e4e6074f36a
7
- data.tar.gz: dfd4ebb3f66e9d70de6f01923653f010484ebf2566b8ecad942fa250d43466703c059293f531deb62dfcb5ba8ae6e2982a997ad7e4de389a23ff433a2fe4ec56
6
+ metadata.gz: f09512f8c327c1019a11ee1ca47c289b3e5a1b316bfdf7d26f541c516b3bf85c83cd947ec16f51e9c91433b9df4a18deea8a840e8a5a7ad72568fc89572d8737
7
+ data.tar.gz: 2d95ec09a6a80539a692981d2db5660b61d40a0a834cb46d95897edcb75c2954f25f3c46ea07359b36733f383d36eb011df4603d45de22377304df029429e08a
data/hotwire_crud.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'hotwire_crud'
5
- spec.version = '1.0.0'
5
+ spec.version = '1.1.0'
6
6
  spec.summary = 'crud generator with hotwire approach and static routes'
7
7
  spec.description = 'Crud generator with static routes which lazy loads content using content routes'
8
8
  spec.authors = ['Umair Azam']
@@ -18,12 +18,22 @@
18
18
  #
19
19
 
20
20
  # lib/generators/hotwire_crud_generator.rb
21
+ require 'English'
21
22
  class HotwireCrudGenerator < Rails::Generators::NamedBase
22
23
  source_root File.expand_path('templates', __dir__)
23
24
 
24
25
  argument :actions, type: :array, default: %w[index edit new show]
25
26
 
26
27
  def create_static_controller_file
28
+ file_name_singular = file_name.singularize
29
+
30
+ @actions_data_paths = {
31
+ index: "#{file_name}_path",
32
+ new: "new_#{file_name_singular}_path",
33
+ edit: "edit_#{file_name_singular}_path",
34
+ show: "#{file_name_singular}_path"
35
+ }
36
+
27
37
  template 'static_controller.erb', File.join('app/controllers/static', "#{file_name}_controller.rb")
28
38
  end
29
39
 
@@ -52,4 +62,49 @@ class HotwireCrudGenerator < Rails::Generators::NamedBase
52
62
  route_namespace = 'static'
53
63
  route "namespace :#{route_namespace} do\n resources :#{file_name}, only: #{actions.map(&:to_sym).inspect}\nend"
54
64
  end
65
+
66
+ def generate_constants
67
+ constants_file_path = File.join('app', 'controllers', 'static', 'hotwire_crud_static_constants.rb')
68
+
69
+ create_file(constants_file_path) unless File.exist?(constants_file_path)
70
+ file_content = File.read(constants_file_path)
71
+
72
+ actions.each do |action|
73
+ const_name = "#{const_prefix}_#{action.upcase}_TURBO_FRAME_TAG_NAME"
74
+ const_value = "#{const_prefix.downcase}_#{action}"
75
+ next if file_content.include?(const_name)
76
+
77
+ append_to_file constants_file_path do
78
+ constants_content(const_name, const_value)
79
+ end
80
+ end
81
+
82
+ # if File.exist?(constants_file_path)
83
+ load constants_file_path
84
+ # end
85
+ end
86
+
87
+ def run_rubocop_with_auto_correct
88
+ rubocop_command = 'bundle exec rubocop -A'
89
+
90
+ system(rubocop_command)
91
+
92
+ if $CHILD_STATUS.success?
93
+ say('RuboCop auto-corrections applied successfully.', :green)
94
+ else
95
+ say('RuboCop auto-corrections failed.', :red)
96
+ end
97
+ end
98
+
99
+ private
100
+
101
+ def constants_content(const_name, const_value)
102
+ <<~RUBY
103
+ #{const_name} = '#{const_value}'
104
+ RUBY
105
+ end
106
+
107
+ def const_prefix
108
+ file_name.pluralize.upcase
109
+ end
55
110
  end
@@ -2,9 +2,7 @@
2
2
  class <%= class_name %>Controller < ApplicationController
3
3
  <% actions.each do |action|%>
4
4
  def <%= action %>
5
- # Your <%= action %> action code goes here
5
+ @turbo_frame_tag_name = <%= class_name.pluralize.upcase %>_<%= action.upcase%>_TURBO_FRAME_TAG_NAME
6
6
  end
7
7
  <% end %>
8
-
9
- # Define other actions here if needed
10
8
  end
@@ -10,6 +10,4 @@ RSpec.describe <%= "#{class_name}Controller" %>, type: :controller do
10
10
  end
11
11
  end
12
12
  <% end %>
13
-
14
- # Define other tests here if needed
15
13
  end
@@ -2,7 +2,11 @@
2
2
  class Static::<%= class_name %>Controller < ApplicationController
3
3
  <% actions.each do |action|%>
4
4
  def <%= action %>
5
- # Your <%= action %> action code goes here
5
+ http_cache_forever(public: true) do
6
+ @turbo_frame_tag_name = <%= class_name.pluralize.upcase %>_<%= action.upcase%>_TURBO_FRAME_TAG_NAME
7
+ @data_path = <%= @actions_data_paths[action.to_sym] %>
8
+ render "static/books/<%= action%>"
9
+ end
6
10
  end
7
11
  <% end %>
8
12
  end
@@ -0,0 +1,2 @@
1
+ = turbo_frame_tag @turbo_frame_tag_name do
2
+ %h hello edit page
@@ -1 +1,2 @@
1
- %h hello index listing
1
+ = turbo_frame_tag @turbo_frame_tag_name do
2
+ %h hello index listing
@@ -0,0 +1,2 @@
1
+ = turbo_frame_tag @turbo_frame_tag_name do
2
+ %h hello new page
@@ -0,0 +1,2 @@
1
+ = turbo_frame_tag @turbo_frame_tag_name do
2
+ %h hello show page
@@ -0,0 +1,2 @@
1
+ = turbo_frame_tag @turbo_frame_tag_name, src: @data_path do
2
+ %p loading...
@@ -1 +1,2 @@
1
- %h hello static index listing
1
+ = turbo_frame_tag @turbo_frame_tag_name, src: @data_path do
2
+ %p loading...
@@ -0,0 +1,2 @@
1
+ = turbo_frame_tag @turbo_frame_tag_name, src: @data_path do
2
+ %p loading...
@@ -0,0 +1,2 @@
1
+ = turbo_frame_tag @turbo_frame_tag_name, src: @data_path do
2
+ %p loading...
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotwire_crud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Umair Azam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-16 00:00:00.000000000 Z
11
+ date: 2023-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -63,6 +63,7 @@ files:
63
63
  - hotwire_crud.gemspec
64
64
  - lib/generators/hotwire_crud/USAGE
65
65
  - lib/generators/hotwire_crud/hotwire_crud_generator.rb
66
+ - lib/generators/hotwire_crud/templates/constants.erb
66
67
  - lib/generators/hotwire_crud/templates/controller.erb
67
68
  - lib/generators/hotwire_crud/templates/controller_spec.erb
68
69
  - lib/generators/hotwire_crud/templates/static_controller.erb