Skip to content

Commit

Permalink
fix(tools.widgets): add utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Aug 18, 2023
1 parent f613566 commit 478d581
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions trame/tools/widgets/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import re

camel_pattern = re.compile(r"(?<!^)(?=[A-Z])")


def camel_to_dash(value):
"MySuperWidget => my-super-widget"
return camel_pattern.sub("-", value).lower()


def attr_to_py(value):
"""
top-left => "top_left"
top-left:default => ("top_left_default", "top-left:default")
v-slot:default.modifier => ("v_slot_default_modifier", "v-slot:default.modifier")
"""
py_name = value.replace("-", "_")
if "." in value or ":" in value:
py_name = py_name.replace(".", "_").replace(":", "_")
return [py_name, value]
return py_name

0 comments on commit 478d581

Please sign in to comment.