Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #8 from fpuc/slash

added conversion to slash
  • Loading branch information...
commit f8edc2c685a821b0fc611516e8821d5e59d62696 2 parents 4a3a18b + 19269c0
@jdc0589 authored
View
3  Default (Linux).sublime-keymap
@@ -4,5 +4,6 @@
{ "keys": ["ctrl+alt+c", "ctrl+alt+p"], "command": "convert_to_pascal"},
{ "keys": ["ctrl+alt+c", "ctrl+alt+d"], "command": "convert_to_dot"},
{ "keys": ["ctrl+alt+c", "ctrl+alt+h"], "command": "convert_to_dash"},
- { "keys": ["ctrl+alt+c", "ctrl+alt+w"], "command": "convert_to_separate_words"}
+ { "keys": ["ctrl+alt+c", "ctrl+alt+w"], "command": "convert_to_separate_words"},
+ { "keys": ["ctrl+alt+c", "ctrl+alt+/"], "command": "convert_to_slash"}
]
View
3  Default (OSX).sublime-keymap
@@ -4,5 +4,6 @@
{ "keys": ["ctrl+alt+c", "ctrl+alt+p"], "command": "convert_to_pascal"},
{ "keys": ["ctrl+alt+c", "ctrl+alt+d"], "command": "convert_to_dot"},
{ "keys": ["ctrl+alt+c", "ctrl+alt+h"], "command": "convert_to_dash"},
- { "keys": ["ctrl+alt+c", "ctrl+alt+w"], "command": "convert_to_separate_words"}
+ { "keys": ["ctrl+alt+c", "ctrl+alt+w"], "command": "convert_to_separate_words"},
+ { "keys": ["ctrl+alt+c", "ctrl+alt+/"], "command": "convert_to_slash"}
]
View
3  Default (Windows).sublime-keymap
@@ -4,5 +4,6 @@
{ "keys": ["ctrl+alt+c", "ctrl+alt+p"], "command": "convert_to_pascal"},
{ "keys": ["ctrl+alt+c", "ctrl+alt+d"], "command": "convert_to_dot"},
{ "keys": ["ctrl+alt+c", "ctrl+alt+h"], "command": "convert_to_dash"},
- { "keys": ["ctrl+alt+c", "ctrl+alt+w"], "command": "convert_to_separate_words"}
+ { "keys": ["ctrl+alt+c", "ctrl+alt+w"], "command": "convert_to_separate_words"},
+ { "keys": ["ctrl+alt+c", "ctrl+alt+/"], "command": "convert_to_slash"}
]
View
4 Default.sublime-commands
@@ -22,5 +22,9 @@
{
"caption": "Convert Case: separate␣words",
"command": "convert_to_separate_words"
+ },
+ {
+ "caption": "Convert Case: separate/with/slash",
+ "command": "convert_to_slash"
}
]
View
3  Main.sublime-menu
@@ -12,7 +12,8 @@
{ "command": "convert_to_pascal", "caption": "PascalCase" },
{ "command": "convert_to_dot", "caption": "dot.case" },
{ "command": "convert_to_dash", "caption": "dash-case" },
- { "command": "convert_to_separate_words", "caption": "separate␣words" }
+ { "command": "convert_to_separate_words", "caption": "separate␣words" },
+ { "command": "convert_to_slash", "caption": "separate/with/slash" }
]
}
]
View
22 case_conversion.py
@@ -9,6 +9,12 @@ def to_snake_case(text):
return text.lower()
return re.sub('(?<=[^_])([A-Z])', r'_\1', text).lower()
+def to_snake_case_graceful(text):
+ text = re.sub('[-. _]+', '_', text)
+ if text.isupper():
+ # Entirely uppercase; assume case is insignificant.
+ return text;
+ return re.sub('(?<=[^_])([A-Z])', r'_\1', text)
def strip_wrapping_underscores(text):
return re.sub("^(_*)(.*?)(_*)$", r'\2', text)
@@ -35,14 +41,21 @@ def to_dash_case(text):
return text.replace("_", "-")
+def to_slash(text):
+ return text.replace("_", "/")
+
+
def to_separate_words(text):
return text.replace("_", " ")
-def run_on_selections(view, edit, func):
+def run_on_selections(view, edit, func, no_lower=False):
for s in view.sel():
region = s if s else view.word(s)
- text = to_snake_case(view.substr(region))
+ if no_lower:
+ text = to_snake_case_graceful(view.substr(region))
+ else:
+ text = to_snake_case(view.substr(region))
text = strip_wrapping_underscores(text)
view.replace(edit, region, func(text))
@@ -75,3 +88,8 @@ def run(self, edit):
class ConvertToSeparateWords(sublime_plugin.TextCommand):
def run(self, edit):
run_on_selections(self.view, edit, to_separate_words)
+
+
+class ConvertToSlash(sublime_plugin.TextCommand):
+ def run(self, edit):
+ run_on_selections(self.view, edit, to_slash, True )
View
1  readme.md
@@ -9,6 +9,7 @@ camel, snake, dot, dash (hyphen) cases, and separated words.
- to dot.case: "ctrl+alt+c", "ctrl+alt+d"
- to dash-case: "ctrl+alt+c", "ctrl+alt+h"
- to separate words: "ctrl+alt+c", "ctrl+alt+w"
+- to seperate with slashes: "ctrl+alt+c", "ctrl+alt+/"
## Install
#### Git Clone
Please sign in to comment.
Something went wrong with that request. Please try again.