Class: WebpackNative::HelperGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_webpack_helperObject

this is used to generate/add the helper file to rails project



7
8
9
# File 'lib/generators/webpack_native/helper_generator.rb', line 7

def add_webpack_helper
  template "webpack_native_helper.rb", File.join("app/helpers", "webpack_native_helper.rb")
end

#include_webpack_helperObject

include_webpack_helper in application_controller.rb



12
13
14
15
16
17
18
19
20
# File 'lib/generators/webpack_native/helper_generator.rb', line 12

def include_webpack_helper
  application_controller = "#{Rails.root}/app/controllers/application_controller.rb"

  include_webpack_helper = "\n\tinclude WebpackNativeHelper"

  class_declaration = 'class ApplicationController < ActionController::Base'

  inject_into_file application_controller, include_webpack_helper, after: class_declaration
end