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


Python pystache.parse函数代码示例

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


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

示例1: _render

    def _render(self, articles):
        template_string = ''
        with open(self.template['content'], 'r') as f:
            template_string = f.read().decode('utf-8')
        content_parsed = pystache.parse(template_string)
        with open(self.template['layout'], 'r') as f:
            template_string = f.read().decode('utf-8')
        layout_parsed = pystache.parse(template_string)

        params = []
        for article in articles:
            dt = datetime.datetime.fromtimestamp(article['issued'])
            params.append({
                'href': article['filename'] + '.html',
                'date': dt.strftime('%b %d, %Y'),
                'title': article['title'],
                })
        contents = self.renderer.render(content_parsed, {'articles': params})

        dt = datetime.datetime.now()
        param = {
            'content': contents,
            'date': dt.strftime('%b %d, %Y'),
            'date_iso': dt.isoformat(),
            'author': articles[0]['author'],
            'url': self.html_filename,
            }

        dest_path = os.path.join(self.output_path, self.html_filename)
        with open(dest_path, 'w') as f:
            f.write(self.renderer.render(layout_parsed, param).encode('utf-8'))
开发者ID:cou929,项目名称:Misc-stuffs,代码行数:31,代码来源:view.py

示例2: __init__

    def __init__(self, template_file, dest_file_template_str, overwrite=True):
        """Ctor.

        @param template_file: Filename of the mustache template.
        @param dest_file_template_str: Destination file name. This is a
            mustache template, so each resource can write to a unique file.
        @param overwrite: If True, destination file is ovewritten if it exists.
        """
        template_str = unicode(open(template_file, "r").read())
        self.template = pystache.parse(template_str)
        dest_file_template_str = unicode(dest_file_template_str)
        self.dest_file_template = pystache.parse(dest_file_template_str)
        self.overwrite = overwrite
开发者ID:GGGO,项目名称:asterisk,代码行数:13,代码来源:transform.py

示例3: mustache_template

def mustache_template(self, namespace, data):
    """
    Takes a namespace and finds it's file.  Takes that file and parses it's
    template.  Then takes that template, loads the partials for it, and
    renderers the template, given the data and the partials.
    """
    partials_path = config.build_paths['partials_path'] + "/"

    paths = namespace.split('.') 
    file_path = '/'.join(paths) + '.mustache'
    partials = dict()
    if self.application.debug == True:
        with open(config.build_paths['mustache_path'] + '/' + file_path) as f:
            read_data = f.read()
        read_data = unicode(read_data)
        for (dirpath, dirname, filenames) in os.walk(partials_path):
            dirpath += '/' if not dirpath.endswith('/') else ''
            new_namespace = dirpath.replace(partials_path, '')
            new_namespace = new_namespace.replace('/', '.')
            for filename in filenames:
                if filename.endswith('.mustache'):
                    with open(dirpath + filename) as f:
                        read_file = f.read()
                    filename = filename.replace(".mustache", "")
                    partials[new_namespace + filename] = read_file


        parsed_template = pystache.parse(read_data)
        renderer = pystache.Renderer(partials=partials)
        return renderer.render(parsed_template, data)
    else:
        return 'no bueno'
开发者ID:benasher44,项目名称:clornado,代码行数:32,代码来源:template_methods.py

示例4: parse_templates

    def parse_templates(self, templates):
        for template in templates:
            print "Parse template: %s" % os.path.join(self.template_dir, template)

            with codecs.open(os.path.join(self.template_dir, template), 'r', 'utf-8') as content_file:
                content = content_file.read()
                self.templates[template.strip('.mustache')] = pystache.parse(content)
开发者ID:benjiao,项目名称:torrent-bot,代码行数:7,代码来源:responses.py

示例5: parse_template

 def parse_template(template_text):
   if six.PY2:
     # pystache does a typecheck for unicode in python 2.x but rewrites its sources to deal
     # unicode via str in python 3.x.
     template_text = unicode(template_text)
   template = pystache.parse(template_text)
   return template
开发者ID:MathewJennings,项目名称:pants,代码行数:7,代码来源:mustache.py

示例6: generate_xmls

def generate_xmls(json_filenames):
    xml_template_str = unicode(open('tool-template.xml').read())
    xml_template = pystache.parse(xml_template_str)
    for tool_path in json_filenames:
        desc = json.load(open(tool_path))
        desc['collectionName'] = desc['collectionName'].capitalize()
        print pystache.render(xml_template, desc)
开发者ID:edamontology,项目名称:toolinfowarehouse,代码行数:7,代码来源:json2xml.py

