diff options
| author | Brett Terpstra | 2011-12-21 17:24:15 -0600 |
|---|---|---|
| committer | Brett Terpstra | 2011-12-21 17:24:15 -0600 |
| commit | 6622502c015bbf00f9bca22e4f01f9cbc3d1539b (patch) | |
| tree | 24b70410d4d703fbf9a879a8627ee0a0c497410c | |
| parent | 4efb2328510bc44ca3e716b299f30a7cc6c30782 (diff) | |
| download | KeyBindings-6622502c015bbf00f9bca22e4f01f9cbc3d1539b.tar.bz2 | |
adding auto-documentation script
| -rwxr-xr-x | document_keybindings.rb | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/document_keybindings.rb b/document_keybindings.rb new file mode 100755 index 0000000..aa7ba8d --- /dev/null +++ b/document_keybindings.rb @@ -0,0 +1,126 @@ +#!/usr/bin/ruby +# encoding: utf-8 + +require 'rubygems' + +infile = File.new('DefaultKeyBinding.dict','r') +input = infile.read +infile.close + +output = '' +style =<<STYLE +<style> +table { margin-bottom:20px; border:none; width: 100%; } + +caption { text-align:left; padding:5px; font-weight:bold; border: dotted 1px #777;background:#eee; margin-bottom:10px } +td,th { font-weight:bold; padding:3px; border: solid 1px #ccc; padding:4px } +td:nth-child(1),td:nth-child(2),td:nth-child(3) { width:40px} +td:first-child {font-weight:bold !important} +td:last-child { font-weight:normal;width:auto } + +</style> + +STYLE + +intro =<<INTRO +DefaultKeyBindings.dict file (`~/Library/KeyBindings/DefaultKeyBindings.dict`) for Mac OS X, created by [Brett Terpstra][] and based heavily on work done by [Lri][lrikeys]. See Lri's [gists][lrigists] and [website][lriweb] for more coding madness. + +[lrikeys]: http://www.cs.helsinki.fi/u/lranta/keybindings/ +[lriweb]: http://www.cs.helsinki.fi/u/lranta/ +[lrigists]: https://gist.github.com/Lri +[brett terpstra]: http://brettterpstra.com + +This documentation is generated automatically from the comments and commands in the DefaultKeyBinding.dict file. The script `document_keybindings.rb` is free for use, but it's specifically designed for use with my formatting in the bindings plist (i.e. it's a little finicky). + +*Grouped items begin with the groups shortcut (if exists), followed by a subgroup (if exists) followed by the keys specified.* + +INTRO + +toplevel = [] + +level = 0 +prefix = false +group_command = '' +group_desc = '' +subgroup_command = '' +subgroup_desc = '' +desc = '' +command = '' +skip = false +note = '' + +def e_sh(str) + str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''") +end + +def translate_command(str) + str = str.gsub(/~/,'⌥').gsub(/@/,'⌘').gsub(/\$/,'⇧') + str = str.gsub('\Uf700','↑').gsub('\Uf701','↓').gsub('\UF703','→').gsub('\UF702','←') + str = str.gsub('\U0009','⇥').gsub('\U000D','↩').gsub('\U001B','⎋').gsub('\U000A','␍') + str = str.gsub(/([\[\]|])/,"\\\1") + str = str.gsub(/([A-Z])/,'⇧\\1').downcase + str +end + +input.split("\n").each {|line| + + if line =~ /^\s*$/ || line =~ /^\s*\/\/\s*(TODO)/ + next + elsif line =~ /^\s*\/\/\s*>\s*(.*)$/ + note += " " + $1 + elsif line =~ /^\s*\};\s*$/ + level -= 1 + if level == 1 + subgroup_command = '' + subgroup_desc = '' + output += "|||||\n" + elsif level == 0 + output += "[ #{group_desc} ]\n\n" + group_command = '' + group_desc = '' + end + next + elsif line =~ /^\s*\/\/\s*(.*)/ + desc = $1 + next + elsif line =~ /^\s*"([^"]+)"\s*=\s*\{.*?\/\/\s*(.*)/ + level += 1 + if level == 1 + group_command = translate_command($1) + group_desc = $2 + output += "\n|#{group_desc} (#{group_command})||||\n|:----:|:----:|:----:|:----|\n" + elsif level == 2 + subgroup_command = translate_command($1) + subgroup_desc = $2 + output += "|#{subgroup_desc} (#{subgroup_command})||| |\n" + else + prefix = $1 + end + next + elsif line =~ /^\s*"([^"]+)"\s*=\s*\(/ + command = translate_command($1) + if level == 0 + toplevel.push("|#{command}|#{desc}|\n") + else + command = prefix + "," + command if prefix + note = "(#{note})" if note != '' + output += "|#{group_command} |#{subgroup_command} |#{command} |#{desc} #{note}|\n" + end + note = '' + end +} +topoutput = "|General Commands||\n|Key|Function|\n|:----:|:----|\n" +toplevel.each {|line| + topoutput += line +} +topoutput += "[ General Commands ]\n\n" + +# output = style + topoutput + output +output = topoutput + output + +htmlout = %x{echo #{e_sh output}|/usr/local/bin/multimarkdown} + +outfile = File.new('readme.md','w') +outfile.puts intro +outfile.puts htmlout +outfile.close
\ No newline at end of file |
