Class: HotwireDebug::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/hotwire_debug/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#append_javascript_importsObject



4
5
6
7
8
# File 'lib/generators/hotwire_debug/install/install_generator.rb', line 4

def append_javascript_imports
  js = 'app/assets/javascripts/application.js'
  File.new(js,File::CREAT) unless File.exists?(js)
  inject_into_file js, "\n//= require hotwire-debug\n"
end

#append_stylesheet_importsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/hotwire_debug/install/install_generator.rb', line 10

def append_stylesheet_imports

  css = 'app/assets/stylesheets/application.css'
  scss = 'app/assets/stylesheets/application.scss'
  if File.exists?(css)
    target = css
  elsif File.exists?(scss)
    target = scss
  else
    # if neither exist, create a css file
    File.new(css,File::CREAT) unless File.exists?(css)
    target = css
  end

  inject_into_file target, <<~STYLE
  /*
  *= require hotwire-debug
  */
  STYLE
end