示例7: parse_mustache_template

 def parse_mustache_template(self, origin, source):
     if origin not in self._parsed or settings.DEBUG:  # no cache in DEBUG mode
         try:
             self._parsed[origin] = pystache.parse(smart_unicode(source))
         except pystache.parser.ParsingError, e:
             # better error
             raise pystache.parser.ParsingError("Mustache couldn't parse {0}, reason : '{1}'.".format(origin, e))
开发者ID:liberation,项目名称:django-mustache,代码行数:7,代码来源:loader.py

示例8: render

def render(values):
	renderer = pystache.Renderer()
	with codecs.open('template.mustache', 'r', 'utf-8') as templateFile:
		template = templateFile.read()
		parsed = pystache.parse(template)

	return renderer.render(parsed, values)
开发者ID:avilaton,项目名称:iritrac-robots,代码行数:7,代码来源:txt2kml.py

示例9: remove_components

    def remove_components(self, template, tags):
        new_components = []
        tags = set(tags)

        parsed = pystache.parse(safe_decode(template))

        last_removed = False
        for i, el in enumerate(parsed._parse_tree):
            if hasattr(el, 'parsed'):
                keys = [e.key for e in el.parsed._parse_tree if hasattr(e, 'key') and e.key not in tags]
                if keys:
                    new_components.append(self.build_first_of_template(keys))
                    last_removed = False
                else:
                    last_removed = True
            elif hasattr(el, 'key'):
                if el.key not in tags:
                    new_components.append('{{{{{{{key}}}}}}}'.format(key=el.key))
                    last_removed = False
                else:
                    last_removed = True

            elif not last_removed:
                new_components.append(el)
            else:
                last_removed = False
        return ''.join(new_components).strip()
开发者ID:BERENZ,项目名称:libpostal,代码行数:27,代码来源:formatter.py

示例10: subscribe

def subscribe(args):
    consumer = KafkaConsumer(args.kafka_topic,
                         group_id=args.kafka_group_id,
                          metadata_broker_list=args.kafka_server.split(','))

    renderer = pystache.Renderer()
    logging.info("rsync_cmd: [{0}]".format(" ".join(args.rsync_cmd)))
    templates = [ pystache.parse(unicode(c,"UTF-8")) for c in args.rsync_cmd ]

    for message in consumer:
        o = json.loads(message.value)
        if not "maskname" in o:
           continue
        if o["maskname"] in ["IN_IGNORED","IN_DELETE"]:
           continue
        if 'dir' in o and o['dir']:
           continue
        cmd = [ renderer.render(t, {'o': o,'args':args}) for t in templates ]
        target = cmd[-1]
        # ensure the parent folder exists, having a hard time
        # otherwise getting rsync to do this
        folder = os.path.dirname(cmd[-1])
        if not os.path.exists(folder):
            os.makedirs(folder)
        cmd.insert(0,"rsync")
        logging.info("executing: "+" ".join(cmd))
        try:
            subprocess.check_call(cmd)
        except subprocess.CalledProcessError, e:
            logging.info("failed to execute: "+" ".join(cmd))
            if e.output:
               logging.info(e.output)
开发者ID:fullergalway,项目名称:docker-inotify2kafka,代码行数:32,代码来源:kafka-rsync.py

示例11: __init__

 def __init__(self, template_text, **template_data):
   # pystache does a typecheck for unicode in python 2.x but rewrites its sources to deal unicode
   # via str in python 3.x.
   if Compatibility.PY2:
     template_text = unicode(template_text)
   self._template =  pystache.parse(template_text)
   self.template_data = template_data
开发者ID:steliokontos,项目名称:commons,代码行数:7,代码来源:generator.py

示例12: build

	def build(self, profile):
		""" Build static website """
		Console.info("Executing Konstrukteur...")
		Console.indent()

		self.__templatePath = os.path.join("source", "template")
		self.__contentPath = os.path.join("source", "content")
		self.__sourcePath = os.path.join("source")

		self.__profile = profile
		self.__fileManager = FileManager.FileManager(profile)

		if not os.path.exists(self.__templatePath):
			raise RuntimeError("Path to templates not found : %s" % self.__templatePath)
		if not os.path.exists(self.__contentPath):
			raise RuntimeError("Path to content not found : %s" % self.__contentPath)

		if self.theme:
			theme = session.getProjectByName(self.theme)
			if not theme:
				raise RuntimeError("Theme '%s' not found" % self.theme)

		self.__postUrl = pystache.parse(self.posturl)
		self.__pageUrl = pystache.parse(self.pageurl)
		self.__feedUrl = pystache.parse(self.feedurl)

		self.__parseTemplate()
		self.__build()

		if self.regenerate:
			fileChangeEventHandler = konstrukteur.FileWatcher.FileChangeEventHandler()
			observer = Observer()
			observer.schedule(fileChangeEventHandler, self.__sourcePath, recursive=True)
			observer.start()
			try:
				Console.info("Waiting for file changes (abort with CTRL-C)")
				while True:
					time.sleep(1)
					if fileChangeEventHandler.dirty:
						fileChangeEventHandler.dirty = False
						self.__build()
			except KeyboardInterrupt:
				observer.stop()
			observer.join()

		Console.outdent()
