·
DTO 社区 - 一个类似 Hacker News, Lobsters 的技术文章链接分享社区 https://dto.pipecraft.net/ 《好工具周刊》发现并分享有趣,有创意,免费、好用的工具,每周四发布。支持 RSS 订阅,邮箱订阅,微信订阅。 https://discuss-cn.bestxtools.com/

这种在 PHP,Ruby 这种语言的代码里很常见吧。

举例: Lobsters 源码里的代码

<li id="story_<%= story.short_id %>" data-shortid="<%= story.short_id %>"
class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
<%= story.vote && story.vote[:vote] == -1 ? "flagged" : "" %>
<%= story.score <= -1 ? "negative_1" : "" %>
<%= story.score <= -3 ? "negative_3" : "" %>
<%= story.score <= -5 ? "negative_5" : "" %>
<%= story.is_hidden_by_cur_user ? "hidden" : "" %>
<%= story.is_saved_by_cur_user ? "saved" : "" %>
<%= story.is_deleted? ? "deleted" : "" %>">

如果不用换行分割,使 class 用空格拼接在一起,代码的可读性会很差。

Replies
1

+1 确实见识少了 stuck_out_tongue 不过这样写最终 html 代码可读性就差了些