Module: PuppetStrings::Markdown

Defined in:
lib/puppet-strings/markdown.rb,
lib/puppet-strings/markdown/base.rb,
lib/puppet-strings/markdown/function.rb,
lib/puppet-strings/markdown/data_type.rb,
lib/puppet-strings/markdown/puppet_plan.rb,
lib/puppet-strings/markdown/puppet_task.rb,
lib/puppet-strings/markdown/defined_type.rb,
lib/puppet-strings/markdown/puppet_class.rb,
lib/puppet-strings/markdown/resource_type.rb

Overview

Implements classes that make elements in a YARD::Registry hash easily accessible for template.

Defined Under Namespace

Modules: Helpers Classes: Base, DataType, DefinedType, Function, PuppetClass, PuppetPlan, PuppetTask, ResourceType

Class Method Summary collapse

Class Method Details

.erb(path) ⇒ ERB

Helper function to load an ERB template.

Parameters:

  • path (String)

    The full path to the template file.

Returns:

  • (ERB)

    Template



78
79
80
# File 'lib/puppet-strings/markdown.rb', line 78

def self.erb(path)
  ERB.new(File.read(path), trim_mode: '-')
end

.generateString

generates markdown documentation

Returns:

  • (String)

    markdown doc



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/puppet-strings/markdown.rb', line 32

def self.generate
  output = [
    "# Reference\n\n",
    "<!-- DO NOT EDIT: This document was generated by Puppet Strings -->\n\n",
    "## Table of Contents\n\n"
  ]

  # Create table of contents
  template = erb(File.join(__dir__, 'markdown', 'templates', 'table_of_contents.erb'))
  groups.each do |group|
    group_name = group.group_name
    items = group.items.map(&:toc_info)
    has_private = items.any? { |item| item[:private] }
    has_public = items.any? { |item| !item[:private] }

    output << template.result(binding)
  end

  # Create actual contents
  groups.each do |group|
    items = group.items.reject(&:private?)
    unless items.empty?
      output << "## #{group.group_name}\n\n"
      output.append(items.map(&:render))
    end
  end

  output.join
end

.groupsArray[class]

Get classes that handle collecting and rendering each section/group.

Returns:

  • (Array[class])

    The classes



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet-strings/markdown.rb', line 18

def self.groups
  [
    PuppetStrings::Markdown::PuppetClass,
    PuppetStrings::Markdown::DefinedType,
    PuppetStrings::Markdown::ResourceType,
    PuppetStrings::Markdown::Function,
    PuppetStrings::Markdown::DataType,
    PuppetStrings::Markdown::PuppetTask,
    PuppetStrings::Markdown::PuppetPlan
  ]
end

.render(path = nil) ⇒ Object

mimicks the behavior of the json render, although path will never be nil

Parameters:

  • path (String) (defaults to: nil)

    path to destination file



64
65
66
67
68
69
70
71
72
# File 'lib/puppet-strings/markdown.rb', line 64

def self.render(path = nil)
  if path.nil?
    puts generate
    exit
  else
    File.write(path, generate)
    YARD::Logger.instance.debug "Wrote markdown to #{path}"
  end
end