Skip to content
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

Feature: pl-card to simplify the requirements of bootstrap card usage. #6971

Closed
coatless opened this issue Jan 20, 2023 · 2 comments · Fixed by #6978
Closed

Feature: pl-card to simplify the requirements of bootstrap card usage. #6971

coatless opened this issue Jan 20, 2023 · 2 comments · Fixed by #6978

Comments

@coatless
Copy link
Contributor

This is a sister issue to #6609 as it seeks to improve the decorative PrairieLearn element options. I would argue this is also different than the proposed #6747 PR as it seeks to provide a structured component that could be incorporated into templates. I'm revisiting the issue as #6800 revisited the age-old issues of bootstrap logic in documentation (c.f. #1753) and unofficial usage in courses complicating the upgrade process to Bootstrap v5.

Note: The element was previously discussed on Slack (message thread - 12/14/22)

The proposal here is to move toward a pl-card implementation matching the HTML + mustache templating of:

<div class="card my-2">
{{#title}}
<div class="card-header">
{{title}
</div>
{{/title}}
<div class="card-body">
{{content}}
</div>
</div>

The pl-card element would then be used as:

<pl-card title="Title here">
<pl-question-panel>
<markdown>Some content</markdown>
</pl-question-panel>
</pl-card>
@coatless
Copy link
Contributor Author

I think this work.

info.json

{
    "controller": "pl-card.py"
}

pl-card.mustache

<div class="card my-2">
{{#title}}
<div class="card-header">
{{{title}}}
</div>
{{/title}}
<div class="card-body">
{{{content}}}
</div>
</div>

pl-card.py

import lxml.html
import prairielearn as pl

TITLE_DEFAULT = ""

def prepare(element_html, data):
    element = lxml.html.fragment_fromstring(element_html)
    required_attribs = []
    optional_attribs = ["title"]
    pl.check_attribs(element, required_attribs, optional_attribs)


def render(element_html, data):
    element = lxml.html.fragment_fromstring(element_html)

    # Get title
    title = pl.get_string_attrib(element, "title", TITLE_DEFAULT)

    # Retrieve content
    content = pl.inner_html(element)

    # Create and return html
    html_params = {"title": title, "content": content}
    with open("pl-card.mustache", "r", encoding="utf-8") as f:
        html = chevron.render(f, html_params).strip()

    return html

@tdy
Copy link
Contributor

tdy commented Jan 21, 2023

IMO pl-card should have header, title, and subtitle attributes to mirror bootstrap's card-header, card-title, and card-subtitle classes. I can work on this one if there are no objections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants