hotwire_crud 0.1.2 → 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: e25f04e72ad847d12f99121934f13baaf8da963481b04628f6a76357d42f9820
4
- data.tar.gz: 287751890a2a0621252beea80b0e49e124ad5ada68b5fa2a25daffa2d63eed66
3
+ metadata.gz: 7440b0ff951cbd011abf2479b8842efeb4d57c42ec7533ec596f494da015d777
4
+ data.tar.gz: 07d704e527c643a27991621454a34650ae64f53aee1e25104f2fc3425c4bf64d
5
5
  SHA512:
6
- metadata.gz: 6b1edd548ae2dc3a89abc980a787af39e50bc9e96782703c70d3c95f8e2c119f1bc3017b9d19904bdc9584998c94df81a13bf03c13e478a9b53a1f5c83815ca6
7
- data.tar.gz: 823d42026f4c4aa9607379e4a966c3f8696c627cca2fb34d577879446070eecd221b81c4406a766d0b8c438971533b297f6e53f214d15628478f8d55f1cc5038
6
+ metadata.gz: f09512f8c327c1019a11ee1ca47c289b3e5a1b316bfdf7d26f541c516b3bf85c83cd947ec16f51e9c91433b9df4a18deea8a840e8a5a7ad72568fc89572d8737
7
+ data.tar.gz: 2d95ec09a6a80539a692981d2db5660b61d40a0a834cb46d95897edcb75c2954f25f3c46ea07359b36733f383d36eb011df4603d45de22377304df029429e08a
data/hotwire_crud.gemspec CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Gem::Specification.new do |spec|
2
4
  spec.name = 'hotwire_crud'
3
- spec.version = '0.1.2'
5
+ spec.version = '1.1.0'
4
6
  spec.summary = 'crud generator with hotwire approach and static routes'
5
7
  spec.description = 'Crud generator with static routes which lazy loads content using content routes'
6
8
  spec.authors = ['Umair Azam']
@@ -10,10 +12,12 @@ Gem::Specification.new do |spec|
10
12
 
11
13
  spec.files = Dir['lib/**/*', 'templates/**/*', '*.gemspec']
12
14
  spec.require_paths = ['lib']
13
-
15
+ spec.required_ruby_version = '3.1.2'
14
16
  spec.add_runtime_dependency 'rails', '>= 6.0'
15
17
  # Add other dependencies if needed
16
18
 
17
19
  # Specify the custom generator file(s)
18
20
  spec.add_development_dependency 'railties'
19
- end
21
+ spec.add_development_dependency 'rubocop', '~> 1.0'
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
23
+ end
@@ -2,7 +2,7 @@ Description:
2
2
  Explain the generator
3
3
 
4
4
  Example:
5
- bin/rails generate hotwire_crud Thing
5
+ bin/rails generate hotwire_crud books
6
6
 
7
7
  This will create:
8
8
  what/will/it/create
@@ -1,30 +1,58 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # A Rails generator that creates a CRUD (Create, Read, Update, Delete) controller
4
+ # with Hotwire support.
5
+ #
6
+ # This generator creates a controller file, view files, and sets up the
7
+ # routes for the CRUD operations. It is designed to be used with Hotwire
8
+ # for a more interactive and dynamic user interface.
9
+ #
10
+ # Usage:
11
+ # rails generate hotwire_crud resource_controller_name
12
+ #
13
+ # Example:
14
+ # rails generate hotwire_crud products
15
+ #
16
+ # This will generate a Products controller with actions for index, show, new, edit,
17
+ # create, update, and destroy, along with corresponding view templates.
18
+ #
19
+
20
+ # lib/generators/hotwire_crud_generator.rb
21
+ require 'English'
3
22
  class HotwireCrudGenerator < Rails::Generators::NamedBase
4
- source_root File.expand_path("templates", __dir__)
23
+ source_root File.expand_path('templates', __dir__)
5
24
 
