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.

Files changed (211) hide show
  1. data/.yardopts +2 -0
  2. data/ChangeLog +1064 -0
  3. data/README.md +103 -42
  4. data/Rakefile +3 -2
  5. data/benchmarks/parsing.rb +2 -1
  6. data/bin/yard +4 -0
  7. data/bin/yard-graph +1 -1
  8. data/bin/yard-server +4 -0
  9. data/docs/GettingStarted.md +8 -8
  10. data/docs/Handlers.md +5 -5
  11. data/docs/Overview.md +5 -5
  12. data/docs/Parser.md +1 -1
  13. data/docs/Tags.md +1 -1
  14. data/docs/Templates.md +27 -6
  15. data/docs/WhatsNew.md +222 -2
  16. data/lib/rubygems_plugin.rb +1 -0
  17. data/lib/yard.rb +7 -1
  18. data/lib/yard/autoload.rb +46 -6
  19. data/lib/yard/cli/{base.rb → command.rb} +20 -6
  20. data/lib/yard/cli/command_parser.rb +87 -0
  21. data/lib/yard/cli/diff.rb +176 -0
  22. data/lib/yard/cli/gems.rb +74 -0
  23. data/lib/yard/cli/{yard_graph.rb → graph.rb} +9 -8
  24. data/lib/yard/cli/help.rb +18 -0
  25. data/lib/yard/cli/server.rb +137 -0
  26. data/lib/yard/cli/stats.rb +210 -0
  27. data/lib/yard/cli/yardoc.rb +315 -116
  28. data/lib/yard/cli/yri.rb +45 -4
  29. data/lib/yard/code_objects/base.rb +73 -30
  30. data/lib/yard/code_objects/class_object.rb +9 -1
  31. data/lib/yard/code_objects/method_object.rb +11 -0
  32. data/lib/yard/code_objects/namespace_object.rb +8 -2
  33. data/lib/yard/code_objects/proxy.rb +2 -2
  34. data/lib/yard/core_ext/array.rb +3 -49
  35. data/lib/yard/core_ext/file.rb +7 -0
  36. data/lib/yard/core_ext/insertion.rb +60 -0
  37. data/lib/yard/docstring.rb +34 -7
  38. data/lib/yard/globals.rb +2 -2
  39. data/lib/yard/handlers/base.rb +101 -20
  40. data/lib/yard/handlers/processor.rb +23 -7
  41. data/lib/yard/handlers/ruby/alias_handler.rb +1 -0
  42. data/lib/yard/handlers/ruby/attribute_handler.rb +8 -0
  43. data/lib/yard/handlers/ruby/base.rb +71 -2
  44. data/lib/yard/handlers/ruby/class_condition_handler.rb +10 -0
  45. data/lib/yard/handlers/ruby/class_handler.rb +7 -4
  46. data/lib/yard/handlers/ruby/class_variable_handler.rb +1 -0
  47. data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
  48. data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
  49. data/lib/yard/handlers/ruby/extend_handler.rb +2 -3
  50. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +1 -0
  51. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -0
  52. data/lib/yard/handlers/ruby/legacy/base.rb +15 -2
  53. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +5 -0
  54. data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -4
  55. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +1 -0
  56. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +1 -0
  57. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -0
  58. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -3
  59. data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -3
  60. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +2 -1
  61. data/lib/yard/handlers/ruby/legacy/module_handler.rb +1 -0
  62. data/lib/yard/handlers/ruby/legacy/process_handler.rb +1 -0
  63. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +1 -0
  64. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +1 -0
  65. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -0
  66. data/lib/yard/handlers/ruby/method_handler.rb +5 -1
  67. data/lib/yard/handlers/ruby/mixin_handler.rb +2 -1
  68. data/lib/yard/handlers/ruby/module_handler.rb +1 -0
  69. data/lib/yard/handlers/ruby/process_handler.rb +7 -1
  70. data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -0
  71. data/lib/yard/handlers/ruby/visibility_handler.rb +8 -2
  72. data/lib/yard/handlers/ruby/yield_handler.rb +1 -0
  73. data/lib/yard/logging.rb +7 -1
  74. data/lib/yard/parser/base.rb +1 -0
  75. data/lib/yard/parser/c_parser.rb +2 -0
  76. data/lib/yard/parser/ruby/ast_node.rb +82 -63
  77. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +36 -10
  78. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
  79. data/lib/yard/parser/ruby/legacy/statement.rb +9 -5
  80. data/lib/yard/parser/ruby/legacy/statement_list.rb +20 -11
  81. data/lib/yard/parser/ruby/ruby_parser.rb +18 -1
  82. data/lib/yard/parser/source_parser.rb +6 -1
  83. data/lib/yard/registry.rb +284 -278
  84. data/lib/yard/registry_store.rb +4 -2
  85. data/lib/yard/serializers/base.rb +30 -13
  86. data/lib/yard/serializers/file_system_serializer.rb +10 -1
  87. data/lib/yard/server/adapter.rb +51 -0
  88. data/lib/yard/server/commands/base.rb +98 -0
  89. data/lib/yard/server/commands/display_file_command.rb +20 -0
  90. data/lib/yard/server/commands/display_object_command.rb +50 -0
  91. data/lib/yard/server/commands/frames_command.rb +31 -0
  92. data/lib/yard/server/commands/library_command.rb +83 -0
  93. data/lib/yard/server/commands/library_index_command.rb +23 -0
  94. data/lib/yard/server/commands/list_command.rb +44 -0
  95. data/lib/yard/server/commands/search_command.rb +67 -0
  96. data/lib/yard/server/commands/static_file_command.rb +45 -0
  97. data/lib/yard/server/doc_server_helper.rb +22 -0
  98. data/lib/yard/server/doc_server_serializer.rb +29 -0
  99. data/lib/yard/server/library_version.rb +86 -0
  100. data/lib/yard/server/rack_adapter.rb +38 -0
  101. data/lib/yard/server/router.rb +110 -0
  102. data/lib/yard/server/static_caching.rb +16 -0
  103. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +78 -0
  104. data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
  105. data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +12 -0
  106. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +32 -0
  107. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +46 -0
  108. data/lib/yard/server/templates/default/layout/html/headers.erb +11 -0
  109. data/lib/yard/server/templates/doc_server/frames/html/frames.erb +13 -0
  110. data/lib/yard/server/templates/doc_server/frames/html/setup.rb +3 -0
  111. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +34 -0
  112. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +10 -0
  113. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +13 -0
  114. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +26 -0
  115. data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +12 -0
  116. data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +3 -0
  117. data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -0
  118. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +51 -0
  119. data/lib/yard/server/templates/doc_server/processing/html/setup.rb +3 -0
  120. data/lib/yard/server/templates/doc_server/search/html/search.erb +19 -0
  121. data/lib/yard/server/templates/doc_server/search/html/setup.rb +8 -0
  122. data/lib/yard/server/webrick_adapter.rb +38 -0
  123. data/lib/yard/tags/default_factory.rb +0 -5
  124. data/lib/yard/tags/library.rb +61 -22
  125. data/lib/yard/tags/tag.rb +26 -4
  126. data/lib/yard/templates/engine.rb +12 -1
  127. data/lib/yard/templates/erb_cache.rb +2 -1
  128. data/lib/yard/templates/helpers/base_helper.rb +96 -3
  129. data/lib/yard/templates/helpers/filter_helper.rb +5 -0
  130. data/lib/yard/templates/helpers/html_helper.rb +204 -94
  131. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -0
  132. data/lib/yard/templates/helpers/markup_helper.rb +58 -3
  133. data/lib/yard/templates/helpers/method_helper.rb +7 -0
  134. data/lib/yard/templates/helpers/module_helper.rb +5 -0
  135. data/lib/yard/templates/helpers/text_helper.rb +10 -1
  136. data/lib/yard/templates/helpers/uml_helper.rb +13 -0
  137. data/lib/yard/templates/section.rb +106 -0
  138. data/lib/yard/templates/template.rb +20 -19
  139. data/lib/yard/verifier.rb +21 -2
  140. data/spec/cli/command_parser_spec.rb +43 -0
  141. data/spec/cli/diff_spec.rb +170 -0
  142. data/spec/cli/help_spec.rb +22 -0
  143. data/spec/cli/server_spec.rb +140 -0
  144. data/spec/cli/stats_spec.rb +75 -0
  145. data/spec/cli/yardoc_spec.rb +438 -182
  146. data/spec/cli/yri_spec.rb +13 -1
  147. data/spec/code_objects/base_spec.rb +51 -6
  148. data/spec/code_objects/class_object_spec.rb +15 -1
  149. data/spec/code_objects/method_object_spec.rb +29 -0
  150. data/spec/code_objects/namespace_object_spec.rb +150 -129
  151. data/spec/core_ext/array_spec.rb +4 -23
  152. data/spec/core_ext/insertion_spec.rb +37 -0
  153. data/spec/docstring_spec.rb +63 -0
  154. data/spec/handlers/attribute_handler_spec.rb +4 -0
  155. data/spec/handlers/base_spec.rb +98 -26
  156. data/spec/handlers/class_handler_spec.rb +5 -1
  157. data/spec/handlers/examples/attribute_handler_001.rb.txt +5 -0
  158. data/spec/handlers/examples/class_handler_001.rb.txt +4 -0
  159. data/spec/handlers/examples/module_handler_001.rb.txt +6 -1
  160. data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
  161. data/spec/handlers/method_handler_spec.rb +5 -0
  162. data/spec/handlers/module_handler_spec.rb +4 -0
  163. data/spec/handlers/visibility_handler_spec.rb +6 -0
  164. data/spec/parser/source_parser_spec.rb +24 -0
  165. data/spec/registry_spec.rb +44 -8
  166. data/spec/server/adapter_spec.rb +38 -0
  167. data/spec/server/commands/base_spec.rb +87 -0
  168. data/spec/server/commands/static_file_command_spec.rb +67 -0
  169. data/spec/server/doc_server_serializer_spec.rb +58 -0
  170. data/spec/server/router_spec.rb +115 -0
  171. data/spec/server/spec_helper.rb +17 -0
  172. data/spec/server/static_caching_spec.rb +39 -0
  173. data/spec/server/webrick_servlet_spec.rb +20 -0
  174. data/spec/templates/constant_spec.rb +40 -0
  175. data/spec/templates/engine_spec.rb +9 -5
  176. data/spec/templates/examples/class002.html +1 -3
  177. data/spec/templates/examples/constant001.txt +25 -0
  178. data/spec/templates/examples/constant002.txt +7 -0
  179. data/spec/templates/examples/constant003.txt +11 -0
  180. data/spec/templates/examples/module001.txt +1 -1
  181. data/spec/templates/examples/module002.html +319 -0
  182. data/spec/templates/helpers/base_helper_spec.rb +2 -2
  183. data/spec/templates/helpers/html_helper_spec.rb +93 -3
  184. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +5 -0
  185. data/spec/templates/helpers/markup_helper_spec.rb +94 -67
  186. data/spec/templates/helpers/shared_signature_examples.rb +9 -0
  187. data/spec/templates/helpers/text_helper_spec.rb +12 -0
  188. data/spec/templates/module_spec.rb +21 -4
  189. data/spec/templates/section_spec.rb +146 -0
  190. data/spec/templates/template_spec.rb +9 -20
  191. data/templates/default/class/setup.rb +5 -5
  192. data/templates/default/constant/text/header.erb +11 -0
  193. data/templates/default/constant/text/setup.rb +3 -0
  194. data/templates/default/fulldoc/html/css/style.css +29 -3
  195. data/templates/default/fulldoc/html/js/app.js +67 -1
  196. data/templates/default/fulldoc/html/js/full_list.js +3 -8
  197. data/templates/default/fulldoc/html/js/jquery.js +150 -15
  198. data/templates/default/fulldoc/html/setup.rb +9 -0
  199. data/templates/default/layout/html/footer.erb +1 -1
  200. data/templates/default/layout/html/setup.rb +7 -25
  201. data/templates/default/method_details/html/source.erb +1 -1
  202. data/templates/default/module/html/attribute_summary.erb +2 -2
  203. data/templates/default/module/html/method_summary.erb +2 -2
  204. data/templates/default/module/setup.rb +27 -4
  205. data/templates/default/onefile/html/files.erb +5 -0
  206. data/templates/default/onefile/html/layout.erb +22 -0
  207. data/templates/default/onefile/html/readme.erb +3 -0
  208. data/templates/default/onefile/html/setup.rb +40 -0
  209. data/templates/default/root/html/setup.rb +1 -0
  210. data/templates/default/tags/setup.rb +26 -33
  211. metadata +80 -10
@@ -4,7 +4,6 @@ module YARD
4
4
  TYPELIST_OPENING_CHARS = '[({<'
5
5
  TYPELIST_CLOSING_CHARS = '>})]'
6
6
 
7
- ##
8
7
  # Parses tag text and creates a new tag with descriptive text
9
8
  #
10
9
  # @param tag_name the name of the tag to parse
@@ -14,7 +13,6 @@ module YARD
14
13
  Tag.new(tag_name, text)
15
14
  end
16
15
 
17
- ##
18
16
  # Parses tag text and creates a new tag with a key name and descriptive text
19
17
  #
20
18
  # @param tag_name the name of the tag to parse
@@ -25,7 +23,6 @@ module YARD
25
23
  Tag.new(tag_name, text, nil, name)
26
24
  end
27
25
 
28
- ##
29
26
  # Parses tag text and creates a new tag with formally declared types and
30
27
  # descriptive text
31
28
  #
@@ -38,7 +35,6 @@ module YARD
38
35
  Tag.new(tag_name, text, types)
39
36
  end
40
37
 
41
- ##
42
38
  # Parses tag text and creates a new tag with formally declared types, a key
43
39
  # name and descriptive text
44
40
  #
@@ -76,7 +72,6 @@ module YARD
76
72
 
77
73
  private
78
74
 
79
- ##
80
75
  # Extracts the name from raw tag text returning the name and remaining value
81
76
  #
82
77
  # @param [String] text the raw tag text
@@ -1,6 +1,5 @@
1
1
  module YARD
2
2
  module Tags
3
- ##
4
3
  # Holds all the registered meta tags. If you want to extend YARD and add
5
4
  # a new meta tag, you can do it in one of two ways.
6
5
  #
@@ -69,8 +68,40 @@ module YARD
69
68
  def default_factory=(factory)
70
69
  @default_factory = factory.is_a?(Class) ? factory.new : factory
71
70
  end
71
+
72
+ # Returns the factory method used to parse the tag text for a specific tag
73
+ #
74
+ # @param [Symbol] tag the tag name
75
+ # @return [Symbol] the factory method name for the tag
76
+ # @return [Class<Tag>] the Tag class to use to parse the tag
77
+ # @return [nil] if the tag is freeform text
78
+ # @since 0.6.0
79
+ def factory_method_for(tag)
80
+ @factory_methods[tag]
81
+ end
82
+
83
+ # Sets the list of tags to display when rendering templates. The order of
84
+ # tags in the list is also significant, as it represents the order that
85
+ # tags are displayed in templates.
86
+ #
87
+ # You can use the {Array#place} to insert new tags to be displayed in
88
+ # the templates at specific positions:
89
+ #
90
+ # Library.visible_tags.place(:mytag).before(:return)
91
+ #
92
+ # @return [Array<Symbol>] a list of ordered tags
93
+ # @since 0.6.0
94
+ attr_accessor :visible_tags
95
+
96
+ # Sets the list of tags that should apply to any children inside the
97
+ # namespace they are defined in. For instance, a "@since" tag should
98
+ # apply to all methods inside a module is it defined in. Transitive
99
+ # tags can be overridden by directly defining a tag on the child object.
100
+ #
101
+ # @return [Array<Symbol>] a list of transitive tags
102
+ # @since 0.6.0
103
+ attr_accessor :transitive_tags
72
104
 
73
- ##
74
105
  # Sorts the labels lexically by their label name, often used when displaying
75
106
  # the tags.
76
107
  #
@@ -79,14 +110,13 @@ module YARD
79
110
  labels.sort_by {|a| a.last.downcase }
80
111
  end
81
112
 
82
- ##
83
113
  # Convenience method to define a new tag using one of {Tag}'s factory methods, or the
84
114
  # regular {DefaultFactory#parse_tag} factory method if none is supplied.
85
115
  #
86
116
  # @param [#to_s] tag the tag name to create
87
117
  # @param [#to_s, Class<Tag>] meth the {Tag} factory method to call when
88
118
  # creating the tag or the name of the class to directly create a tag for
89
- def define_tag(label, tag, meth = "")
119
+ def define_tag(label, tag, meth = nil)
90
120
  if meth.is_a?(Class) && Tag > meth
91
121
  class_eval <<-eof, __FILE__, __LINE__
92
122
  def #{tag}_tag(text)
@@ -103,6 +133,8 @@ module YARD
103
133
 
104
134
  @labels ||= SymbolHash.new(false)
105
135
  @labels.update(tag => label)
136
+ @factory_methods ||= SymbolHash.new(false)
137
+ @factory_methods.update(tag => meth)
106
138
  tag
107
139
  end
108
140
  end
@@ -129,29 +161,36 @@ module YARD
129
161
  self.factory = factory
130
162
  end
131
163
 
132
- define_tag "Parameters", :param, :with_types_and_name
133
- define_tag "Yield Parameters", :yieldparam, :with_types_and_name
134
- define_tag "Yield Returns", :yieldreturn, :with_types
135
- define_tag "Yields", :yield, :with_types
136
- define_tag "Default Value", :default, :with_name
137
- define_tag "Returns", :return, :with_types
138
- define_tag "Deprecated", :deprecated
139
- define_tag "Author", :author
140
- define_tag "Raises", :raise, :with_types
141
- define_tag "See Also", :see, :with_name
142
- define_tag "Since", :since
143
- define_tag "Version", :version
164
+ define_tag "Abstract", :abstract
144
165
  define_tag "API Visibility", :api
145
- define_tag "Note", :note
146
- define_tag "Todo Item", :todo
166
+ define_tag "Attribute", :attr, :with_types_and_name
167
+ define_tag "Attribute Getter", :attr_reader, :with_types_and_name
168
+ define_tag "Attribute Setter", :attr_writer, :with_types_and_name
169
+ define_tag "Author", :author
170
+ define_tag "Deprecated", :deprecated
147
171
  define_tag "Example", :example, :with_title_and_text
172
+ define_tag "End Grouping", :endgroup
173
+ define_tag "Grouping", :group
174
+ define_tag "Note", :note
148
175
  define_tag "Options Hash", :option, :with_options
149
176
  define_tag "Overloads", :overload, OverloadTag
177
+ define_tag "Parameters", :param, :with_types_and_name
150
178
  define_tag "Private", :private
151
- define_tag "Abstract", :abstract
152
- define_tag "Attribute", :attr, :with_types_and_name
153
- define_tag "Attribute Getter", :attr_reader, :with_types_and_name
154
- define_tag "Attribute Setter", :attr_writer, :with_types_and_name
179
+ define_tag "Raises", :raise, :with_types
180
+ define_tag "Returns", :return, :with_types
181
+ define_tag "See Also", :see, :with_name
182
+ define_tag "Since", :since
183
+ define_tag "Todo Item", :todo
184
+ define_tag "Version", :version
185
+ define_tag "Yields", :yield, :with_types
186
+ define_tag "Yield Parameters", :yieldparam, :with_types_and_name
187
+ define_tag "Yield Returns", :yieldreturn, :with_types
188
+
189
+ self.visible_tags = [:abstract, :deprecated, :note, :todo, :example, :overload,
190
+ :param, :option, :yield, :yieldparam, :yieldreturn, :return, :raise,
191
+ :see, :author, :since, :version]
192
+
193
+ self.transitive_tags = [:since]
155
194
  end
