<commit_before># -*- coding: utf-8 -*-
#------------------------------------------------------------------------------
# file: $Id$
# lib:  templatealchemy.jinja2
# auth: <NAME> <<EMAIL>>
# date: 2013/07/03
# copy: (C) Copyright 2013 Cadit Health Inc., All Rights Reserved.
#------------------------------------------------------------------------------

from __future__ import absolute_import

import jinja2
from templatealchemy import api, util

#------------------------------------------------------------------------------
def loadRenderer(spec=None):
  return Jinja2Renderer(spec)

#------------------------------------------------------------------------------
class Jinja2Renderer(api.Renderer):

  #----------------------------------------------------------------------------
  def __init__(self, spec):
    # TODO: expose control of `jinja2.template.Template()` args/kwargs...
    self.spec = spec

  #----------------------------------------------------------------------------
  def render(self, context, data, params):
    tpl = jinja2.Template(data)
    return tpl.render(**params)
<commit_msg>updated to new stream-oriented API<commit_after># -*- coding: utf-8 -*-
#------------------------------------------------------------------------------
# file: $Id$
# lib:  templatealchemy.jinja2
# auth: <NAME> <<EMAIL>>
# date: 2013/07/03
# copy: (C) Copyright 2013 Cadit Health Inc., All Rights Reserved.
#------------------------------------------------------------------------------

from __future__ import absolute_import

import jinja2
from templatealchemy import api, util

#------------------------------------------------------------------------------
def loadRenderer(spec=None):
  return Jinja2Renderer(spec)

#------------------------------------------------------------------------------
class Jinja2Renderer(api.Renderer):

  #----------------------------------------------------------------------------
  def __init__(self, spec):
    # TODO: expose control of `jinja2.template.Template()` args/kwargs...
    self.spec = spec

  #----------------------------------------------------------------------------
  def render(self, context, stream, params):
    tpl = jinja2.Template(stream.read())
    return tpl.render(**params)

{'fraction_non_alphanumeric': 0.4928825622775801, 'fraction_numerical': 0.016903914590747332, 'mean_word_length': 0.8883291351805206, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '88603', 'n_tokens_mistral': 499, 'n_tokens_neox': 458, 'n_words': 122}