├── .gitignore ├── Default.sublime-keymap ├── tomdoc.sublime-snippet ├── LICENSE ├── README.md └── tomdoc.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /Default.sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["ctrl+enter"], "command": "tomdoc"} 3 | ] 4 | -------------------------------------------------------------------------------- /tomdoc.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | ${9:'TomTomTomTom'} 12 | # 13 | # ${10:Returns the duplicated String}. 14 | ]]> 15 | tom 16 | 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2012 Vladimir Penkin 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## SublimeText package for generating TomDoc 2 | 3 | [TomDoc](http://tomdoc.org/) 4 | 5 | ### Installation 6 | 7 | ### Without package manager 8 | 9 | Go to your Sublime Text 2 Packages directory and clone the repository using the command below: 10 | 11 | git clone git@github.com:shell/sublime-tomdoc.git 12 | 13 | Don't forget to keep updating it, though! 14 | 15 | ### Usage 16 | 17 | Pressing **ctrl+enter** on the previous line of method definition 18 | 19 | def hello a, b 20 | end 21 | 22 | results 23 | 24 | # Public: Duplicate some text an arbitrary number of times. 25 | # 26 | # a - 27 | # b - 28 | # 29 | # Returns the duplicated String. 30 | def hello a, b 31 | 32 | end 33 | 34 | Works respectfully for all other supported constructions 35 | 36 | Type 'tom' and hit **TAB** to generate default TomDoc skeleton text. 37 | 38 | Support following constructions for TomDoc: 39 | 40 | * Method Documentation 41 | * Initialize method Documentation 42 | * Class/Module Documentation 43 | * Constants Documentation 44 | * Attributes 45 | 46 | 47 | ### Author 48 | 49 | Vladimir Penkin 50 | 51 | Credits to: 52 | 53 | * [Revath S Kumar](https://github.com/revathskumar/sublime-yardoc) 54 | * [Brandon Hilkert](https://github.com/brandonhilkert/tomdoc-sublime) 55 | 56 | Please see [licence](http://github.com/shell/sublime-tomdoc/blob/master/LICENSE) 57 | 58 | -------------------------------------------------------------------------------- /tomdoc.py: -------------------------------------------------------------------------------- 1 | import sublime_plugin 2 | import re 3 | 4 | class TomdocCommand(sublime_plugin.TextCommand): 5 | def run(self, edit): 6 | point = self.view.sel()[0].end() 7 | line = self.read_line(point + 1) 8 | if not self.check_doc(point): 9 | return 10 | doc = self.compose_doc(line, edit) 11 | self.view.insert(edit, point, doc) 12 | 13 | def check_doc(self,point): 14 | current_line = self.read_line(point) 15 | params_match = re.search('#[ ]+Public |#[ ]+Examples |#[ ]+Returns |#', current_line) 16 | if not params_match: 17 | return True 18 | return False 19 | 20 | # Returns skeleton for initialize method 21 | def initialize_doc(self, params_match, current_line): 22 | indent = self.get_indent(current_line) 23 | lines = [] 24 | lines.append(indent + "# Public: Initialize a Widget.") 25 | lines.append(indent + "#") 26 | params = [p.strip() for p in params_match.group(1).split(',') if len(p.strip()) > 0] 27 | for param in params: 28 | lines.append("%s# %s -" % (indent, param)) 29 | return "\r\n" + "\r\n".join(lines) 30 | 31 | # Returns skeleton for initialize method 32 | def method_doc(self,params_match,current_line): 33 | params = [p.strip() for p in params_match.group(1).split(',') if len(p.strip()) > 0] 34 | indent = self.get_indent(current_line) 35 | lines = [] 36 | lines.append(indent + "# Public: Duplicate some text an arbitrary number of times.") 37 | lines.append(indent + "#") 38 | for param in params: 39 | lines.append("%s# %s -" % (indent, param)) 40 | if len(params) > 0: 41 | lines.append(indent + "#") 42 | lines.append(indent + "# Returns the duplicated String.") 43 | return "\r\n" + "\r\n".join(lines) 44 | 45 | 46 | # Returns skeleton for Class/Module 47 | def class_doc(self, params_match, current_line): 48 | indent = self.get_indent(current_line) 49 | lines = [] 50 | lines.append(indent + "# Public: Various methods useful for performing mathematical operations.") 51 | lines.append(indent + "# All methods are module methods and should be called on the Math module.") 52 | lines.append(indent + "#") 53 | return "\r\n" + "\r\n".join(lines) 54 | 55 | # Returns skeleton for constant def 56 | # Example: 57 | # # Public: Integer number of seconds to wait before connection timeout. 58 | def const_doc(self, params_match, current_line): 59 | indent = self.get_indent(current_line) 60 | lines = [] 61 | lines.append(indent + "# Public: Integer number of seconds to wait before connection timeout.") 62 | return "\r\n" + "\r\n".join(lines) 63 | 64 | # Returns skeleton for attributes def 65 | # Example: 66 | # attr_reader - # Public: Returns the String name of the user. 67 | # attr_writer - # Public: Sets the String name of the user. 68 | # attr_accessor - # Public: Gets/Sets the String name of the user. 69 | # # Public: Returns the String name of the user. 70 | def attributes_doc(self, params_match, current_line): 71 | indent = self.get_indent(current_line) 72 | lines = [] 73 | param = params_match.group(0).strip() 74 | if param == 'attr_reader': 75 | lines.append(indent + "# Public: Returns the String name of the user.") 76 | elif param == 'attr_writer': 77 | lines.append(indent + "# Public: Sets the String name of the user.") 78 | elif param == 'attr_accessor': 79 | lines.append(indent + "# Public: Gets/Sets the String name of the user.") 80 | return "\r\n" + "\r\n".join(lines) 81 | 82 | def compose_doc(self,current_line, edit): 83 | # Method definition 84 | params_match = re.search('def +[^ (]+[ (]*([^)]*)\)?', current_line) 85 | if params_match: 86 | if re.search('def initialize*', current_line): 87 | return self.initialize_doc(params_match, current_line) 88 | else: 89 | return self.method_doc(params_match, current_line) 90 | 91 | # Class/Module definition 92 | params_match = re.search('class | module', current_line) 93 | if params_match: 94 | return self.class_doc(params_match, current_line) 95 | 96 | # Constant definition definition 97 | params_match = re.search('[A-Z]+[ ]+=', current_line) 98 | if params_match: 99 | return self.const_doc(params_match, current_line) 100 | 101 | # Attributes definition 102 | # attr_reader, attr_writer, and attr_accessor 103 | params_match = re.search('attr_reader | attr_writer | attr_accessor ', current_line) 104 | if params_match: 105 | return self.attributes_doc(params_match, current_line) 106 | 107 | # Returns current indent 108 | def get_indent(self, line): 109 | return re.search('(^ *)', line).group(0) 110 | 111 | def read_line(self, point): 112 | if (point >= self.view.size()): 113 | return 114 | 115 | next_line = self.view.line(point) 116 | return self.view.substr(next_line) 117 | --------------------------------------------------------------------------------