Created
May 3, 2012 23:47
-
-
Save zszugyi/2590494 to your computer and use it in GitHub Desktop.
sublime text 2 plugin that adds yard docs to the selected Ruby or Python methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sublime, sublime_plugin | |
| import re | |
| class AddYardDocs(sublime_plugin.TextCommand): | |
| def run(self, edit): | |
| for selection in reversed(self.view.sel()): | |
| current_line_region = self.view.line(selection) | |
| current_line = self.view.substr(current_line_region) | |
| if 'def ' not in current_line: | |
| continue | |
| params_match = re.search('\((.*)\)', current_line) | |
| params = [p.strip() for p in params_match.group(1).split(',')] | |
| indent = re.search('(^ *)', current_line).group(0) | |
| lines = ["%s# @param [] %s" % (indent, param) for param in params] | |
| lines.insert(0, indent + "# ") | |
| lines.append(indent + "# @return ") | |
| # TODO: get the line ending from sublime | |
| comment = "\r\n".join(lines) + "\r\n" | |
| self.view.insert(edit, current_line_region.begin(), comment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment