File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ {{ "src/example1.scss" | compiled_name }}?digest={{ "src/example1.scss" | hash }}
Original file line number Diff line number Diff line change @@ -128,6 +128,32 @@ def test_jinja_basic(src_folder: Path):
128
128
assert "b" in (src_folder / "dist" / "example1.txt" ).read_text ("utf8" )
129
129
130
130
131
+ def test_jinja_hash (src_folder : Path ):
132
+ config = create_config (
133
+ src_folder ,
134
+ {
135
+ "sass" : {
136
+ "files" : {
137
+ "src/example1.scss" : "dist/example1.css" ,
138
+ },
139
+ "precision" : 5 ,
140
+ "sourcemap" : True ,
141
+ "format" : "compressed" ,
142
+ "encoding" : "utf8" ,
143
+ },
144
+ "jinja" : {
145
+ "files" : {"src/example4.j2" : "dist/example4.txt" },
146
+ },
147
+ },
148
+ )
149
+ result = CliRunner ().invoke (run_compile , ["-c" , str (config )])
150
+ assert result .exit_code == 3 , result .output
151
+ assert (src_folder / "dist" / "example4.txt" ).exists (), result .output
152
+ assert "example1.css?digest=" in (src_folder / "dist" / "example4.txt" ).read_text (
153
+ "utf8"
154
+ )
155
+
156
+
131
157
def test_full (src_folder : Path ):
132
158
config = create_config (
133
159
src_folder ,
Original file line number Diff line number Diff line change @@ -424,7 +424,14 @@ def _get_compiled_name(path):
424
424
raise KeyError (f"No compiled path: { path } " )
425
425
return file_map .get (Path (path )).name
426
426
427
+ def _get_hash (path ):
428
+ if not path or Path (path ) not in file_map :
429
+ raise KeyError (f"No compiled path: { path } " )
430
+ input_path = root / Path (path )
431
+ return hash_file (input_path .read_text ("utf8" ))
432
+
427
433
jinja_env .filters ["compiled_name" ] = _get_compiled_name
434
+ jinja_env .filters ["hash" ] = _get_hash
428
435
for input_str , output_str in (jinja_files or {}).items ():
429
436
input_path = root / input_str
430
437
output_path = root / output_str
You can’t perform that action at this time.
0 commit comments