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

前端 未结 9 1493
谎友^
谎友^ 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条回答
  •  醉酒成梦
    2021-02-04 05:12

    EDIT: The answer below was packaged into the html_routes gem which supports Rails 3 and 4.

    The code below was made with the current Rails 3.2.3, groups by controller and looks awesome. Remember to change the to your app name and add gem 'syntax' to your Gemfile.

    Sample image

    desc 'Pretty print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
    
    task :routes => :environment do
    if ENV['CONTROLLER']
      all_routes = ::Application.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] }
    else
      all_routes = ::Application.routes
    end
    
    convertor = Syntax::Convertors::HTML.for_syntax "ruby"
    
    File.open(File.join(Rails.root, "routes.html"), "w") do |f|
      f.puts "Your APP
             
             "
    
      last_contrl = nil
    
      routes = all_routes.routes.collect do |route|
        if !route.requirements.empty?
          if route.requirements[:controller] != last_contrl
            f.puts "" if last_contrl
            last_contrl = route.requirements[:controller]
            f.puts "
    Controller: #{last_contrl}
    " + "" end reqs = route.requirements.inspect verb = route.verb.source verb = verb[1..(verb.length-2)] if verb r = { :name => route.name, :verb => verb, :path => route.path, :reqs => reqs } f.puts "" + "" end end f.puts "
    NameVerbPathRequirements
    #{r[:name]}#{r[:verb]}#{r[:path]}#{convertor.convert(r[:reqs])}
    " end end

提交回复
热议问题