-
Notifications
You must be signed in to change notification settings - Fork 4
Flags :D #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Flags :D #60
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
{% import "macros/formatting.html.jinja" as fmt -%} | ||
|
||
<div id="{{ entry.id.path }}" class="entry"> | ||
<div id="{{ entry.id.path }}" class="entry | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
{% if entry.flag is not none %} | ||
{{ entry.flag.css_classnames() }} | ||
{% endif %}"> | ||
{% call fmt.maybe_spoilered(entry) %} | ||
{{- fmt.section_header(entry, "h3", "entry-title") }} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
{% set page_anchor_id = entry.id.path ~ "@" ~ page.anchor %} | ||
|
||
{#- page content (not required because EmptyPage uses this template directly) #} | ||
<div id="{{ page_anchor_id }}"> | ||
<div id="{{ page_anchor_id }}" class="{% if entry.flag is not none %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
{{ entry.flag.css_classnames() }} | ||
{% endif %}"> | ||
{% block body scoped %}{% endblock %} | ||
</div> | ||
{% else %} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from typing import Any | ||
|
||
from pydantic import model_validator | ||
|
||
from hexdoc.model import HexdocModel | ||
|
||
|
||
class Flag(HexdocModel): | ||
name: str | ||
negated: bool = False | ||
|
||
@model_validator(mode="before") | ||
@classmethod | ||
def parse_flag(cls, data: Any) -> Any: | ||
if isinstance(data, str): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I'd probably do a |
||
assert ( | ||
"," not in data | ||
) # not sure if there are other invalid characters or not | ||
Comment on lines
+16
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if data.startswith("!"): | ||
return {"name": data[1:], "negated": True} | ||
return {"name": data} | ||
|
||
return data | ||
|
||
def css_classname(self) -> str: | ||
base = "flag-" + self.name.replace(":", "-") | ||
if self.negated: | ||
return "not-" + base | ||
return base | ||
|
||
|
||
class FlagExpression(HexdocModel): | ||
flags: list[Flag] | ||
conjuctive: bool = True | ||
|
||
@model_validator(mode="before") | ||
@classmethod | ||
def parse_flags(cls, data: Any) -> Any: | ||
if isinstance(data, str): | ||
if data.startswith("|") or data.startswith("&"): # must be a list | ||
return { | ||
"flags": data[1:].split(","), | ||
"conjuctive": data.startswith("&"), | ||
} | ||
return {"flags": [data]} | ||
Comment on lines
+40
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these could (and probably should) return instances of the class instead of dicts. for example: |
||
|
||
return data | ||
|
||
def css_classnames(self) -> str: | ||
flagclasses = " ".join(flag.css_classname() for flag in self.flags) | ||
if self.conjuctive: | ||
return "flagall " + flagclasses | ||
return "flagany " + flagclasses |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,7 +166,7 @@ | |
</details> | ||
</nav> | ||
<main class="book-body"> | ||
<section id="basics"> | ||
<section id="basics" class=""> | ||
<h2 class="category-title page-header"> | ||
<img | ||
title="Amethyst Shard" | ||
|
@@ -184,7 +184,8 @@ | |
title="Permalink" | ||
><i class="bi bi-link-45deg"></i></a></h2> | ||
<p>The practitioners of this art would cast their so-called <span style="color: #b38ef3">Hexes</span> by drawing strange patterns in the air with a <a href="GITHUB_PAGES_URL/v/latest/main/en_us#items/staff"><span style="color: #b0b">Staff</span></a> -- or craft <a href="GITHUB_PAGES_URL/v/latest/main/en_us#items/hexcasting"><span style="color: #b0b">powerful magical items</span></a> to do the casting for them. How might I do the same?</p> | ||
<div id="baz" class="entry"> | ||
<div id="baz" class="entry | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (this is what i mentioned above) |
||
"> | ||
<div class="spoilered"> | ||
<h3 class="entry-title page-header"> | ||
<img | ||
|
@@ -207,7 +208,7 @@ | |
</div> | ||
</div> | ||
</section> | ||
<section id="foo"> | ||
<section id="foo" class=""> | ||
<div class="spoilered"> | ||
<h2 class="category-title page-header"> | ||
<img | ||
|
@@ -227,7 +228,8 @@ | |
><i class="bi bi-link-45deg"></i></a></h2> | ||
<p>The practitioners of this art would cast their so-called <span style="color: #b38ef3">Hexes</span> by drawing strange patterns in the air with a <a href="GITHUB_PAGES_URL/v/latest/main/en_us#items/staff"><span style="color: #b0b">Staff</span></a> -- or craft <a href="GITHUB_PAGES_URL/v/latest/main/en_us#items/hexcasting"><span style="color: #b0b">powerful magical items</span></a> to do the casting for them. How might I do the same?</p> | ||
</div> | ||
<div id="bar" class="entry"> | ||
<div id="bar" class="entry | ||
"> | ||
<div class="spoilered"> | ||
<h3 class="entry-title page-header"> | ||
<img | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this is also helpful because the current code adds extra newlines to the output, as you can see in the snapshots)