加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – “rake notes”应扫描haml

发布时间:2020-12-17 03:18:17 所属栏目:百科 来源:网络整理
导读:根据 guides: … is done in files with extension .builder,.rb,.erb,.haml and .slim for both default and custom annotations. 但即使手动配置,它也无法正常工作: $rails -v Rails 4.2.3$grep -r annotations config/environments/development.rb conf
根据 guides:

… is done in files with extension .builder,.rb,.erb,.haml and .slim for both default and custom annotations.

但即使手动配置,它也无法正常工作:

$rails -v
  Rails 4.2.3
$grep -r annotations config/environments/development.rb
  config/environments/development.rb:  config.annotations.register_extensions('haml') { |a| /#s*(#{a}):?s*(.*)$/ }
$grep -r TODO app/views
  app/views/orders/show.html.haml:  -# TODO: Add link
$rake notes
  app/models/order.rb:
    * [12] [TODO] Refactor

有谁知道如何让它工作?

解决方法

简短的回答

添加此行

SourceAnnotationExtractor::Annotation.register_extensions("haml") { |tag| /(?://|#)s*(#{tag}):?s*(.*)$/ }

在Rails文件的Rails文件末尾.

更长的答案

rake notes

在那里定义:
https://github.com/rails/rails/blob/master/railties/lib/rails/tasks/annotations.rake

task :notes do
  SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO",tag: true
end

此任务不依赖于:环境,因此,例如,将不会为此任务执行config / initializers /或config / environment中的代码.将任何配置放在那里对rake音符没有任何影响.

Rakefile只需要config / application.rb.
https://github.com/rails/rails/blob/master/railties/lib/rails/source_annotation_extractor.rb告诉我们,我们可以为Annotations定义一个新的文件扩展名,如下所示:

SourceAnnotationExtractor::Annotation.register_extensions("css","scss","sass","less","js") { |tag| ///s*(#{tag}):?s*(.*)$/ }

所以在Rakefile或config / application.rb中添加这一行将在执行notes任务之前定义新的注释.

我不确定为什么它不能用于haml的开箱即用,因为它是在haml-rails中定义的.目前,使用Rails 4.2.2和haml-rails 0.9.0,上面的简短答案应该可行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读