开发者ID:fastner,项目名称:konstrukteur,代码行数:46,代码来源:Konstrukteur.py

示例13: __init__

 def __init__(self):
   client = pymongo.MongoClient()
   self.auth_db = flowboard_auth.AuthDatabase(client)
   self.auth_service = flowboard_auth.AuthService(self.auth_db)
   self.posts_db = flowboard_posts.PostDatabase(client)
   FlowBoard.instance = self
   self.secret = "6LekGR4TAAAAADn4OR-Gr8pYqdpIJiv79re8fy24"
   self.index_parsed = pystache.parse(''.join(open('index.html').readlines()))
   self.renderer = pystache.Renderer()
   self.recent_posts_html = self.most_recent_posts_html(10)
   self.notify_update()
开发者ID:daemon,项目名称:flowboard,代码行数:11,代码来源:flowboard.py

示例14: render

    def render(self, template_path, output_path, variables={}):
        with open (self.template_root + template_path, "r") as myfile:
            data=myfile.read()

        parsed = pystache.parse(u"%(data)s" % locals())
        renderer = pystache.Renderer()

        output = renderer.render(parsed, variables)

        with open (os.getcwd() + "/temp/" + output_path, "w") as myfile:
	        myfile.write(output)
        return os.getcwd() + "/temp/" + output_path
开发者ID:Cygnus-Labs,项目名称:opendaylight-integration,代码行数:12,代码来源:deploy.py

示例15: main

def main(config_path):

    with open(config_path) as simple_config_file:
        simple_config=json.load(simple_config_file)
        # These are not something the user will put into their simple config,
        # so we need to get it from the environment (it will have been set by the start_services_in_container.sh script)
        simple_config['sensu_server_ip_address'] = os.environ['SENSU_SERVER_IP_ADDRESS']
        simple_config['queue_host'] = os.environ['SENSU_SERVER_IP_ADDRESS']
        simple_config['fleet_name'] = os.environ['FLEET_NAME']

    config_path = os.path.dirname(__file__)
    with open(config_path +'/pancancer_config.mustache') as mustache_template_file:
        mustache_template=mustache_template_file.read()

    renderer=pystache.Renderer()
    parsed=pystache.parse(mustache_template)
    rendered_str=renderer.render(parsed,(simple_config))
    data=json.loads(rendered_str)

    # The master config file should be written to ~/.pancancer/pancancer_config.json
    with open(config_path + '/pancancer_config.json','w') as master_config_file:
        master_config_file.write(str(json.dumps(data,sort_keys=True, indent=4) ))

    # Youxia config should go to ~/.youxia/config
    with open(config_path + '/youxia_config','w') as youxia_file:
        youxia_settings=data['youxia']
        youxia_str=processYouxiaSettings(youxia_settings)
        youxia_file.write(youxia_str)

    # params.json should go to ~/params.json
    with open(config_path + '/params.json','w') as params_json_file:
        params_settings=data['params']
        params_str=processParams(params_settings)
        params_json_file.write(params_str)

    # masterConfig should go to ~/arch3/config/masterConfig.ini
    with open(config_path + '/masterConfig.ini','w') as consonance_file:
        consonance_settings=data['consonance']
        consonance_str=processConsonanceSettings(consonance_settings)
        consonance_file.write(consonance_str)

    #create the server tags, if necessary. The user can change this file later, and we won't touch it (since it already exists).
    server_tags_path = os.path.expanduser('~/arch3/server-tags.json')
    if not os.path.exists(server_tags_path):
        with open(server_tags_path,'w') as server_tags_file:
            server_tags={'KEEP':os.environ['FLEET_NAME']}
            server_tags_file.write(str(json.dumps(server_tags,sort_keys=True, indent=4) ))

    shutil.copy2(config_path + '/youxia_config','/home/ubuntu/.youxia/config')
    shutil.copy2(config_path + '/masterConfig.ini','/home/ubuntu/arch3/config/masterConfig.ini')
    shutil.copy2(config_path + '/params.json','/home/ubuntu/params.json')
开发者ID:vferretti,项目名称:cli,代码行数:51,代码来源:process_config.py


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