module PuppetStrings::Yard::Util
The module for various puppet-strings utility helpers.
Public Class Methods
Source
Source
# File lib/puppet-strings/yard/util.rb, line 60 def self.docstring_to_hash(docstring, select_tags = nil) hash = {} hash[:text] = docstring if docstring.is_a? YARD::Docstring tags = tags_to_hashes(docstring.tags.select { |t| select_tags.nil? || select_tags.include?(t.tag_name.to_sym) }) unless tags.empty? hash[:tags] = tags # .sort_by do |tag| # sort_key = tag[:tag_name].dup # sort_key << "-#{tag[:name]}" if tag[:name] # sort_key << "-#{tag[:opt_name]}" if tag[:opt_name] # sort_key # end end end hash end
Converts a YARD::Docstring (or String) to a docstring hash for JSON output. @param [YARD::Docstring, String] docstring The docstring to convert to a hash. @param [Array] select_tags List of tags to select. Other tags will be filtered out. @return [Hash] Returns a hash representation of the given docstring.
Source
# File lib/puppet-strings/yard/util.rb, line 25 def self.github_to_yard_links(data) data.scan(/href="\#(.+)"/).each do |bad_link| data = data.gsub("=\"##{bad_link.first}\"", "=\"#label-#{bad_link.first.capitalize.tr('-', '+')}\"") end data end
hacksville, usa YARD
creates ids in the html with with the style of “label-Module+description”, where the markdown we use in the README involves the GitHub-style, which is module-description. This takes our GitHub-style links and converts them to reference the YARD-style ids. @see github.com/octokit/octokit.rb/blob/0f13944e8dbb0210d1e266addd3335c6dc9fe36a/yard/default/layout/html/setup.rb#L5-L14 @param [String] data HTML document to convert @return [String] HTML document with links converted
Source
# File lib/puppet-strings/yard/util.rb, line 11 def self.scrub_string(str) match = str.match(/^%[Qq]{(.*)}$/m) return Puppet::Util::Docs.scrub(match[1]) if match Puppet::Util::Docs.scrub(str) end
Trims indentation from trailing whitespace and removes ruby literal quotation syntax ‘%Q{}` and `%{q}` from parsed strings. @param [String] str The string to scrub. @return [String] A scrubbed string.