<commit_before># coding=utf-8

"""
    jinja_atoms.decotators
    ~~~~~~~~~~~~~~~~~~~~~~

    Implements Jinja Atoms decorators
    for atoms marking and managing.

    :copyright: 2013 by <NAME>.
    :license: BSD, see LICENSE for more details.
"""

from functools import wraps

from jinja2 import Environment, PackageLoader, ChoiceLoader

from .ext import JinjaAtomsExtension


class AtomFactory():

    def __init__(self):
        self.atom_envs = {}

    def get_env(self, atom_package=None):
        if atom_package and atom_package in self.atom_envs:
            return self.atom_envs[atom_package]

        new_env = Environment(
            loader=ChoiceLoader([
                PackageLoader(atom_package, 'html'),
                PackageLoader(atom_package, 'templates')
            ]),
            extensions=[JinjaAtomsExtension]
        )
        self.atom_envs[atom_package] = new_env

        return new_env

    def build(self):
        def atom(package_path, jinja_path):
            env = self.get_env(package_path)
            template = env.get_template(jinja_path)
            def wrapper(func):
                @wraps(func)
                def atom_args(*args, **kwargs):
                    template_context = func(*args, **kwargs)
                    return template.render(template_context)
                return atom_args
            return wrapper
        return atom


atom_factory = AtomFactory()
atom = atom_factory.build()<commit_msg>@atom improved and simplified<commit_after># coding=utf-8

"""
    jinja_atoms.decotators
    ~~~~~~~~~~~~~~~~~~~~~~

    Implements Jinja Atoms decorators
    for atoms marking and managing.

    :copyright: 2013 by <NAME>.
    :license: BSD, see LICENSE for more details.
"""

from jinja2 import environmentfunction
from jinja2 import PackageLoader, ChoiceLoader


def atom(package_path, jinja_path):
    def wrapper(func):
        @environmentfunction
        def atom_args(*args, **kwargs):
            linked_env, args = args[0], args[1:]
            overlay_env = linked_env.overlay(
                loader=ChoiceLoader([
                    PackageLoader(package_path, 'html'),
                    PackageLoader(package_path, 'templates')
                ]),
            )
            template = overlay_env.get_template(jinja_path)
            template_context = func(*args, **kwargs)
            return template.render(template_context)
        return atom_args
    return wrapper
{'fraction_non_alphanumeric': 0.09979633401221996, 'fraction_numerical': 0.006109979633401222, 'mean_word_length': 2.3099730458221024, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4088701', 'n_tokens_mistral': 699, 'n_tokens_neox': 648, 'n_words': 160}