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
29 changes: 6 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,12 @@ robert_march ---> amy
which results can be seen [here](https://mermaid.live/edit#pako:eNptj8FOw0AMRH9l5XPzA3tAAnFC9AIHpOIKuYlJUmo72jqHqOq_46zEiZzGbzzS2DdorWPI0DQNqo9-4ZxeRw9NHyasqHXTF5qGhCrcfyLsuUc4op4t4MXqfGIfgp5CKpMsgY-yVCp24uJfQqVdU28V037Ff_sUjQ8pmrbss225a_mWH0fADoSL0NjFlzfUlBB8YGGEHGNH5QcB9R45mt3eF20he5l5B_PUkfPzSPG9QP6myzXcifRg9sf3X1ADb2E)

## Roadmap
### October 2023
1-to-1 implementation of [flowchart](https://mermaid.js.org/syntax/flowchart.html#flowcharts-basic-syntax)
- [ ] All features of flowchart
- [x] Chart title
- [x] Nodes shapes
- [x] Links between nodes
- [x] Subgraph
- [ ] Links between nodes with subgraphs
- [ ] Directions ([#24](https://github.com/Dynnammo/python_mermaid/issues/24))
- [ ] Interaction
- [ ] Styling and classes ([#19](https://github.com/Dynnammo/python_mermaid/issues/19) and [#20](https://github.com/Dynnammo/python_mermaid/issues/20))
- [ ] Basic support for fontawesome ([#23](https://github.com/Dynnammo/python_mermaid/issues/23))

### November 2023
- [ ] Main Features of stateflow-v2
- [x] Nodes
- [x] Notes
- [x] Start and End nodes
- [x] Named links between nodes
- [ ] Graph configuration

### End 2023
- [ ] Architecture improvements for easing diagram creation
### Available features
- [x] Create basic [flowcharts](https://mermaid.js.org/syntax/flowchart.html) and [statecharts](https://mermaid.js.org/syntax/stateDiagram.html)

### Roadmap
See [issues](https://github.com/Dynnammo/python_mermaid/issues)

## Development
- Requirements: install [Poetry](https://python-poetry.org). Here is the official method below. ⚠️ Please consider getting a look at Poetry's documentation if it doesn't work. ⚠️
```shell
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "python_mermaid"
version = "0.1.5"
version = "0.1.6"
description = "A (quite) simple that helps creating on-the-fly Mermaid diagrams"
authors = ["Dynnammo <contact@dynnammo.com>"]
readme = "README.md"
Expand Down
22 changes: 16 additions & 6 deletions python_mermaid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@
from unidecode import unidecode


def snake_case(s):
def snake_case(s: str):
s = unidecode(s)
s = "_".join(
sub(
"([A-Z][a-z]+)", r" \1", sub("([A-Z]+)", r" \1", s.replace("-", " "))
).split()
).lower()

s = s.replace("-", " ")
s = s.replace("_", " ")

s = sub(" ([A-Z]+)", r"_\1", s) # All caps word

s = sub(" ([A-Z][a-z]+)", r"_\1", s) # Capitalized word

s = sub("([a-z])([A-Z])", r"\1_\2", s) # Camel Case word

s = sub("([A-Z])([A-Z])([a-z]+)", r"\1_\2\3", s) # words such as THESEWords

s = sub("( )", r"__", s) # Multiple spaces

s = "_".join(s.split()).lower()

return s

Expand Down
Empty file added tests/snakeCase/__init__.py
Empty file.
55 changes: 55 additions & 0 deletions tests/snakeCase/test_snake_case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pytest

from python_mermaid.utils import snake_case


def test_one_lowercase_letter():
assert snake_case("a") == "a"

def test_one_capital_letter():
assert snake_case("A") == "a"

def test_one_word():
assert snake_case("testing") == "testing"

def test_one_word_all_caps():
assert snake_case("TESTING") == "testing"

def test_already_snake_case():
assert snake_case("already_snake_case") == "already_snake_case"

def test_already_snake_case__fully_all_caps():
assert snake_case("ALL_CAPS_SNAKE_CASE") == "all_caps_snake_case"

def test_camel_case():
assert snake_case("camelCaseInput") == "camel_case_input"

def test_mixed_cases():
assert snake_case("MIXEDCases mixedCases mixed_cases") == "mixed_cases_mixed_cases_mixed_cases"

def test_capitalized_word():
assert snake_case("Capitalized") == "capitalized"

def test_mix_of_hyphens_underscores_spaces():
assert snake_case("hyphenated-words spaced apart SNAKE_CASE_CONSTANT") == "hyphenated_words_spaced_apart_snake_case_constant"

def test_capital_letter_after_hyphen():
assert snake_case("Capital-After-Hyphen") == "capital_after_hyphen"

def test_capital_letter_after_space():
assert snake_case("Capital After Space") == "capital_after_space"

def test_capital_letter_after_underscore():
assert snake_case("Capital_After_Underscore") == "capital_after_underscore"

def test_already_snake_case__partially_all_caps():
assert snake_case("ALLCAPS_SURROUNDED_BY_UNDERSCORES_lowercase") == "allcaps_surrounded_by_underscores_lowercase"

def test_capitalized_mix_of_hyphens_underscores_spaces():
assert snake_case("Capitalized-Hyphenated Capitalized Spaced Capitalized_Underscores") == "capitalized_hyphenated_capitalized_spaced_capitalized_underscores"

def test_multiple_underscores_in_a_row():
assert snake_case("multiple__underscores") == "multiple__underscores"

def test_multiple_underscores_in_a_row__capital_after_underscore():
assert snake_case("multiple__Underscores") == "multiple__underscores"