`rake notes`应该扫描haml

Zub*_*bin 5 rake ruby-on-rails ruby-on-rails-4.2

根据指南:

...在扩展名为.builder,.rb,.erb,.haml和.slim的文件中完成,用于默认和自定义注释.

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

$ 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
Run Code Online (Sandbox Code Playgroud)

有谁知道如何让它工作?

Eri*_*nil 5

简短的回答

添加此行

SourceAnnotationExtractor::Annotation.register_extensions("haml") { |tag| /(?:\/\/|#)\s*(#{tag}):?\s*(.*)$/ }
Run Code Online (Sandbox Code Playgroud)

在Rails文件的Rails文件末尾.

更长的答案

rake notes
Run Code Online (Sandbox Code Playgroud)

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

task :notes do
  SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", tag: true
end
Run Code Online (Sandbox Code Playgroud)

此任务不依赖于:环境,因此,例如,将不会为此任务执行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*(.*)$/ }
Run Code Online (Sandbox Code Playgroud)

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

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


Arv*_*ind 0

将以下内容放入config/initializers/

Rails.application.config.annotations.tap do |notes|
  notes.register_extensions('haml') { |annotation| %r(#\s*(#{annotation}):?\s*(.*?)$) }
end
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,您可以参考