Module: YARD::Templates::Helpers::BaseHelper
- Included in:
- CLI::Stats, Server::Commands::ListCommand, 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.
-
#serializer ⇒ Object
Returns the value of attribute serializer.
Managing Global Template State collapse
-
#globals ⇒ OpenStruct
An object that keeps track of global state throughout the entire template rendering process (including any sub-templates).
Running the Verifier collapse
-
#run_verifier(list) ⇒ Array<CodeObjects::Base>
Runs a list of objects against the Verifier object passed into the template and returns the subset of verified objects.
Escaping Text collapse
-
#h(text) ⇒ Object
Escapes text.
Linking Objects and URLs collapse
-
#link_file(filename, title = nil, anchor = nil) ⇒ String
Links to an extra file.
-
#link_include_file(file) ⇒ String
Include a file as a docstring in output.
-
#link_include_object(object) ⇒ String
Includes an object’s docstring into output.
-
#link_object(object, title = nil) ⇒ String
Links to an object with an optional title.
-
#link_url(url, title = nil, params = nil) ⇒ String
Links to a URL.
-
#linkify(*args) ⇒ Object
Links objects or URLs.
Formatting Object Attributes collapse
-
#format_object_title(object) ⇒ String
The page title name for a given object.
-
#format_object_type(object) ⇒ String
The human-readable formatted #type for the object.
-
#format_source(value) ⇒ String
Indents and formats source code.
-
#format_types(list, brackets = true) ⇒ String
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 |
#serializer ⇒ Object
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
#format_object_title(object) ⇒ String
Returns the page title name for a given object.
173 174 175 176 177 178 179 180 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 173 def format_object_title(object) case object when YARD::CodeObjects::RootObject "Top Level Namespace" else format_object_type(object) + ": " + object.path end end |
#format_object_type(object) ⇒ String
Returns the human-readable formatted #type for the object.
159 160 161 162 163 164 165 166 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 159 def format_object_type(object) case object when YARD::CodeObjects::ClassObject object.is_exception? ? "Exception" : "Class" else object.type.to_s.capitalize end end |
#format_source(value) ⇒ String
Indents and formats source code
186 187 188 189 190 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 186 def format_source(value) sp = value.split("\n").last[/^(\s+)/, 1] num = sp ? sp.size : 0 value.gsub(/^\s{#{num}}/, '') end |
#format_types(list, brackets = true) ⇒ String
Formats a list of return types for output and links each type.
145 146 147 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 145 def format_types(list, brackets = true) list.nil? || list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", ")) end |
#globals ⇒ OpenStruct
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 |
#h(text) ⇒ Object
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 |
#link_file(filename, title = nil, anchor = nil) ⇒ String
Links to an extra file
130 131 132 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 130 def link_file(filename, title = nil, anchor = nil) filename end |
#link_include_file(file) ⇒ String
Include a file as a docstring in output
91 92 93 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 91 def link_include_file(file) File.read(file) end |
#link_include_object(object) ⇒ String
Includes an object’s docstring into output.
83 84 85 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 83 def link_include_object(object) object.docstring end |
#link_object(object, title = nil) ⇒ String
Links to an object with an optional title
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 100 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 |
#link_url(url, title = nil, params = nil) ⇒ String
Links to a URL
119 120 121 |
# File 'lib/yard/templates/helpers/base_helper.rb', line 119 def link_url(url, title = nil, params = nil) url end |
#linkify(*args) ⇒ Object
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 69 70 71 72 73 74 75 76 77 |
# 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:file:(\S+)/ file = $1 if 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 /^file:(\S+?)(?:#(\S+))?$/ link_file($1, args[1] ? args[1] : $1, $2) else link_object(*args) end else link_object(*args) end end |
#run_verifier(list) ⇒ Array<CodeObjects::Base>
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 |