forked from telerik/ajax-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RakeFile
95 lines (77 loc) · 3.05 KB
/
RakeFile
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
task :build_inheritance do
require 'yaml'
config = YAML.load_file("helper_tools/build_inheritance.yml")
path = config["path"]
file_paths = config["files"]
override_inheritance = config["override_inheritance"]
override_slug = config["override_slug"]
title = "## Inheritance Hierarchy"
files = file_paths.empty? ? Dir[path + "/**/*.md"] : file_paths.collect{ |file| file = Dir[path + "/**/#{file}"].first }
files.each do |file|
content = File.read(file)
file_config = YAML.load(content)
generate_slug = file_config["slug"].nil? || override_slug
generate_inheritance = !content.include?(title) || override_inheritance
next unless generate_slug || generate_inheritance
if generate_slug
original_config = file_config.to_yaml
file_config["slug"] = file_config["title"]
content = content.gsub(original_config, file_config.to_yaml)
end
if generate_inheritance
heading = content[/#.*/]
classes = heading.split(':').collect{|value| value = value.sub(/^#/, "").strip.sub(/^enum/, "").strip.sub(/<.*>/, "").strip }
classes.reverse!
list = classes.collect{|item|
if !item[/^Sys/].nil?
item = "* #{item}"
elsif item == file_config["title"]
item = "* *[#{item}]({%slug #{item}%})*"
else
item = "* [#{item}]({%slug #{item}%})"
end
}
list = list.join("\n")
append_index = content.index(heading) + heading.length
content = content.insert(append_index, "\n\n#{title}\n\n#{list}")
end
File.write(file, content)
end
end
## Obsolete tasks
# task :xaml_docs do
# require "./helper_tools/submodules.rb"
# submodule = Submodule.new("xaml_docs", "./helper_tools/submodules.yml")
# submodule.init()
# submodule.update()
# submodule.map_folders()
# submodule.destroy()
# # replace all {% if site.site_name == 'WPF' %}
# # to {% if site.site_name == 'AJAX' %}
# original_regex = /{% if site.site_name == 'WPF' %}WPF|{% if site.site_name == 'WPF' %}/
# original_string = "{% if site.site_name == 'WPF' %}"
# replacement = "{% if site.site_name == 'AJAX' %}"
# # additionally, we need to change the page_title attributes of each article as per to our conventions
# mappings = [
# { folder: "controls/wordsprocessing", title_add: " | RadWordsProcessing for ASP.NET AJAX Documentation" },
# { folder: "controls/pdfprocessing", title_add: " | RadPdfProcessing for ASP.NET AJAX Documentation"},
# { folder: "controls/ziplibrary", title_add: " | RadZipLibrary for ASP.NET AJAX Documentation"},
# { folder: "controls/spreadprocessing", title_add: " | RadSpreadProcessing for ASP.NET AJAX Documentation"}
# ]
# mappings.each do |map|
# folder = map[:folder]
# files = Dir[folder + "/**/*.md"]
# files.each do |file|
# content = File.read(file)
# content = content.gsub(/page_title:.*/){ |match|
# match.rstrip + map[:title_add]
# }
# if content.include?(original_string)
# content = content.gsub(original_regex){ |match|
# match.end_with?("WPF") ? replacement + "AJAX" : replacement
# }
# end
# File.write(file, content)
# end
# end
# end