当前位置: 首页>>代码示例>>Python>>正文


Python csspacker.CSSPacker类代码示例

本文整理汇总了Python中csspacker.CSSPacker的典型用法代码示例。如果您正苦于以下问题:Python CSSPacker类的具体用法?Python CSSPacker怎么用?Python CSSPacker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CSSPacker类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_function_from_file

	def make_function_from_file(self,path,file):
		fp = os.path.splitext(path)
		basename = fp[0].replace(' ','_').replace('/','_').replace('-','_').replace('.','_').replace('+','_')
		ext = fp[1][1:]

		filetype = ''
		contents = ''

		if ext=='html':
			filetype = 'page'
		elif ext=='css':
			filetype = 'style'
		elif ext=='js':
			filetype = 'script'	

		file_contents = open(os.path.expanduser(file)).read()

		# minimize javascript, css files
		if ext == 'js':
			file_contents = jspacker.jsmin(file_contents)
			self.compile_js(file_contents)
		elif ext == 'css':
			packer = CSSPacker(file_contents)
			file_contents = packer.pack()

		data = str(file_contents).encode("hex")
		method = "dataWithHexString(@\"%s\")" % data
		return {'method':method,'path':path}
开发者ID:armsteadj1,项目名称:LevidTitanium,代码行数:28,代码来源:compiler.py

示例2: make_function_from_file

	def make_function_from_file(self,file):
	
		fp = os.path.splitext(file)
		ext = fp[1][1:]

		thefile = os.path.expanduser(file)
		file_contents = open(thefile).read()
		save_off = False
		parse_modules = True

		# minimize javascript, css files
		if ext == 'js':
			file_contents = jspacker.jsmin(file_contents)
			save_off = True
		elif ext == 'css':
			packer = CSSPacker(file_contents)
			file_contents = packer.pack()
			save_off = True
			parse_modules = False

		if save_off:
				of = open(thefile,'w')
				of.write(file_contents)
				of.close()
				print "[DEBUG] compressing: %s" % thefile
		
		if parse_modules:
			# determine which modules this file is using
			self.extract_modules(file_contents)
开发者ID:GCrean,项目名称:titanium_mobile,代码行数:29,代码来源:compiler.py

示例3: add_compiled_resources

		def add_compiled_resources(source,target):
			print "[DEBUG] copy resources from %s to %s" % (source,target)
			compiled_targets = {}
			for root, dirs, files in os.walk(source):
				for name in ignoreDirs:
					if name in dirs:
						dirs.remove(name)	# don't visit ignored directories			  
				for file in files:
					if file in ignoreFiles:
						continue					
					prefix = root[len(source):]
					from_ = os.path.join(root, file)			  
					to_ = os.path.expanduser(from_.replace(source, target, 1))
					to_directory = os.path.expanduser(os.path.split(to_)[0])
					if not os.path.exists(to_directory):
						os.makedirs(to_directory)
					fp = os.path.splitext(file)
					ext = fp[1]
					if ext == '.jss': continue
					if len(fp)>1 and write_routing and ext in ['.html','.js','.css']:
						path = prefix + os.sep + file
						path = path[1:]
						entry = {'path':path,'from':from_,'to':to_}
						if compiled_targets.has_key(ext):
							compiled_targets[ext].append(entry)
						else:
							compiled_targets[ext]=[entry]
					else:
						# only copy if different filesize or doesn't exist
						if not os.path.exists(to_) or os.path.getsize(from_)!=os.path.getsize(to_):
							print "[DEBUG] copying: %s to %s" % (from_,to_)
							shutil.copyfile(from_, to_)	
		
			if compiled_targets.has_key('.html'):
				compiled = self.process_html_files(compiled_targets,source)
				if len(compiled) > 0:
					for c in compiled:
						from_ = c['from']
						to_ = c['to']
						path = c['path']
						print "[DEBUG] copying: %s to %s" % (from_,to_)
						file_contents = open(from_).read()
						file_contents = jspacker.jsmin(file_contents)
						file_contents = file_contents.replace('Titanium.','Ti.')
						to = open(to_,'w')
						to.write(file_contents)
						to.close()
						
			for ext in ('.css','.html'):
				if compiled_targets.has_key(ext):
					for css_file in compiled_targets[ext]:
						from_ = css_file['from']
						to_ = css_file['to']
						print "[DEBUG] copying: %s to %s" % (from_,to_)
						if path.endswith('.css'):
							file_contents = open(from_).read()
							packer = CSSPacker(file_contents)
							file_contents = packer.pack()
							to = open(to_,'w')
							to.write(file_contents)
							to.close()
						else:
							shutil.copyfile(from_, to_)	
			
			if compiled_targets.has_key('.js'):	
				for js_file in compiled_targets['.js']:
					path = js_file['path']
					from_ = js_file['from']
					to_ = js_file['to']
					print "[DEBUG] compiling: %s" % from_
					metadata = Compiler.make_function_from_file(path,from_,self)
					method = metadata['method']
					eq = path.replace('.','_')
					impf.write('         [map setObject:%s forKey:@"%s"];\n' % (method,eq))
