Class: RorGenerators::Generators::NewGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/ror_generators/new_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_routeObject



34
35
36
# File 'lib/generators/ror_generators/new_generator.rb', line 34

def add_route 
  route "resources :#{module_name.downcase.pluralize}, only: :index"
end

#client_dest_prefixObject



12
13
14
# File 'lib/generators/ror_generators/new_generator.rb', line 12

def client_dest_prefix 
  "client/app/bundles/#{module_name}/"
end

#copy_config_filesObject



45
46
47
# File 'lib/generators/ror_generators/new_generator.rb', line 45

def copy_config_files 
  template "client/startup/registration.jsx.erb", "#{client_dest_prefix}/startup/registration.jsx"
end

#copy_package_jsonObject



60
61
62
# File 'lib/generators/ror_generators/new_generator.rb', line 60

def copy_package_json 
  template "client/package.json.tt", "client/package.json" unless dest_file_exists?("client/package.json")
end

#copy_server_filesObject



38
39
40
41
42
43
# File 'lib/generators/ror_generators/new_generator.rb', line 38

def copy_server_files
  empty_directory("app/views/#{module_name}")
  template "server/controller.rb", "app/controllers/#{module_name.pluralize}_controller.rb"
  template "server/index.html.erb", "app/views/#{module_name.pluralize}/index.html.erb"
  template "server/layout.html.erb", "app/views/layouts/#{module_name}.html.erb"
end

#copy_template_filesObject



26
27
28
29
30
31
32
# File 'lib/generators/ror_generators/new_generator.rb', line 26

def copy_template_files 
  client_template_files.each do |file|
    file_name = file[2] ? module_name.capitalize : module_name
    template "client/#{file[0]}/#{file[1]}", 
      "#{client_dest_prefix}/#{file[0]}/#{file_name}#{file[1].gsub('.erb', '')}"
  end
end

#copy_webpack_configObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/generators/ror_generators/new_generator.rb', line 49

def copy_webpack_config
  if dest_file_exists?("client/webpack.config.json")
    inject_into_file "client/webpack.config.js.erb", after: "'babel-polyfill',\n" do <<-'RUBY'
      puts "'./app/bundles/#{module_name}/startup/registration',"
    RUBY
    end
  else
    template "client/webpack.config.js.erb", "client/webpack.config.js"
  end
end

#create_react_directoriesObject



16
17
18
19
# File 'lib/generators/ror_generators/new_generator.rb', line 16

def create_react_directories
  dirs = %w[components containers startup]
  dirs.each { |name| empty_directory("#{client_dest_prefix}/#{name}") }
end

#create_redux_directoriesObject



21
22
23
24
# File 'lib/generators/ror_generators/new_generator.rb', line 21

def create_redux_directories
  dirs = %w[actions constants reducers store]
  dirs.each { |name| empty_directory("#{client_dest_prefix}/#{name}") }
end

#module_nameObject



8
9
10
# File 'lib/generators/ror_generators/new_generator.rb', line 8

def module_name 
  @module_name ||= "#{file_name}"
end