Is there a way to make “rake routes” look better?

前端 未结 9 1306
谎友^
谎友^ 2021-02-04 04:38

I am always forced to make my terminal window two dual monitors wide just to see read them right. I\'m not a stickler for buttery GUI\'s, but this is ridiculous.

Is ther

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 05:23

    Great tip. Thanks.

    I prepared working version for Rails 3.0. Enjoy.

    desc 'Pretty print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
    
    task :pretty_routes => :environment do
      all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
      routes = all_routes.collect do |route|
        reqs = route.requirements.empty? ? "" : route.requirements.inspect
        {:name => route.name, :verb => route.verb, :path => route.path, :reqs => reqs}
      end
      File.open(File.join(RAILS_ROOT, "routes.html"), "w") do |f|
        f.puts "Rails 3 Routes"
        f.puts ""
        routes.each do |r|
          f.puts ""
        end
        f.puts "
    NameVerbPathRequirements
    #{r[:name]}#{r[:verb]}#{r[:path]}#{r[:reqs]}
    " end end

提交回复
热议问题