Module: YARD::Templates::Helpers::BaseHelper
- Included in:
- CLI::Stats, Server::Commands::ListCommand, Server::Commands::SearchCommand, Template
- 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.
-
- (CodeObjects::Base) owner
readonly
The object representing the current generated page.
-
- (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.
-
- (String) link_include_file(file)
Include a file as a docstring in output.
-
- (String) link_include_object(obj)
Includes an object's docstring into output.
-
- (String) link_object(obj, 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 |
- (CodeObjects::Base) owner (readonly)
Returns the object representing the current generated page. Might not be the current #object when inside sub-templates.
8 9 10 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 8 def owner @owner 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)
Returns the page title name for a given object
193 194 195 196 197 198 199 200 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 193 def format_object_title(object) case object when YARD::CodeObjects::RootObject "Top Level Namespace" else format_object_type(object) + ": " + object.title end end |
- (String) format_object_type(object)
Returns the human-readable formatted #type for the object
179 180 181 182 183 184 185 186 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 179 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
206 207 208 209 210 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 206 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.
165 166 167 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 165 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).
19 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 19 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.
37 38 39 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 37 def h(text) text end |
- (String) link_file(filename, title = nil, anchor = nil)
Links to an extra file
149 150 151 152 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 149 def link_file(filename, title = nil, anchor = nil) return filename.filename if CodeObjects::ExtraFileObject === filename filename end |
- (String) link_include_file(file)
Include a file as a docstring in output
110 111 112 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 110 def link_include_file(file) File.read(file) end |
- (String) link_include_object(obj)
Includes an object's docstring into output.
102 103 104 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 102 def link_include_object(obj) obj.docstring end |
- (String) link_object(obj, title = nil)
Links to an object with an optional title
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 119 def link_object(obj, title = nil) return title if title case obj when YARD::CodeObjects::Base, YARD::CodeObjects::Proxy obj.title when String, Symbol P(obj).title else obj end end |
- (String) link_url(url, title = nil, params = nil)
Links to a URL
138 139 140 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 138 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.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 54 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:file:(\S+)/ file = $1 relpath = File.relative_path(Dir.pwd, File.(file)) if relpath =~ /^\.\./ log.warn "Cannot include file from path `#{file}'" "" elsif File.file?(file) link_include_file(file) else log.warn "Cannot find file at `#{file}' for inclusion" "" end 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 /^render:(\S+)/ path = $1 if obj = YARD::Registry.resolve(object, path) opts = .dup opts.delete(:serializer) obj.format(opts) else '' end when /^file:(\S+?)(?:#(\S+))?$/ link_file($1, args[1] ? args[1] : nil, $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.
29 30 31 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 29 def run_verifier(list) .verifier ? .verifier.run(list) : list end |