yard-appendix 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/yard-appendix.rb +10 -7
- data/lib/yard-appendix/handlers/appendix_handler.rb +2 -3
- data/lib/yard-appendix/handlers/ruby/appendix_handler.rb +49 -0
- data/lib/yard-appendix/handlers/ruby/legacy/appendix_handler.rb +26 -0
- data/lib/yard-appendix/namespace_resolver.rb +31 -4
- data/lib/yard-appendix/version.rb +1 -1
- data/spec/handlers/appendix_handler_spec.rb +6 -3
- data/spec/handlers/appendix_legacy_handler_spec.rb +120 -0
- metadata +5 -2
data/lib/yard-appendix.rb
CHANGED
@@ -23,19 +23,22 @@
|
|
23
23
|
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
24
24
|
|
25
25
|
require 'yard'
|
26
|
-
require 'yard-appendix/version'
|
27
|
-
require 'yard-appendix/namespace_resolver'
|
28
|
-
require 'yard-appendix/code_objects/appendix_object'
|
29
|
-
require 'yard-appendix/tags/appendix_directive'
|
30
|
-
require 'yard-appendix/handlers/appendix_handler'
|
31
|
-
require 'yard-appendix/templates/helpers/html_helper'
|
32
26
|
|
33
27
|
module YARD
|
34
28
|
module AppendixPlugin
|
35
29
|
ROOT = File.dirname(__FILE__)
|
36
30
|
TEMPLATE_PATH = File.join(%W[#{ROOT} .. templates])
|
31
|
+
RUBY_19 = RUBY_VERSION >= '1.9.'
|
37
32
|
end
|
38
33
|
|
34
|
+
require 'yard-appendix/version'
|
35
|
+
require 'yard-appendix/namespace_resolver'
|
36
|
+
require 'yard-appendix/code_objects/appendix_object'
|
37
|
+
require 'yard-appendix/tags/appendix_directive'
|
38
|
+
require 'yard-appendix/handlers/ruby/appendix_handler' if RUBY19
|
39
|
+
require 'yard-appendix/handlers/ruby/legacy/appendix_handler' unless RUBY19
|
40
|
+
require 'yard-appendix/templates/helpers/html_helper'
|
41
|
+
|
39
42
|
module Templates
|
40
43
|
Engine.register_template_path YARD::AppendixPlugin::TEMPLATE_PATH
|
41
44
|
end
|
@@ -43,4 +46,4 @@ module YARD
|
|
43
46
|
module Tags
|
44
47
|
Library.define_directive(:appendix, :with_title_and_text, AppendixDirective)
|
45
48
|
end
|
46
|
-
end
|
49
|
+
end
|
@@ -20,7 +20,7 @@
|
|
20
20
|
# SOFTWARE.
|
21
21
|
#
|
22
22
|
|
23
|
-
require 'yard/handlers/ruby/
|
23
|
+
require 'yard/handlers/ruby/base'
|
24
24
|
|
25
25
|
module YARD
|
26
26
|
module Handlers
|
@@ -29,7 +29,7 @@ module YARD
|
|
29
29
|
# it with the NamespaceResolver.
|
30
30
|
#
|
31
31
|
# @see YARD::AppendixPlugin::NamespaceResolver
|
32
|
-
class AppendixHandler <
|
32
|
+
class AppendixHandler < BaseHandler
|
33
33
|
handles :class, :module
|
34
34
|
|
35
35
|
def initialize(*args)
|
@@ -43,7 +43,6 @@ module YARD
|
|
43
43
|
end
|
44
44
|
end # AppendixHandler
|
45
45
|
|
46
|
-
CommentHandler.inherited(AppendixHandler)
|
47
46
|
end # Ruby
|
48
47
|
end # Handlers
|
49
48
|
end # YARD
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2013 Instructure, Inc.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
5
|
+
# copy of this software and associated documentation files (the "Software"),
|
6
|
+
# to deal in the Software without restriction, including without limitation
|
7
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
8
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
9
|
+
# Software is furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
17
|
+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
+
# SOFTWARE.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'yard/handlers/ruby/comment_handler'
|
24
|
+
|
25
|
+
module YARD
|
26
|
+
module Handlers
|
27
|
+
module Ruby
|
28
|
+
# Tracks every namespace defining statement and registers
|
29
|
+
# it with the NamespaceResolver.
|
30
|
+
#
|
31
|
+
# @see YARD::AppendixPlugin::NamespaceResolver
|
32
|
+
class AppendixHandler < CommentHandler
|
33
|
+
handles :class, :module
|
34
|
+
|
35
|
+
def initialize(*args)
|
36
|
+
super(*args)
|
37
|
+
|
38
|
+
globals.resolver ||= YARD::AppendixPlugin::NamespaceResolver.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def process
|
42
|
+
globals.resolver.register_namespace(statement, namespace)
|
43
|
+
end
|
44
|
+
end # AppendixHandler
|
45
|
+
|
46
|
+
CommentHandler.inherited(AppendixHandler)
|
47
|
+
end # Ruby
|
48
|
+
end # Handlers
|
49
|
+
end # YARD
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'yard/handlers/ruby/legacy/base'
|
2
|
+
|
3
|
+
|
4
|
+
module YARD
|
5
|
+
module Handlers
|
6
|
+
module Ruby
|
7
|
+
module Legacy
|
8
|
+
class AppendixHandler < Base
|
9
|
+
MATCH = /\A(class|module)\s+([\w|_])+\s*[<|;|\n]?/
|
10
|
+
handles MATCH
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super(*args)
|
14
|
+
|
15
|
+
globals.resolver ||= YARD::AppendixPlugin::NamespaceResolver.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def process
|
19
|
+
ns = statement.tokens.to_s.split(/\s+/).last
|
20
|
+
globals.resolver.register_namespace(ns, namespace)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -118,7 +118,7 @@ module YARD
|
|
118
118
|
lines_to_namespaces.each_pair { |line, ast|
|
119
119
|
distance = statement.line - line
|
120
120
|
if closest.empty? || distance < closest[:distance]
|
121
|
-
closest = { node
|
121
|
+
closest = { :node => ast, :distance => distance }
|
122
122
|
end
|
123
123
|
}
|
124
124
|
|
@@ -134,16 +134,43 @@ module YARD
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
-
|
138
|
-
|
139
|
-
|
137
|
+
|
138
|
+
if node.is_a?(YARD::Parser::Ruby::AstNode)
|
139
|
+
path += case node.type
|
140
|
+
when :class; node.class_name.path.first
|
141
|
+
when :module; node.module_name.path.first
|
142
|
+
end
|
143
|
+
else
|
144
|
+
path += node.to_s
|
140
145
|
end
|
146
|
+
|
147
|
+
path
|
141
148
|
end
|
142
149
|
|
143
150
|
def path_to(ast, ns)
|
144
151
|
(ast && @namespaces[path_from_ast(ast, ns)]) || ns.to_s
|
145
152
|
end
|
146
153
|
|
154
|
+
# Legacy YARD handler compatibility
|
155
|
+
module LegacyResolver
|
156
|
+
def self.included(b)
|
157
|
+
log.debug "yard-appendix: namespace resolver running in legacy mode"
|
158
|
+
|
159
|
+
b.instance_eval {
|
160
|
+
remove_method(:locate_enclosing_ns)
|
161
|
+
include InstanceMethods
|
162
|
+
}
|
163
|
+
end
|
164
|
+
|
165
|
+
module InstanceMethods
|
166
|
+
def locate_enclosing_ns(__comment, outer_ns)
|
167
|
+
outer_ns.to_s
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
include(LegacyResolver) unless RUBY19
|
147
173
|
end
|
174
|
+
|
148
175
|
end
|
149
176
|
end
|
@@ -20,6 +20,8 @@
|
|
20
20
|
# SOFTWARE.
|
21
21
|
#
|
22
22
|
|
23
|
+
unless RUBY_VERSION < '1.9.'
|
24
|
+
|
23
25
|
include Handlers::Ruby
|
24
26
|
|
25
27
|
describe YARD::Handlers::Ruby::AppendixHandler do
|
@@ -34,14 +36,14 @@ describe YARD::Handlers::Ruby::AppendixHandler do
|
|
34
36
|
def process; @@resolver ||= globals.resolver end
|
35
37
|
|
36
38
|
# have to do this manually as to not clutter up the other specs
|
37
|
-
AppendixHandler.clear_subclasses
|
39
|
+
# AppendixHandler.clear_subclasses
|
38
40
|
end
|
39
41
|
|
40
|
-
AppendixHandler.inherited(StubHandler)
|
42
|
+
# AppendixHandler.inherited(StubHandler)
|
41
43
|
}
|
42
44
|
|
43
45
|
after {
|
44
|
-
AppendixHandler.clear_subclasses
|
46
|
+
# AppendixHandler.clear_subclasses
|
45
47
|
}
|
46
48
|
|
47
49
|
it "should track a namespace statement" do
|
@@ -114,4 +116,5 @@ describe YARD::Handlers::Ruby::AppendixHandler do
|
|
114
116
|
|
115
117
|
end
|
116
118
|
|
119
|
+
end
|
117
120
|
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2013 Instructure, Inc.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
5
|
+
# copy of this software and associated documentation files (the "Software"),
|
6
|
+
# to deal in the Software without restriction, including without limitation
|
7
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
8
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
9
|
+
# Software is furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
17
|
+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
+
# SOFTWARE.
|
21
|
+
#
|
22
|
+
|
23
|
+
unless RUBY19
|
24
|
+
|
25
|
+
include Handlers::Ruby::Legacy
|
26
|
+
|
27
|
+
describe YARD::Handlers::Ruby::Legacy::AppendixHandler do
|
28
|
+
|
29
|
+
before {
|
30
|
+
Registry.clear
|
31
|
+
|
32
|
+
class StubHandler < AppendixHandler
|
33
|
+
handles AppendixHandler::MATCH
|
34
|
+
|
35
|
+
def self.resolver; @@resolver end
|
36
|
+
def process; @@resolver ||= globals.resolver end
|
37
|
+
end
|
38
|
+
}
|
39
|
+
|
40
|
+
it "should track a namespace statement" do
|
41
|
+
YARD.parse_string <<-'eof'
|
42
|
+
module SomeModule
|
43
|
+
class SomeClass
|
44
|
+
# comment in SomeClass
|
45
|
+
end
|
46
|
+
|
47
|
+
# comment in SomeModule
|
48
|
+
end
|
49
|
+
eof
|
50
|
+
|
51
|
+
StubHandler.resolver.namespaces.size.should == 2
|
52
|
+
StubHandler.resolver.namespaces["SomeModule"].should == "SomeModule"
|
53
|
+
StubHandler.resolver.namespaces["SomeClass"].should == "SomeModule::SomeClass"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should locate an enclosing ns for a comment" do
|
57
|
+
class StubCommentHandler < Handlers::Ruby::Legacy::Base
|
58
|
+
handles TkCOMMENT
|
59
|
+
namespace_only
|
60
|
+
|
61
|
+
class << self
|
62
|
+
def comments; @@comments end
|
63
|
+
end
|
64
|
+
|
65
|
+
def process
|
66
|
+
@@comments ||= []
|
67
|
+
@@comments << [ statement.tokens.to_s, namespace ]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
YARD.parse_string <<-'eof'
|
73
|
+
module SomeModule
|
74
|
+
class SomeClass
|
75
|
+
def f() end
|
76
|
+
# comment in SomeClass
|
77
|
+
|
78
|
+
# another comment in SomeClass
|
79
|
+
end
|
80
|
+
|
81
|
+
# comment in SomeModule
|
82
|
+
end # should be ignored
|
83
|
+
|
84
|
+
# comment in :root
|
85
|
+
eof
|
86
|
+
|
87
|
+
comments = StubCommentHandler.comments
|
88
|
+
comments.size.should == 4
|
89
|
+
|
90
|
+
resolver = StubHandler.resolver
|
91
|
+
resolver.namespaces.size.should == 2
|
92
|
+
|
93
|
+
resolver.
|
94
|
+
namespace_for(
|
95
|
+
comments[0][0],
|
96
|
+
comments[0][1]).
|
97
|
+
should == Registry.at('SomeModule::SomeClass')
|
98
|
+
|
99
|
+
resolver.
|
100
|
+
namespace_for(
|
101
|
+
comments[1][0],
|
102
|
+
comments[1][1]).
|
103
|
+
should == Registry.at('SomeModule::SomeClass')
|
104
|
+
|
105
|
+
resolver.
|
106
|
+
namespace_for(
|
107
|
+
comments[2][0],
|
108
|
+
comments[2][1]).
|
109
|
+
should == Registry.at('SomeModule')
|
110
|
+
|
111
|
+
resolver.
|
112
|
+
namespace_for(
|
113
|
+
comments[3][0],
|
114
|
+
comments[3][1]).
|
115
|
+
should == Registry.root
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yard-appendix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|
@@ -56,11 +56,14 @@ files:
|
|
56
56
|
- lib/yard-appendix/code_objects/appendix_object.rb
|
57
57
|
- lib/yard-appendix/version.rb
|
58
58
|
- lib/yard-appendix/handlers/appendix_handler.rb
|
59
|
+
- lib/yard-appendix/handlers/ruby/appendix_handler.rb
|
60
|
+
- lib/yard-appendix/handlers/ruby/legacy/appendix_handler.rb
|
59
61
|
- lib/yard-appendix/namespace_resolver.rb
|
60
62
|
- lib/yard-appendix/tags/appendix_directive.rb
|
61
63
|
- lib/yard-appendix/templates/helpers/html_helper.rb
|
62
64
|
- lib/yard-appendix.rb
|
63
65
|
- spec/code_objects/appendix_object_spec.rb
|
66
|
+
- spec/handlers/appendix_legacy_handler_spec.rb
|
64
67
|
- spec/handlers/appendix_handler_spec.rb
|
65
68
|
- spec/spec_helper.rb
|
66
69
|
- spec/tags/appendix_directive_spec.rb
|