Skip to content

Commit

Permalink
Add link to edit original game opengaming#911
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Jan 8, 2022
1 parent 360dc77 commit 374fa61
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
8 changes: 6 additions & 2 deletions _ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

@dataclass
class Game:
names: List[str]
item: Dict
meta: Dict
clones: List

@property
def names(self) -> List[str]:
return names(self.item)

@property
def slug(self) -> str:
return re.sub(r'[^a-z0-9]+', '-', self.names[0].lower()).strip('-')
Expand Down Expand Up @@ -211,7 +215,7 @@ def parse_items(site, item, key):
for game in item[key]:
parse_global_tags(site, game, 'lang', game['name'])

getattr(site, key).append(Game(names(item), meta, [parse_fn(i) for i in item[key]]))
getattr(site, key).append(Game(item, meta, [parse_fn(i) for i in item[key]]))


def show_error(game_name, error_str):
Expand Down
18 changes: 11 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT"
python = "^3.8"
natsort = "8.0.0"
pykwalify = "1.8.0"
pykwalify-webform = "0.1.4"
pykwalify-webform = "0.2.1"
PyYAML = "6.0"
Unidecode = "1.3.2"
htmlmin = "0.1.12"
Expand Down
12 changes: 7 additions & 5 deletions render.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import functools
import argparse
import logging
import re
from distutils.dir_util import copy_tree
from pathlib import Path

Expand Down Expand Up @@ -70,6 +69,9 @@ def render_all(target):
render_to('index.html', f'{target}/index.html', site=site)
for game in ctx().games:
render_to('game.html', f'{target}/{game.slug}/index.html', site=site, game=game)
render_game_form(
"schema/originals.yaml", f"{target}/{game.slug}/edit.html", f"Edit {game.names[0]}", value=game.item
)


def normalize(text):
Expand All @@ -78,13 +80,13 @@ def normalize(text):
return html.escape(unidecode.unidecode(text.lower()))


def render_add_game_form(schema: str, out_path: str, form_name: str):
def render_game_form(schema: str, out_path: str, form_name: str, value=None):
with open(schema) as f:
schemata = safe_load(f)
renderer = Renderer(schemata, HERE / "templates/forms")
os.makedirs(os.path.dirname(out_path), exist_ok=True)
with open(out_path, "w") as f:
f.write(renderer.render("", name=form_name, static_url="/_add_form"))
f.write(renderer.render("", name=form_name, value=value, static_url="/_add_form"))


def main():
Expand All @@ -96,8 +98,8 @@ def main():
render_all(args.dest)

# Render add game forms
render_add_game_form("schema/games.yaml", f"{args.dest}/add_game.html", "Add Game")
render_add_game_form("schema/originals.yaml", f"{args.dest}/add_original.html", "Add Original")
render_game_form("schema/games.yaml", f"{args.dest}/add_game.html", "Add Game")
render_game_form("schema/originals.yaml", f"{args.dest}/add_original.html", "Add Original")

# Copy static files
copy_tree(str(HERE / "templates/forms/static"), f"{args.dest}/_add_form")
Expand Down
11 changes: 7 additions & 4 deletions templates/games.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{% import 'templates/video.html' as video %}
{% import 'templates/tags.html' as tags %}

{% macro render_name(name, game, first, use_external_link) %}
{%- if not use_external_link -%}
{% set link = "/" + game.slug %}
{%- else -%}
{% macro render_name(name, game, first, show_details) %}
{%- if show_details -%}
{% set link = game.wikilink %}
{%- else -%}
{% set link = "/" + game.slug %}
{%- endif -%}
<dt {% if first %}id="{{ show_id(name) }}"{% endif %} class="searchable">
<a href="{{ link }}">{{ name }}</a>
{% if first %}
{{ tags.render_tag_groups('genre', game.meta['genre']) }}
{{ tags.render_tag_groups('subgenre', game.meta['subgenre']) }}
{{ tags.render_tag_groups('theme', game.meta['theme']) }}
{% if show_details %}
<a class="add-link" href="/{{ game.slug }}/edit.html" target="_blank"><i class="far fa-edit"></i>Edit</a>
{% endif %}
{% endif %}
</dt>
{% endmacro %}
Expand Down

0 comments on commit 374fa61

Please sign in to comment.