b4um_generators 0.4.2 → 0.5.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 +4 -4
- data/CHANGELOG.md +27 -0
- data/README.de.md +118 -4
- data/README.md +118 -4
- data/lib/b4um_generators/version.rb +1 -1
- data/lib/generators/b4um/help/help_generator.rb +89 -0
- data/lib/generators/b4um/install/templates/b4um/theme.css +23 -0
- data/lib/generators/b4um/todo/templates/_progress.html.erb.tt +22 -0
- data/lib/generators/b4um/todo/templates/_task.html.erb.tt +42 -0
- data/lib/generators/b4um/todo/templates/create_tasks.rb.tt +13 -0
- data/lib/generators/b4um/todo/templates/index.html.erb.tt +101 -0
- data/lib/generators/b4um/todo/templates/task.rb.tt +7 -0
- data/lib/generators/b4um/todo/templates/tasks_controller.rb.tt +190 -0
- data/lib/generators/b4um/todo/templates/todo.css +347 -0
- data/lib/generators/b4um/todo/templates/todo_controller.js +35 -0
- data/lib/generators/b4um/todo/todo_generator.rb +201 -0
- metadata +12 -3
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/generators"
|
|
4
|
+
require "rails/generators/named_base"
|
|
5
|
+
|
|
6
|
+
module B4um
|
|
7
|
+
module Generators
|
|
8
|
+
class TodoGenerator < Rails::Generators::NamedBase
|
|
9
|
+
include Rails::Generators::Migration
|
|
10
|
+
|
|
11
|
+
source_root File.expand_path("templates", __dir__)
|
|
12
|
+
|
|
13
|
+
class_option :owner,
|
|
14
|
+
type: :string,
|
|
15
|
+
default: nil,
|
|
16
|
+
desc: "Associates tasks with the specified owner model."
|
|
17
|
+
|
|
18
|
+
class << self
|
|
19
|
+
def desc(_description = nil)
|
|
20
|
+
"Creates a complete To-Do list with Turbo and Stimulus."
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def validate_owner
|
|
25
|
+
return if options[:owner].nil?
|
|
26
|
+
|
|
27
|
+
owner_name = options[:owner].to_s
|
|
28
|
+
|
|
29
|
+
return if owner_name.match?(/\A[A-Z][A-Za-z0-9]*\z/)
|
|
30
|
+
|
|
31
|
+
raise Thor::Error,
|
|
32
|
+
"Invalid owner model: #{owner_name}"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def create_todo_migration
|
|
36
|
+
return if todo_migration_exists?
|
|
37
|
+
|
|
38
|
+
migration_template(
|
|
39
|
+
"create_tasks.rb.tt",
|
|
40
|
+
"db/migrate/create_#{plural_table_name}.rb"
|
|
41
|
+
)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.next_migration_number(_dirname)
|
|
45
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def create_todo_model
|
|
49
|
+
model_path = "app/models/#{file_path}.rb"
|
|
50
|
+
|
|
51
|
+
return if File.exist?(
|
|
52
|
+
File.join(destination_root, model_path)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
template(
|
|
56
|
+
"task.rb.tt",
|
|
57
|
+
model_path
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def update_owner_model
|
|
62
|
+
return unless owner?
|
|
63
|
+
|
|
64
|
+
owner_path = "app/models/#{owner_file_name}.rb"
|
|
65
|
+
|
|
66
|
+
unless File.exist?(
|
|
67
|
+
File.join(destination_root, owner_path)
|
|
68
|
+
)
|
|
69
|
+
raise Thor::Error,
|
|
70
|
+
"Owner model not found: #{owner_path}"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
association = "has_many :#{plural_table_name}, dependent: :destroy"
|
|
74
|
+
|
|
75
|
+
return if File.read(
|
|
76
|
+
File.join(destination_root, owner_path)
|
|
77
|
+
).include?(association)
|
|
78
|
+
|
|
79
|
+
inject_into_class(
|
|
80
|
+
owner_path,
|
|
81
|
+
owner_class_name,
|
|
82
|
+
" #{association}\n"
|
|
83
|
+
)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def create_todo_controller
|
|
87
|
+
controller_path = "app/controllers/#{plural_table_name}_controller.rb"
|
|
88
|
+
|
|
89
|
+
return if File.exist?(
|
|
90
|
+
File.join(destination_root, controller_path)
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
template(
|
|
94
|
+
"tasks_controller.rb.tt",
|
|
95
|
+
controller_path
|
|
96
|
+
)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def add_todo_routes
|
|
100
|
+
routes_path = "config/routes.rb"
|
|
101
|
+
|
|
102
|
+
full_path = File.join(destination_root, routes_path)
|
|
103
|
+
|
|
104
|
+
raise Thor::Error, "Routes file not found: #{routes_path}" unless File.exist?(full_path)
|
|
105
|
+
|
|
106
|
+
routes_content = File.read(full_path)
|
|
107
|
+
|
|
108
|
+
resource_name = plural_table_name
|
|
109
|
+
|
|
110
|
+
return if routes_content.match?(
|
|
111
|
+
/^\s*resources\s+:#{Regexp.escape(resource_name)}\b/
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
route(
|
|
115
|
+
"resources :#{resource_name}, only: %i[index create update destroy]"
|
|
116
|
+
)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def create_todo_views
|
|
120
|
+
views_path = "app/views/#{plural_table_name}"
|
|
121
|
+
|
|
122
|
+
{
|
|
123
|
+
"index.html.erb.tt" => "index.html.erb",
|
|
124
|
+
"_task.html.erb.tt" => "_task.html.erb",
|
|
125
|
+
"_progress.html.erb.tt" => "_progress.html.erb"
|
|
126
|
+
}.each do |template_name, output_name|
|
|
127
|
+
destination = "#{views_path}/#{output_name}"
|
|
128
|
+
|
|
129
|
+
next if File.exist?(
|
|
130
|
+
File.join(destination_root, destination)
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
template(template_name, destination)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def create_todo_stylesheet
|
|
138
|
+
stylesheet_path = "app/assets/stylesheets/b4um_todo.css"
|
|
139
|
+
|
|
140
|
+
return if File.exist?(
|
|
141
|
+
File.join(destination_root, stylesheet_path)
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
copy_file(
|
|
145
|
+
"todo.css",
|
|
146
|
+
stylesheet_path
|
|
147
|
+
)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def create_todo_stimulus_controller
|
|
151
|
+
controller_path = "app/javascript/controllers/b4um_todo_controller.js"
|
|
152
|
+
|
|
153
|
+
return if File.exist?(
|
|
154
|
+
File.join(destination_root, controller_path)
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
copy_file(
|
|
158
|
+
"todo_controller.js",
|
|
159
|
+
controller_path
|
|
160
|
+
)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
private
|
|
164
|
+
|
|
165
|
+
def current_owner_method
|
|
166
|
+
"current_#{owner_file_name}"
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def migration_version
|
|
170
|
+
version = Gem.loaded_specs.fetch("railties").version
|
|
171
|
+
|
|
172
|
+
"#{version.segments[0]}.#{version.segments[1]}"
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def todo_migration_exists?
|
|
176
|
+
Dir.glob(
|
|
177
|
+
File.join(
|
|
178
|
+
destination_root,
|
|
179
|
+
"db/migrate/*_create_#{plural_table_name}.rb"
|
|
180
|
+
)
|
|
181
|
+
).any?
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def owner?
|
|
185
|
+
options[:owner].present?
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def owner_class_name
|
|
189
|
+
options[:owner].to_s.camelize
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def owner_file_name
|
|
193
|
+
owner_class_name.underscore
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def owner_reference_name
|
|
197
|
+
owner_file_name
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: b4um_generators
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Baum
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-10-14 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: railties
|
|
@@ -168,6 +168,15 @@ files:
|
|
|
168
168
|
- lib/generators/b4um/sortable/templates/sortable_controller.js
|
|
169
169
|
- lib/generators/b4um/table/table_generator.rb
|
|
170
170
|
- lib/generators/b4um/table/templates/_table.html.erb.tt
|
|
171
|
+
- lib/generators/b4um/todo/templates/_progress.html.erb.tt
|
|
172
|
+
- lib/generators/b4um/todo/templates/_task.html.erb.tt
|
|
173
|
+
- lib/generators/b4um/todo/templates/create_tasks.rb.tt
|
|
174
|
+
- lib/generators/b4um/todo/templates/index.html.erb.tt
|
|
175
|
+
- lib/generators/b4um/todo/templates/task.rb.tt
|
|
176
|
+
- lib/generators/b4um/todo/templates/tasks_controller.rb.tt
|
|
177
|
+
- lib/generators/b4um/todo/templates/todo.css
|
|
178
|
+
- lib/generators/b4um/todo/templates/todo_controller.js
|
|
179
|
+
- lib/generators/b4um/todo/todo_generator.rb
|
|
171
180
|
- lib/generators/b4um/trix/templates/b4um_rich_text_helper.rb
|
|
172
181
|
- lib/generators/b4um/trix/templates/b4um_trix.js
|
|
173
182
|
- lib/generators/b4um/trix/trix_generator.rb
|
|
@@ -192,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
192
201
|
- !ruby/object:Gem::Version
|
|
193
202
|
version: '0'
|
|
194
203
|
requirements: []
|
|
195
|
-
rubygems_version: 3.6.
|
|
204
|
+
rubygems_version: 3.6.2
|
|
196
205
|
specification_version: 4
|
|
197
206
|
summary: Rails generators for b4um applications
|
|
198
207
|
test_files: []
|