Skip to content

Instantly share code, notes, and snippets.

@asaaki
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asaaki/8691714 to your computer and use it in GitHub Desktop.
Save asaaki/8691714 to your computer and use it in GitHub Desktop.
Include .rabl templates files for `rake notes` task
module SourceAnnotationExtractorExtension
extend ActiveSupport::Concern
included do
def find_in_with_rabl 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|rabl|rb|coffee)$/
results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/))
elsif item =~ /\.erb$/
results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/))
elsif item =~ /\.haml$/
results.update(extract_annotations_from(item, /-\s*#\s*(#{tag}):?\s*(.*)$/))
elsif item =~ /\.slim$/
results.update(extract_annotations_from(item, /\/\s*\s*(#{tag}):?\s*(.*)$/))
end
end
results
end
alias_method_chain :find_in, :rabl
end
end
SourceAnnotationExtractor.send :include, SourceAnnotationExtractorExtension if SourceAnnotationExtractor.method_defined?(:find_in)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment