Skip to content

Commit ce35f62

Browse files
committed
Added rake task to build client-side api inheritance.
1 parent 0d51158 commit ce35f62

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

RakeFile

+49-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,52 @@ task :xaml_docs do
4242
File.write(file, content)
4343
end
4444
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

helper_tools/build_inheritance.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
path: "api/client"
2+
files: []
3+
override_inheritance: false
4+
override_slug: false

0 commit comments

Comments
 (0)