示例#1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on Jun 19, 2009

@author: sergey
'''
import unittest
import sys
from zencoding import zen_core as zen, stparser

zen.update_settings(stparser.get_settings())

def expandAbbr(abbr, doc_type='html', profile_name='plain'):
	return zen.expand_abbreviation(abbr, doc_type, profile_name)

def extractAbbr(line):
	return zen.find_abbr_in_line(line, len(line))[0]


def wrap(abbr, content):
	return zen.wrap_with_abbreviation(abbr, content)


class Test(unittest.TestCase):
	
	def testAbbreviationWrap(self):
		self.assertEqual('<p class="test">hello world</p>', wrap('p.test', 'hello world'));
		self.assertEqual('<p></p><p class="test">hello world</p>', wrap('p+p.test', 'hello world'));
		self.assertEqual('<ul id="nav" class="simple"><li>hello world</li></ul>', wrap('ul#nav.simple>li', 'hello world'));
		self.assertEqual('<ul id="nav" class="simple"><li>hello world</li><li>hello world</li></ul>', wrap('ul#nav.simple>li*2', 'hello world'));
示例#2
0
import unittest

from zencoding import zen_core as zen
from zencoding import stparser

my_zen_settings = {
	'html': {
		'snippets': {
			'dol': '\\$db->connect()\n\t\\$\\$\\$more dollaz$'
		}
	}
}

zen.set_caret_placeholder('|')

zen.update_settings(stparser.get_settings(my_zen_settings))

def expandAbbr(abbr, doc_type='html', profile_name='plain'):
	return zen.expand_abbreviation(abbr, doc_type, profile_name)

def extractAbbr(line):
	return zen.extract_abbreviation(line)

class Test(unittest.TestCase):
	
	def testPlusOperator(self):
		self.assertEqual('<p></p><p></p>', expandAbbr('p+p'))
		self.assertEqual('<p></p><p></p>', expandAbbr('p+P'))
		self.assertEqual('<p class="name"></p><p></p><p></p>', expandAbbr('p.name+p+p'))
		
	def testChildOperator(self):
def load_settings():
    """
    Load zen coding's settings, combined with user-defined snippets
    """
    defaults = NSUserDefaults.standardUserDefaults()
    
    # Construct our initial settings dictionary
    objc_dict = defaults.objectForKey_('TEAZenSettings')
    if objc_dict is not None:
        user_settings = tea_utils.nsdict_to_pydict(objc_dict)
    else:
        user_settings = dict()
    
    # Add the CSS filter if we're adding a space after properties
    if defaults.boolForKey_('TEAZenAddSpaceCSSProperties'):
        user_settings['css'] = {'filters': 'html, fc'}
    
    # Check to see if we're converting user snippets to zen abbreviations
    convert_to_zen = defaults.boolForKey_('TEAConvertUserSnippetsToZen')
    if convert_to_zen:
        orig_date = os.path.getmtime(plist_path)
        
        need_reload = True
        
        # Does our cache path exist and is writable?
        cache_dir_exists = os.path.isdir(cache_folder)
        if not cache_dir_exists:
            # Attempt to create the cache folder
            try:
                os.makedirs(cache_folder, 0755)
                cache_dir_exists = True
            except os.error:
                NSLog('TEA Error: Cannot create zen coding cache path for user snippets')
        
        # In worst case scenario, we can't read or write to the cache file
        # so we'll need to read from preferences every time
        # This variable tracks the user snippets in case of that eventuality
        _data = None
        
        # check if cached file exists and up-to-date
        if cache_dir_exists and (not os.path.exists(cache_file) or \
           os.path.getmtime(cache_file) < orig_date):
            # need to reparse and cache data
            _data = _convert_user_snippets_to_zen_settings()
            try:
                fp = open(cache_file, 'wb')
                pickle.dump(_data, fp)
                fp.close()
            except IOError:
                NSLog('TEA Error: Zen user snippets cache file is not writable')
            need_reload = False
        
        if need_reload:
            try:
                fp = open(cache_file, 'rb')
                _data = pickle.load(fp)
                fp.close()
            except IOError:
                NSLog('TEA Error: Zen user snippets cache file is not readable')
        
        if _data is not None:
            # Add the settings to the user_settings dict
            user_settings.update(_data)
    
    # The settings dictionary is setup, return the full zen settings
    return stparser.get_settings(user_settings)