Permalink
Browse files

zenify allows 4 different modes

  • Loading branch information...
1 parent efb77ae commit f2c57ac2dffd7e616e1121d35306d6a07a2766b8 @fmarcia committed May 25, 2010
Showing with 70 additions and 37 deletions.
  1. +24 −10 zencoding/html_navigation.py
  2. +1 −2 zencoding/my_zen_settings.py
  3. +43 −23 zencoding/plugin.py
  4. +2 −2 zencoding/zen_editor.py
@@ -224,7 +224,7 @@ def outer_bounds(self, offset_start, offset_end):
return None, None
- def zenify(self, content):
+ def zenify(self, content, mode):
result = ''
@@ -234,33 +234,47 @@ def zenify(self, content):
zen_id = ''
zen_class = ''
zen_children = []
+ zen_attributes = []
+
for child in self.children:
+
name = child.name.lower()
- if child.type == 'attribute' and name in ['id', 'class']:
+
+ if mode > 0 and child.type == 'attribute' and name in ['id', 'class']:
for grand_child in child.children:
if grand_child.type == 'value' and grand_child.start < grand_child.end and not grand_child.children:
if name == 'id':
zen_id = '#' + content[grand_child.start:grand_child.end]
elif name == 'class':
zen_class = '.' + '.'.join(filter(lambda s: s, re.split(' +', content[grand_child.start:grand_child.end])))
- if child.type in Node.tag_types_basic:
- zen_children.append(child.zenify(content))
- zen_children = filter(lambda s: s, zen_children)
+ elif mode > 1 and child.type == 'attribute':
+ for grand_child in child.children:
+ if grand_child.type == 'value' and grand_child.start < grand_child.end and not grand_child.children:
+ if mode == 2 or name.startswith('on'):
+ zen_attributes.append(name)
+ else:
+ zen_attributes.append(name + '="' + content[grand_child.start:grand_child.end] + '"')
- zen_children = factorize(zen_children)
+ elif child.type in Node.tag_types_basic:
+ zen_children.append(child.zenify(content, mode))
+ zen_children = factorize(zen_children)
if len(zen_children) == 0:
zen_children_string = ''
elif len(zen_children) == 1:
zen_children_string = '>' + zen_children[0]
else:
zen_children_string = '>(' + '+'.join(zen_children) + ')'
+ zen_attributes_string = ''
+ if zen_attributes:
+ zen_attributes_string = '[' + ' '.join(zen_attributes) + ']'
+
if zen_children_string:
- return '(' + self.name + zen_id + zen_class + zen_children_string + ')'
+ return '(' + self.name + zen_id + zen_class + zen_attributes_string + zen_children_string + ')'
else:
- return self.name + zen_id + zen_class
+ return self.name + zen_id + zen_class + zen_attributes_string
def show(self, level = 0):
children = ''
@@ -603,7 +617,7 @@ def outer_bounds(self, offset_start, offset_end, content):
return current.outer_bounds(offset_start, offset_end)
return None, None
- def zenify(self, offset_start, offset_end, content):
+ def zenify(self, offset_start, offset_end, content, mode = 3):
current_start = self._prepare(offset_start, offset_start, content)
while current_start.type not in Node.tag_types_basic:
@@ -648,7 +662,7 @@ def zenify(self, offset_start, offset_end, content):
result = []
for node in nodes:
- result.append(node.zenify(content))
+ result.append(node.zenify(content, mode))
result = factorize(result)
return '+'.join(result)
@@ -7,8 +7,7 @@
'html': {
'abbreviations': {
'jq': '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>',
- 'link:css': '<link rel="stylesheet" type="text/css" href="" media="all" />',
- 'meta': '<meta name="" content="" />'
+ 'link:css': '<link rel="stylesheet" type="text/css" href="" media="all" />'
},
'snippets': {
'dtdd': '<dt>${child}|</dt>\n<dd></dd>',
View
@@ -32,33 +32,40 @@
<menu name="EditMenu" action="Edit">
<placeholder name="EditOps_5">
<menu action="ZenCodingMenuAction">
- <menuitem name="ZenCodingExpand" action="ZenCodingExpandAction"/>
- <menuitem name="ZenCodingExpandW" action="ZenCodingExpandWAction"/>
- <menuitem name="ZenCodingWrap" action="ZenCodingWrapAction"/>
+ <menuitem name="ZenCodingExpand" action="ZenCodingExpandAction"/>
+ <menuitem name="ZenCodingExpandW" action="ZenCodingExpandWAction"/>
+ <menuitem name="ZenCodingWrap" action="ZenCodingWrapAction"/>
<separator/>
- <menuitem name="ZenCodingZenify" action="ZenCodingZenifyAction"/>
+ <placeholder name="EditOps_5">
+ <menu action="ZenCodingZenifyAction">
+ <menuitem name="ZenCodingZenify0" action="ZenCodingZenify0Action"/>
+ <menuitem name="ZenCodingZenify1" action="ZenCodingZenify1Action"/>
+ <menuitem name="ZenCodingZenify2" action="ZenCodingZenify2Action"/>
+ <menuitem name="ZenCodingZenify3" action="ZenCodingZenify3Action"/>
+ </menu>
+ </placeholder>
<separator/>
- <menuitem name="LoremIpsum" action="LoremIpsumAction"/>
+ <menuitem name="LoremIpsum" action="LoremIpsumAction"/>
<separator/>
- <menuitem name="ZenCodingInward" action="ZenCodingInwardAction"/>
- <menuitem name="ZenCodingOutward" action="ZenCodingOutwardAction"/>
+ <menuitem name="ZenCodingInward" action="ZenCodingInwardAction"/>
+ <menuitem name="ZenCodingOutward" action="ZenCodingOutwardAction"/>
<separator/>
- <menuitem name="ZenCodingPTag" action="ZenCodingPTagAction"/>
- <menuitem name="ZenCodingNTag" action="ZenCodingNTagAction"/>
- <menuitem name="ZenCodingPNode" action="ZenCodingPNodeAction"/>
- <menuitem name="ZenCodingNNode" action="ZenCodingNNodeAction"/>
- <menuitem name="ZenCodingPrev" action="ZenCodingPrevAction"/>
- <menuitem name="ZenCodingNext" action="ZenCodingNextAction"/>
+ <menuitem name="ZenCodingPTag" action="ZenCodingPTagAction"/>
+ <menuitem name="ZenCodingNTag" action="ZenCodingNTagAction"/>
+ <menuitem name="ZenCodingPNode" action="ZenCodingPNodeAction"/>
+ <menuitem name="ZenCodingNNode" action="ZenCodingNNodeAction"/>
+ <menuitem name="ZenCodingPrev" action="ZenCodingPrevAction"/>
+ <menuitem name="ZenCodingNext" action="ZenCodingNextAction"/>
<separator/>
- <menuitem name="ZenCodingSize" action="ZenCodingSizeAction"/>
- <menuitem name="ZenCodingData" action="ZenCodingDataAction"/>
+ <menuitem name="ZenCodingSize" action="ZenCodingSizeAction"/>
+ <menuitem name="ZenCodingData" action="ZenCodingDataAction"/>
<separator/>
- <menuitem name="ZenCodingMerge" action="ZenCodingMergeAction"/>
- <menuitem name="ZenCodingRemove" action="ZenCodingRemoveAction"/>
- <menuitem name="ZenCodingSplit" action="ZenCodingSplitAction"/>
- <menuitem name="ZenCodingComment" action="ZenCodingCommentAction"/>
+ <menuitem name="ZenCodingMerge" action="ZenCodingMergeAction"/>
+ <menuitem name="ZenCodingRemove" action="ZenCodingRemoveAction"/>
+ <menuitem name="ZenCodingSplit" action="ZenCodingSplitAction"/>
+ <menuitem name="ZenCodingComment" action="ZenCodingCommentAction"/>
<separator/>
- <menuitem name="ZenCodingSettings" action="ZenCodingSettingsAction"/>
+ <menuitem name="ZenCodingSettings" action="ZenCodingSettingsAction"/>
</menu>
</placeholder>
</menu>
@@ -75,7 +82,11 @@ def activate(self, window):
('ZenCodingExpandAction', None, '_Expand abbreviation', '<Ctrl>E', "Expand abbreviation to raw HTML/CSS", self.expand_abbreviation),
('ZenCodingExpandWAction', None, 'E_xpand with abbreviation...', '<Ctrl><Alt>E', "Type in an abbreviation to expand", self.expand_with_abbreviation),
('ZenCodingWrapAction', None, '_Wrap with abbreviation...', '<Ctrl><Shift>E', "Wrap with code expanded from abbreviation", self.wrap_with_abbreviation),
- ('ZenCodingZenifyAction', None, '_Zenify...', '<Ctrl><Alt>Z', "Reduce to abbreviation", self.zenify),
+ ('ZenCodingZenifyAction', None, '_Zenify', None, "Reduce to abbreviation", None),
+ ('ZenCodingZenify0Action', None, '_Tag names', '<Ctrl><Alt>Z', "Reduce to tag names only", self.zenify0),
+ ('ZenCodingZenify1Action', None, ' + _Ids and classes', None, "Reduce with ids and classes", self.zenify1),
+ ('ZenCodingZenify2Action', None, ' + All other _attributes', None, "Reduce with all attributes", self.zenify2),
+ ('ZenCodingZenify3Action', None, ' + _Values', None, "Reduce with all attributes and values", self.zenify3),
('LoremIpsumAction', None, '_Lorem ipsum...', '<Ctrl><Alt>X', "Insert a lorem ipsum string", self.lorem_ipsum),
('ZenCodingInwardAction', None, 'Select _inward', '<Ctrl><Alt>I', "Select inner tag's content", self.match_pair_inward),
('ZenCodingOutwardAction', None, 'Select _outward', '<Ctrl><Alt>O', "Select outer tag's content", self.match_pair_outward),
@@ -132,8 +143,17 @@ def expand_with_abbreviation(self, action, window):
def wrap_with_abbreviation(self, action, window):
self.editor.wrap_with_abbreviation(window)
- def zenify(self, action, window):
- self.editor.zenify(window)
+ def zenify0(self, action, window):
+ self.editor.zenify(window, 0)
+
+ def zenify1(self, action, window):
+ self.editor.zenify(window, 1)
+
+ def zenify2(self, action, window):
+ self.editor.zenify(window, 2)
+
+ def zenify3(self, action, window):
+ self.editor.zenify(window, 3)
def lorem_ipsum(self, action, window):
self.editor.lorem_ipsum(window)
View
@@ -347,10 +347,10 @@ def wrap_with_abbreviation(self, window):
#---------------------------------------------------------------------------------------
- def zenify(self, window):
+ def zenify(self, window, mode):
self.set_context(window)
offset_start, offset_end, content = self.prepare_nav(window)
- result = self.html_navigation.zenify(offset_start, offset_end, content)
+ result = self.html_navigation.zenify(offset_start, offset_end, content, mode)
if result:
self.save_selection()
self.prompt(result)

0 comments on commit f2c57ac

Please sign in to comment.