将 put() 的输出解释/渲染为 HTML
当我运行 ruby 脚本时,我希望将输出呈现为 HTML,最好使用浏览器(例如 Chrome)。但是,我非常希望不必启动网络服务,因为我不制作网站。我尝试过 sinatra,它的问题是,每次更改代码时我都必须重新启动服务器,而且它具有我需要的请求(如 GET/POST 参数)真的不需要。
我只是更喜欢 Ruby 程序的输出显示为 HTML,而不是控制台文本——因为 html 允许更具创造性/表现力的输出。有没有好的/简单/有效的方法来做到这一点? (我正在使用记事本++编辑我的代码,所以如果可以以某种方式将上面的内容与它结合起来,那就太棒了)。
多谢 :)
When I run my ruby script, I want the output to be rendered as HTML, preferably with a browser (e.g. Chrome). However, I would very much prefer if I didn't have to start a webservice, because I'm not making a website. I've tried sinatra
, and the problem with it, is that I have to restart the server every time I do changes to my code, plus it features requests (like GET/POST-arguments) which I don't really need.
I simply prefer the output from my Ruby program to appear as HTML as opposed to console-text -- since html allows for more creative/expressive output. Is there a good/simple/effective way to do this? (I'm using notepad++ to edit my code, so if its possible to combine the above with it somehow, that would be awesome).
Thanks alot :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 gem
shotgun
,您可以运行 Sinatra 应用程序,该应用程序会自动重新加载更改,而无需重新启动服务器。或者,使用像
awesome_print
这样具有 HTML 格式的库,您可以编写一个函数来获取输出并将其保存到文件中。然后在 Chrome 中打开该文件。如果您不想在 Chrome 中手动刷新页面,您可以查看
guard-livereload
(https://github.com/guard/guard-livereload),它将监控使用guard
gem 的给定文件并重新加载 Chrome。 Ryan Bates 在此处提供了一张屏幕截图,http://railscasts.com/episodes/264-guard。这是一个重写 Kernel#puts 的函数,用于将字符串打印到 STDOUT 并将其 HTML 格式版本写入 output.html。
Using the gem
shotgun
you can run a Sinatra app that automatically reloads changes without restarting the server.Alternatively, using a library like
awesome_print
which has HTML formatting, you could write a function which takes the output and saves it to a file. Then open the file in Chrome.If you don't want to have to manually refresh the page in Chrome, you could take a look at
guard-livereload
(https://github.com/guard/guard-livereload) which will monitor a given file using theguard
gem and reload Chrome. Ryan Bates has a screenshot on guard here, http://railscasts.com/episodes/264-guard.Here's a function that overrides Kernel#puts to print the string to STDOUT and write the HTML formatted version of it to output.html.