Skip to content

Commit

Permalink
Creating component files only if they do not exist yet
Browse files Browse the repository at this point in the history
  • Loading branch information
mesemus committed Jan 18, 2024
1 parent 1e0cba5 commit 477c4da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nrp-devtools"
version = "0.1.7"
version = "0.1.8"
description = "NRP repository development tools"
readme = "README.md"
authors = [
Expand Down
22 changes: 13 additions & 9 deletions src/nrp_devtools/cli/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,26 @@ def create_less_component(*args, **kwargs):

# create variable and override files
component_variables_file.parent.mkdir(parents=True, exist_ok=True)
component_variables_file.write_text(f"""
if not component_variables_file.exists():
component_variables_file.write_text(f"""
/* https://github.com/Semantic-Org/example-github/blob/master/semantic/src/themes/default/globals/site.variables */
/* @{component_name}Background: @inputBackground; */
""")
""")
click.secho(f"Place variables that parametrize the component inside {component_variables_file}",
fg="green")

component_overrides_file.parent.mkdir(parents=True, exist_ok=True)
component_overrides_file.touch()
if not component_overrides_file.exists():
component_overrides_file.touch()

# create the component
less_data = (Path(__file__).parent.parent / "templates" / "component.less").read_text()
less_data = less_data.replace('{{component_type}}', component_type)
less_data = less_data.replace('{{component_name}}', component_name)

component_file.parent.mkdir(parents=True, exist_ok=True)
component_file.write_text(less_data)
if not component_file.exists():
component_file.write_text(less_data)
click.secho(f"Put the default css to {component_file}", fg="green")

# add the component to the registration file
Expand All @@ -216,11 +219,12 @@ def create_jinjax_component(*args, **kwargs):
jinjax_component_file = ui_dir / "templates" / ui_name / f"{component_name_capitalized}.jinja"

jinjax_component_file.parent.mkdir(parents=True, exist_ok=True)
jinjax_component_file.write_text(f"""{{# def #}}
<div class="ui {component_name}">
Overwrite this file with your own jinja template.
</div>
""")
if not jinjax_component_file.exists():
jinjax_component_file.write_text(f"""{{# def #}}
<div class="ui {component_name}">
Overwrite this file with your own jinja template.
</div>
""")
click.secho(f"Place the HTML code of the component to {jinjax_component_file} "
f"and reference it from elsewhere as <components.{component_name_capitalized} /> or <{component_name_capitalized} />. "
f"Do not forget to put css classes 'ui {component_name}' to the root element of the template.",
Expand Down

0 comments on commit 477c4da

Please sign in to comment.