-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfunctions.rb
More file actions
58 lines (51 loc) · 2.28 KB
/
functions.rb
File metadata and controls
58 lines (51 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
# frozen_string_literal: true
require 'puppet_references'
require 'json'
require 'erb'
require 'ostruct'
require 'pathname'
module PuppetReferences
module Puppet
class Functions < PuppetReferences::Reference
TEMPLATE_FILE = Pathname.new(File.expand_path(__FILE__)).dirname + 'functions_template.erb'
OUTPUT_DIR = PuppetReferences::OUTPUT_DIR + 'openvox'
PREAMBLE_FILE = Pathname.new(File.expand_path(__FILE__)).dirname + 'functions_preamble.md'
PREAMBLE = PREAMBLE_FILE.read
def initialize(*)
@latest = '/openvox/latest'
super
end
def build_all
build_variant('function.md')
end
def build_variant(filename, preferred_version = 'ruby4x')
OUTPUT_DIR.mkpath
puts "Functions ref (#{filename}): Building"
strings_data = PuppetReferences::Puppet::Strings.new
functions = strings_data['puppet_functions']
header_data = { title: 'Built-in function reference',
canonical: "#{@latest}/function.html",
toc_levels: 2,
toc: 'columns', }
# Deal with the duplicate function stub situation.
# 1. Figure out which functions are duplicated.
names = functions.map { |func| func['name'] }
duplicates = names.uniq.select { |name| names.count(name) > 1 }
# 2. Reject the unpreferred version of any dupes.
functions = functions.reject do |func|
duplicates.include?(func['name']) && func['type'] != preferred_version
end
body = ERB.new(File.read(TEMPLATE_FILE), trim_mode: '-').result_with_hash(functions: functions)
# This substitution could potentially make things a bit brittle, but it has to be done because the jump
# From H2s to H4s is causing issues with the DITA-OT, which sees this as a rule violation. If it
# Does become an issue, we should return to this and figure out a better way to generate the functions doc.
content = make_header(header_data) + "\n\n" + PREAMBLE + "\n\n" + body.gsub(/#####\s(.*?:)/, '**\1**').gsub(
/####\s/, '###\s'
)
output_path = OUTPUT_DIR + filename
output_path.open('w') { |f| f.write(content) }
puts "Functions ref (#{filename}): Done!"
end
end
end
end