Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@pmontrasio

Description

@pmontrasio

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions