【问题标题】:Comments in Embedded Coffeescript (ECO) templatesEmbedded Coffeescript (ECO) 模板中的注释
【发布时间】:2014-03-31 17:12:33
【问题描述】:

有没有办法将 cmets(单行和多行)放在 ECO templates 中,这样它们就不会出现在渲染输出中?

例如,Django 模板允许您在 single line 上执行此操作:

{# greeting #}hello

multiple lines:

<p>Rendered text with {{ pub_date|date:"c" }}</p>
{% comment %}
    <p>Commented out text with {{ create_date|date:"c" }}</p>
{% endcomment %}

【问题讨论】:

    标签: coffeescript eco


    【解决方案1】:

    &lt;% %&gt; 中的所有内容实际上都是咖啡脚本(ECO = Embedded CoffeeScript)。 CoffeeScript 中的注释使用# 字符来注释单行(而### 用于多行cmets)。见coffeescript - How to comment? "/* this */" doesn't work

    所以在 ECO 中你会这样评论:

    <% #This is a single line comment %>
    

    如果您检查ECO templates 的源代码,您可以看到处理scanner.js 中的注释情况的正则表达式。

    Scanner.modePatterns = {
          data: /(.*?)(<%%|<%\s*(\#)|<%(([=-])?)|\n|$)/,
          code: /(.*?)((((:|(->|=>))\s*))?%>|\n|$)/,
          comment: /(.*?)(%>|\n|$)/
        };
    

    【讨论】:

      【解决方案2】:

      评论有一个特殊的标签,即&lt;%# %&gt;

      例子:

      <%# This is a single line comment %>
      

      【讨论】:

        猜你喜欢
        • 2013-07-16
        • 2013-03-10
        • 2012-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多