【问题标题】:Unable to Implement itemprop attribute into Refinery CMS - Rails 4无法将 itemprop 属性实现到 Refinery CMS - Rails 4
【发布时间】:2013-12-30 00:39:36
【问题描述】:

如果您熟悉 Refinery CMS(Rails 的 CMS),是不是我无法创建 schema.org 属性。

我打开一个页面,进行编辑,然后声明:

<figure itemscope itemtype="http://schema.org/Person">
    <img src="#" alt="Example"/>
    <figcaption>
          <span itemprop="name">Bobby Orr</span> - CEO of Example.com
    </figcaption>
</figure>

结果如下:

<figure>
    <img src="#" alt="Example"/>
    <figcaption>
        <span>Bobby Orr</span> - CEO of Example.com
    </figcaption>
</figure>

有谁知道在不移除 Refinery 的情况下保留模式的方法?

【问题讨论】:

    标签: ruby-on-rails attributes refinerycms schema.org refinery


    【解决方案1】:

    您可以将适当的标签添加到 config/initializers/refinery/core.rb 中的 config.wymeditor_whitelist_tags 哈希

    这应该适用于您的图形标签:

    config.whitelist_tags = {'figure' => {'attributes' =>{ '1': 'itemscope', '2': 'itemtype'}}}
    

    请注意,如果您走这条路线,您将需要更改添加项目的方式。

    在您的 html 中,它需要如下所示:

    <figure itemscope="itemscope" itemtype="http://schema.org/Person">
    

    特别注意它必须是itemscope="itemscope",否则它会被剥离。

    根据这个问题,这是有效的 HTML5:HTML5 valid itemscope

    您可以在此处找到有关白名单的更多信息:http://ugisozols.com/blog/2013/06/20/whitelisting-html-tags-and-attributes-in-refinery-cms-wymeditor/

    如果您有很多标签并且想要完全关闭验证,您可以将 app/assets/javascripts/wymeditor/validators.js.erb 复制到您的应用中,并像这样注释掉大部分 getValidTagAttributes 函数:

      getValidTagAttributes: function(tag, attributes)
      {
        var valid_attributes = {};
        var possible_attributes = this.getPossibleTagAttributes(tag);
        var regexp_attributes = [];
        $.each((possible_attributes || []), function(i, val) {
          if (val.indexOf("*") > -1) {
            regexp_attributes.push(new RegExp(val));
          }
        });
        var h = WYMeditor.Helper;
        for(var attribute in attributes) {
          var value = attributes[attribute];
        //if(!h.contains(this.skipped_attributes, attribute) && !h.contains(this.skipped_attribute_values, value)){
        //  if (typeof value != 'function') {
        //    if (h.contains(possible_attributes, attribute)) {
        //      if (this.doesAttributeNeedsValidation(tag, attribute)) {
        //        if(this.validateAttribute(tag, attribute, value)){
        //          valid_attributes[attribute] = value;
        //        }
        //      }else{
                  valid_attributes[attribute] = value;
        //      }
        //    }
        //    else {
        //      $.each(regexp_attributes, function(i, val) {
        //        if (attribute.match(val)) {
        //          valid_attributes[attribute] = value;
        //        }
        //      });
        //    }
        //  }
        //}
        }
        return valid_attributes;
      },
    

    请注意,关闭此类标签的所有验证可能非常危险。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      相关资源
      最近更新 更多