Created
July 27, 2010 04:54
-
-
Save iiska/491762 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'source_annotation_extractor' | |
class SourceAnnotationExtractor | |
# Override the directories that the SourceAnnotationExtractor | |
# traverses when you call rake notes | |
def find(dirs=%w(app lib spec public/javascripts)) | |
dirs.inject({}) { |h, dir| h.update(find_in(dir)) } | |
end | |
# Override to extract annotations from .haml and .js files | |
def find_in(dir) | |
results = {} | |
Dir.glob("#{dir}/*") do |item| | |
next if File.basename(item)[0] == ?. | |
if File.directory?(item) | |
results.update(find_in(item)) | |
elsif item =~ /\.(builder|(r(?:b|xml|js)))$/ | |
results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/)) | |
elsif item =~ /\.(rhtml|erb)$/ | |
results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/)) | |
elsif item =~ /\.(haml|js)$/ | |
results.update(extract_annotations_from(item, /\/?\/\s*(#{tag}):?\s*(.*)$/)) | |
end | |
end | |
results | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Extracts annotations from *.haml and *.js files also. 'public/javascripts' path is added to the traversed directories. Place this to lib/tasks and use rake notes normally.