Skip to content

Instantly share code, notes, and snippets.

@Lawouach
Last active January 30, 2017 16:28
Show Gist options
  • Save Lawouach/c888885e2efbb2aa629da23d2abef831 to your computer and use it in GitHub Desktop.
Save Lawouach/c888885e2efbb2aa629da23d2abef831 to your computer and use it in GitHub Desktop.
Suffixes Python class name with Rug
# -*- coding: utf-8 -*-
from typing import Dict, Any
__all__ = ["editor"]
def edit(project: Any, params: Dict[str, str]) -> Dict[str, str]:
"""
Update each class name of a project with a new suffix.
"""
eng = project.context().pathExpressionEngine()
res = eng.evaluate(project, "/*//PythonRawFile()//classdef()/NAME")
for match in res.matches():
match.update(match.value() + params['class_suffix'])
return {"status":"OK", "message": "Suffix added to all your classes"}
editor = {
"tags": ["python"],
"name": "SuffixClassName",
"description": "Suffixes Python class names",
"parameters": [
{
"required": True,
"description": "the suffix value",
"displayName": "Suffix to append",
"displayable": True,
"validInput": "the suffix value",
"pattern": "^[\\w]*$",
"minLength": 1,
"name": "class_suffix"
}
],
"edit": edit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment