diff --git a/Main.sublime-menu b/Main.sublime-menu index 65787f2..e62fa30 100755 --- a/Main.sublime-menu +++ b/Main.sublime-menu @@ -1,113 +1,125 @@ [ -{ - "caption": "Edit", - "mnemonic": "E", - "id": "edit", - "children": - [ + { + "caption": "Edit", + "mnemonic": "E", + "id": "edit", + "children": [ - { - "caption": "Tag", - "id": "tag", - "children": - [ - {"caption":"-"}, + { + "caption": "Tag", + "id": "tag", + "children": [ + { + "caption": "-" + }, { "command": "tag_insert_as_tag", - "id":"tag-insert-as-tag", - "caption":"Insert as Tag" + "id": "tag-insert-as-tag", + "caption": "Insert as Tag" + }, + { + "command": "tag_classes", + "id": "tag-classes", + "caption": "Get CSS Classes" + }, + { + "caption": "-" }, - {"caption":"-"}, { "command": "tag_indent", - "id":"tag-indent-selection", - "caption":"Auto-Format Tags on Selection" + "id": "tag-indent-selection", + "caption": "Auto-Format Tags on Selection" }, { "command": "tag_indent_document", - "id":"tag-indent-document", - "caption":"Auto-Format Tags on Document" + "id": "tag-indent-document", + "caption": "Auto-Format Tags on Document" + }, + { + "caption": "-" }, - {"caption":"-"}, { "command": "tag_remove_picked_in_selection", - "id":"tag-remove-picked-in-selection", - "caption":"Remove Picked Tags in Selection" + "id": "tag-remove-picked-in-selection", + "caption": "Remove Picked Tags in Selection" }, { "command": "tag_remove_picked_in_document", - "id":"tag-remove-picked-in-document", - "caption":"Remove Picked Tags in Document" + "id": "tag-remove-picked-in-document", + "caption": "Remove Picked Tags in Document" }, { "command": "tag_remove_all_in_selection", - "id":"tag-remove-all-in-selection", - "caption":"Remove All Tags in Selection" + "id": "tag-remove-all-in-selection", + "caption": "Remove All Tags in Selection" }, { "command": "tag_remove_all_in_document", - "id":"tag-remove-all-in-document", - "caption":"Remove All Tags in Document" + "id": "tag-remove-all-in-document", + "caption": "Remove All Tags in Document" + }, + { + "caption": "-" }, - {"caption":"-"}, { "command": "tag_remove_picked_attributes_in_selection", - "id":"tag-remove-picked-attributes-in-selection", - "caption":"Remove Picked Attributes From Tags in Selection" + "id": "tag-remove-picked-attributes-in-selection", + "caption": "Remove Picked Attributes From Tags in Selection" }, { "command": "tag_remove_picked_attributes_in_document", - "id":"tag-remove-picked-attributes-in-document", - "caption":"Remove Picked Attributes From Tags in Document" + "id": "tag-remove-picked-attributes-in-document", + "caption": "Remove Picked Attributes From Tags in Document" }, { "command": "tag_remove_all_attributes_in_selection", - "id":"tag-remove-all-attributes-in-selection", - "caption":"Remove All Attributes From Tags in Selection" + "id": "tag-remove-all-attributes-in-selection", + "caption": "Remove All Attributes From Tags in Selection" }, { "command": "tag_remove_all_attributes_in_document", - "id":"tag-remove-all-attributes-in-document", - "caption":"Remove All Attributes From Tags in Document" + "id": "tag-remove-all-attributes-in-document", + "caption": "Remove All Attributes From Tags in Document" + }, + { + "caption": "-" }, - {"caption":"-"}, { "command": "tag_lint", - "id":"tag-lint", - "caption":"Tag Lint" + "id": "tag-lint", + "caption": "Tag Lint" }, - {"caption":"-"} + { + "caption": "-" + } ] } ] }, - { + { "caption": "Preferences", "mnemonic": "n", "id": "preferences", - "children": - [ + "children": [ { "caption": "Package Settings", "mnemonic": "P", "id": "package-settings", - "children": - [ + "children": [ { "caption": "Tag", - "children": - [ + "children": [ { - "command": "open_file", "args": - { - "file": "${packages}/Tag/Tag Package.sublime-settings" + "command": "open_file", + "args": { + "file": "${packages}/Tag/Tag Package.sublime-settings" }, "caption": "Settings – Default" }, { - "command": "open_file", "args": - { - "file": "${packages}/User/Tag Package.sublime-settings" + "command": "open_file", + "args": { + "file": "${packages}/User/Tag Package.sublime-settings" }, "caption": "Settings – User" } @@ -117,4 +129,4 @@ } ] } -] +] \ No newline at end of file diff --git a/Tag Classes/Commands.sublime-commands b/Tag Classes/Commands.sublime-commands new file mode 100644 index 0000000..f85a241 --- /dev/null +++ b/Tag Classes/Commands.sublime-commands @@ -0,0 +1,6 @@ +[ + { + "caption": "Tag: Get CSS Classes", + "command": "tag_classes" + } +] \ No newline at end of file diff --git a/Tag Package.sublime-settings b/Tag Package.sublime-settings index def3936..19b8ff8 100755 --- a/Tag Package.sublime-settings +++ b/Tag Package.sublime-settings @@ -1,19 +1,17 @@ { /* TAG INDENT SETTINGS */ - // example:
- "empty_tags_close_on_same_line" : true, + // example:
+ "empty_tags_close_on_same_line": true, - // example:
this contains less than 80 characters
- "tags_with_little_content_on_same_line" : true, - "little_content_means_this_number_of_characters" : 60, + // example:
this contains less than 80 characters
+ "tags_with_little_content_on_same_line": true, + "little_content_means_this_number_of_characters": 60, - "preserve_additional_new_lines" : true, + "preserve_additional_new_lines": true, /* END TAG INDENT SETTINGS */ - - "enable_live_tag_linting": true, /* lint these documents */ @@ -24,5 +22,9 @@ ], //close tag on slash - "enable_close_tag_on_slash":true + "enable_close_tag_on_slash": true, + + //copy css classes to clipboard + "tag_classes_sort": false + } \ No newline at end of file diff --git a/tag_classes.py b/tag_classes.py new file mode 100644 index 0000000..7a1bada --- /dev/null +++ b/tag_classes.py @@ -0,0 +1,29 @@ +import sublime, sublime_plugin +import re + +class TagClassesCommand(sublime_plugin.TextCommand): + def run(self, edit): + data = '' + classes = [] + for region in self.view.sel(): + if region.empty(): + continue + data += self.view.substr(sublime.Region(region.begin(), region.end())) + + if not data: + data += self.view.substr(sublime.Region(0, self.view.size())) + + if data: + re_classes = (" ".join(re.compile('class="([^"]+)"').findall(data))).split() + for item in re_classes: + item = item.strip() + if '.'+item+' {}' not in classes: + classes.append('.'+item+' {}') + if classes: + s = sublime.load_settings('Tag Package.sublime-settings') + if s.get('tag_classes_sort', False): + classes.sort() + sublime.set_clipboard("\n".join(classes)) + sublime.status_message("CSS Classes Copied to Clipboard") + +