Skip to content

Commit

Permalink
Merge pull request #34 from lordfuoco/master
Browse files Browse the repository at this point in the history
Added conversion between Camel Case and Dash
  • Loading branch information
akalongman authored Jan 24, 2017
2 parents 2926133 + 9535eba commit 4d64de5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions Context.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{ "command": "convert_html_to_chars", "caption" : "Convert HTML Entities to Chars" },
{ "caption": "-" },
{ "command": "convert_camel_underscores", "caption" : "Convert camelCase <-> Underscores" },
{ "command": "convert_camel_dash", "caption" : "Convert camelCase <-> Dash" },
{ "command": "convert_pascal_underscores", "caption" : "Convert PascalCase <-> Underscores" },
{ "caption": "-" },
{ "command": "convert_single_quotes_to_double", "caption" : "Convert Single Quotes To Double" },
Expand Down
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"caption": "String Utilities: Convert camelCase <-> Underscores",
"command": "convert_camel_underscores"
},
{
"caption": "String Utilities: Convert camelCase <-> Dash",
"command": "convert_camel_dash"
},
{
"caption": "String Utilities: Convert PascalCase <-> Underscores",
"command": "convert_pascal_underscores"
Expand Down
16 changes: 16 additions & 0 deletions stringutilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ def toUnderscores(self, name):
def toCamelCase(self, name):
return ''.join(ch.capitalize() if i > 0 else ch for i, ch in enumerate(name.split('_')))

class ConvertCamelDashCommand(sublime_plugin.TextCommand):
#Convert camelCase to dash and vice versa
def run(self, edit):
for region in self.view.sel():
if not region.empty():
text = self.view.substr(region)
text = self.toCamelCase(text) if '-' in text and text[0].islower() else (text[0].islower() and self.toDash(text))
self.view.replace(edit, region, text)

def toDash(self, name):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1-\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1-\2', s1).lower()

def toCamelCase(self, name):
return ''.join(ch.capitalize() if i > 0 else ch for i, ch in enumerate(name.split('-')))


class ConvertPascalUnderscoresCommand(sublime_plugin.TextCommand):
#Convert PascalCase to under_scores and vice versa
Expand Down

0 comments on commit 4d64de5

Please sign in to comment.