Skip to content

Commit 2a0ac85

Browse files
authored
Merge pull request #21 from pydsigner/improvements
Small enhancements
2 parents 74e2fa6 + 228f983 commit 2a0ac85

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

examples/css_transformer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
color: #abc;
1212
}
1313
14+
.a, .b {
15+
.c, .d {
16+
color: #def;
17+
}
18+
}
19+
1420
p {
1521
color: #fff;
1622
a {

src/anchovy/jinja.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from .dependencies import pip_dependency, Dependency
1010

1111
if t.TYPE_CHECKING:
12-
import commonmark
13-
import commonmark.render.renderer
1412
from jinja2 import Environment
1513

1614

src/anchovy/paths.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ def _trim_ext_prefix(path: Path, match: re.Match[str]):
1717
return path
1818

1919

20-
def _to_dir_inner(dest: Path, ext: str | None, context: Context, path: Path, match: t.Any):
20+
def _to_dir_inner(dest: Path,
21+
ext: str | None,
22+
context: Context,
23+
path: Path,
24+
match: t.Any,
25+
transform: t.Callable[[Path], Path] | None = None):
2126
path = _trim_ext_prefix(path, match) if ext and isinstance(match, re.Match) else path
2227

2328
rel = path.relative_to(
2429
context['input_dir']
2530
if path.is_relative_to(context['input_dir'])
2631
else context['working_dir']
2732
)
33+
if transform:
34+
rel = transform(rel)
2835
new_path = dest / rel
2936

3037
if ext:
@@ -41,12 +48,13 @@ class DirPathCalc(PathCalc[T]):
4148
extension information for the input paths, allowing for meaningful work
4249
with extensions that `pathlib.Path` does not reflect, like `.tar.gz`.
4350
"""
44-
def __init__(self, dest: Path, ext: str | None = None):
51+
def __init__(self, dest: Path, ext: str | None = None, transform: t.Callable[[Path], Path] | None = None):
4552
self.dest = dest
4653
self.ext = ext
54+
self.transform = transform
4755

4856
def __call__(self, context: Context, path: Path, match: T) -> Path:
49-
return _to_dir_inner(self.dest, self.ext, context, path, match)
57+
return _to_dir_inner(self.dest, self.ext, context, path, match, self.transform)
5058

5159

5260
class OutputDirPathCalc(PathCalc[T]):
@@ -58,11 +66,12 @@ class OutputDirPathCalc(PathCalc[T]):
5866
meaningful work with extensions that `pathlib.Path` does not reflect, like
5967
`.tar.gz`.
6068
"""
61-
def __init__(self, ext: str | None = None):
69+
def __init__(self, ext: str | None = None, transform: t.Callable[[Path], Path] | None = None):
6270
self.ext = ext
71+
self.transform = transform
6372

6473
def __call__(self, context: Context, path: Path, match: T) -> Path:
65-
return _to_dir_inner(context['output_dir'], self.ext, context, path, match)
74+
return _to_dir_inner(context['output_dir'], self.ext, context, path, match, self.transform)
6675

6776

6877
class WorkingDirPathCalc(PathCalc[T]):
@@ -74,11 +83,12 @@ class WorkingDirPathCalc(PathCalc[T]):
7483
meaningful work with extensions that `pathlib.Path` does not reflect, like
7584
`.tar.gz`.
7685
"""
77-
def __init__(self, ext: str | None = None):
86+
def __init__(self, ext: str | None = None, transform: t.Callable[[Path], Path] | None = None):
7887
self.ext = ext
88+
self.transform = transform
7989

8090
def __call__(self, context: Context, path: Path, match: T) -> Path:
81-
return _to_dir_inner(context['working_dir'], self.ext, context, path, match)
91+
return _to_dir_inner(context['working_dir'], self.ext, context, path, match, self.transform)
8292

8393

8494
class REMatcher(Matcher[re.Match | None]):

0 commit comments

Comments
 (0)