yard 0.5.8 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- data/.yardopts +2 -0
- data/ChangeLog +1064 -0
- data/README.md +103 -42
- data/Rakefile +3 -2
- data/benchmarks/parsing.rb +2 -1
- data/bin/yard +4 -0
- data/bin/yard-graph +1 -1
- data/bin/yard-server +4 -0
- data/docs/GettingStarted.md +8 -8
- data/docs/Handlers.md +5 -5
- data/docs/Overview.md +5 -5
- data/docs/Parser.md +1 -1
- data/docs/Tags.md +1 -1
- data/docs/Templates.md +27 -6
- data/docs/WhatsNew.md +222 -2
- data/lib/rubygems_plugin.rb +1 -0
- data/lib/yard.rb +7 -1
- data/lib/yard/autoload.rb +46 -6
- data/lib/yard/cli/{base.rb → command.rb} +20 -6
- data/lib/yard/cli/command_parser.rb +87 -0
- data/lib/yard/cli/diff.rb +176 -0
- data/lib/yard/cli/gems.rb +74 -0
- data/lib/yard/cli/{yard_graph.rb → graph.rb} +9 -8
- data/lib/yard/cli/help.rb +18 -0
- data/lib/yard/cli/server.rb +137 -0
- data/lib/yard/cli/stats.rb +210 -0
- data/lib/yard/cli/yardoc.rb +315 -116
- data/lib/yard/cli/yri.rb +45 -4
- data/lib/yard/code_objects/base.rb +73 -30
- data/lib/yard/code_objects/class_object.rb +9 -1
- data/lib/yard/code_objects/method_object.rb +11 -0
- data/lib/yard/code_objects/namespace_object.rb +8 -2
- data/lib/yard/code_objects/proxy.rb +2 -2
- data/lib/yard/core_ext/array.rb +3 -49
- data/lib/yard/core_ext/file.rb +7 -0
- data/lib/yard/core_ext/insertion.rb +60 -0
- data/lib/yard/docstring.rb +34 -7
- data/lib/yard/globals.rb +2 -2
- data/lib/yard/handlers/base.rb +101 -20
- data/lib/yard/handlers/processor.rb +23 -7
- data/lib/yard/handlers/ruby/alias_handler.rb +1 -0
- data/lib/yard/handlers/ruby/attribute_handler.rb +8 -0
- data/lib/yard/handlers/ruby/base.rb +71 -2
- data/lib/yard/handlers/ruby/class_condition_handler.rb +10 -0
- data/lib/yard/handlers/ruby/class_handler.rb +7 -4
- data/lib/yard/handlers/ruby/class_variable_handler.rb +1 -0
- data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
- data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/extend_handler.rb +2 -3
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -0
- data/lib/yard/handlers/ruby/legacy/base.rb +15 -2
- data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +5 -0
- data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -4
- data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/constant_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -3
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -3
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +2 -1
- data/lib/yard/handlers/ruby/legacy/module_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/process_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/yield_handler.rb +1 -0
- data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -0
- data/lib/yard/handlers/ruby/method_handler.rb +5 -1
- data/lib/yard/handlers/ruby/mixin_handler.rb +2 -1
- data/lib/yard/handlers/ruby/module_handler.rb +1 -0
- data/lib/yard/handlers/ruby/process_handler.rb +7 -1
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -0
- data/lib/yard/handlers/ruby/visibility_handler.rb +8 -2
- data/lib/yard/handlers/ruby/yield_handler.rb +1 -0
- data/lib/yard/logging.rb +7 -1
- data/lib/yard/parser/base.rb +1 -0
- data/lib/yard/parser/c_parser.rb +2 -0
- data/lib/yard/parser/ruby/ast_node.rb +82 -63
- data/lib/yard/parser/ruby/legacy/ruby_lex.rb +36 -10
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
- data/lib/yard/parser/ruby/legacy/statement.rb +9 -5
- data/lib/yard/parser/ruby/legacy/statement_list.rb +20 -11
- data/lib/yard/parser/ruby/ruby_parser.rb +18 -1
- data/lib/yard/parser/source_parser.rb +6 -1
- data/lib/yard/registry.rb +284 -278
- data/lib/yard/registry_store.rb +4 -2
- data/lib/yard/serializers/base.rb +30 -13
- data/lib/yard/serializers/file_system_serializer.rb +10 -1
- data/lib/yard/server/adapter.rb +51 -0
- data/lib/yard/server/commands/base.rb +98 -0
- data/lib/yard/server/commands/display_file_command.rb +20 -0
- data/lib/yard/server/commands/display_object_command.rb +50 -0
- data/lib/yard/server/commands/frames_command.rb +31 -0
- data/lib/yard/server/commands/library_command.rb +83 -0
- data/lib/yard/server/commands/library_index_command.rb +23 -0
- data/lib/yard/server/commands/list_command.rb +44 -0
- data/lib/yard/server/commands/search_command.rb +67 -0
- data/lib/yard/server/commands/static_file_command.rb +45 -0
- data/lib/yard/server/doc_server_helper.rb +22 -0
- data/lib/yard/server/doc_server_serializer.rb +29 -0
- data/lib/yard/server/library_version.rb +86 -0
- data/lib/yard/server/rack_adapter.rb +38 -0
- data/lib/yard/server/router.rb +110 -0
- data/lib/yard/server/static_caching.rb +16 -0
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +78 -0
- data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
- data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +12 -0
- data/lib/yard/server/templates/default/fulldoc/html/js/live.js +32 -0
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +46 -0
- data/lib/yard/server/templates/default/layout/html/headers.erb +11 -0
- data/lib/yard/server/templates/doc_server/frames/html/frames.erb +13 -0
- data/lib/yard/server/templates/doc_server/frames/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +34 -0
- data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +10 -0
- data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +13 -0
- data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +26 -0
- data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +12 -0
- data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -0
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +51 -0
- data/lib/yard/server/templates/doc_server/processing/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/search/html/search.erb +19 -0
- data/lib/yard/server/templates/doc_server/search/html/setup.rb +8 -0
- data/lib/yard/server/webrick_adapter.rb +38 -0
- data/lib/yard/tags/default_factory.rb +0 -5
- data/lib/yard/tags/library.rb +61 -22
- data/lib/yard/tags/tag.rb +26 -4
- data/lib/yard/templates/engine.rb +12 -1
- data/lib/yard/templates/erb_cache.rb +2 -1
- data/lib/yard/templates/helpers/base_helper.rb +96 -3
- data/lib/yard/templates/helpers/filter_helper.rb +5 -0
- data/lib/yard/templates/helpers/html_helper.rb +204 -94
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -0
- data/lib/yard/templates/helpers/markup_helper.rb +58 -3
- data/lib/yard/templates/helpers/method_helper.rb +7 -0
- data/lib/yard/templates/helpers/module_helper.rb +5 -0
- data/lib/yard/templates/helpers/text_helper.rb +10 -1
- data/lib/yard/templates/helpers/uml_helper.rb +13 -0
- data/lib/yard/templates/section.rb +106 -0
- data/lib/yard/templates/template.rb +20 -19
- data/lib/yard/verifier.rb +21 -2
- data/spec/cli/command_parser_spec.rb +43 -0
- data/spec/cli/diff_spec.rb +170 -0
- data/spec/cli/help_spec.rb +22 -0
- data/spec/cli/server_spec.rb +140 -0
- data/spec/cli/stats_spec.rb +75 -0
- data/spec/cli/yardoc_spec.rb +438 -182
- data/spec/cli/yri_spec.rb +13 -1
- data/spec/code_objects/base_spec.rb +51 -6
- data/spec/code_objects/class_object_spec.rb +15 -1
- data/spec/code_objects/method_object_spec.rb +29 -0
- data/spec/code_objects/namespace_object_spec.rb +150 -129
- data/spec/core_ext/array_spec.rb +4 -23
- data/spec/core_ext/insertion_spec.rb +37 -0
- data/spec/docstring_spec.rb +63 -0
- data/spec/handlers/attribute_handler_spec.rb +4 -0
- data/spec/handlers/base_spec.rb +98 -26
- data/spec/handlers/class_handler_spec.rb +5 -1
- data/spec/handlers/examples/attribute_handler_001.rb.txt +5 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +4 -0
- data/spec/handlers/examples/module_handler_001.rb.txt +6 -1
- data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
- data/spec/handlers/method_handler_spec.rb +5 -0
- data/spec/handlers/module_handler_spec.rb +4 -0
- data/spec/handlers/visibility_handler_spec.rb +6 -0
- data/spec/parser/source_parser_spec.rb +24 -0
- data/spec/registry_spec.rb +44 -8
- data/spec/server/adapter_spec.rb +38 -0
- data/spec/server/commands/base_spec.rb +87 -0
- data/spec/server/commands/static_file_command_spec.rb +67 -0
- data/spec/server/doc_server_serializer_spec.rb +58 -0
- data/spec/server/router_spec.rb +115 -0
- data/spec/server/spec_helper.rb +17 -0
- data/spec/server/static_caching_spec.rb +39 -0
- data/spec/server/webrick_servlet_spec.rb +20 -0
- data/spec/templates/constant_spec.rb +40 -0
- data/spec/templates/engine_spec.rb +9 -5
- data/spec/templates/examples/class002.html +1 -3
- data/spec/templates/examples/constant001.txt +25 -0
- data/spec/templates/examples/constant002.txt +7 -0
- data/spec/templates/examples/constant003.txt +11 -0
- data/spec/templates/examples/module001.txt +1 -1
- data/spec/templates/examples/module002.html +319 -0
- data/spec/templates/helpers/base_helper_spec.rb +2 -2
- data/spec/templates/helpers/html_helper_spec.rb +93 -3
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +5 -0
- data/spec/templates/helpers/markup_helper_spec.rb +94 -67
- data/spec/templates/helpers/shared_signature_examples.rb +9 -0
- data/spec/templates/helpers/text_helper_spec.rb +12 -0
- data/spec/templates/module_spec.rb +21 -4
- data/spec/templates/section_spec.rb +146 -0
- data/spec/templates/template_spec.rb +9 -20
- data/templates/default/class/setup.rb +5 -5
- data/templates/default/constant/text/header.erb +11 -0
- data/templates/default/constant/text/setup.rb +3 -0
- data/templates/default/fulldoc/html/css/style.css +29 -3
- data/templates/default/fulldoc/html/js/app.js +67 -1
- data/templates/default/fulldoc/html/js/full_list.js +3 -8
- data/templates/default/fulldoc/html/js/jquery.js +150 -15
- data/templates/default/fulldoc/html/setup.rb +9 -0
- data/templates/default/layout/html/footer.erb +1 -1
- data/templates/default/layout/html/setup.rb +7 -25
- data/templates/default/method_details/html/source.erb +1 -1
- data/templates/default/module/html/attribute_summary.erb +2 -2
- data/templates/default/module/html/method_summary.erb +2 -2
- data/templates/default/module/setup.rb +27 -4
- data/templates/default/onefile/html/files.erb +5 -0
- data/templates/default/onefile/html/layout.erb +22 -0
- data/templates/default/onefile/html/readme.erb +3 -0
- data/templates/default/onefile/html/setup.rb +40 -0
- data/templates/default/root/html/setup.rb +1 -0
- data/templates/default/tags/setup.rb +26 -33
- metadata +80 -10
@@ -2,12 +2,15 @@ require 'cgi'
|
|
2
2
|
|
3
3
|
module YARD
|
4
4
|
module Templates::Helpers
|
5
|
+
# The helper module for HTML templates.
|
5
6
|
module HtmlHelper
|
6
7
|
include MarkupHelper
|
7
8
|
include HtmlSyntaxHighlightHelper
|
8
9
|
|
9
10
|
SimpleMarkupHtml = RDoc::Markup::ToHtml.new rescue SM::ToHtml.new
|
10
11
|
|
12
|
+
# @group Escaping Template Data
|
13
|
+
|
11
14
|
# Escapes HTML entities
|
12
15
|
#
|
13
16
|
# @param [String] text the text to escape
|
@@ -24,24 +27,7 @@ module YARD
|
|
24
27
|
CGI.escape(text.to_s)
|
25
28
|
end
|
26
29
|
|
27
|
-
#
|
28
|
-
# by setting the +LANG+ environment variable or by overriding this
|
29
|
-
# method. In Ruby 1.9 you can also modify this value by setting
|
30
|
-
# +Encoding.default_external+.
|
31
|
-
#
|
32
|
-
# @return [String] the current character set
|
33
|
-
def charset
|
34
|
-
return 'utf-8' unless RUBY19 || lang = ENV['LANG']
|
35
|
-
if RUBY19
|
36
|
-
lang = Encoding.default_external.name.downcase
|
37
|
-
else
|
38
|
-
lang = lang.downcase.split('.').last
|
39
|
-
end
|
40
|
-
case lang
|
41
|
-
when "ascii-8bit", "us-ascii", "ascii-7bit"; 'iso-8859-1'
|
42
|
-
else; lang
|
43
|
-
end
|
44
|
-
end
|
30
|
+
# @group Converting Markup to HTML
|
45
31
|
|
46
32
|
# Turns text into HTML using +markup+ style formatting.
|
47
33
|
#
|
@@ -50,30 +36,16 @@ module YARD
|
|
50
36
|
# To add a custom markup type, see {MarkupHelper}
|
51
37
|
# @return [String] the HTML
|
52
38
|
def htmlify(text, markup = options[:markup])
|
39
|
+
markup_meth = "html_markup_#{markup}"
|
40
|
+
return text unless respond_to?(markup_meth)
|
53
41
|
return "" unless text
|
54
42
|
return text unless markup
|
55
43
|
load_markup_provider(markup)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
html = markup_class(markup).new(text).to_html
|
61
|
-
when :textile
|
62
|
-
doc = markup_class(markup).new(text)
|
63
|
-
doc.hard_breaks = false if doc.respond_to?(:hard_breaks=)
|
64
|
-
html = doc.to_html
|
65
|
-
when :rdoc
|
66
|
-
|
67
|
-
begin
|
68
|
-
SimpleMarkupHtml.instance_variable_set("@from_path", url_for(object))
|
69
|
-
html = MarkupHelper::SimpleMarkup.convert(text, SimpleMarkupHtml)
|
70
|
-
end
|
71
|
-
|
72
|
-
html = fix_dash_dash(html)
|
73
|
-
html = fix_typewriter(html)
|
44
|
+
html = send(markup_meth, text)
|
45
|
+
if html.respond_to?(:encode)
|
46
|
+
html = html.force_encoding(text.encoding) # for libs that mess with encoding
|
47
|
+
html = html.encode(:invalid => :replace, :replace => '?')
|
74
48
|
end
|
75
|
-
|
76
|
-
html.force_encoding(Encoding.default_external) if RUBY19
|
77
49
|
html = resolve_links(html)
|
78
50
|
html = html.gsub(/<pre>(?:\s*<code>)?(.+?)(?:<\/code>\s*)?<\/pre>/m) do
|
79
51
|
str = $1
|
@@ -83,6 +55,55 @@ module YARD
|
|
83
55
|
html
|
84
56
|
end
|
85
57
|
|
58
|
+
# Converts Markdown to HTML
|
59
|
+
# @param [String] text input Markdown text
|
60
|
+
# @return [String] output HTML
|
61
|
+
# @since 0.6.0
|
62
|
+
def html_markup_markdown(text)
|
63
|
+
# TODO: other libraries might be more complex
|
64
|
+
markup_class(:markdown).new(text).to_html
|
65
|
+
end
|
66
|
+
|
67
|
+
# Converts Textile to HTML
|
68
|
+
# @param [String] text the input Textile text
|
69
|
+
# @return [String] output HTML
|
70
|
+
# @since 0.6.0
|
71
|
+
def html_markup_textile(text)
|
72
|
+
doc = markup_class(:textile).new(text)
|
73
|
+
doc.hard_breaks = false if doc.respond_to?(:hard_breaks=)
|
74
|
+
doc.to_html
|
75
|
+
end
|
76
|
+
|
77
|
+
# Converts RDoc formatting (SimpleMarkup) to HTML
|
78
|
+
# @param [String] text the input RDoc formatted text
|
79
|
+
# @return [String] output HTML
|
80
|
+
# @since 0.6.0
|
81
|
+
def html_markup_rdoc(text)
|
82
|
+
begin
|
83
|
+
SimpleMarkupHtml.instance_variable_set("@from_path", url_for(object))
|
84
|
+
html = MarkupHelper::SimpleMarkup.convert(text, SimpleMarkupHtml)
|
85
|
+
end
|
86
|
+
|
87
|
+
html = fix_dash_dash(html)
|
88
|
+
html = fix_typewriter(html)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Converts plaintext to HTML
|
92
|
+
# @param [String] text the input text
|
93
|
+
# @return [String] the output HTML
|
94
|
+
# @since 0.6.0
|
95
|
+
def html_markup_text(text)
|
96
|
+
"<pre>" + text + "</pre>"
|
97
|
+
end
|
98
|
+
|
99
|
+
# Converts HTML to HTML
|
100
|
+
# @param [String] text input html
|
101
|
+
# @return [String] output HTML
|
102
|
+
# @since 0.6.0
|
103
|
+
def html_markup_html(text)
|
104
|
+
text
|
105
|
+
end
|
106
|
+
|
86
107
|
# @return [String] HTMLified text as a single line (paragraphs removed)
|
87
108
|
def htmlify_line(*args)
|
88
109
|
"<div class='inline'>" + htmlify(*args) + "</div>"
|
@@ -110,6 +131,40 @@ module YARD
|
|
110
131
|
def fix_dash_dash(text)
|
111
132
|
text.gsub(/—(?=\S)/, '--')
|
112
133
|
end
|
134
|
+
|
135
|
+
# @group Syntax Highlighting Source Code
|
136
|
+
|
137
|
+
# Syntax highlights +source+ in language +type+.
|
138
|
+
#
|
139
|
+
# @note To support a specific language +type+, implement the method
|
140
|
+
# +html_syntax_highlight_TYPE+ in this class.
|
141
|
+
#
|
142
|
+
# @param [String] source the source code to highlight
|
143
|
+
# @param [Symbol] type the language type (:ruby, :plain, etc). Use
|
144
|
+
# :plain for no syntax highlighting.
|
145
|
+
# @return [String] the highlighted source
|
146
|
+
def html_syntax_highlight(source, type = nil)
|
147
|
+
return "" unless source
|
148
|
+
return h(source) if options[:no_highlight]
|
149
|
+
|
150
|
+
type ||= object.source_type || :ruby
|
151
|
+
|
152
|
+
# handle !!!LANG prefix to send to html_syntax_highlight_LANG
|
153
|
+
if source =~ /\A(?:[ \t]*\r?\n)?[ \t]*!!!([\w.+-]+)[ \t]*\r?\n/
|
154
|
+
type, source = $1, $'
|
155
|
+
source = $'
|
156
|
+
end
|
157
|
+
|
158
|
+
meth = "html_syntax_highlight_#{type}"
|
159
|
+
respond_to?(meth) ? send(meth, source) : h(source)
|
160
|
+
end
|
161
|
+
|
162
|
+
# @return [String] unhighlighted source
|
163
|
+
def html_syntax_highlight_plain(source)
|
164
|
+
h(source)
|
165
|
+
end
|
166
|
+
|
167
|
+
# @group Linking Objects and URLs
|
113
168
|
|
114
169
|
# Resolves any text in the form of +{Name}+ to the object specified by
|
115
170
|
# Name. Also supports link titles in the form +{Name title}+.
|
@@ -123,64 +178,42 @@ module YARD
|
|
123
178
|
def resolve_links(text)
|
124
179
|
code_tags = 0
|
125
180
|
text.gsub(/<(\/)?(pre|code|tt)|\{(\S+?)(?:\s(.*?\S))?\}(?=[\W<]|.+<\/|$)/) do |str|
|
126
|
-
closed, tag, name, title = $1, $2, $3, $4
|
181
|
+
closed, tag, name, title, match = $1, $2, $3, $4, $&
|
127
182
|
if tag
|
128
183
|
code_tags += (closed ? -1 : 1)
|
129
184
|
next str
|
130
185
|
end
|
131
186
|
next str unless code_tags == 0
|
132
187
|
|
188
|
+
next(match) if name[0,1] == '|'
|
133
189
|
if object.is_a?(String)
|
134
190
|
object
|
135
191
|
else
|
136
192
|
link = linkify(name, title)
|
137
193
|
if link == name || link == title
|
138
|
-
match =
|
139
|
-
|
140
|
-
|
194
|
+
match = /(.+)?(\{#{Regexp.quote name}(?:\s.*?)?\})(.+)?/.match(text)
|
195
|
+
file = (@file ? @file : object.file) || '(unknown)'
|
196
|
+
line = (@file ? 1 : (object.docstring.line_range ? object.docstring.line_range.first : 1)) + (match ? $`.count("\n") : 0)
|
197
|
+
log.warn "In file `#{file}':#{line}: Cannot resolve link to #{name} from text" + (match ? ":" : ".")
|
198
|
+
log.warn((match[1] ? '...' : '') + match[2].gsub("\n","") + (match[3] ? '...' : '')) if match
|
141
199
|
end
|
142
200
|
|
143
|
-
|
144
|
-
link
|
145
|
-
else
|
146
|
-
"<tt>" + link + "</tt>"
|
147
|
-
end
|
201
|
+
link
|
148
202
|
end
|
149
203
|
end
|
150
204
|
end
|
151
|
-
|
152
|
-
def format_object_name_list(objects)
|
153
|
-
objects.sort_by {|o| o.name.to_s.downcase }.map do |o|
|
154
|
-
"<span class='name'>" + linkify(o, o.name) + "</span>"
|
155
|
-
end.join(", ")
|
156
|
-
end
|
157
|
-
|
158
|
-
# Formats a list of types from a tag.
|
159
|
-
#
|
160
|
-
# @param [Array<String>, FalseClass] typelist
|
161
|
-
# the list of types to be formatted.
|
162
|
-
#
|
163
|
-
# @param [Boolean] brackets omits the surrounding
|
164
|
-
# brackets if +brackets+ is set to +false+.
|
165
|
-
#
|
166
|
-
# @return [String] the list of types formatted
|
167
|
-
# as [Type1, Type2, ...] with the types linked
|
168
|
-
# to their respective descriptions.
|
169
|
-
#
|
170
|
-
def format_types(typelist, brackets = true)
|
171
|
-
return unless typelist.is_a?(Array)
|
172
|
-
list = typelist.map do |type|
|
173
|
-
type = type.gsub(/([<>])/) { h($1) }
|
174
|
-
type = type.gsub(/([\w:]+)/) { $1 == "lt" || $1 == "gt" ? $1 : linkify($1, $1) }
|
175
|
-
"<tt>" + type + "</tt>"
|
176
|
-
end
|
177
|
-
list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
|
178
|
-
end
|
179
205
|
|
206
|
+
# (see BaseHelper#link_file)
|
180
207
|
def link_file(filename, title = nil, anchor = nil)
|
181
208
|
link_url(url_for_file(filename, anchor), title)
|
182
209
|
end
|
210
|
+
|
211
|
+
# (see BaseHelper#link_include_object)
|
212
|
+
def link_include_object(obj)
|
213
|
+
htmlify(obj.docstring)
|
214
|
+
end
|
183
215
|
|
216
|
+
# (see BaseHelper#link_object)
|
184
217
|
def link_object(obj, otitle = nil, anchor = nil, relative = true)
|
185
218
|
return otitle if obj.nil?
|
186
219
|
obj = Registry.resolve(object, obj, true, true) if obj.is_a?(String)
|
@@ -197,22 +230,25 @@ module YARD
|
|
197
230
|
return title if obj.is_a?(CodeObjects::Proxy)
|
198
231
|
|
199
232
|
link = url_for(obj, anchor, relative)
|
200
|
-
link ? link_url(link, title, :title => "#{obj.path} (#{obj.type})") : title
|
233
|
+
link = link ? link_url(link, title, :title => "#{obj.path} (#{obj.type})") : title
|
234
|
+
"<span class='object_link'>" + link + "</span>"
|
201
235
|
end
|
202
236
|
|
237
|
+
# (see BaseHelper#link_url)
|
203
238
|
def link_url(url, title = nil, params = {})
|
204
239
|
title ||= url
|
205
240
|
params = SymbolHash.new(false).update(
|
206
241
|
:href => url,
|
207
242
|
:title => h(title)
|
208
243
|
).update(params)
|
244
|
+
params[:target] ||= '_parent' if url =~ /^(\w+):\/\//
|
209
245
|
"<a #{tag_attrs(params)}>#{title}</a>"
|
210
246
|
end
|
211
247
|
|
212
|
-
|
213
|
-
opts.sort_by {|k, v| k.to_s }.map {|k,v| "#{k}=#{v.to_s.inspect}" if v }.join(" ")
|
214
|
-
end
|
248
|
+
# @group URL Helpers
|
215
249
|
|
250
|
+
# @param [CodeObjects::Base] object the object to get an anchor for
|
251
|
+
# @return [String] the anchor for a specific object
|
216
252
|
def anchor_for(object)
|
217
253
|
case object
|
218
254
|
when CodeObjects::MethodObject
|
@@ -228,6 +264,12 @@ module YARD
|
|
228
264
|
end
|
229
265
|
end
|
230
266
|
|
267
|
+
# Returns the URL for an object.
|
268
|
+
#
|
269
|
+
# @param [String, CodeObjects::Base] obj the object (or object path) to link to
|
270
|
+
# @param [String] anchor the anchor to link to
|
271
|
+
# @param [Boolean] relative use a relative or absolute link
|
272
|
+
# @return [String] the URL location of the object
|
231
273
|
def url_for(obj, anchor = nil, relative = true)
|
232
274
|
link = nil
|
233
275
|
return link unless serializer
|
@@ -256,6 +298,11 @@ module YARD
|
|
256
298
|
link + (anchor ? '#' + urlencode(anchor_for(anchor)) : '')
|
257
299
|
end
|
258
300
|
|
301
|
+
# Returns the URL for a specific file
|
302
|
+
#
|
303
|
+
# @param [String] filename the filename to link to
|
304
|
+
# @param [String] anchor optional anchor
|
305
|
+
# @return [String] the URL pointing to the file
|
259
306
|
def url_for_file(filename, anchor = nil)
|
260
307
|
fromobj = object
|
261
308
|
if CodeObjects::Base === fromobj && !fromobj.is_a?(CodeObjects::NamespaceObject)
|
@@ -271,12 +318,50 @@ module YARD
|
|
271
318
|
link + '.html' + (anchor ? '#' + urlencode(anchor) : '')
|
272
319
|
end
|
273
320
|
|
321
|
+
# @group Formatting Objects and Attributes
|
322
|
+
|
323
|
+
# Formats a list of objects and links them
|
324
|
+
# @return [String] a formatted list of objects
|
325
|
+
def format_object_name_list(objects)
|
326
|
+
objects.sort_by {|o| o.name.to_s.downcase }.map do |o|
|
327
|
+
"<span class='name'>" + linkify(o, o.name) + "</span>"
|
328
|
+
end.join(", ")
|
329
|
+
end
|
330
|
+
|
331
|
+
# Formats a list of types from a tag.
|
332
|
+
#
|
333
|
+
# @param [Array<String>, FalseClass] typelist
|
334
|
+
# the list of types to be formatted.
|
335
|
+
#
|
336
|
+
# @param [Boolean] brackets omits the surrounding
|
337
|
+
# brackets if +brackets+ is set to +false+.
|
338
|
+
#
|
339
|
+
# @return [String] the list of types formatted
|
340
|
+
# as [Type1, Type2, ...] with the types linked
|
341
|
+
# to their respective descriptions.
|
342
|
+
#
|
343
|
+
def format_types(typelist, brackets = true)
|
344
|
+
return unless typelist.is_a?(Array)
|
345
|
+
list = typelist.map do |type|
|
346
|
+
type = type.gsub(/([<>])/) { h($1) }
|
347
|
+
type = type.gsub(/([\w:]+)/) { $1 == "lt" || $1 == "gt" ? $1 : linkify($1, $1) }
|
348
|
+
"<tt>" + type + "</tt>"
|
349
|
+
end
|
350
|
+
list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
|
351
|
+
end
|
352
|
+
|
353
|
+
# Get the return types for a method signature.
|
354
|
+
#
|
355
|
+
# @param [CodeObjects::MethodObject] meth the method object
|
356
|
+
# @param [Boolean] link whether to link the types
|
357
|
+
# @return [String] the signature types
|
358
|
+
# @since 0.5.3
|
274
359
|
def signature_types(meth, link = true)
|
275
360
|
meth = convert_method_to_overload(meth)
|
276
361
|
|
277
362
|
type = options[:default_return] || ""
|
278
363
|
if meth.tag(:return) && meth.tag(:return).types
|
279
|
-
types = meth.tags(:return).map {|t| t.types ? t.types : [] }.flatten
|
364
|
+
types = meth.tags(:return).map {|t| t.types ? t.types : [] }.flatten.uniq
|
280
365
|
first = link ? h(types.first) : format_types([types.first], false)
|
281
366
|
if types.size == 2 && types.last == 'nil'
|
282
367
|
type = first + '<sup>?</sup>'
|
@@ -296,6 +381,15 @@ module YARD
|
|
296
381
|
type
|
297
382
|
end
|
298
383
|
|
384
|
+
# Formats the signature of method +meth+.
|
385
|
+
#
|
386
|
+
# @param [CodeObjects::MethodObject] meth the method object to list
|
387
|
+
# the signature of
|
388
|
+
# @param [Boolean] link whether to link the method signature to the details view
|
389
|
+
# @param [Boolean] show_extras whether to show extra meta-data (visibility, attribute info)
|
390
|
+
# @param [Boolean] full_attr_name whether to show the full attribute name
|
391
|
+
# ("name=" instead of "name")
|
392
|
+
# @return [String] the formatted method signature
|
299
393
|
def signature(meth, link = true, show_extras = true, full_attr_name = true)
|
300
394
|
meth = convert_method_to_overload(meth)
|
301
395
|
|
@@ -328,26 +422,42 @@ module YARD
|
|
328
422
|
end
|
329
423
|
end
|
330
424
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
425
|
+
# @group Getting the Character Encoding
|
426
|
+
|
427
|
+
# Returns the current character set. The default value can be overridden
|
428
|
+
# by setting the +LANG+ environment variable or by overriding this
|
429
|
+
# method. In Ruby 1.9 you can also modify this value by setting
|
430
|
+
# +Encoding.default_external+.
|
431
|
+
#
|
432
|
+
# @return [String] the current character set
|
433
|
+
# @since 0.5.4
|
434
|
+
def charset
|
435
|
+
return 'utf-8' unless RUBY19 || lang = ENV['LANG']
|
436
|
+
if RUBY19
|
437
|
+
lang = Encoding.default_external.name.downcase
|
438
|
+
else
|
439
|
+
lang = lang.downcase.split('.').last
|
440
|
+
end
|
441
|
+
case lang
|
442
|
+
when "ascii-8bit", "us-ascii", "ascii-7bit"; 'iso-8859-1'
|
443
|
+
else; lang
|
339
444
|
end
|
340
|
-
|
341
|
-
meth = "html_syntax_highlight_#{type}"
|
342
|
-
respond_to?(meth) ? send(meth, source) : h(source)
|
343
445
|
end
|
344
446
|
|
345
|
-
|
346
|
-
h(source)
|
347
|
-
end
|
447
|
+
# @endgroup
|
348
448
|
|
349
449
|
private
|
350
450
|
|
451
|
+
# Converts a set of hash options into HTML attributes for a tag
|
452
|
+
#
|
453
|
+
# @param [Hash{String => String}] opts the tag options
|
454
|
+
# @return [String] the tag attributes of an HTML tag
|
455
|
+
def tag_attrs(opts = {})
|
456
|
+
opts.sort_by {|k, v| k.to_s }.map {|k,v| "#{k}=#{v.to_s.inspect}" if v }.join(" ")
|
457
|
+
end
|
458
|
+
|
459
|
+
# Converts a {CodeObjects::MethodObject} into an overload object
|
460
|
+
# @since 0.5.3
|
351
461
|
def convert_method_to_overload(meth)
|
352
462
|
# use first overload tag if it has a return type and method itself does not
|
353
463
|
if !meth.tag(:return) && meth.tags(:overload).size == 1 && meth.tag(:overload).tag(:return)
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module YARD
|
2
2
|
module Templates
|
3
3
|
module Helpers
|
4
|
+
# Helper methods for syntax highlighting.
|
4
5
|
module HtmlSyntaxHighlightHelper
|
6
|
+
# Highlights Ruby source
|
7
|
+
# @param [String] source the Ruby source code
|
8
|
+
# @return [String] the highlighted Ruby source
|
5
9
|
def html_syntax_highlight_ruby(source)
|
6
10
|
tokenlist = Parser::Ruby::RubyParser.parse(source, "(syntax_highlight)").tokens
|
7
11
|
output = ""
|
@@ -2,6 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
module YARD
|
4
4
|
module Templates::Helpers
|
5
|
+
# Helper methods for loading and managing markup types.
|
5
6
|
module MarkupHelper
|
6
7
|
MARKUP_PROVIDERS = {
|
7
8
|
:markdown => [
|
@@ -12,8 +13,27 @@ module YARD
|
|
12
13
|
],
|
13
14
|
:textile => [
|
14
15
|
{:lib => :redcloth, :const => 'RedCloth'}
|
15
|
-
]
|
16
|
+
],
|
17
|
+
:rdoc => [],
|
18
|
+
:text => [],
|
19
|
+
:html => []
|
20
|
+
}
|
21
|
+
|
22
|
+
# Returns a list of extensions for various markup types. To register
|
23
|
+
# extensions for a type, add them to the array of extensions for the
|
24
|
+
# type.
|
25
|
+
# @since 0.6.0
|
26
|
+
MARKUP_EXTENSIONS = {
|
27
|
+
:html => ['htm', 'html', 'shtml'],
|
28
|
+
:text => ['txt'],
|
29
|
+
:textile => ['textile', 'txtile'],
|
30
|
+
:markdown => ['markdown', 'md', 'mdown', 'mkd'],
|
31
|
+
:rdoc => ['rdoc']
|
16
32
|
}
|
33
|
+
|
34
|
+
# Contains the Regexp object that matches the shebang line of extra
|
35
|
+
# files to detect the markup type.
|
36
|
+
MARKUP_FILE_SHEBANG = /\A#!(\S+)\s*$/
|
17
37
|
|
18
38
|
begin
|
19
39
|
require 'rdoc/markup'
|
@@ -45,12 +65,13 @@ module YARD
|
|
45
65
|
@markup_cache[type] ||= {}
|
46
66
|
|
47
67
|
providers = MARKUP_PROVIDERS[type]
|
68
|
+
return if providers && providers.empty?
|
48
69
|
if options[:markup_provider]
|
49
|
-
providers =
|
70
|
+
providers = providers.select {|p| p[:lib] == options[:markup_provider] }
|
50
71
|
end
|
51
72
|
|
52
73
|
if providers == nil || providers.empty?
|
53
|
-
STDERR.puts "Invalid markup type '#{
|
74
|
+
STDERR.puts "Invalid markup type '#{type}'"
|
54
75
|
exit
|
55
76
|
end
|
56
77
|
|
@@ -68,6 +89,40 @@ module YARD
|
|
68
89
|
exit
|
69
90
|
end
|
70
91
|
|
92
|
+
# Checks for a shebang or looks at the file extension to determine
|
93
|
+
# the markup type for the file contents. File extensions are registered
|
94
|
+
# for a markup type in {MARKUP_EXTENSIONS}.
|
95
|
+
#
|
96
|
+
# A shebang should be on the first line of a file and be in the form:
|
97
|
+
#
|
98
|
+
# #!markup_type
|
99
|
+
#
|
100
|
+
# Standard markup types are text, html, rdoc, markdown, textile
|
101
|
+
#
|
102
|
+
# @return [Symbol] the markup type recognized for the file
|
103
|
+
# @see MARKUP_EXTENSIONS
|
104
|
+
# @since 0.6.0
|
105
|
+
def markup_for_file(contents, filename)
|
106
|
+
if contents =~ MARKUP_FILE_SHEBANG # Shebang support
|
107
|
+
return $1.to_sym
|
108
|
+
end
|
109
|
+
|
110
|
+
ext = (File.extname(filename)[1..-1] || '').downcase
|
111
|
+
MARKUP_EXTENSIONS.each do |type, exts|
|
112
|
+
return type if exts.include?(ext)
|
113
|
+
end
|
114
|
+
options[:markup]
|
115
|
+
end
|
116
|
+
|
117
|
+
# Strips any shebang lines on the file contents that pertain to
|
118
|
+
# markup or preprocessing data.
|
119
|
+
#
|
120
|
+
# @return [String] the file contents minus any preprocessing tags
|
121
|
+
# @since 0.6.0
|
122
|
+
def markup_file_contents(contents)
|
123
|
+
contents =~ MARKUP_FILE_SHEBANG ? $' : contents
|
124
|
+
end
|
125
|
+
|
71
126
|
# Gets the markup provider class/module constant for a markup type
|
72
127
|
# Call {#load_markup_provider} before using this method.
|
73
128
|
#
|