當前位置: 首頁>>代碼示例>>Python>>正文


Python Renderer.load_template方法代碼示例

本文整理匯總了Python中pystache.renderer.Renderer.load_template方法的典型用法代碼示例。如果您正苦於以下問題:Python Renderer.load_template方法的具體用法?Python Renderer.load_template怎麽用?Python Renderer.load_template使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pystache.renderer.Renderer的用法示例。


在下文中一共展示了Renderer.load_template方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: crear_plantilla

# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import load_template [as 別名]
def crear_plantilla(archivo_fuente='user.c'):
    print "creando plantilla para archivo %s" % archivo_fuente
    renderer = Renderer()
    template = renderer.load_template(SOURCE_TEMPLATE)
    dato_plantilla = renderer.render(template, {'include_path': archivo_fuente})
    archivo = open(SOURCE_FILE, 'w')
    archivo.write(dato_plantilla)
    archivo.close()
    print "plantilla creada"
開發者ID:fitoria,項目名稱:icaro-cli,代碼行數:11,代碼來源:__init__.py

示例2: main

# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import load_template [as 別名]
def main(sys_argv=sys.argv):
    template, context, c_format, multiple = parse_args(sys_argv, USAGE)

    if template.endswith('.mustache'):
        template = template[:-9]

    renderer = Renderer()

    try:
        template = renderer.load_template(template)
    except TemplateNotFoundError:
        pass

    if context.endswith(".csv") or (c_format and (c_format == "csv")):
        try:
            context = csv.DictReader(open(context, 'rb'))#, delimiter=',', quotechar='"')
        except IOError:
            print('ERROR: Could not parse context as CSV file. Check usage for input format options')
            exit(-1)            
    else:
        try:
            context = json.load(open(context))
        except IOError:
            context = json.loads(context)
        except ValueError: #likely a not well-formed JSON string, or user forgot -f csv.
            print('ERROR: Could not parse context as JSON file or text, check usage for input format options')
            exit(1)

    if (multiple):
        print ("multiple render on field %s" % multiple)
        fileName, fileExt = os.path.splitext(multiple)
        for i,c in enumerate(context):
            if multiple in c:
                f_name = str(c[multiple])
            else:                
                f_name = "%s-%03d%s" % (fileName, i, fileExt)
            with open(f_name, "w") as f: # mode "wx" could be used to prevent overwriting, + pass IOError, adding "--force" option to override.
                rendered = renderer.render(template, c)
                f.write(rendered)
                print ("%s done") % f_name
    else:
        rendered = renderer.render(template, context)
        print rendered
開發者ID:berteh,項目名稱:pystache,代碼行數:45,代碼來源:render.py

示例3: main

# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import load_template [as 別名]
def main(sys_argv=sys.argv):
    template, context = parse_args(sys_argv, USAGE)

    if template.endswith('.mustache'):
        template = template[:-9]

    renderer = Renderer()

    try:
        template = renderer.load_template(template)
    except IOError:
        pass

    try:
        context = json.load(open(context))
    except IOError:
        context = json.loads(context)

    rendered = renderer.render(template, context)
    print rendered
開發者ID:tobiasandtobias,項目名稱:pystache,代碼行數:22,代碼來源:render.py

示例4: MustacheEngine

# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import load_template [as 別名]
class MustacheEngine(TemplateEngine):

    """
    Mustache template engine.
    """

    def __init__(self, **kw):
        """
        Initialize the template renderer.

        :param directories: Keyword parameter. A list of directories used as
            the search path for templates.
        """
        self.renderer = Renderer(search_dirs=kw['directories'])
        TemplateEngine.__init__(self, **kw)

    def get_template(self, name, **kw):
        """
        Get a template.

        :param name: The name of the template.
        """
        parts = name.rsplit('.', 2)
        if len(parts) > 1 and parts[1] == 'mustache':
            name = parts[0]
        return self.renderer.load_template(name)

    def render(self, name, **kw):
        """
        Render a template.

        :param name: The name of the template.
        :param **kw: The values to substitute in the template.
        """
        template = self.templates.get(name, None)
        return self.renderer.render(template, kw)
開發者ID:BlueDragonX,項目名稱:formalchemy_mustache,代碼行數:38,代碼來源:engines.py

示例5: render

# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import load_template [as 別名]
 def render(self, *context, **kwargs):
     renderer = Renderer(search_dirs=[thisDir()])
     template = renderer.load_template('govuk_template')
     return renderer.render(template, *context, **kwargs)
開發者ID:LandRegistry,項目名稱:python-govuk-template,代碼行數:6,代碼來源:govuk_template.py


注:本文中的pystache.renderer.Renderer.load_template方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。