Skip to content

Instantly share code, notes, and snippets.

@iiska
Created July 27, 2010 04:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iiska/491762 to your computer and use it in GitHub Desktop.
Save iiska/491762 to your computer and use it in GitHub Desktop.
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
@iiska
Copy link
Author

iiska commented Jul 27, 2010

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment