This repository has been archived by the owner on Jun 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_help.rb
146 lines (114 loc) · 3.8 KB
/
copy_help.rb
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
help_version = ARGV[0]
if (!help_version)
puts "USAGE: copy_help <version> (e.g. 1.0)"
exit
end
filename_friendly_help_version = help_version.gsub(".", "-")
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), *%w[engine]))
require 'fileutils'
require 'ansi'
require 'aresmush'
require 'erubis'
require 'rspec'
require 'rspec/core/rake_task'
require 'tempfile'
#require 'mongoid'
require_relative 'install/init_db.rb'
require_relative 'install/configure_game.rb'
require_relative 'plugins/help/helpers.rb'
def minimal_boot
bootstrapper = AresMUSH::Bootstrapper.new
bootstrapper.config_reader.load_game_config
AresMUSH::Global.plugin_manager.load_all
bootstrapper.help_reader.load_game_help
bootstrapper.db.load_config
end
class String
def titlecase
self.downcase.strip.gsub(/\b('?[a-z])/) { $1.capitalize }
end
end
def plugin_title(name)
return "AresCentral" if name == "arescentral"
return "IC Time" if name == "ictime"
return "OOC Time" if name == "ooctime"
return "FS3 Skills" if name == "fs3skills"
return "FS3 Combat" if name == "fs3combat"
name.titlecase
end
def format_help(msg, filename_friendly_help_version)
# Take escaped backslashes out of the equation for a moment because
# they throw the other formatters off.
msg = msg.gsub(/%\\/, "~ESCBS~")
# Do substitutions
msg = AresMUSH::SubstitutionFormatter.format(msg, false)
# Replace TOC
msg = msg.gsub("[[toc]]", "{% include toc.html %}")
# Unescape %'s
msg = msg.gsub("\\%", "%")
# Put the escaped backslashes back in.
msg = msg.gsub("~ESCBS~", "\\")
if (msg =~ /\]\(\/help\/([^\)]+)\)/)
match = $1
topic_name = AresMUSH::Help.find_topic(match).first
topic = AresMUSH::Help.topic_index[topic_name]
if (!topic)
raise "Can't find topic #{match} in #{msg}"
end
msg = msg.gsub(/\]\(\/help\/([^\)]+)\)/, "](/help/#{filename_friendly_help_version}/#{topic['plugin']}/#{topic['topic']})")
end
msg
end
minimal_boot
docs_dir = "/Users/lynn/Documents/ares-docs/"
help_dir = "#{docs_dir}/help/"
if (!Dir.exist?(help_dir))
Dir.mkdir help_dir
end
plugins = Dir['plugins/*']
plugin_names = []
toc_topics = {}
AresMUSH::Help.toc.keys.sort.each do |toc|
toc_topics[toc] = AresMUSH::Help.toc_section_topic_data(toc)
end
File.open("#{help_dir}/index.md", 'w') do |file|
file.puts "---"
file.puts "title: Game Help Files - Version #{help_version}"
file.puts "description: Game Help."
file.puts "layout: page"
file.puts "tags:"
file.puts "- help-#{help_version}"
file.puts "---"
file.puts ""
file.puts "These are quick links to the game help files for the current version of AresMUSH."
file.puts ""
toc_topics.each do |toc, topics|
file.puts ""
file.puts "## #{toc}"
file.puts ""
topics.select { |name, data| data['tutorial'] }.sort_by { |name, data| [data['order'] || 99, name] }.each do |name, data|
file.puts "* [#{name.humanize}](https://mush.aresmush.com/help/#{data['topic']})"
end
commands = topics.select { |name, data| !data['tutorial'] }
.sort_by { |name, data| [data['order'] || 99, name] }
.map { |name, data| "[#{name.titleize}](https://mush.aresmush.com/help/#{data['topic']})" }
.join( " • " )
file.puts "\n*Commands*: #{commands}"
end
end
help_files = {
'plugins/login/help/en/privacy.md': "#{docs_dir}/game_privacy.md",
'plugins/manage/help/en/trouble_tutorial.md': "#{docs_dir}/tutorials/manage/trolls.md"
}
help_files.each do |src, dest|
puts "Copying files from #{src} to #{dest}"
orig = File.readlines src.to_s
orig.shift
orig.unshift "layout: help_page\n"
orig.unshift "---\n"
File.open(dest, 'w') do |f|
new_lines = orig.map { |o| format_help(o, filename_friendly_help_version)}
f.write new_lines.join
end
end
puts "Done!"