@@ -42,4 +42,52 @@ task :xaml_docs do
42
42
File.write(file, content)
43
43
end
44
44
end
45
- end
45
+ end
46
+
47
+ task :build_inheritance do
48
+ require 'yaml'
49
+ config = YAML.load_file("helper_tools/build_inheritance.yml")
50
+ path = config["path"]
51
+ file_paths = config["files"]
52
+ override_inheritance = config["override_inheritance"]
53
+ override_slug = config["override_slug"]
54
+ title = "## Inheritance Hierarchy"
55
+
56
+ files = file_paths.empty? ? Dir[path + "/**/*.md"] : file_paths.collect{ |file| file = Dir[path + "/**/#{file}"].first }
57
+ files.each do |file|
58
+ content = File.read(file)
59
+ file_config = YAML.load(content)
60
+
61
+ generate_slug = file_config["slug"].nil? || override_slug
62
+ generate_inheritance = !content.include?(title) || override_inheritance
63
+
64
+ next unless generate_slug || generate_inheritance
65
+
66
+ if generate_slug
67
+ original_config = file_config.to_yaml
68
+ file_config["slug"] = file_config["title"]
69
+ content = content.gsub(original_config, file_config.to_yaml)
70
+ end
71
+
72
+ if generate_inheritance
73
+ heading = content[/#.*/]
74
+ classes = heading.split(':').collect{|value| value = value.sub(/^#/, "").strip.sub(/^enum/, "").strip.sub(/<.*>/, "").strip }
75
+ classes.reverse!
76
+ list = classes.collect{|item|
77
+ if !item[/^Sys/].nil?
78
+ item = "* #{item}"
79
+ elsif item == file_config["title"]
80
+ item = "* *[#{item}]({%slug #{item}%})*"
81
+ else
82
+ item = "* [#{item}]({%slug #{item}%})"
83
+ end
84
+ }
85
+
86
+ list = list.join("\n")
87
+ append_index = content.index(heading) + heading.length
88
+ content = content.insert(append_index, "\n\n#{title}\n\n#{list}")
89
+ end
90
+
91
+ File.write(file, content)
92
+ end
93
+ end
0 commit comments