source_notes 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.textile +35 -0
- data/Rakefile +2 -0
- data/lib/source_notes.rb +108 -0
- data/lib/source_notes/version.rb +3 -0
- data/source_notes.gemspec +17 -0
- metadata +53 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2004 David Heinemeier Hansson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
h1. Source Notes
|
2
|
+
|
3
|
+
A modified version of "Rails":https://github.com/rails/rails SourceAnnotationExtractor.
|
4
|
+
Hopefully to be a bit more generic and reusable.
|
5
|
+
|
6
|
+
h2. Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
@gem 'source_notes'@
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
@bundle@
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
@gem install source_notes@
|
19
|
+
|
20
|
+
h2. Usage
|
21
|
+
|
22
|
+
h2. Contributing
|
23
|
+
|
24
|
+
1. Fork it
|
25
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
26
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
27
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
28
|
+
5. Create new Pull Request
|
29
|
+
|
30
|
+
h2. TODOs
|
31
|
+
|
32
|
+
- Add some instructions
|
33
|
+
- Add tests
|
34
|
+
- Rake-ify
|
35
|
+
- Gemify
|
data/Rakefile
ADDED
data/lib/source_notes.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require "source_notes/version"
|
2
|
+
|
3
|
+
module SourceNotes
|
4
|
+
class Extractor
|
5
|
+
# Annotation objects are triplets <tt>:line</tt>, <tt>:tag</tt>, <tt>:text</tt> that
|
6
|
+
# represent the line where the annotation lives, its tag, and its text. Note
|
7
|
+
# the filename is not stored.
|
8
|
+
#
|
9
|
+
# Annotations are looked for in comments and modulus whitespace they have to
|
10
|
+
# start with the tag optionally followed by a colon. Everything up to the end
|
11
|
+
# of the line (or closing ERB comment tag) is considered to be their text.
|
12
|
+
class Annotation < Struct.new(:line, :tag, :text)
|
13
|
+
# Returns a representation of the annotation that looks like this:
|
14
|
+
#
|
15
|
+
# [126] [TODO] This algorithm is simple and clearly correct, make it faster.
|
16
|
+
#
|
17
|
+
# If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
|
18
|
+
# Otherwise the string contains just line and text.
|
19
|
+
def to_s(options={})
|
20
|
+
s = "[#{line.to_s.rjust(options[:indent])}] "
|
21
|
+
s << "[#{tag}] " if options[:tag]
|
22
|
+
s << text
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Prints all annotations with tag +tag+ under the current PWD
|
27
|
+
# Only filenames with extension +.builder+, +.rb+, +.erb+, +.haml+, +.slim+,
|
28
|
+
# +.css+, +.scss+, +.js+, and +.coffee+ are taken into account.
|
29
|
+
# The +options+ hash is passed to each
|
30
|
+
# annotation's +to_s+.
|
31
|
+
#
|
32
|
+
# This class method is the single entry point for the rake tasks.
|
33
|
+
def self.enumerate(tag, options={})
|
34
|
+
extractor = new(tag)
|
35
|
+
extractor.display(options)
|
36
|
+
end
|
37
|
+
|
38
|
+
attr_reader :tag
|
39
|
+
|
40
|
+
def initialize(tag, options = {})
|
41
|
+
@tag = tag
|
42
|
+
@dirs = options[:dirs] || [Dir::pwd]
|
43
|
+
end
|
44
|
+
|
45
|
+
# Prints the mapping from filenames to annotations in +results+ ordered by filename.
|
46
|
+
# The +options+ hash is passed to each annotation's +to_s+.
|
47
|
+
def display(options={})
|
48
|
+
options[:indent] = find.map { |f, a| a.map(&:line) }.flatten.max.to_s.size
|
49
|
+
find.keys.sort.each do |file|
|
50
|
+
puts "#{file}:"
|
51
|
+
find[file].each do |note|
|
52
|
+
puts " * #{note.to_s(options)}"
|
53
|
+
end
|
54
|
+
puts
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# Returns a hash that maps filenames under +dirs+ (recursively) to arrays
|
61
|
+
# with their annotations.
|
62
|
+
def find
|
63
|
+
@dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns a hash that maps filenames under +dir+ (recursively) to arrays
|
67
|
+
# with their annotations. Only files with annotations are included, and only
|
68
|
+
# those with extension +.builder+, +.rb+, +.erb+, +.haml+, +.slim+, +.css+,
|
69
|
+
# +.scss+, +.js+, and +.coffee+
|
70
|
+
# are taken into account.
|
71
|
+
def find_in(dir)
|
72
|
+
results = {}
|
73
|
+
|
74
|
+
Dir.glob("#{dir}/*") do |item|
|
75
|
+
next if File.basename(item)[0] == ?.
|
76
|
+
|
77
|
+
if File.directory?(item)
|
78
|
+
results.update(find_in(item))
|
79
|
+
elsif item =~ /\.(builder|rb|coffee)$/
|
80
|
+
results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/))
|
81
|
+
elsif item =~ /\.(css|scss|js)$/
|
82
|
+
results.update(extract_annotations_from(item, /\/\/\s*(#{tag}):?\s*(.*)$/))
|
83
|
+
elsif item =~ /\.erb$/
|
84
|
+
results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/))
|
85
|
+
elsif item =~ /\.haml$/
|
86
|
+
results.update(extract_annotations_from(item, /-\s*#\s*(#{tag}):?\s*(.*)$/))
|
87
|
+
elsif item =~ /\.slim$/
|
88
|
+
results.update(extract_annotations_from(item, /\/\s*\s*(#{tag}):?\s*(.*)$/))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
results
|
93
|
+
end
|
94
|
+
|
95
|
+
# If +file+ is the filename of a file that contains annotations this method returns
|
96
|
+
# a hash with a single entry that maps +file+ to an array of its annotations.
|
97
|
+
# Otherwise it returns an empty hash.
|
98
|
+
def extract_annotations_from(file, pattern)
|
99
|
+
lineno = 0
|
100
|
+
result = File.readlines(file).inject([]) do |list, line|
|
101
|
+
lineno += 1
|
102
|
+
next list unless line =~ pattern
|
103
|
+
list << Annotation.new(lineno, $1, $2)
|
104
|
+
end
|
105
|
+
result.empty? ? {} : { file => result }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/source_notes/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["asmega"]
|
6
|
+
gem.email = ["asmega@ph-lee.com"]
|
7
|
+
gem.description = "Extract source notes aka annotations. Based on Rails SourceAnnotationExtractor."
|
8
|
+
gem.summary = "Extract source notes aka annotations. Based on Rails SourceAnnotationExtractor."
|
9
|
+
gem.homepage = "https://github.com/asmega/source_notes"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "source_notes"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = SourceNotes::VERSION
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: source_notes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- asmega
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-20 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Extract source notes aka annotations. Based on Rails SourceAnnotationExtractor.
|
15
|
+
email:
|
16
|
+
- asmega@ph-lee.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.textile
|
25
|
+
- Rakefile
|
26
|
+
- lib/source_notes.rb
|
27
|
+
- lib/source_notes/version.rb
|
28
|
+
- source_notes.gemspec
|
29
|
+
homepage: https://github.com/asmega/source_notes
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.5
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Extract source notes aka annotations. Based on Rails SourceAnnotationExtractor.
|
53
|
+
test_files: []
|