Class: Koi::AdminRouteGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Koi::AdminRouteGenerator
- Includes:
- Rails::Generators::ResourceHelpers
- Defined in:
- lib/generators/koi/admin_route/admin_route_generator.rb
Instance Method Summary collapse
Instance Method Details
#add_navigation ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/koi/admin_route/admin_route_generator.rb', line 28 def gsub_file("config/initializers/koi.rb", /Koi::Menu.modules = ({}|{\n(?:\s+.*\n)*})\n/) do |match| config = eval(match) # rubocop:disable Security/Eval # we know that this only during generation label = [*regular_class_path.map(&:humanize), human_name.pluralize].join(" ") path = "/admin#{route_url}" config[label] = path config = config.sort.to_h StringIO.new.tap do |io| io.puts "Koi::Menu.modules = {" config.each do |k, v| if v.is_a?(Hash) io.puts " #{k.inspect} => {" v.each do |kk, vv| io.puts " #{kk.inspect} => #{vv.inspect}," end io.puts " }," else io.puts " #{k.inspect} => #{v.inspect}," end end io.puts "}" end.string end end |
#add_route ⇒ Object
18 19 20 |
# File 'lib/generators/koi/admin_route/admin_route_generator.rb', line 18 def add_route route "resources :#{file_name.pluralize}", namespace: regular_class_path end |
#create_navigation ⇒ Object
22 23 24 25 26 |
# File 'lib/generators/koi/admin_route/admin_route_generator.rb', line 22 def return if Pathname.new(destination_root).join("config/initializers/koi.rb").exist? template("initializer.rb", "config/initializers/koi.rb") end |
#create_routes ⇒ Object
12 13 14 15 16 |
# File 'lib/generators/koi/admin_route/admin_route_generator.rb', line 12 def create_routes return if Pathname.new(destination_root).join("config/routes/admin.rb").exist? template("routes.rb", "config/routes/admin.rb") end |