我正在寻找一种 gem 或优雅的方式来设置系统,我可以在其中查看某些 HTML 内容的来源。我正在做一个大项目,很多时候我都在确定某段 HTML 内容的来源。我知道您可以看到哪些布局、部分用于在日志中呈现页面,但我正在寻找更实用的东西。
这方面的一个例子是。
<!-- ... app/views/layouts/main.html.slim -->
<body>
<!-- ... app/views/people/index.html.slim -->
<div class="foo">
<table clas="items">
<!-- ... app/views/people/shared/_person.html.slim -->
<td>
<span>John Doe</span>
</td>
</table>
</div>
</body>
在渲染任何部分/页面/布局 Rails 渲染引擎之前,将添加描述来源的注释。
最佳答案
也许这个 rails_view_annotator
gem 将是一个很好的起点:
The Rails View Annotator wraps the rendering of Rails partials with html comments indicating the disk location of the rendered partial.
根据项目 README,gem 将输出这样的渲染内容:
<!-- begin: app/views/user/_bio.html.haml (from app/views/user/show.html.haml:4) -->
<div class='bio'>Ed's Bio</div>
<!-- end: app/views/user/_bio.html.haml (from app/views/user/show.html.haml:4) -->
但是,它看起来不像在积极开发中,因此可能与最近的 Rails 版本 YMMV 不兼容。
关于ruby-on-rails - Rails 描述 HTML 内容源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40464511/