rdoc-tags 1.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,8 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ Autotest.add_hook :initialize do |at|
6
+ at.testlib = 'minitest/autorun'
7
+ end
8
+
@@ -0,0 +1,5 @@
1
+ === 1.0 / 2010-12-23
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
5
+
@@ -0,0 +1,8 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/rdoc/discover.rb
7
+ lib/rdoc/generator/tags.rb
8
+ test/test_rdoc_generator_tags.rb
@@ -0,0 +1,52 @@
1
+ = rdoc_tags
2
+
3
+ * https://github.com/rdoc/rdoc-tags
4
+
5
+ == DESCRIPTION:
6
+
7
+ A TAGS file generator based on http://ctags.sourceforge.net/FORMAT. rdoc-tags
8
+ handles namespaced classes and modules, ! and ? methods, constants and
9
+ attributes better than Exuberant Ctags.
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ * Much slower that Exuberant Ctags
14
+ * Only outputs vim-format tags
15
+ * Only works for ruby files, not Ruby/C files
16
+
17
+ == SYNOPSIS:
18
+
19
+ rdoc -f tags lib
20
+
21
+ == REQUIREMENTS:
22
+
23
+ * RDoc 3+
24
+
25
+ == INSTALL:
26
+
27
+ * gem install rdoc-tags
28
+
29
+ == LICENSE:
30
+
31
+ (The MIT License)
32
+
33
+ Copyright (c) 2010 Eric Hodel
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining
36
+ a copy of this software and associated documentation files (the
37
+ 'Software'), to deal in the Software without restriction, including
38
+ without limitation the rights to use, copy, modify, merge, publish,
39
+ distribute, sublicense, and/or sell copies of the Software, and to
40
+ permit persons to whom the Software is furnished to do so, subject to
41
+ the following conditions:
42
+
43
+ The above copyright notice and this permission notice shall be
44
+ included in all copies or substantial portions of the Software.
45
+
46
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
47
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
48
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
49
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
50
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
51
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
52
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :git
7
+ Hoe.plugin :isolate
8
+ Hoe.plugin :minitest
9
+ Hoe.plugins.delete :rubyforge
10
+
11
+ Hoe.spec 'rdoc-tags' do
12
+ developer 'Eric Hodel', 'drbrain@segment7.net'
13
+
14
+ extra_deps << ['rdoc', '~> 3']
15
+ extra_dev_deps << ['isolate', '~> 3']
16
+
17
+ self.isolate_dir = 'tmp/isolated'
18
+ end
19
+
20
+ # vim: syntax=Ruby
@@ -0,0 +1,6 @@
1
+ begin
2
+ gem 'rdoc', '~> 3'
3
+ require 'rdoc/generator/tags'
4
+ rescue Gem::LoadError
5
+ end
6
+
@@ -0,0 +1,144 @@
1
+ require 'rdoc/rdoc'
2
+ require 'rdoc/generator'
3
+
4
+ ##
5
+ # A TAGS file generator based on http://ctags.sourceforge.net/FORMAT
6
+
7
+ class RDoc::Generator::Tags
8
+
9
+ ##
10
+ # The version of the tags generator you are using
11
+
12
+ VERSION = '1.0'
13
+
14
+ RDoc::RDoc.add_generator self
15
+
16
+ ##
17
+ # Extra Tags options to be added to RDoc::Options
18
+
19
+ module Options
20
+
21
+ ##
22
+ # Valid tag styles
23
+
24
+ TAG_STYLES = [:vim]
25
+
26
+ ##
27
+ # Which tag style shall we output?
28
+
29
+ attr_accessor :tag_style
30
+
31
+ end
32
+
33
+ ##
34
+ # Adds tags-generator options to the RDoc::Options instance +options+
35
+
36
+ def self.setup_options options
37
+ options.force_output = true
38
+ options.op_dir = '.'
39
+
40
+ options.extend Options
41
+
42
+ options.tag_style = :vim
43
+
44
+ op = options.option_parser
45
+
46
+ op.separator nil
47
+ op.separator 'tags generator options:'
48
+ op.separator nil
49
+
50
+ op.on('--tag-style=TAG_STYLE', Options::TAG_STYLES,
51
+ 'Which type of TAGS file to output') do |value|
52
+ options.tag_style = value
53
+ end
54
+
55
+ op.separator nil
56
+ end
57
+
58
+ ##
59
+ # Creates a new tags generator
60
+
61
+ def initialize options
62
+ @options = options
63
+ @dry_run = options.dry_run
64
+ @tags = {}
65
+ end
66
+
67
+ ##
68
+ # Generates a TAGS file from +top_levels+
69
+
70
+ def generate top_levels
71
+ top_levels.each do |top_level|
72
+ @tags[top_level.relative_name] = [top_level.relative_name, 0, 'F']
73
+ end
74
+
75
+ RDoc::TopLevel.all_classes_and_modules.each do |klass|
76
+ kind = "class:#{klass.full_name}"
77
+
78
+ address =
79
+ unless RDoc::TopLevel === klass.parent then
80
+ "/#{klass.type} \\(#{klass.parent.full_name}::\\)\\?#{klass.name}/"
81
+ else
82
+ "/#{klass.type} #{klass.full_name}/"
83
+ end
84
+
85
+ klass.in_files.each do |file|
86
+ @tags[klass.full_name] = [file.relative_name, address, 'c']
87
+ @tags[klass.name] = [file.relative_name, address, 'c']
88
+ end
89
+
90
+ klass.each_attribute do |attr|
91
+ where = [
92
+ attr.file.relative_name,
93
+ "/attr\\w\\*\\s\\*\\[:'\"]#{attr.name}/",
94
+ 'f',
95
+ kind
96
+ ]
97
+
98
+ @tags[attr.name] = where
99
+ @tags["#{attr.name}="] = where
100
+ end
101
+
102
+ klass.each_constant do |constant|
103
+ @tags[constant.name] = [
104
+ constant.file.relative_name, "/#{constant.name}\\s\\*=/", 'd', kind]
105
+ end
106
+
107
+ klass.each_method do |method|
108
+ address = if method.singleton then
109
+ # \w doesn't appear to work in [] with nomagic
110
+ "/def \\[A-Za-z0-9_:]\\+.#{method.name}/"
111
+ else
112
+ "/def #{method.name}/"
113
+ end
114
+
115
+ @tags[method.name] = [
116
+ method.file.relative_name, address, 'f', kind]
117
+ end
118
+ end
119
+
120
+ write_tags unless @dry_run
121
+ end
122
+
123
+ ##
124
+ # Writes the TAGS file
125
+
126
+ def write_tags
127
+ open 'TAGS', 'w' do |io|
128
+ io.write <<-INFO
129
+ !_TAG_FILE_FORMAT\t2
130
+ !_TAG_FILE_SORTED\t1
131
+ !_TAG_PROGRAM_AUTHOR\tEric Hodel\t/drbrain@segment7.net/
132
+ !_TAG_PROGRAM_NAME\trdoc-tags
133
+ !_TAG_PROGRAM_URL\thttps://github.com/rdoc/rdoc-tags
134
+ !_TAG_PROGRAM_VERSION\t#{VERSION}
135
+ INFO
136
+
137
+ @tags.sort.each do |name, (file, address, *field)|
138
+ io.write "#{name}\t#{file}\t#{address};\"\t#{field.join "\t"}\n"
139
+ end
140
+ end
141
+ end
142
+
143
+ end
144
+
@@ -0,0 +1,184 @@
1
+ require 'rubygems'
2
+ gem 'rdoc', '~> 3'
3
+
4
+ require 'minitest/autorun'
5
+ require 'rdoc/rdoc'
6
+ require 'rdoc/generator/tags'
7
+ require 'tmpdir'
8
+ require 'fileutils'
9
+
10
+ class TestRDocGeneratorTags < MiniTest::Unit::TestCase
11
+
12
+ def setup
13
+ @options = RDoc::Options.new
14
+ @options.extend RDoc::Generator::Tags::Options
15
+
16
+ @pwd = Dir.pwd
17
+ RDoc::TopLevel.reset
18
+
19
+ @tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_tags_#{$$}"
20
+ FileUtils.mkdir_p @tmpdir
21
+ Dir.chdir @tmpdir
22
+
23
+ @g = RDoc::Generator::Tags.new @options
24
+
25
+ @top_level = RDoc::TopLevel.new 'file.rb'
26
+
27
+ @klass = @top_level.add_class RDoc::NormalClass, 'Object'
28
+ @klass.record_location @top_level
29
+
30
+ @A = @top_level.add_class RDoc::NormalClass, 'A'
31
+ @A.record_location @top_level
32
+
33
+ @B = @A.add_class RDoc::NormalClass, 'B'
34
+ @B.record_location @top_level
35
+
36
+ @meth = RDoc::AnyMethod.new nil, 'method'
37
+ @meth.record_location @top_level
38
+
39
+ @meth_bang = RDoc::AnyMethod.new nil, 'method!'
40
+ @meth_bang.record_location @top_level
41
+
42
+ @attr = RDoc::Attr.new nil, 'attr', 'RW', ''
43
+ @attr.record_location @top_level
44
+
45
+ @smeth = RDoc::AnyMethod.new nil, 's_method'
46
+ @smeth.singleton = true
47
+ @smeth.record_location @top_level
48
+
49
+ @const = RDoc::Constant.new 'CONST', '', ''
50
+ @const.record_location @top_level
51
+
52
+ @klass.add_method @meth
53
+ @klass.add_method @smeth
54
+ @klass.add_method @meth_bang
55
+ @klass.add_attribute @attr
56
+ @klass.add_constant @const
57
+ end
58
+
59
+ def teardown
60
+ Dir.chdir @pwd
61
+ FileUtils.rm_rf @tmpdir
62
+ end
63
+
64
+ def test_class_setup_options
65
+ options = RDoc::Options.new
66
+
67
+ op = OptionParser.new
68
+
69
+ options.option_parser = op
70
+
71
+ RDoc::Generator::Tags.setup_options options
72
+
73
+ assert_equal :vim, options.tag_style
74
+
75
+ assert_includes op.top.long, 'tag-style'
76
+ end
77
+
78
+ def test_generate_emacs
79
+ skip "test incomplete"
80
+
81
+ @options.tag_style = :emacs
82
+
83
+ @g.generate [@top_level]
84
+
85
+ tags_file = File.join @tmpdir, 'TAGS'
86
+
87
+ assert File.file? tags_file
88
+
89
+ tags = File.read(tags_file).lines
90
+
91
+ assert_equal "!_TAG_FILE_FORMAT\t2\n", tags.next
92
+ assert_equal "!_TAG_FILE_SORTED\t1\n", tags.next
93
+ assert_equal "!_TAG_PROGRAM_AUTHOR\tEric Hodel\t/drbrain@segment7.net/\n",
94
+ tags.next
95
+ assert_equal "!_TAG_PROGRAM_NAME\trdoc-tags\n", tags.next
96
+ assert_equal "!_TAG_PROGRAM_URL\thttp://rdoc.rubyforge.org/rdoc-tags\n",
97
+ tags.next
98
+ assert_equal "!_TAG_PROGRAM_VERSION\t#{RDoc::Generator::Tags::VERSION}\n",
99
+ tags.next
100
+
101
+ assert_equal "A\tfile.rb\t/class A/;\"\tc\n", tags.next
102
+ assert_equal "A::B\tfile.rb\t/class \\(A::\\)\\?B/;\"\tc\n", tags.next
103
+ assert_equal "B\tfile.rb\t/class \\(A::\\)\\?B/;\"\tc\n", tags.next
104
+
105
+ assert_equal "CONST\tfile.rb\t/CONST\\s\\*=/;\"\td\tclass:Object\n", tags.next
106
+
107
+ assert_equal "Object\tfile.rb\t/class Object/;\"\tc\n", tags.next
108
+
109
+ assert_equal "attr\tfile.rb\t/attr\\w\\*\\s\\*\\[:'\"]attr/;\"\tf\tclass:Object\n",
110
+ tags.next
111
+ assert_equal "attr=\tfile.rb\t/attr\\w\\*\\s\\*\\[:'\"]attr/;\"\tf\tclass:Object\n",
112
+ tags.next
113
+
114
+ assert_equal "file.rb\tfile.rb\t0;\"\tF\n", tags.next
115
+
116
+ assert_equal "method\tfile.rb\t/def method/;\"\tf\tclass:Object\n",
117
+ tags.next
118
+ assert_equal "method!\tfile.rb\t/def method!/;\"\tf\tclass:Object\n",
119
+ tags.next
120
+
121
+ assert_equal "s_method\tfile.rb\t/def \\[A-Za-z0-9_:]\\+.s_method/;\"\tf\tclass:Object\n",
122
+ tags.next
123
+
124
+ assert_raises StopIteration do line = tags.next; flunk line end
125
+ end
126
+
127
+ def test_generate_vim
128
+ @options.tag_style = :vim
129
+
130
+ @g.generate [@top_level]
131
+
132
+ tags_file = File.join @tmpdir, 'TAGS'
133
+
134
+ assert File.file? tags_file
135
+
136
+ tags = File.read(tags_file).lines
137
+
138
+ assert_equal "!_TAG_FILE_FORMAT\t2\n", tags.next
139
+ assert_equal "!_TAG_FILE_SORTED\t1\n", tags.next
140
+ assert_equal "!_TAG_PROGRAM_AUTHOR\tEric Hodel\t/drbrain@segment7.net/\n",
141
+ tags.next
142
+ assert_equal "!_TAG_PROGRAM_NAME\trdoc-tags\n", tags.next
143
+ assert_equal "!_TAG_PROGRAM_URL\thttps://github.com/rdoc/rdoc-tags\n",
144
+ tags.next
145
+ assert_equal "!_TAG_PROGRAM_VERSION\t#{RDoc::Generator::Tags::VERSION}\n",
146
+ tags.next
147
+
148
+ assert_equal "A\tfile.rb\t/class A/;\"\tc\n", tags.next
149
+ assert_equal "A::B\tfile.rb\t/class \\(A::\\)\\?B/;\"\tc\n", tags.next
150
+ assert_equal "B\tfile.rb\t/class \\(A::\\)\\?B/;\"\tc\n", tags.next
151
+
152
+ assert_equal "CONST\tfile.rb\t/CONST\\s\\*=/;\"\td\tclass:Object\n", tags.next
153
+
154
+ assert_equal "Object\tfile.rb\t/class Object/;\"\tc\n", tags.next
155
+
156
+ assert_equal "attr\tfile.rb\t/attr\\w\\*\\s\\*\\[:'\"]attr/;\"\tf\tclass:Object\n",
157
+ tags.next
158
+ assert_equal "attr=\tfile.rb\t/attr\\w\\*\\s\\*\\[:'\"]attr/;\"\tf\tclass:Object\n",
159
+ tags.next
160
+
161
+ assert_equal "file.rb\tfile.rb\t0;\"\tF\n", tags.next
162
+
163
+ assert_equal "method\tfile.rb\t/def method/;\"\tf\tclass:Object\n",
164
+ tags.next
165
+ assert_equal "method!\tfile.rb\t/def method!/;\"\tf\tclass:Object\n",
166
+ tags.next
167
+
168
+ assert_equal "s_method\tfile.rb\t/def \\[A-Za-z0-9_:]\\+.s_method/;\"\tf\tclass:Object\n",
169
+ tags.next
170
+
171
+ assert_raises StopIteration do line = tags.next; flunk line end
172
+ end
173
+
174
+ def test_generate_dry_run
175
+ @options.dry_run = true
176
+ @g = RDoc::Generator::Tags.new @options
177
+
178
+ @g.generate [@top_level]
179
+
180
+ refute File.exist? File.join(@tmpdir, 'TAGS')
181
+ end
182
+
183
+ end
184
+
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdoc-tags
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ version: "1.0"
10
+ platform: ruby
11
+ authors:
12
+ - Eric Hodel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ - |
17
+ -----BEGIN CERTIFICATE-----
18
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
19
+ YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
20
+ ZXQwHhcNMDcxMjIxMDIwNDE0WhcNMDgxMjIwMDIwNDE0WjBBMRAwDgYDVQQDDAdk
21
+ cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
22
+ FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76
23
+ LV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J
24
+ U5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm
25
+ Gj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY
26
+ mUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd
27
+ g62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh
28
+ sCANiQ8BAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
29
+ BBS5k4Z75VSpdM0AclG2UvzFA/VW5DANBgkqhkiG9w0BAQUFAAOCAQEAHagT4lfX
30
+ kP/hDaiwGct7XPuVGbrOsKRVD59FF5kETBxEc9UQ1clKWngf8JoVuEoKD774dW19
31
+ bU0GOVWO+J6FMmT/Cp7nuFJ79egMf/gy4gfUfQMuvfcr6DvZUPIs9P/TlK59iMYF
32
+ DIOQ3DxdF3rMzztNUCizN4taVscEsjCcgW6WkUJnGdqlu3OHWpQxZBJkBTjPCoc6
33
+ UW6on70SFPmAy/5Cq0OJNGEWBfgD9q7rrs/X8GGwUWqXb85RXnUVi/P8Up75E0ag
34
+ 14jEc90kN+C7oI/AGCBN0j6JnEtYIEJZibjjDJTSMWlUKKkj30kq7hlUC2CepJ4v
35
+ x52qPcexcYZR7w==
36
+ -----END CERTIFICATE-----
37
+
38
+ date: 2010-12-23 00:00:00 -08:00
39
+ default_executable:
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ prerelease: false
44
+ requirement: &id001 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ hash: 5
50
+ segments:
51
+ - 3
52
+ version: "3"
53
+ type: :runtime
54
+ version_requirements: *id001
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ prerelease: false
58
+ requirement: &id002 !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 15
64
+ segments:
65
+ - 2
66
+ - 0
67
+ - 0
68
+ version: 2.0.0
69
+ type: :development
70
+ version_requirements: *id002
71
+ - !ruby/object:Gem::Dependency
72
+ name: isolate
73
+ prerelease: false
74
+ requirement: &id003 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ hash: 5
80
+ segments:
81
+ - 3
82
+ version: "3"
83
+ type: :development
84
+ version_requirements: *id003
85
+ - !ruby/object:Gem::Dependency
86
+ name: hoe
87
+ prerelease: false
88
+ requirement: &id004 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 19
94
+ segments:
95
+ - 2
96
+ - 7
97
+ - 0
98
+ version: 2.7.0
99
+ type: :development
100
+ version_requirements: *id004
101
+ description: |-
102
+ A TAGS file generator based on http://ctags.sourceforge.net/FORMAT. rdoc-tags
103
+ handles namespaced classes and modules, ! and ? methods, constants and
104
+ attributes better than Exuberant Ctags.
105
+ email:
106
+ - drbrain@segment7.net
107
+ executables: []
108
+
109
+ extensions: []
110
+
111
+ extra_rdoc_files:
112
+ - History.txt
113
+ - Manifest.txt
114
+ - README.txt
115
+ files:
116
+ - .autotest
117
+ - History.txt
118
+ - Manifest.txt
119
+ - README.txt
120
+ - Rakefile
121
+ - lib/rdoc/discover.rb
122
+ - lib/rdoc/generator/tags.rb
123
+ - test/test_rdoc_generator_tags.rb
124
+ has_rdoc: true
125
+ homepage: https://github.com/rdoc/rdoc-tags
126
+ licenses: []
127
+
128
+ post_install_message:
129
+ rdoc_options:
130
+ - --main
131
+ - README.txt
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ hash: 3
140
+ segments:
141
+ - 0
142
+ version: "0"
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ requirements: []
153
+
154
+ rubyforge_project: rdoc-tags
155
+ rubygems_version: 1.3.7
156
+ signing_key:
157
+ specification_version: 3
158
+ summary: A TAGS file generator based on http://ctags.sourceforge.net/FORMAT
159
+ test_files:
160
+ - test/test_rdoc_generator_tags.rb
Binary file