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
|
# File 'lib/magellan/cli/reference_generator.rb', line 46
def process(klass, filename, name = nil)
if cmd = klass.all_commands["help"]
cmd.description = I18n.t(:help, scope: [:base, :cmd])
end
rel_path = File.join(@subdir, filename)
path = File.expand_path(rel_path, @dest)
FileUtils.mkdir_p(File.dirname(path))
instance = klass.new
open(path, "w") do |f|
f.puts "---"
f.puts "layout: index"
version = Magellan::Cli::VERSION.split(/\./)[0,2].join(".")
f.puts "title: " << [name, "magellan-cli-#{version} (#{I18n.locale})", "Reference"].compact.join(" | ")
lang_links = I18n.available_locales.map do |locale|
(locale == I18n.locale) ? locale.to_s :
begin
path = rel_path.sub(/\/#{I18n.locale}\//, "/#{locale}/").sub(/\.md\z/, ".html")
%!<a href="/#{path}">#{locale}</a>!
end
end
f.puts %!breadcrumb: <a href="/">Top</a> / <a href="/reference">Reference</a> / <a href="/reference/magellan-cli/#{I18n.locale}">magellan-cli-#{version}</a> / #{name} #{lang_links.join(' ')}!
f.puts "---"
f.puts
f.puts "## "<< I18n.t(:commands, scope: :reference)
f.puts
klass.sorted_commands.each do |cmd|
rel_path =
Magellan::Cli::Resources::MAPPING.values.include?(cmd.name) ? "./resources/#{cmd.name}.html" :
Magellan::Cli::Messaging::MAPPING.values.include?(cmd.name) ? "./messaging/#{cmd.name}.html" : "##{cmd.name}"
f.puts "- [%s](%s)" % [Thor.send(:banner, cmd, false, false), rel_path]
end
f.puts
f.puts "## " << I18n.t(:global_options, scope: :reference)
f.puts
change_global_var_temporarily(["$stdout", f], ["$stderr", f]) do
f.puts "```text"
klass.send(:print_options, @shell, klass.class_options.values)
f.puts "```"
f.puts
end
f.puts
f.puts "## " << I18n.t(:details, scope: :reference)
klass.sorted_commands.each do |cmd|
next if Magellan::Cli::Resources::MAPPING.values.include?(cmd.name)
next if Magellan::Cli::Messaging::MAPPING.values.include?(cmd.name)
f.puts "### <a name=\"#{cmd.name}\"></a>#{cmd.name}"
f.puts
f.puts "```text"
f.puts Thor.send(:banner, cmd)
f.puts "```"
f.puts
unless cmd.options.empty?
change_global_var_temporarily(["$stdout", f], ["$stderr", f]) do
f.puts "```text"
klass.send(:print_options, @shell, cmd.options.values)
f.puts "```"
f.puts
end
end
if cmd.long_description
f.puts cmd.long_description
else
f.puts cmd.description
end
f.puts
end
end
end
|