在 Slim for Ruby on Rails 4 应用程序中 Google 再营销代码的正确语法?



我正在尝试以纤细的部分和测试中安装一些再营销代码,输出看起来不太正确。

这是我得到的JavaScript:

<!-- Google Code for Remarketing Tag -->
<!--------------------------------------------------
Remarketing tags may not be associated with personally identifiable information or placed on pages related to sensitive categories. See more information and instructions on how to setup the tag on: http://google.com/ads/remarketingsetup
--------------------------------------------------->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = my_id_here;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/my_id_here/?guid=ON&amp;script=0"/>
</div>
</noscript>

这是我要将其转换为(通过sublime中的HTML2SLIM软件包)

- if Rails.env.development?
    /! Google Code for Remarketing Tag
    /!
      | ------------------------------------------------
      | Remarketing tags may not be associated with personally identifiable information or placed on pages related to sensitive categories. See more information and instructions on how to setup the tag on: http://google.com/ads/remarketingsetup
      | -------------------------------------------------
    javascript:
      /!*  */
      | var google_conversion_id = my_id_here;
      | var google_custom_params = window.google_tag_params;
      | var google_remarketing_only = true;
      /!*  */
    script src="//www.googleadservices.com/pagead/conversion.js" type="text/javascript" 
    noscript
      div style="display:inline;" 
        img alt="" height="1" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/my_id_here/?guid=ON&amp;script=0" style="border-style:none;" width="1" /

当我在开发中运行此操作时,这是DOM

中输出的内容
<!--Google Code for Remarketing Tag--><!--| ------------------------------------------------
| Remarketing tags may not be associated with personally identifiable information or placed on pages related to sensitive categories. See more information and instructions on how to setup the tag on: http://google.com/ads/remarketingsetup
| --------------------------------------------------->
<script>
    /!*  */
    | var google_conversion_id = my_id_here;
    | var google_custom_params = window.google_tag_params;
    | var google_remarketing_only = true;
    /!*  */
</script>
<script src="//www.googleadservices.com/pagead/conversion.js" type="text/javascript"></script><noscript><div style="display:inline;"><img alt="" height="1" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/my_id_here/?guid=ON&amp;amp;script=0" style="border-style:none;" width="1" /></div></noscript>

除了几件事外,一切似乎都很好:

  1. 我失去了/* <![CDATA[ *//* ]]> */行(很确定Google需要这些。
  2. 所有脚本标签都放下type="text/javascript"属性,但我猜这没关系

所以我的问题是,我如何确保/* <![CDATA[ *//* ]]> */使用细长的语言渲染,或者有没有办法逃脱该文件中的语言并放在Javascript的原始块中?

弄清楚了。只是使用简单的|表示"逐字文本"。这就像纤细语言的最基本语法规则。

这是代码最终的外观:

javascript:
      | /* <![CDATA[ */
      | var google_conversion_id = my_id_here;
      | var google_custom_params = window.google_tag_params;
      | var google_remarketing_only = true;
      | /* ]]> */

derp。Slim的超级不错

最新更新