Class: Rolemodel::UiComponents::ModalsGenerator

Inherits:
GeneratorBase
  • Object
show all
Defined in:
lib/generators/rolemodel/ui_components/modals/modals_generator.rb

Instance Method Summary collapse

Instance Method Details

#helpers_and_viewsObject



13
14
15
16
17
18
19
20
# File 'lib/generators/rolemodel/ui_components/modals/modals_generator.rb', line 13

def helpers_and_views
  say 'generating views & helpers', :green

  copy_file 'app/helpers/turbo_frame_link_helper.rb'

  directory 'app/views/application'
  directory 'app/views/layouts'
end

#inject_into_layoutObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/rolemodel/ui_components/modals/modals_generator.rb', line 35

def inject_into_layout
  say 'updating application layout', :green

  inject_into_file 'app/views/layouts/application.html.slim', after: /\bbody.*\n/ do
    optimize_indentation <<~SLIM, 4
      = turbo_frame_tag 'modal'
      = render 'confirm'
    SLIM
  end
end

#javascript_entrypointObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/rolemodel/ui_components/modals/modals_generator.rb', line 22

def javascript_entrypoint
  say 'generating & importing javascript files', :green

  directory 'app/javascript/controllers'
  directory 'app/javascript/initializers'

  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

#register_stimulus_controllerObject



67
68
69
70
71
# File 'lib/generators/rolemodel/ui_components/modals/modals_generator.rb', line 67

def register_stimulus_controller
  say 'updating stimulus manifest', :green

  run 'rails stimulus:manifest:update'
end

#to_panel_or_not_to_panelObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/generators/rolemodel/ui_components/modals/modals_generator.rb', line 46

def to_panel_or_not_to_panel
  if options.panels?
    say 'Setting Up RoleModel Panel', :green

    inject_into_file 'app/views/layouts/application.html.slim', after: /\bturbo_frame_tag 'modal'\n/ do
      optimize_indentation <<~SLIM, 4
        = turbo_frame_tag 'panel'
      SLIM
    end

    inject_into_file 'app/assets/stylesheets/application.scss',
                    after: "@import '@rolemodel/optics/dist/css/optics';\n" do
      <<~SCSS
        @import '@rolemodel/optics/dist/css/addons/panel';
      SCSS
    end
  else
    remove_file 'app/views/layouts/panel.html.slim'
  end
end

#turbo_confirmObject



7
8
9
10
11
# File 'lib/generators/rolemodel/ui_components/modals/modals_generator.rb', line 7

def turbo_confirm
  say 'Installing Turbo Confirm package', :green

  run 'yarn add @rolemodel/turbo-confirm'
end