Class: React::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#create_directoryObject

Make an empty `components/` directory in the right place:


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/generators/react/install_generator.rb', line 20

def create_directory
  components_dir = if webpacker?
    Pathname.new(javascript_dir).parent.to_s
  else
    javascript_dir
  end
  empty_directory File.join(components_dir, 'components')
  unless options[:skip_git]
    create_file File.join(components_dir, 'components/.gitkeep')
  end
end

#create_server_renderingObject


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/generators/react/install_generator.rb', line 41

def create_server_rendering
  if options[:skip_server_rendering]
    return
  elsif webpacker?
    ssr_manifest_path = File.join(javascript_dir, 'server_rendering.js')
    template('server_rendering_pack.js', ssr_manifest_path)
  else
    ssr_manifest_path = File.join(javascript_dir, 'server_rendering.js')
    template('server_rendering.js', ssr_manifest_path)
    initializer_path = 'config/initializers/react_server_rendering.rb'
    template('react_server_rendering.rb', initializer_path)
  end
end

#setup_reactObject

Add requires, setup UJS


33
34
35
36
37
38
39
# File 'lib/generators/react/install_generator.rb', line 33

def setup_react
  if webpacker?
    setup_react_webpacker
  else
    setup_react_sprockets
  end
end