6
25
  argument :actions, type: :array, default: %w[index edit new show]
7
26
 
8
27
  def create_static_controller_file
9
- template "static_controller.erb", File.join("app/controllers/static", "#{file_name}_controller.rb")
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
+
37
+ template 'static_controller.erb', File.join('app/controllers/static', "#{file_name}_controller.rb")
10
38
  end
11
39
 
12
40
  def create_static_controller_test
13
- template "static_controller_spec.erb", File.join("spec/controllers/static", "#{file_name}_controller_spec.rb")
41
+ template 'static_controller_spec.erb', File.join('spec/controllers/static', "#{file_name}_controller_spec.rb")
14
42
  end
15
43
 
16
44
  def create_controller_file
17
- template "controller.erb", File.join("app/controllers", "#{file_name}_controller.rb")
45
+ template 'controller.erb', File.join('app/controllers', "#{file_name}_controller.rb")
18
46
  end
19
47
 
20
48
  def create_controller_test
21
- template "controller_spec.erb", File.join("spec/controllers", "#{file_name}_controller_spec.rb")
49
+ template 'controller_spec.erb', File.join('spec/controllers', "#{file_name}_controller_spec.rb")
22
50
  end
23
51
 
24
52
  def create_views
25
53
  actions.each do |action|
26
- template "views/static_#{action}.html.erb", File.join("app/views/static", file_name, "#{action}.html.haml")
27
- template "views/#{action}.html.erb", File.join("app/views", file_name, "#{action}.html.haml")
54
+ template "views/static_#{action}.html.erb", File.join('app/views/static', file_name, "#{action}.html.haml")
55
+ template "views/#{action}.html.erb", File.join('app/views', file_name, "#{action}.html.haml")
28
56
  end
29
57
  end
30
58
 
@@ -34,4 +62,49 @@ class HotwireCrudGenerator < Rails::Generators::NamedBase
34
62
  route_namespace = 'static'
35
63
  route "namespace :#{route_namespace} do\n resources :#{file_name}, only: #{actions.map(&:to_sym).inspect}\nend"
36
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
37
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: 0.1.2
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
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
41
55
  description: Crud generator with static routes which lazy loads content using content
42
56
  routes
43
57
  email:
@@ -49,6 +63,7 @@ files:
49
63
  - hotwire_crud.gemspec
50
64
  - lib/generators/hotwire_crud/USAGE
51
65
  - lib/generators/hotwire_crud/hotwire_crud_generator.rb
66
+ - lib/generators/hotwire_crud/templates/constants.erb
52
67
  - lib/generators/hotwire_crud/templates/controller.erb
53
68
  - lib/generators/hotwire_crud/templates/controller_spec.erb
54
69
  - lib/generators/hotwire_crud/templates/static_controller.erb
@@ -64,23 +79,24 @@ files:
64
79
  homepage: https://github.com/omairrazam/hotwire_crud.git
65
80
  licenses:
66
81
  - MIT
67
- metadata: {}
82
+ metadata:
83
+ rubygems_mfa_required: 'true'
68
84
  post_install_message:
69
85
  rdoc_options: []
70
86
  require_paths:
71
87
  - lib
72
88
  required_ruby_version: !ruby/object:Gem::Requirement
73
89
  requirements:
74
- - - ">="
90
+ - - '='
75
91
  - !ruby/object:Gem::Version
76
- version: '0'
92
+ version: 3.1.2
77
93
  required_rubygems_version: !ruby/object:Gem::Requirement
78
94
  requirements:
79
95
  - - ">="
80
96
  - !ruby/object:Gem::Version
81
97
  version: '0'
82
98
  requirements: []
83
- rubygems_version: 3.3.26
99
+ rubygems_version: 3.3.7
84
100
  signing_key:
85
101
  specification_version: 4
86
102
  summary: crud generator with hotwire approach and static routes