def test_function_with_transform(): from jinja2 import contextfunction @contextfunction def url(context, base): return base + "/" + context["project"] + "/" + context["version"] + "/" context = {"version": "5.0.1", "project": "yinja"} yaml_text = """ yinja: text: project text2: version url: {{ url ('http://example.com') }} """ env = dict(globals=dict(url=url)) target = TEMP.child_file("test_function_with_transform") target.delete() result_path = transform(yaml_text, target.path, context, jinja_env=env) assert result_path result_path = File(result_path) assert result_path.exists result = yaml.load(result_path.read_all()) result = result["yinja"] assert result["text"] == "project" assert result["text2"] == "version" assert result["url"] == "http://example.com/yinja/5.0.1/"
def gen(source, data, target=None): source_command = ShellCommand(cwd=source.path) if source.child_file("requirements.txt").exists: source_command.call("pip", "install", "-r", "requirements.txt") if source.child_file("package.json").exists: source_command.call("npm", "install") # Generate target = target or data.target or source.parent.child("dist/www") dist = Folder(target) dist.make() template = source.child_file(data.config_template or "env.yaml") conf = source.child_file(data.config_file_name or "settings.gitbot") transform(template, conf, data) source_command.call("hyde", "gen", "-r", "-c", conf.name, "-d", dist.path) return dist