Permalink
Browse files

adding files

  • Loading branch information...
1 parent 400f0a8 commit 4ebf41ad1212f72d933f36c360e86759551f8c40 @aroscoe committed May 29, 2012
Showing with 59 additions and 0 deletions.
  1. +3 −0 Default (Linux).sublime-keymap
  2. +3 −0 Default (OSX).sublime-keymap
  3. +3 −0 Default (Windows).sublime-keymap
  4. +35 −0 Hex-to-RGBA.py
  5. +15 −0 Main.sublime-menu
@@ -0,0 +1,3 @@
+[
+ { "keys": ["shift+ctrl+r"], "command": "hex_to_rgba" }
+]
@@ -0,0 +1,3 @@
+[
+ { "keys": ["shift+super+r"], "command": "hex_to_rgba" }
+]
@@ -0,0 +1,3 @@
+[
+ { "keys": ["shift+ctrl+r"], "command": "hex_to_rgba" }
+]
View
@@ -0,0 +1,35 @@
+import sublime, sublime_plugin, re, string
+
+class HexToRGBACommand(sublime_plugin.TextCommand):
+ def run(self, edit):
+ for selection in self.view.sel():
+ word_region = self.view.word(selection)
+ if not word_region.empty():
+ rgba_css = self.convert_to_rgba_css(word_region)
+ if rgba_css:
+ if (self.view.substr(word_region.begin()-1) == "#"):
+ tmp_region = sublime.Region(word_region.begin()-1, word_region.end())
+ self.view.replace(edit, tmp_region, rgba_css)
+ elif (self.view.substr(word_region.begin()) == "#"):
+ tmp_region = sublime.Region(word_region.begin(), word_region.end())
+ self.view.replace(edit, tmp_region, rgba_css)
+ else:
+ print 'false'
+
+ def hex_to_rgba(self, value):
+ value = value.lstrip('#')
+ lv = len(value)
+ return tuple(int(value[i:i+lv/3], 16) for i in range(0, lv, lv/3))+(1,)
+
+ def convert_to_rgba_css(self, word_region):
+ word = self.view.substr(word_region)
+
+ re_hex_color = re.compile('#?([0-9a-fA-F]{3}([0-9a-fA-F]{3})?){1}$')
+ match = re_hex_color.match(word)
+
+ if match:
+ rgba = self.hex_to_rgba(word)
+ rgba_css = 'rgba(%s,%s,%s,%s)' % rgba
+ return rgba_css
+
+ return False
View
@@ -0,0 +1,15 @@
+[
+ {
+ "id": "edit",
+ "children":
+ [
+ {
+ "id": "hextorgba"
+ },
+ {
+ "command": "hex_to_rgba",
+ "caption": "Convert Hex to RGBA"
+ }
+ ]
+ }
+]

0 comments on commit 4ebf41a

Please sign in to comment.