简体   繁体   English

无法在炼油厂CMS中实现itemprop属性-Rails 4

[英]Unable to Implement itemprop attribute into Refinery CMS - Rails 4

If you're familiar with Refinery CMS - a CMS for Rails - is that I can't make schema.org attributes. 如果您熟悉Refinery CMS(Rails的CMS),那就是我无法设置schema.org属性。

I open a page, go to edit, and state: 我打开一个页面,进行编辑并声明:

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

And it comes out as: 结果如下:

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

Does anyone know of a method to keep the schema in without Refinery removing them? 有谁知道一种无需精炼厂就可以删除架构的方法?

You can do this be adding the appropriate tags to the config.wymeditor_whitelist_tags hash in config/initializers/refinery/core.rb 您可以通过在config / initializers / refinery / core.rb中的config.wymeditor_whitelist_tags哈希中添加适当的标签来实现

This should work for your figure tag: 这应该适用于您的图形标签:

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

Please note that if you go this route, you will need to change how you are adding itemsope. 请注意,如果您选择这条路线,则需要更改添加项目的方式。

In your html, it will need to look like this: 在您的html中,它将需要如下所示:

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

Specifically note it needs to be itemscope="itemscope" or else it will get stripped. 特别注意,它必须是itemscope="itemscope" ,否则它将被剥离。

That is valid HTML5 according to this question: HTML5 valid itemscope 根据以下问题,这是有效的HTML5: HTML5有效itemscope

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

If you have a lot of tags and you want to turn off the validation completely, you can copy over app/assets/javascripts/wymeditor/validators.js.erb into your app and comment out most of the getValidTagAttributes function like so: 如果您有很多标签,并且想要完全关闭验证,则可以将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;
  },

Please note turning off all the validation of tags like this is potentially very dangerous. 请注意,关闭所有这样的标签验证可能非常危险。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM