lib/ctioga2/commands/doc/html.rb in ctioga2-0.11 vs lib/ctioga2/commands/doc/html.rb in ctioga2-0.12

- old
+ new

@@ -87,10 +87,20 @@ # Ouputs HTML code to document all groups and commands def write_commands(opts, out = STDOUT) cmds, groups = @doc.documented_commands + if opts['snippets'] + require 'yaml' + snippets = begin + YAML.load(IO.readlines(opts['snippets']).join()) + rescue Exception => e + Log::error { "Failed to load snippets file '#{opts['snippets']}'\n => #{e.inspect}" } + {} + end + end + write_page_menu(opts, out) do |out| out.puts "<div class='quick-jump'>" out.puts "<h3>Quick jump</h3>" out.puts "<ul>\n" for g in groups @@ -118,9 +128,26 @@ out.puts "</p>" for cmd in commands out.puts out.puts command_documentation(cmd) + if snippets + snpts = snippets[cmd.name] + if snpts + str = "" + for k in snpts.keys.sort + s = snpts[k] + ln = s[:line].chomp + # if ln[-1] == '\\' + # ln = ln[0..-2] + # end + # Strip links from the line + ln.gsub!(/<a[^>]+>(.*?)<\/a>/) { || $1 } + str += "<pre class='#{s[:cls]}'><a href='#{k}'>#{ln}</a></pre>\n" + end + out.puts "<h5 id='#snippets-h5-#{cmd.name}' onclick='toggleExamples(this);'>Examples...</h5>\n<div id='#snippets-#{cmd.name}' class='snippets'>#{str}</div>" + end + end end end end end