do_by icon indicating copy to clipboard operation
do_by copied to clipboard

Override rake notes to make it work with this gem's annotations

Open pmontrasio opened this issue 11 years ago • 0 comments

Unfortunately rake notes won't find the annotations made for this gem. I hacked this together

echo "require File.expand_path('../lib/tasks/notes', __FILE__)" >> Rakefile

The file lib/tasks/notes is

class SourceAnnotationExtractor
  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))
      else
        pattern =
            case item
            when /\.rb$/
              /[#]{0,1}\s*(#{tag}):?\s*(.*)$/
            when /\.(builder|coffee|rake)$/
              /#\s*(#{tag}):?\s*(.*)$/
            when /\.(css|scss|sass|less|js)$/
              /\/\/\s*(#{tag}):?\s*(.*)$/
            when /\.erb$/
              /<%\s*[#]{0,1}\s*(#{tag}):?\s*(.*?)\s*%>/
            when /\.haml$/
              /-\s*#\s*(#{tag}):?\s*(.*)$/
            when /\.slim$/
              /\/\s*\s*(#{tag}):?\s*(.*)$/
            else nil
            end
        results.update(extract_annotations_from(item, pattern)) if pattern
      end
    end

    results
  end
end

The original is from railties-4.1.6/lib/rails/source_annotation_extractor.rb

I changed the REs for .rb, Rake and .erb. They recognize both the # TAG and the TAG form. I don't have builder, coffee, haml, slim files to test with so I didn't touch their RE.

This is hardly the right way to do it but I had little time to think about it. Hopefully somebody will put it together in a more proper form.

pmontrasio avatar Oct 12 '14 14:10 pmontrasio