Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/example_src/example4.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ "src/example1.scss" | compiled_name }}?digest={{ "src/example1.scss" | hash }}
26 changes: 26 additions & 0 deletions tests/test_run_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,32 @@ def test_jinja_basic(src_folder: Path):
assert "b" in (src_folder / "dist" / "example1.txt").read_text("utf8")


def test_jinja_hash(src_folder: Path):
config = create_config(
src_folder,
{
"sass": {
"files": {
"src/example1.scss": "dist/example1.css",
},
"precision": 5,
"sourcemap": True,
"format": "compressed",
"encoding": "utf8",
},
"jinja": {
"files": {"src/example4.j2": "dist/example4.txt"},
},
},
)
result = CliRunner().invoke(run_compile, ["-c", str(config)])
assert result.exit_code == 3, result.output
assert (src_folder / "dist" / "example4.txt").exists(), result.output
assert "example1.css?digest=" in (src_folder / "dist" / "example4.txt").read_text(
"utf8"
)


def test_full(src_folder: Path):
config = create_config(
src_folder,
Expand Down
7 changes: 7 additions & 0 deletions web_compile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,14 @@ def _get_compiled_name(path):
raise KeyError(f"No compiled path: {path}")
return file_map.get(Path(path)).name

def _get_hash(path):
if not path or Path(path) not in file_map:
raise KeyError(f"No compiled path: {path}")
input_path = root / Path(path)
return hash_file(input_path.read_text("utf8"))

jinja_env.filters["compiled_name"] = _get_compiled_name
jinja_env.filters["hash"] = _get_hash
for input_str, output_str in (jinja_files or {}).items():
input_path = root / input_str
output_path = root / output_str
Expand Down