Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pmontrasio opened this issue Oct 12, 2014 · 0 comments
Open

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

pmontrasio opened this issue Oct 12, 2014 · 0 comments

Comments

@pmontrasio
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant