Module: YARD::Templates::Helpers::BaseHelper
- Defined in:
- lib/yard/templates/helpers/base_helper.rb
Overview
The base helper module included in all templates.
Instance Attribute Summary (collapse)
-
- (Object) object
Returns the value of attribute object.
-
- (Object) serializer
Returns the value of attribute serializer.
Managing Global Template State (collapse)
-
- (OpenStruct) globals
An object that keeps track of global state throughout the entire template rendering process (including any sub-templates).
Running the Verifier (collapse)
-
- (Array<CodeObjects::Base>) run_verifier(list)
Runs a list of objects against the Verifier object passed into the template and returns the subset of verified objects.
Escaping Text (collapse)
-
- (Object) h(text)
Escapes text.
Linking Objects and URLs (collapse)
-
- (String) link_file(filename, title = nil, anchor = nil)
Links to an extra file.
-
- (Object) link_include_object(object)
Includes an object's docstring into output.
-
- (String) link_object(object, title = nil)
Links to an object with an optional title.
-
- (String) link_url(url, title = nil, params = nil)
Links to a URL.
-
- (Object) linkify(*args)
Links objects or URLs.
Formatting Object Attributes (collapse)
-
- (String) format_object_title(object)
The page title name for a given object.
-
- (String) format_object_type(object)
The human-readable formatted #type for the object.
-
- (String) format_source(value)
Indents and formats source code.
-
- (String) format_types(list, brackets = true)
Formats a list of return types for output and links each type.
Instance Attribute Details
- (Object) object
Returns the value of attribute object
4 5 6 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 4 def object @object end |
- (Object) serializer
Returns the value of attribute serializer
4 5 6 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 4 def serializer @serializer end |
Instance Method Details
- (String) format_object_title(object)
The page title name for a given object
154 155 156 157 158 159 160 161 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 154 def format_object_title(object) case object when YARD::CodeObjects::RootObject "Top Level Namespace" else format_object_type(object) + ": " + object.path end end |
- (String) format_object_type(object)
The human-readable formatted #type for the object
140 141 142 143 144 145 146 147 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 140 def format_object_type(object) case object when YARD::CodeObjects::ClassObject object.is_exception? ? "Exception" : "Class" else object.type.to_s.capitalize end end |
- (String) format_source(value)
Indents and formats source code
167 168 169 170 171 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 167 def format_source(value) sp = value.split("\n").last[/^(\s+)/, 1] num = sp ? sp.size : 0 value.gsub(/^\s{#{num}}/, '') end |
- (String) format_types(list, brackets = true)
Formats a list of return types for output and links each type.
126 127 128 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 126 def format_types(list, brackets = true) list.nil? || list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", ")) end |
- (OpenStruct) globals
An object that keeps track of global state throughout the entire template rendering process (including any sub-templates).
13 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 13 def globals; [:__globals] end |
- (Object) h(text)
Escapes text. This is used a lot by the HtmlHelper and there should be some helper to "clean up" text for whatever, this is it.
31 32 33 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 31 def h(text) text end |
- (String) link_file(filename, title = nil, anchor = nil)
Links to an extra file
111 112 113 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 111 def link_file(filename, title = nil, anchor = nil) filename end |
- (Object) link_include_object(object)
Includes an object's docstring into output.
72 73 74 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 72 def link_include_object(object) object.docstring end |
- (String) link_object(object, title = nil)
Links to an object with an optional title
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 81 def link_object(object, title = nil) return title if title case object when YARD::CodeObjects::Base, YARD::CodeObjects::Proxy object.path when String, Symbol P(object).path else object end end |
- (String) link_url(url, title = nil, params = nil)
Links to a URL
100 101 102 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 100 def link_url(url, title = nil, params = nil) url end |
- (Object) linkify(*args)
Links objects or URLs. This method will delegate to the correct link_ method depending on the arguments passed in.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 48 def linkify(*args) if args.first.is_a?(String) case args.first when %r{://}, /^mailto:/ link_url(args[0], args[1], {:target => '_parent'}.merge(args[2]||{})) when /^include:(\S+)/ path = $1 if obj = YARD::Registry.resolve(object.namespace, path) link_include_object(obj) else log.warn "Cannot find object at `#{path}' for inclusion" end when /^file:(\S+?)(?:#(\S+))?$/ link_file($1, args[1] ? args[1] : $1, $2) else link_object(*args) end else link_object(*args) end end |
- (Array<CodeObjects::Base>) run_verifier(list)
Runs a list of objects against the Verifier object passed into the template and returns the subset of verified objects.
23 24 25 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 23 def run_verifier(list) [:verifier] ? [:verifier].run(list) : list end |