Class: PuppetReadmeGenerator::Generator
- Inherits:
-
Object
- Object
- PuppetReadmeGenerator::Generator
- Defined in:
- lib/puppet_readme_generator.rb
Instance Method Summary collapse
- #classes ⇒ Object
- #defined_types ⇒ Object
- #documentation ⇒ Object
- #documentation_path ⇒ Object
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
- #long_description ⇒ Object
- #main_class ⇒ Object
- #markdown ⇒ Object
- #metadata ⇒ Object
- #metadata_path ⇒ Object
- #puppet_module ⇒ Object
Constructor Details
#initialize ⇒ Generator
Returns a new instance of Generator.
7 8 9 10 11 12 |
# File 'lib/puppet_readme_generator.rb', line 7 def initialize patterns ||= PuppetStrings::DEFAULT_SEARCH_PATTERNS = {} [:json] = 'documentation.json' PuppetStrings.generate(patterns, ) end |
Instance Method Details
#classes ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/puppet_readme_generator.rb', line 92 def classes if @classes.nil? @classes = documentation['puppet_classes'].map do |c| Class.new c end end @classes end |
#defined_types ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/puppet_readme_generator.rb', line 101 def defined_types if @defined_types.nil? @defined_types = documentation['defined_types'].map do |c| DefinedType.new c end end @defined_types end |
#documentation ⇒ Object
65 66 67 |
# File 'lib/puppet_readme_generator.rb', line 65 def documentation @documentation ||= JSON.parse(File.open(documentation_path).read) end |
#documentation_path ⇒ Object
61 62 63 |
# File 'lib/puppet_readme_generator.rb', line 61 def documentation_path 'documentation.json' end |
#long_description ⇒ Object
81 82 83 |
# File 'lib/puppet_readme_generator.rb', line 81 def long_description ['long_description'] end |
#main_class ⇒ Object
85 86 87 88 89 90 |
# File 'lib/puppet_readme_generator.rb', line 85 def main_class classes.each do |c| return c if c.name == puppet_module end nil end |
#markdown ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 |
# File 'lib/puppet_readme_generator.rb', line 14 def markdown output = [] output << "# #{puppet_module}\n" output << "#### Table of Contents\n" count = 1 unless long_description.nil? output << "#{count}. [Description](#description)" count += 1 end if classes.length > 0 output << "#{count}. [Classes](#classes)" count += 1 end if defined_types.length > 0 output << "#{count}. [Defined Types](#defined-types)" count += 1 end unless long_description.nil? output << '## Description' output << long_description output << '' end if classes.length > 0 output << '## Classes' classes.each do |c| output << '' output << c.markdown end end if defined_types.length > 0 output << '## DefinedTypes' defined_types.each do |dt| output << '' output << dt.markdown end end output.join("\n") end |
#metadata ⇒ Object
73 74 75 |
# File 'lib/puppet_readme_generator.rb', line 73 def @metadata ||= JSON.parse(File.open().read) end |
#metadata_path ⇒ Object
69 70 71 |
# File 'lib/puppet_readme_generator.rb', line 69 def 'metadata.json' end |
#puppet_module ⇒ Object
77 78 79 |
# File 'lib/puppet_readme_generator.rb', line 77 def puppet_module ['name'].split('-')[1] end |