156
195
  end
157
196
  end
data/lib/yard/tags/tag.rb CHANGED
@@ -1,9 +1,32 @@
1
1
  module YARD
2
2
  module Tags
3
+ # Represents a metadata tag value (+@tag+). Tags can have any combination of
4
+ # {#types}, {#name} and {#text}, or none of the above.
5
+ #
6
+ # @example Programmatic tag creation
7
+ # # The following docstring syntax:
8
+ # # @param [String, nil] arg an argument
9
+ # #
10
+ # # is equivalent to:
11
+ # Tag.new(:param, 'an argument', ['String', 'nil'], 'arg')
3
12
  class Tag
4
- attr_accessor :tag_name, :text, :types, :name, :object
13
+ # @return [String] the name of the tag
14
+ attr_accessor :tag_name
15
+
16
+ # @return [String] the tag text associated with the tag
17
+ # @return [nil] if no tag text is supplied
18
+ attr_accessor :text
19
+
20
+ # @return [Array<String>] a list of types associated with the tag
21
+ # @return [nil] if no types are associated with the tag
22
+ attr_accessor :types
23
+
24
+ # @return [String] a name associated with the tag
25
+ attr_accessor :name
26
+
27
+ # @return [CodeObjects::Base] the associated object
28
+ attr_accessor :object
5
29
 
6
- ##
7
30
  # Creates a new tag object with a tag name and text. Optionally, formally declared types
8
31
  # and a key name can be specified.
9
32
  #
@@ -12,7 +35,7 @@ module YARD
12
35
  # Key names are for tags that declare meta data for a specific key or name, such as +param+,
13
36
  # +raise+, etc.
14
37
  #
15
- # @param tag_name the tag name to create the tag for
38
+ # @param [#to_s] tag_name the tag name to create the tag for
16
39
  # @param [String] text the descriptive text for this tag
17
40
  # @param [Array<String>] types optional type list of formally declared types
18
41
  # for the tag
@@ -21,7 +44,6 @@ module YARD
21
44
  @tag_name, @text, @name, @types = tag_name.to_s, text, name, (types ? [types].flatten.compact : nil)
22
45
  end
23
46
 
24
- ##
25
47
  # Convenience method to access the first type specified. This should mainly
26
48
  # be used for tags that only specify one type.
27
49
  #
@@ -1,5 +1,13 @@
1
+ require 'ostruct'
2
+
1
3
  module YARD
2
4
  module Templates
5
+ # This module manages all creation, handling and rendering of {Engine::Template}
6
+ # objects.
7
+ #
8
+ # * To create a template object at a path, use {template}.
9
+ # * To render a template, call {render}.
10
+ # * To register a template path in the lookup paths, call {register_template_path}.
3
11
  module Engine
4
12
  class << self
5
13
  # @return [Array<String>] the list of registered template paths
@@ -20,6 +28,8 @@ module YARD
20
28
  # generated module as mixins (for overriding).
21
29
  #
22
30
  # @param [Array<String, Symbol>] path a list of path components
31
+ # @raise [ArgumentError] if the path does not exist within one of the
32
+ # {template_paths} on disk.
23
33
  # @return [Template] the module representing the template
24
34
  def template(*path)
25
35
  from_template = nil
@@ -43,7 +53,7 @@ module YARD
43
53
  full_paths ||= [path]
44
54
  full_paths = [full_paths] unless full_paths.is_a?(Array)
45
55
  name = template_module_name(full_paths.first)
46
- return const_get(name) rescue NameError
56
+ begin; return const_get(name); rescue NameError; end
47
57
 
48
58
  mod = const_set(name, Module.new)
49
59
  mod.send(:include, Template)
@@ -120,6 +130,7 @@ module YARD
120
130
  # @option options [Symbol] :template (:default) the default template
121
131
  # @return [void]
122
132
  def set_default_options(options = {})
133
+ options[:__globals] ||= OpenStruct.new
123
134
  options[:format] ||= :text
124
135
  options[:type] ||= options[:object].type if options[:object]
