gpt4 book ai didi

ruby-on-rails - `rake notes` 应该扫描haml

转载 作者:行者123 更新时间:2023-12-04 19:03:04 25 4
gpt4 key购买 nike

根据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 应用程序内的 Rakefile 末尾。

更长的答案
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

此任务不依赖于 :environment,因此例如,不会为此任务执行 config/initializers/或 config/environment 中的任何代码。将任何配置放在那里不会对 rake 笔记产生任何影响。

只需要 config/application.rb 文件,来自 Rakefile。
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,上面的简短回答应该可以。

关于ruby-on-rails - `rake notes` 应该扫描haml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32492734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com