The README for the annotate gem mentions models, fixtures, specs, and files generated by specific gems, but not presenters.
Is there any way to make annotate add annotations to presenters?
The README for the annotate gem mentions models, fixtures, specs, and files generated by specific gems, but not presenters.
Is there any way to make annotate add annotations to presenters?
There doesn't seem to be a gem-supported way to add model annotations to other types of classes which wrap around models, like presenters, decorators, and exhibitors. But, since pretty much all the main code in the gem is in a single file (lib/annotate/annotate_models.rb
), you could bundle open annotate
and hack around on it to get what you want, assuming you don't mind a bit of monkey patching. For example, assuming your presenters are in app/presenters
, you could make the following kinds of edits to the file directly:
module AnnotateModels
# Towards the top of the file where all the directory
# declarations are...
PRESENTER_DIR = File.join("app", "presenters")
PRESENTER_TEST_DIR = File.join("test", "presenters")
PRESENTER_SPEC_DIR = File.join("spec", "presenters")
PRESENTER_PATTERNS = [
File.join(PRESENTER_DIR, "%MODEL_NAME%_presenter.rb"),
File.join(PRESENTER_TEST_DIR, "%MODEL_NAME%_presenter_test.rb"),
File.join(PRESENTER_SPEC_DIR, "%MODEL_NAME%_presenter_spec.rb"),
]
# ...
def annotate
# ...
# add in presenters to the list of file types that require annotations
%w(test fixture factory serializer presenter).each do |key|
# ...
end
end
def remove_annotations
# ...
# add presenter files to list needing annotation removal
(TEST_PATTERNS + FIXTURE_PATTERNS + FACTORY_PATTERNS + SERIALIZER_PATTERNS + PRESENTER_PATTERNS).map { ... }
end
# ...
end
Certainly not an elegant solution, but if this kind of change works for you, you could consider forking the gem and moving any changes there, or maybe even submit a pull request back to the gem. Looking at the annotate gem issue tracker, there doesn't seem to have been any feature requests or discussion around the addition of presenters or decorators to the file types that could be annotated.