openvox-strings 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +407 -0
- data/LICENSE +177 -0
- data/README.md +116 -0
- data/lib/openvox-strings/describe.rb +75 -0
- data/lib/openvox-strings/json.rb +33 -0
- data/lib/openvox-strings/markdown/base.rb +236 -0
- data/lib/openvox-strings/markdown/data_type.rb +39 -0
- data/lib/openvox-strings/markdown/defined_type.rb +20 -0
- data/lib/openvox-strings/markdown/function.rb +59 -0
- data/lib/openvox-strings/markdown/helpers.rb +21 -0
- data/lib/openvox-strings/markdown/puppet_class.rb +20 -0
- data/lib/openvox-strings/markdown/puppet_plan.rb +20 -0
- data/lib/openvox-strings/markdown/puppet_task.rb +29 -0
- data/lib/openvox-strings/markdown/resource_type.rb +56 -0
- data/lib/openvox-strings/markdown/templates/classes_and_defines.erb +94 -0
- data/lib/openvox-strings/markdown/templates/data_type.erb +101 -0
- data/lib/openvox-strings/markdown/templates/data_type_function.erb +67 -0
- data/lib/openvox-strings/markdown/templates/function.erb +106 -0
- data/lib/openvox-strings/markdown/templates/puppet_task.erb +28 -0
- data/lib/openvox-strings/markdown/templates/resource_type.erb +156 -0
- data/lib/openvox-strings/markdown/templates/table_of_contents.erb +26 -0
- data/lib/openvox-strings/markdown.rb +81 -0
- data/lib/openvox-strings/monkey_patches/display_object_command.rb +16 -0
- data/lib/openvox-strings/tasks/generate.rb +54 -0
- data/lib/openvox-strings/tasks/gh_pages.rb +72 -0
- data/lib/openvox-strings/tasks/validate.rb +42 -0
- data/lib/openvox-strings/tasks.rb +14 -0
- data/lib/openvox-strings/version.rb +5 -0
- data/lib/openvox-strings/yard/code_objects/base.rb +16 -0
- data/lib/openvox-strings/yard/code_objects/class.rb +60 -0
- data/lib/openvox-strings/yard/code_objects/data_type.rb +102 -0
- data/lib/openvox-strings/yard/code_objects/data_type_alias.rb +60 -0
- data/lib/openvox-strings/yard/code_objects/defined_type.rb +59 -0
- data/lib/openvox-strings/yard/code_objects/function.rb +106 -0
- data/lib/openvox-strings/yard/code_objects/group.rb +33 -0
- data/lib/openvox-strings/yard/code_objects/plan.rb +59 -0
- data/lib/openvox-strings/yard/code_objects/provider.rb +98 -0
- data/lib/openvox-strings/yard/code_objects/task.rb +69 -0
- data/lib/openvox-strings/yard/code_objects/type.rb +196 -0
- data/lib/openvox-strings/yard/code_objects.rb +14 -0
- data/lib/openvox-strings/yard/handlers/helpers.rb +10 -0
- data/lib/openvox-strings/yard/handlers/json/base.rb +8 -0
- data/lib/openvox-strings/yard/handlers/json/task_handler.rb +34 -0
- data/lib/openvox-strings/yard/handlers/puppet/base.rb +52 -0
- data/lib/openvox-strings/yard/handlers/puppet/class_handler.rb +29 -0
- data/lib/openvox-strings/yard/handlers/puppet/data_type_alias_handler.rb +26 -0
- data/lib/openvox-strings/yard/handlers/puppet/defined_type_handler.rb +29 -0
- data/lib/openvox-strings/yard/handlers/puppet/function_handler.rb +54 -0
- data/lib/openvox-strings/yard/handlers/puppet/plan_handler.rb +29 -0
- data/lib/openvox-strings/yard/handlers/ruby/base.rb +55 -0
- data/lib/openvox-strings/yard/handlers/ruby/data_type_handler.rb +411 -0
- data/lib/openvox-strings/yard/handlers/ruby/function_handler.rb +386 -0
- data/lib/openvox-strings/yard/handlers/ruby/provider_handler.rb +127 -0
- data/lib/openvox-strings/yard/handlers/ruby/rsapi_handler.rb +157 -0
- data/lib/openvox-strings/yard/handlers/ruby/type_base.rb +146 -0
- data/lib/openvox-strings/yard/handlers/ruby/type_extras_handler.rb +65 -0
- data/lib/openvox-strings/yard/handlers/ruby/type_handler.rb +105 -0
- data/lib/openvox-strings/yard/handlers.rb +28 -0
- data/lib/openvox-strings/yard/parsers/json/parser.rb +38 -0
- data/lib/openvox-strings/yard/parsers/json/task_statement.rb +37 -0
- data/lib/openvox-strings/yard/parsers/puppet/parser.rb +89 -0
- data/lib/openvox-strings/yard/parsers/puppet/statement.rb +182 -0
- data/lib/openvox-strings/yard/parsers.rb +14 -0
- data/lib/openvox-strings/yard/tags/enum_tag.rb +13 -0
- data/lib/openvox-strings/yard/tags/factory.rb +18 -0
- data/lib/openvox-strings/yard/tags/overload_tag.rb +112 -0
- data/lib/openvox-strings/yard/tags/parameter_directive.rb +25 -0
- data/lib/openvox-strings/yard/tags/property_directive.rb +25 -0
- data/lib/openvox-strings/yard/tags/summary_tag.rb +10 -0
- data/lib/openvox-strings/yard/tags.rb +11 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/css/common.css +8 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_class.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_defined_type.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_function.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_plan.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_task.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/setup.rb +93 -0
- data/lib/openvox-strings/yard/templates/default/layout/html/footer.erb +3 -0
- data/lib/openvox-strings/yard/templates/default/layout/html/objects.erb +37 -0
- data/lib/openvox-strings/yard/templates/default/layout/html/setup.rb +231 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/box_info.erb +26 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/setup.rb +16 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/setup.rb +15 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +19 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/box_info.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/setup.rb +7 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/box_info.erb +14 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/overview.erb +18 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/setup.rb +7 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/box_info.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/setup.rb +13 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/box_info.erb +14 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/collection.erb +17 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/features.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/setup.rb +31 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/box_info.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/input.erb +5 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/parameters.erb +16 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/setup.rb +24 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/supports_noop.erb +3 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/box_info.erb +20 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/features.erb +13 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/parameters.erb +35 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/setup.rb +36 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/tags/html/enum.erb +17 -0
- data/lib/openvox-strings/yard/templates/default/tags/html/puppet_overload.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/tags/setup.rb +20 -0
- data/lib/openvox-strings/yard/util.rb +87 -0
- data/lib/openvox-strings/yard.rb +132 -0
- data/lib/openvox-strings.rb +88 -0
- data/lib/puppet/application/strings.rb +7 -0
- data/lib/puppet/face/strings.rb +185 -0
- data/lib/puppet/feature/rgen.rb +5 -0
- data/lib/puppet/feature/yard.rb +5 -0
- metadata +263 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/json'
|
4
|
+
|
5
|
+
# module for parsing Yard Registries and generating markdown
|
6
|
+
module OpenvoxStrings::Markdown
|
7
|
+
require_relative 'markdown/puppet_class'
|
8
|
+
require_relative 'markdown/function'
|
9
|
+
require_relative 'markdown/defined_type'
|
10
|
+
require_relative 'markdown/data_type'
|
11
|
+
require_relative 'markdown/resource_type'
|
12
|
+
require_relative 'markdown/puppet_task'
|
13
|
+
require_relative 'markdown/puppet_plan'
|
14
|
+
|
15
|
+
# Get classes that handle collecting and rendering each section/group.
|
16
|
+
#
|
17
|
+
# @return [Array[class]] The classes
|
18
|
+
def self.groups
|
19
|
+
[
|
20
|
+
OpenvoxStrings::Markdown::PuppetClass,
|
21
|
+
OpenvoxStrings::Markdown::DefinedType,
|
22
|
+
OpenvoxStrings::Markdown::ResourceType,
|
23
|
+
OpenvoxStrings::Markdown::Function,
|
24
|
+
OpenvoxStrings::Markdown::DataType,
|
25
|
+
OpenvoxStrings::Markdown::PuppetTask,
|
26
|
+
OpenvoxStrings::Markdown::PuppetPlan
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
# generates markdown documentation
|
31
|
+
# @return [String] markdown doc
|
32
|
+
def self.generate
|
33
|
+
output = [
|
34
|
+
"# Reference\n\n",
|
35
|
+
"<!-- DO NOT EDIT: This document was generated by Puppet Strings -->\n\n",
|
36
|
+
"## Table of Contents\n\n"
|
37
|
+
]
|
38
|
+
|
39
|
+
# Create table of contents
|
40
|
+
template = erb(File.join(__dir__, 'markdown', 'templates', 'table_of_contents.erb'))
|
41
|
+
groups.each do |group|
|
42
|
+
group_name = group.group_name
|
43
|
+
items = group.items.map(&:toc_info)
|
44
|
+
has_private = items.any? { |item| item[:private] }
|
45
|
+
has_public = items.any? { |item| !item[:private] }
|
46
|
+
|
47
|
+
output << template.result(binding)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Create actual contents
|
51
|
+
groups.each do |group|
|
52
|
+
items = group.items.reject(&:private?)
|
53
|
+
unless items.empty?
|
54
|
+
output << "## #{group.group_name}\n\n"
|
55
|
+
output.append(items.map(&:render))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
output.join
|
60
|
+
end
|
61
|
+
|
62
|
+
# mimicks the behavior of the json render, although path will never be nil
|
63
|
+
# @param [String] path path to destination file
|
64
|
+
def self.render(path = nil)
|
65
|
+
if path.nil?
|
66
|
+
puts generate
|
67
|
+
exit
|
68
|
+
else
|
69
|
+
File.write(path, generate)
|
70
|
+
YARD::Logger.instance.debug "Wrote markdown to #{path}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Helper function to load an ERB template.
|
75
|
+
#
|
76
|
+
# @param [String] path The full path to the template file.
|
77
|
+
# @return [ERB] Template
|
78
|
+
def self.erb(path)
|
79
|
+
ERB.new(File.read(path), trim_mode: '-')
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Monkey patch URL decoding in object displays. Usually :: is interpreted as a
|
4
|
+
# namespace, but this is disabled in our base object, and so instead gets
|
5
|
+
# URL-encoded.
|
6
|
+
require 'yard/server/commands/display_object_command'
|
7
|
+
|
8
|
+
# Monkey patch YARD::Server::Commands::DisplayObjectCommand object_path.
|
9
|
+
class YARD::Server::Commands::DisplayObjectCommand
|
10
|
+
private
|
11
|
+
|
12
|
+
alias object_path_yard object_path
|
13
|
+
def object_path
|
14
|
+
object_path_yard.gsub('_3A', ':')
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings'
|
4
|
+
|
5
|
+
# Implements the strings:generate task.
|
6
|
+
namespace :strings do
|
7
|
+
desc 'Generate Puppet documentation with YARD.'
|
8
|
+
task :generate, [:patterns, :debug, :backtrace, :markup, :json, :markdown, :yard_args] do |_t, args|
|
9
|
+
patterns = args[:patterns]
|
10
|
+
patterns = patterns.split if patterns
|
11
|
+
patterns ||= OpenvoxStrings::DEFAULT_SEARCH_PATTERNS
|
12
|
+
|
13
|
+
options = {
|
14
|
+
debug: args[:debug] == 'true',
|
15
|
+
backtrace: args[:backtrace] == 'true',
|
16
|
+
markup: args[:markup] || 'markdown'
|
17
|
+
}
|
18
|
+
|
19
|
+
raise('Error: Both JSON and Markdown output have been selected. Please select one.') if args[:json] == 'true' && args[:markdown] == 'true'
|
20
|
+
|
21
|
+
# rubocop:disable Style/PreferredHashMethods
|
22
|
+
# Because of Ruby, true and false from the args are both strings and both true. Here,
|
23
|
+
# when the arg is set to false (or empty), set it to real false, else real true. Then,
|
24
|
+
# if the arg is set simply to 'true', assume default behavior is expected and set the path
|
25
|
+
# to nil to elicit that, else set to the path given.
|
26
|
+
# @param [Hash] args from the Rake task cli
|
27
|
+
# @param [Hash] options to send to the generate function
|
28
|
+
# @param [Symbol] possible format option
|
29
|
+
# @return nil
|
30
|
+
def parse_format_option(args, options, format)
|
31
|
+
return unless args.has_key? format
|
32
|
+
|
33
|
+
options[format] = !(args[format] == 'false' || args[format].empty?)
|
34
|
+
return unless options[format]
|
35
|
+
|
36
|
+
options[:path] = args[format] == 'true' ? nil : args[format]
|
37
|
+
end
|
38
|
+
# rubocop:enable Style/PreferredHashMethods
|
39
|
+
|
40
|
+
%i[json markdown].each { |format| parse_format_option(args, options, format) }
|
41
|
+
|
42
|
+
warn('yard_args behavior is a little dodgy, use at your own risk') if args[:yard_args]
|
43
|
+
options[:yard_args] = args[:yard_args].split if args.key? :yard_args
|
44
|
+
|
45
|
+
OpenvoxStrings.generate(patterns, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
namespace :generate do
|
49
|
+
desc 'Generate Puppet Reference documentation.'
|
50
|
+
task :reference, [:patterns, :debug, :backtrace] do |_t, args|
|
51
|
+
Rake::Task['strings:generate'].invoke(args[:patterns], args[:debug], args[:backtrace], nil, 'false', 'true')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
require 'openvox-strings/tasks'
|
5
|
+
|
6
|
+
namespace :strings do
|
7
|
+
namespace :gh_pages do
|
8
|
+
task :checkout do
|
9
|
+
if Dir.exist?('doc')
|
10
|
+
raise "The 'doc' directory (#{File.expand_path('doc')}) is not a Git repository! Remove it and run the Rake task again." unless Dir.exist?('doc/.git')
|
11
|
+
|
12
|
+
Dir.chdir('doc') do
|
13
|
+
system 'git checkout gh-pages'
|
14
|
+
exit 1 unless $?.success?
|
15
|
+
system 'git pull --rebase origin gh-pages'
|
16
|
+
exit 1 unless $?.success?
|
17
|
+
end
|
18
|
+
else
|
19
|
+
git_uri = `git config --get remote.origin.url`.strip
|
20
|
+
raise "Could not determine the remote URL for origin: ensure the current directory is a Git repro with a remote named 'origin'." unless $CHILD_STATUS.success?
|
21
|
+
|
22
|
+
Dir.mkdir('doc')
|
23
|
+
Dir.chdir('doc') do
|
24
|
+
system 'git init'
|
25
|
+
exit 1 unless $?.success?
|
26
|
+
system "git remote add origin #{git_uri}"
|
27
|
+
exit 1 unless $?.success?
|
28
|
+
system 'git pull origin gh-pages'
|
29
|
+
exit 1 unless $?.success?
|
30
|
+
system 'git checkout -b gh-pages'
|
31
|
+
exit 1 unless $?.success?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
task :configure do
|
37
|
+
unless File.exist?(File.join('doc', '_config.yml'))
|
38
|
+
Dir.chdir('doc') do
|
39
|
+
File.write('_config.yml', 'include: _index.html')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Task to push the gh-pages branch. Argument :msg_prefix is the beginning
|
45
|
+
# of the message and the actual commit will have "at Revision <git_sha>"
|
46
|
+
# appended.
|
47
|
+
task :push, [:msg_prefix] do |_t, args|
|
48
|
+
msg_prefix = args[:msg_prefix] || '[strings] Generated Documentation Update'
|
49
|
+
|
50
|
+
output = `git describe --long 2>/dev/null`
|
51
|
+
# If a project has never been tagged, fall back to latest SHA
|
52
|
+
git_sha = output.empty? ? `git log --pretty=format:'%H' -n 1` : output
|
53
|
+
|
54
|
+
Dir.chdir('doc') do
|
55
|
+
system 'git add .'
|
56
|
+
exit 1 unless $?.success?
|
57
|
+
system "git commit -m '#{msg_prefix} at Revision #{git_sha}'"
|
58
|
+
# Do not check status of commit, as it will error if there are no changes.
|
59
|
+
system 'git push origin gh-pages -f'
|
60
|
+
exit 1 unless $?.success?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'Update docs on the gh-pages branch and push to GitHub.'
|
65
|
+
task update: %i[
|
66
|
+
checkout
|
67
|
+
strings:generate
|
68
|
+
configure
|
69
|
+
push
|
70
|
+
]
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
namespace :strings do
|
7
|
+
namespace :validate do
|
8
|
+
desc 'Validate the reference is up to date'
|
9
|
+
task :reference, [:patterns, :debug, :backtrace] do |_t, args|
|
10
|
+
filename = 'REFERENCE.md'
|
11
|
+
|
12
|
+
unless File.exist?(filename)
|
13
|
+
warn "#{filename} does not exist"
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
|
17
|
+
patterns = args[:patterns]
|
18
|
+
patterns = patterns.split if patterns
|
19
|
+
patterns ||= OpenvoxStrings::DEFAULT_SEARCH_PATTERNS
|
20
|
+
|
21
|
+
generated = Tempfile.create do |file|
|
22
|
+
options = {
|
23
|
+
debug: args[:debug] == 'true',
|
24
|
+
backtrace: args[:backtrace] == 'true',
|
25
|
+
json: false,
|
26
|
+
markdown: true,
|
27
|
+
path: file
|
28
|
+
}
|
29
|
+
OpenvoxStrings.generate(patterns, options)
|
30
|
+
|
31
|
+
file.read
|
32
|
+
end
|
33
|
+
|
34
|
+
existing = File.read(filename)
|
35
|
+
|
36
|
+
if generated != existing
|
37
|
+
warn "#{filename} is outdated; to regenerate: bundle exec rake strings:generate:reference"
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/tasklib'
|
5
|
+
|
6
|
+
# Ensure OpenvoxStrings is loaded.
|
7
|
+
module OpenvoxStrings end
|
8
|
+
|
9
|
+
# The module for Puppet Strings rake tasks.
|
10
|
+
module OpenvoxStrings::Tasks
|
11
|
+
require 'openvox-strings/tasks/generate'
|
12
|
+
require 'openvox-strings/tasks/gh_pages'
|
13
|
+
require 'openvox-strings/tasks/validate'
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Implements the base code object.
|
4
|
+
class OpenvoxStrings::Yard::CodeObjects::Base < YARD::CodeObjects::NamespaceObject
|
5
|
+
# Allocates a new code object.
|
6
|
+
# @param [Array] args The arguments to initialize the code object with.
|
7
|
+
# @return Returns the code object.
|
8
|
+
def self.new(*args)
|
9
|
+
# Skip the super class' implementation because it detects :: in names and this will cause namespaces in the output we don't want
|
10
|
+
object = Object.class.instance_method(:new).bind_call(self, *args)
|
11
|
+
existing = YARD::Registry.at(object.path)
|
12
|
+
object = existing if existing.instance_of?(self)
|
13
|
+
yield(object) if block_given?
|
14
|
+
object
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/yard/code_objects/group'
|
4
|
+
|
5
|
+
# Implements the group for Puppet classes.
|
6
|
+
class OpenvoxStrings::Yard::CodeObjects::Classes < OpenvoxStrings::Yard::CodeObjects::Group
|
7
|
+
# Gets the singleton instance of the group.
|
8
|
+
# @return Returns the singleton instance of the group.
|
9
|
+
def self.instance
|
10
|
+
super(:puppet_classes)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Gets the display name of the group.
|
14
|
+
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
|
15
|
+
# @return [String] Returns the display name of the group.
|
16
|
+
def name(_prefix = false)
|
17
|
+
'Puppet Classes'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Implements the Puppet class code object.
|
22
|
+
class OpenvoxStrings::Yard::CodeObjects::Class < OpenvoxStrings::Yard::CodeObjects::Base
|
23
|
+
attr_reader :statement, :parameters
|
24
|
+
|
25
|
+
# Initializes a Puppet class code object.
|
26
|
+
# @param [OpenvoxStrings::Parsers::ClassStatement] statement The class statement that was parsed.
|
27
|
+
# @return [void]
|
28
|
+
def initialize(statement)
|
29
|
+
@statement = statement
|
30
|
+
@parameters = statement.parameters.map { |p| [p.name, p.value] }
|
31
|
+
super(OpenvoxStrings::Yard::CodeObjects::Classes.instance, statement.name)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Gets the type of the code object.
|
35
|
+
# @return Returns the type of the code object.
|
36
|
+
def type
|
37
|
+
:puppet_class
|
38
|
+
end
|
39
|
+
|
40
|
+
# Gets the source of the code object.
|
41
|
+
# @return Returns the source of the code object.
|
42
|
+
def source
|
43
|
+
@statement.source
|
44
|
+
end
|
45
|
+
|
46
|
+
# Converts the code object to a hash representation.
|
47
|
+
# @return [Hash] Returns a hash representation of the code object.
|
48
|
+
def to_hash
|
49
|
+
hash = {}
|
50
|
+
hash[:name] = name
|
51
|
+
hash[:file] = file
|
52
|
+
hash[:line] = line
|
53
|
+
hash[:inherits] = statement.parent_class if statement.parent_class
|
54
|
+
hash[:docstring] = OpenvoxStrings::Yard::Util.docstring_to_hash(docstring)
|
55
|
+
defaults = Hash[*parameters.reject { |p| p[1].nil? }.flatten]
|
56
|
+
hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
|
57
|
+
hash[:source] = source unless source.nil? || source.empty?
|
58
|
+
hash
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/yard/code_objects/group'
|
4
|
+
require 'openvox-strings/yard/util'
|
5
|
+
|
6
|
+
# Implements the group for Puppet DataTypes.
|
7
|
+
class OpenvoxStrings::Yard::CodeObjects::DataTypes < OpenvoxStrings::Yard::CodeObjects::Group
|
8
|
+
# Gets the singleton instance of the group.
|
9
|
+
# @return Returns the singleton instance of the group.
|
10
|
+
def self.instance
|
11
|
+
super(:puppet_data_types)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Gets the display name of the group.
|
15
|
+
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
|
16
|
+
# @return [String] Returns the display name of the group.
|
17
|
+
def name(_prefix = false)
|
18
|
+
'Puppet Data Types'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Implements the Puppet DataType code object.
|
23
|
+
class OpenvoxStrings::Yard::CodeObjects::DataType < OpenvoxStrings::Yard::CodeObjects::Base
|
24
|
+
# Initializes a Puppet class code object.
|
25
|
+
# @param [String] The name of the Data Type
|
26
|
+
# @return [void]
|
27
|
+
def initialize(name)
|
28
|
+
super(OpenvoxStrings::Yard::CodeObjects::DataTypes.instance, name)
|
29
|
+
@defaults = {}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Gets the type of the code object.
|
33
|
+
# @return Returns the type of the code object.
|
34
|
+
def type
|
35
|
+
:puppet_data_type
|
36
|
+
end
|
37
|
+
|
38
|
+
# Gets the source of the code object.
|
39
|
+
# @return Returns the source of the code object.
|
40
|
+
def source
|
41
|
+
# Not implemented, but would be nice!
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_parameter(name, type, default)
|
46
|
+
tag = docstring.tags(:param).find { |item| item.name == name }
|
47
|
+
if tag.nil?
|
48
|
+
tag = YARD::Tags::Tag.new(:param, '', nil, name)
|
49
|
+
docstring.add_tag(tag)
|
50
|
+
end
|
51
|
+
type = [type] unless type.is_a?(Array)
|
52
|
+
tag.types = type if tag.types.nil?
|
53
|
+
set_parameter_default(name, default)
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_parameter_default(param_name, default)
|
57
|
+
defaults.delete(param_name)
|
58
|
+
defaults[param_name] = default unless default.nil?
|
59
|
+
end
|
60
|
+
|
61
|
+
def parameters
|
62
|
+
docstring.tags(:param).map { |tag| [tag.name, defaults[tag.name]] }
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_function(name, return_type, parameter_types)
|
66
|
+
meth_obj = YARD::CodeObjects::MethodObject.new(self, name, :class)
|
67
|
+
|
68
|
+
# Add return tag
|
69
|
+
meth_obj.add_tag(YARD::Tags::Tag.new(:return, '', return_type))
|
70
|
+
|
71
|
+
# Add parameters
|
72
|
+
parameter_types.each_with_index do |param_type, index|
|
73
|
+
meth_obj.add_tag(YARD::Tags::Tag.new(:param, '', [param_type], "param#{index + 1}"))
|
74
|
+
end
|
75
|
+
|
76
|
+
meths << meth_obj
|
77
|
+
end
|
78
|
+
|
79
|
+
def functions
|
80
|
+
meths
|
81
|
+
end
|
82
|
+
|
83
|
+
# Converts the code object to a hash representation.
|
84
|
+
# @return [Hash] Returns a hash representation of the code object.
|
85
|
+
def to_hash
|
86
|
+
hash = {}
|
87
|
+
hash[:name] = name
|
88
|
+
hash[:file] = file
|
89
|
+
hash[:line] = line
|
90
|
+
hash[:docstring] = OpenvoxStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example])
|
91
|
+
hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
|
92
|
+
hash[:source] = source unless source.nil? || source.empty?
|
93
|
+
hash[:functions] = functions.map do |func|
|
94
|
+
{
|
95
|
+
name: func.name,
|
96
|
+
signature: func.signature,
|
97
|
+
docstring: OpenvoxStrings::Yard::Util.docstring_to_hash(func.docstring, %i[param option enum return example])
|
98
|
+
}
|
99
|
+
end
|
100
|
+
hash
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/yard/code_objects/group'
|
4
|
+
require 'openvox-strings/yard/util'
|
5
|
+
|
6
|
+
# Implements the group for Puppet DataTypeAliases.
|
7
|
+
class OpenvoxStrings::Yard::CodeObjects::DataTypeAliases < OpenvoxStrings::Yard::CodeObjects::Group
|
8
|
+
# Gets the singleton instance of the group.
|
9
|
+
# @return Returns the singleton instance of the group.
|
10
|
+
def self.instance
|
11
|
+
super(:puppet_data_type_aliases)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Gets the display name of the group.
|
15
|
+
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
|
16
|
+
# @return [String] Returns the display name of the group.
|
17
|
+
def name(_prefix = false)
|
18
|
+
'Puppet Data Type Aliases'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Implements the Puppet DataTypeAlias code object.
|
23
|
+
class OpenvoxStrings::Yard::CodeObjects::DataTypeAlias < OpenvoxStrings::Yard::CodeObjects::Base
|
24
|
+
attr_reader :statement
|
25
|
+
attr_accessor :alias_of
|
26
|
+
|
27
|
+
# Initializes a Puppet data type alias code object.
|
28
|
+
# @param [OpenvoxStrings::Parsers::DataTypeAliasStatement] statement The data type alias statement that was parsed.
|
29
|
+
# @return [void]
|
30
|
+
def initialize(statement)
|
31
|
+
@statement = statement
|
32
|
+
@alias_of = statement.alias_of
|
33
|
+
super(OpenvoxStrings::Yard::CodeObjects::DataTypeAliases.instance, statement.name)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Gets the type of the code object.
|
37
|
+
# @return Returns the type of the code object.
|
38
|
+
def type
|
39
|
+
:puppet_data_type_alias
|
40
|
+
end
|
41
|
+
|
42
|
+
# Gets the source of the code object.
|
43
|
+
# @return Returns the source of the code object.
|
44
|
+
def source
|
45
|
+
# Not implemented, but would be nice!
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
# Converts the code object to a hash representation.
|
50
|
+
# @return [Hash] Returns a hash representation of the code object.
|
51
|
+
def to_hash
|
52
|
+
hash = {}
|
53
|
+
hash[:name] = name
|
54
|
+
hash[:file] = file
|
55
|
+
hash[:line] = line
|
56
|
+
hash[:docstring] = OpenvoxStrings::Yard::Util.docstring_to_hash(docstring)
|
57
|
+
hash[:alias_of] = alias_of
|
58
|
+
hash
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/yard/code_objects/group'
|
4
|
+
|
5
|
+
# Implements the group for Puppet defined types.
|
6
|
+
class OpenvoxStrings::Yard::CodeObjects::DefinedTypes < OpenvoxStrings::Yard::CodeObjects::Group
|
7
|
+
# Gets the singleton instance of the group.
|
8
|
+
# @return Returns the singleton instance of the group.
|
9
|
+
def self.instance
|
10
|
+
super(:puppet_defined_types)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Gets the display name of the group.
|
14
|
+
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
|
15
|
+
# @return [String] Returns the display name of the group.
|
16
|
+
def name(_prefix = false)
|
17
|
+
'Defined Types'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Implements the Puppet defined type code object.
|
22
|
+
class OpenvoxStrings::Yard::CodeObjects::DefinedType < OpenvoxStrings::Yard::CodeObjects::Base
|
23
|
+
attr_reader :statement, :parameters
|
24
|
+
|
25
|
+
# Initializes a Puppet defined type code object.
|
26
|
+
# @param [OpenvoxStrings::Parsers::DefinedTypeStatement] statement The defined type statement that was parsed.
|
27
|
+
# @return [void]
|
28
|
+
def initialize(statement)
|
29
|
+
@statement = statement
|
30
|
+
@parameters = statement.parameters.map { |p| [p.name, p.value] }
|
31
|
+
super(OpenvoxStrings::Yard::CodeObjects::DefinedTypes.instance, statement.name)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Gets the type of the code object.
|
35
|
+
# @return Returns the type of the code object.
|
36
|
+
def type
|
37
|
+
:puppet_defined_type
|
38
|
+
end
|
39
|
+
|
40
|
+
# Gets the source of the code object.
|
41
|
+
# @return Returns the source of the code object.
|
42
|
+
def source
|
43
|
+
@statement.source
|
44
|
+
end
|
45
|
+
|
46
|
+
# Converts the code object to a hash representation.
|
47
|
+
# @return [Hash] Returns a hash representation of the code object.
|
48
|
+
def to_hash
|
49
|
+
hash = {}
|
50
|
+
hash[:name] = name
|
51
|
+
hash[:file] = file
|
52
|
+
hash[:line] = line
|
53
|
+
hash[:docstring] = OpenvoxStrings::Yard::Util.docstring_to_hash(docstring)
|
54
|
+
defaults = Hash[*parameters.reject { |p| p[1].nil? }.flatten]
|
55
|
+
hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
|
56
|
+
hash[:source] = source unless source.nil? || source.empty?
|
57
|
+
hash
|
58
|
+
end
|
59
|
+
end
|