-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose renderer as a standalone plugin
- Loading branch information
Showing
21 changed files
with
158 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Plugin that invokes the built-in template renderer.""" | ||
|
||
|
||
__all__ = [ | ||
"render", | ||
] | ||
|
||
|
||
from typing import Dict, List, Optional | ||
|
||
from beet import Context, Plugin | ||
from beet.core.utils import JsonDict | ||
|
||
|
||
def beet_default(ctx: Context): | ||
config = ctx.meta.get("render", {}) | ||
|
||
resource_pack = config.get("resource_pack") | ||
data_pack = config.get("data_pack") | ||
|
||
ctx.require(render(resource_pack, data_pack)) | ||
|
||
|
||
def render( | ||
resource_pack: Optional[Dict[str, List[str]]] = None, | ||
data_pack: Optional[Dict[str, List[str]]] = None, | ||
) -> Plugin: | ||
"""Return a plugin that processes the data pack and the resource pack with Jinja.""" | ||
|
||
def plugin(ctx: Context): | ||
for groups, pack in zip([resource_pack or {}, data_pack or {}], ctx.packs): | ||
for group, patterns in groups.items(): | ||
try: | ||
proxy = getattr(pack, group) | ||
file_paths = proxy.match(*patterns) | ||
except: | ||
raise ValueError(f"Invalid pattern group {group!r}.") from None | ||
else: | ||
for path in file_paths: | ||
ctx.template.render_file( | ||
proxy[path], | ||
__render__={"path": path, "group": group}, | ||
) | ||
|
||
return plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pipeline": ["demo"], | ||
"meta": { | ||
"message": "foo" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from beet import Context, Function | ||
from beet.contrib.render import render | ||
|
||
|
||
def beet_default(ctx: Context): | ||
ctx.data["demo:foo"] = Function(["say {{ ctx.meta.message }}"]) | ||
|
||
ctx.require(render(data_pack={"functions": ["*"]})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pipeline": ["demo"], | ||
"meta": { | ||
"message": "foo" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from beet import Context, Function, sandbox | ||
from beet.contrib.render import render | ||
|
||
|
||
def beet_default(ctx: Context): | ||
ctx.data["demo:foo"] = Function(["say {{ ctx.meta.message }}"]) | ||
ctx.require(render_functions) | ||
|
||
ctx.data["demo:bar"] = Function(["say {{ ctx.meta.message }}"]) | ||
ctx.require(sandbox(add_function, render_functions)) | ||
|
||
|
||
def add_function(ctx: Context): | ||
ctx.data["demo:isolated"] = Function(["say isolated {{ ctx.meta.message }}"]) | ||
|
||
|
||
def render_functions(ctx: Context): | ||
ctx.require(render(data_pack={"functions": ["*"]})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"pipeline": [ | ||
{ | ||
"data_pack": { | ||
"load": ["pack1"] | ||
} | ||
}, | ||
{ | ||
"data_pack": { | ||
"load": ["pack2"] | ||
} | ||
}, | ||
"beet.contrib.render" | ||
], | ||
"meta": { | ||
"pack1_message": "foo", | ||
"pack2_message": "bar", | ||
"render": { | ||
"data_pack": { | ||
"functions": ["demo:*"] | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
tests/examples/load_subpipelines_render/pack1/data/demo/functions/foo.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say {{ ctx.meta.pack1_message }} |
1 change: 1 addition & 0 deletions
1
tests/examples/load_subpipelines_render/pack2/data/demo/functions/bar.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say {{ ctx.meta.pack2_message }} |
1 change: 1 addition & 0 deletions
1
...ender_plugin__0.data_pack/code_render_plugin_data_pack/data/demo/functions/foo.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say foo |
6 changes: 6 additions & 0 deletions
6
.../examples__build_code_render_plugin__0.data_pack/code_render_plugin_data_pack/pack.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 6, | ||
"description": "" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...s__build_code_render_plugin__1.resource_pack/code_render_plugin_resource_pack/pack.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 6, | ||
"description": "" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...dbox_render__0.data_pack/code_sandbox_render_data_pack/data/demo/functions/bar.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say {{ ctx.meta.message }} |
1 change: 1 addition & 0 deletions
1
...dbox_render__0.data_pack/code_sandbox_render_data_pack/data/demo/functions/foo.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say foo |
1 change: 1 addition & 0 deletions
1
...render__0.data_pack/code_sandbox_render_data_pack/data/demo/functions/isolated.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say isolated |
6 changes: 6 additions & 0 deletions
6
...xamples__build_code_sandbox_render__0.data_pack/code_sandbox_render_data_pack/pack.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 6, | ||
"description": "" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
..._build_code_sandbox_render__1.resource_pack/code_sandbox_render_resource_pack/pack.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 6, | ||
"description": "" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...render__0.data_pack/load_subpipelines_render_data_pack/data/demo/functions/bar.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say bar |
1 change: 1 addition & 0 deletions
1
...render__0.data_pack/load_subpipelines_render_data_pack/data/demo/functions/foo.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
say foo |
6 changes: 6 additions & 0 deletions
6
...uild_load_subpipelines_render__0.data_pack/load_subpipelines_render_data_pack/pack.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 6, | ||
"description": "" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...d_subpipelines_render__1.resource_pack/load_subpipelines_render_resource_pack/pack.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 6, | ||
"description": "" | ||
} | ||
} |