-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodals_generator.rb
64 lines (51 loc) · 1.99 KB
/
modals_generator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module Rolemodel
class ModalsGenerator < Rails::Generators::Base
source_root File.expand_path('templates', __dir__)
def install_turbo_confirm
say 'Installing Turbo Confirm package', :green
run 'yarn add @rolemodel/turbo-confirm'
end
def copy_files
say 'generating views & link helpers', :green
copy_file 'app/helpers/turbo_frame_link_helper.rb'
template 'app/views/layouts/modal.html.slim'
template 'app/views/layouts/panel.html.slim'
copy_file 'app/views/application/_confirm.html.slim'
end
def amend_javascript_entrypoint
say 'generating & importing javascript files', :green
copy_file 'app/javascript/controllers/toggle_controller.js'
copy_file 'app/javascript/initializers/turbo_confirm.js'
copy_file 'app/javascript/initializers/frame_missing_handler.js'
copy_file 'app/javascript/initializers/before_morph_handler.js'
append_to_file 'app/javascript/application.js', <<~JS
import './initializers/turbo_confirm.js'
import './initializers/frame_missing_handler.js'
import './initializers/before_morph_handler.js'
JS
end
def amend_stylesheet_entrypoint
say 'importing Optics stylesheets and defining custom properties', :green
inject_into_file 'app/assets/stylesheets/application.scss',
after: "@import '@rolemodel/optics/dist/scss/optics';\n" do
<<~SCSS
@import '@rolemodel/optics/dist/scss/addons/panel';
SCSS
end
end
def amend_application_layout
say 'amending application layout', :green
inject_into_file 'app/views/layouts/application.html.slim', after: /\bbody.*\n/ do
optimize_indentation <<~SLIM, 4
= turbo_frame_tag 'modal'
= turbo_frame_tag 'panel'
= render 'confirm'
SLIM
end
end
def register_stimulus_controller
say 'updating stimulus manifest', :green
run 'rails stimulus:manifest:update'
end
end
end