125
136
  options[:template] ||= :default
@@ -1,12 +1,13 @@
1
1
  module YARD
2
2
  module Templates
3
+ # @since 0.5.4
3
4
  module ErbCache
4
5
  def self.method_for(filename, &block)
5
6
  @methods ||= {}
6
7
  return @methods[filename] if @methods[filename]
7
8
  @methods[filename] = name = "_erb_cache_#{@methods.size}"
8
9
  erb = yield.src
9
- encoding = erb[/\A(#coding:.*\r?\n)/, 1] || ''
10
+ encoding = erb[/\A(#coding[:=].*\r?\n)/, 1] || ''
10
11
  module_eval "#{encoding}def #{name}; #{erb}; end", filename
11
12
 
12
13
  name
@@ -1,23 +1,62 @@
1
1
  module YARD::Templates::Helpers
2
+ # The base helper module included in all templates.
2
3
  module BaseHelper
3
4
  attr_accessor :object, :serializer
4
5
 
6
+ # @group Managing Global Template State
7
+
8
+ # An object that keeps track of global state throughout the entire template
9
+ # rendering process (including any sub-templates).
10
+ #
11
+ # @return [OpenStruct] a struct object that stores state
12
+ # @since 0.6.0
13
+ def globals; options[:__globals] end
14
+
15
+ # @group Running the Verifier
16
+
17
+ # Runs a list of objects against the {Verifier} object passed into the
18
+ # template and returns the subset of verified objects.
19
+ #
20
+ # @param [Array<CodeObjects::Base>] list a list of code objects
21
+ # @return [Array<CodeObjects::Base>] a list of code objects that match
22
+ # the verifier. If no verifier is supplied, all objects are returned.
5
23
  def run_verifier(list)
6
- return list unless options[:verifier]
7
- list.reject {|item| options[:verifier].call(item).is_a?(FalseClass) }
24
+ options[:verifier] ? options[:verifier].run(list) : list
8
25
  end
9
26
 
10
- # This is used a lot by the HtmlHelper and there should
27
+ # @group Escaping Text
28
+
29
+ # Escapes text. This is used a lot by the HtmlHelper and there should
11
30
  # be some helper to "clean up" text for whatever, this is it.
12
31
  def h(text)
13
32
  text
14
33
  end
15
34
 
35
+ # @group Linking Objects and URLs
36
+
37
+ # Links objects or URLs. This method will delegate to the correct +link_+
38
+ # method depending on the arguments passed in.
39
+ #
40
+ # @example Linking a URL
41
+ # linkify('http://example.com')
42
+ # @example Including docstring contents of an object
43
+ # linkify('include:YARD::Docstring')
44
+ # @example Linking to an extra file
45
+ # linkify('file:README')
46
+ # @example Linking an object by path
47
+ # linkify('YARD::Docstring')
16
48
  def linkify(*args)
17
49
  if args.first.is_a?(String)
18
50
  case args.first
19
51
  when %r{://}, /^mailto:/
20
52
  link_url(args[0], args[1], {:target => '_parent'}.merge(args[2]||{}))
53
+ when /^include:(\S+)/
54
+ path = $1
55
+ if obj = YARD::Registry.resolve(object.namespace, path)
56
+ link_include_object(obj)
57
+ else
58
+ log.warn "Cannot find object at `#{path}' for inclusion"
59
+ end
21
60
  when /^file:(\S+?)(?:#(\S+))?$/
22
61
  link_file($1, args[1] ? args[1] : $1, $2)
23
62
  else
@@ -27,7 +66,18 @@ module YARD::Templates::Helpers
27
66
  link_object(*args)
28
67
  end
29
68
  end
69
+
70
+ # Includes an object's docstring into output.
71
+ # @since 0.6.0
72
+ def link_include_object(object)
73
+ object.docstring
74
+ end
30
75
 
76
+ # Links to an object with an optional title
77
+ #
78
+ # @param [CodeObjects::Base] object the object to link to
79
+ # @param [String] title the title to use for the link
80
+ # @return [String] the linked object
31
81
  def link_object(object, title = nil)
32
82
  return title if title
33
83
 
@@ -41,18 +91,52 @@ module YARD::Templates::Helpers
41
91
  end
42
92
  end
43
93
 
94
+ # Links to a URL
95
+ #
96
+ # @param [String] url the URL to link to
97
+ # @param [String] title the optional title to display the link as
98
+ # @param [Hash] params optional parameters for the link
99
+ # @return [String] the linked URL
44
100
  def link_url(url, title = nil, params = nil)
45
101
  url
46
102
  end
47
103
 
104
+ # Links to an extra file
105
+ #
106
+ # @param [String] filename the filename to link to
107
+ # @param [String] title the title of the link
108
+ # @param [String] anchor optional anchor
109
+ # @return [String] the link to the file
110
+ # @since 0.5.5
48
111
  def link_file(filename, title = nil, anchor = nil)
49
112
  filename
50
113
  end
51
114
 
115
+ # @group Formatting Object Attributes
116
+
117
+ # Formats a list of return types for output and links each type.
118
+ #
119
+ # @example Formatting types
120
+ # format_types(['String', 'Array']) #=> "(String, Array)"
121
+ # @example Formatting types without surrounding brackets
122
+ # format_types(['String', 'Array'], false) #=> "String, Array"
123
+ # @param [Array<String>] list a list of types
124
+ # @param [Boolean] brackets whether to surround the types in brackets
125
+ # @return [String] the formatted list of Ruby types
52
126
  def format_types(list, brackets = true)
53
127
  list.nil? || list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
54
128
  end
55
129
 
130
+ # @example Formatted type of an exception class
131
+ # o = ClassObject.new(:root, :MyError)
132
+ # o.superclass = P('RuntimeError')
133
+ # format_object_type(o) # => "Exception"
134
+ # @example Formatted type of a method
135
+ # o = MethodObject.new(:root, :to_s)
136
+ # format_object_type(o) # => "Method"
137
+ # @param [CodeObjects::Base] object the object to retrieve the type for
138
+ # @return [String] the human-readable formatted {CodeObjects::Base#type #type}
139
+ # for the object
56
140
  def format_object_type(object)
57
141
  case object
58
142
  when YARD::CodeObjects::ClassObject
@@ -62,6 +146,11 @@ module YARD::Templates::Helpers
62
146
  end
63
147
  end
64
148
 
149
+ # @example
150
+ # s = format_object_title ModuleObject.new(:root, :MyModuleName)
151
+ # s # => "Module: MyModuleName"
152
+ # @param [CodeObjects::Base] object the object to retrieve a title for
153
+ # @return [String] the page title name for a given object
65
154
  def format_object_title(object)
66
155
  case object
67
156
  when YARD::CodeObjects::RootObject
@@ -71,6 +160,10 @@ module YARD::Templates::Helpers
71
160
  end
72
161
  end
73
162
 
163
+ # Indents and formats source code
164
+ #
165
+ # @param [String] value the input source code
166
+ # @return [String] formatted source code
74
167
  def format_source(value)
75
168
  sp = value.split("\n").last[/^(\s+)/, 1]
76
169
  num = sp ? sp.size : 0
@@ -1,18 +1,23 @@
1
1
  module YARD
2
2
  module Templates::Helpers
3
+ # Helpers for various object types
3
4
  module FilterHelper
5
+ # @return [Boolean] whether an object is a method
4
6
  def is_method?(object)
5
7
  object.type == :method
6
8
  end
7
9
 
10
+ # @return [Boolean] whether an object is a namespace
8
11
  def is_namespace?(object)
9
12
  object.is_a?(CodeObjects::NamespaceObject)
10
13
  end
11
14
 
15
+ # @return [Boolean] whether an object is a class
12
16
  def is_class?(object)
13
17
  object.is_a?(CodeObjects::ClassObject)
14
18
  end
15
19
 
20
+ # @return [Boolean] whether an object is a module
16
21
  def is_module?(object)
17
22
  object.is_a?(CodeObjects::ModuleObject)
18
23
  end