开发者ID:JMjones,项目名称:titanium_mobile,代码行数:74,代码来源:compiler.py

示例4: make_function_from_file

	def make_function_from_file(self,path,file):
	
		fp = os.path.splitext(path)
		basename = fp[0].replace(' ','_').replace('/','_').replace('-','_').replace('.','_').replace('+','_')
		ext = fp[1][1:]

		url = 'app://%s/%s' % (self.appid,path)

		filetype = ''
		contents = ''
	
		if ext=='html':
			filetype = 'page'
		elif ext=='css':
			filetype = 'style'
		elif ext=='js':
			filetype = 'script'	
	
		methodname = "%sNamed%s%s" % (filetype,basename[0:1].upper(),basename[1:])
		method_define = "- (NSData*) %s;" % methodname
	
		seed = random.randint(1,9)
		key = "%s%d%s" % (self.appid,seed,methodname)
	
		file_contents = open(os.path.expanduser(file)).read()
		_file_contents = file_contents

		# minimize javascript, css files
		if ext == 'js':
			file_contents = jspacker.jsmin(file_contents)
		elif ext == 'css':
			packer = CSSPacker(file_contents)
			file_contents = packer.pack()
		
		# determine which modules this file is using
		self.extract_modules(file_contents)

		if self.debug and ext == 'js':
			file_contents = """
try
{
%s
}
catch(__ex__)
{
  if (typeof __ex__ == 'string')
  {
     var msg = __ex__
     __ex__ = {line:3,sourceURL:'%s',message:msg};
  }
  var _sur = __ex__.sourceURL;
  if (_sur)
  {
    _sur = _sur.substring(%d);
  }
  Titanium.API.reportUnhandledException(__ex__.line-3,_sur,__ex__.message);
}
""" % (_file_contents,url.encode("utf-8"),len('app://%s/'%self.appid))

		if self.encrypt:		
			out = subprocess.Popen([self.encryptor,file,key], stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()[0]
			data = str(out).strip()
			method = """
	%s
	{
	   NSString *k1 = @"%s";
	   int seed = %d;
	   NSString *k2 = @"%s";
	   NSData *d = AES128DecryptWithKey(dataWithHexString(@"%s"), [NSString stringWithFormat:@"%%@%%d%%@",k1,seed,k2]);
	   if ([d length] == 0) return nil;
	   return decode64(d);
	}
			""" % (method_define,self.appid,seed,methodname,data)
		else:
			sys.stdout.flush()
			data = str(file_contents).encode("hex")
			method = """
	%s
	{
		NSData *d = dataWithHexString(@"%s");
	   	if ([d length] == 0) return nil;
		return d;
	}
			""" % (method_define,data)
			
		return {'name':methodname,'method':method,'define':method_define,'url':url,'path':path}
开发者ID:soundarya,项目名称:titanium_mobile,代码行数:86,代码来源:compiler.py


注:本文中的csspacker.CSSPacker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。