gpt4 book ai didi

ruby-on-rails - 有没有办法让 "rake routes"看起来更好?

转载 作者:行者123 更新时间:2023-12-03 13:47:24 27 4
gpt4 key购买 nike

我总是被迫让我的终端窗口宽两个双显示器,只是为了正确阅读它们。我不是黄油 GUI 的忠实拥护者,但这很荒谬。

这个命令有 pretty-print 吗?

最佳答案

编辑:下面的答案被打包到 html_routes支持 Rails 3 和 4 的 gem。

下面的代码是用当前 制作的。 rails 3.2.3 ,按 Controller 分组,看起来很棒。记得更改<Your APP>添加到您的应用名称并将 gem 'syntax' 添加到您的 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 = <Your APP>::Application.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] }
else
all_routes = <Your APP>::Application.routes
end

convertor = Syntax::Convertors::HTML.for_syntax "ruby"

File.open(File.join(Rails.root, "routes.html"), "w") do |f|
f.puts "<html><head><title>Your APP</title>
<style type='text/css'>
body { background-color: #333; color: #FFF; }
table { border: 1px solid #777; background-color: #111; }
td, th { font-size: 11pt; text-align: left; padding-right: 10px; }
th { font-size: 12pt; }
pre { maring: 0; padding: 0; }
.contrl_head { font-size: 14pt; padding: 15px 0 5px 0; }
.contrl_name { color: #ACE; }
.punct { color: #99F; font-weight: bold; }
.symbol { color: #7DD; }
.regex { color: #F66; }
.string { color: #F99; }4
</style></head>
<body>"

last_contrl = nil

routes = all_routes.routes.collect do |route|
if !route.requirements.empty?
if route.requirements[:controller] != last_contrl
f.puts "</table>" if last_contrl
last_contrl = route.requirements[:controller]
f.puts "<div class='contrl_head'><b>Controller: <span class='contrl_name'>#{last_contrl}</span></b></div>" +
"<table width='100%' border='0'><tr><th>Name</th><th>Verb</th><th>Path</th><th>Requirements</th></tr>"
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 "<tr><td width='12%'><b>#{r[:name]}</b></td><td width='5%'><b>#{r[:verb]}</b></td>" +
"<td width='3%'>#{r[:path]}</td><td width='80%'>#{convertor.convert(r[:reqs])}</td></tr>"
end
end

f.puts "</table></body></html>"
end
end

关于ruby-on-rails - 有没有办法让 "rake routes"看起来更好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3986997/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com