用于Ruby on Rails 4应用程序的Slim中谷歌再营销代码的正确语法?

时间:2016-12-07 20:39:27

标签: ruby-on-rails slim-lang

我正在尝试在细长的部分中安装一些再营销代码,并且在测试中,输出看起来不太合适。

这是我给出的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"属性,但我猜这不会太重要
  3. 所以我的问题是,如何确保/* <![CDATA[ *//* ]]> */使用苗条语言进行呈现OR是否有办法逃避此文件中的语言并放入原始的javascript块?

1 个答案:

答案 0 :(得分:0)

想出来。只是使用简单的|来表示“逐字文字”。它就像Slim语言最基本的语法规则。

这里的代码最终看起来像:

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

DERP。苗条的超级好看