According to the guides:
... is done in files with extension .builder, .rb, .erb, .haml and .slim for both default and custom annotations.
But it isn't working, even when manually configured:
$ 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
Anyone know how to get it working?
Short answer
Add this line
SourceAnnotationExtractor::Annotation.register_extensions("haml") { |tag| /(?:\/\/|#)\s*(#{tag}):?\s*(.*)$/ }
at the end of Rakefile inside of your Rails app.
Longer answer
rake notes
is defined there : https://github.com/rails/rails/blob/master/railties/lib/rails/tasks/annotations.rake
task :notes do
SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", tag: true
end
this task doesn't depend on :environment, so for example, no code inside config/initializers/ or config/environment will be executed for this task. Putting any configuration there won't have any effect for rake notes.
Only config/application.rb will be required, from Rakefile. https://github.com/rails/rails/blob/master/railties/lib/rails/source_annotation_extractor.rb tells us that we can define a new file extension for Annotations like this :
SourceAnnotationExtractor::Annotation.register_extensions("css", "scss", "sass", "less", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }
so adding this line inside Rakefile or config/application.rb will define the new annotation before the notes task is executed.
I'm not sure why it doesn't work out of the box for haml, since it's defined in haml-rails. For the time being, with Rails 4.2.2 and haml-rails 0.9.0, the short answer above should do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With