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

Vanilla Macro loader example (DO NOT MERGE) #14209

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ bleach==6.0.0
numpy==1.24.4
python-slugify==8.0.1
djlint==1.34.1
Jinja2
77 changes: 77 additions & 0 deletions templates/desktop/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "desktop/base_desktop.html" %}
{% from "_macros/tiered-list.jinja" import tiered_list %}

{% block title %}Ubuntu Desktop PC operating system{% endblock %}

Expand All @@ -16,6 +17,82 @@

{% block content %}

{%- call(slot) tiered_list(is_description_full_width_on_desktop=false, is_list_full_width_on_tablet=true) -%}
{%- if slot == 'title' -%}
<h2>H2 - up to two lines; ideally one.</h2>
jmuzina marked this conversation as resolved.
Show resolved Hide resolved
{%- endif -%}

{%- if slot == 'description' -%}
<p>A <a href="#">private cloud</a> provides organisations with on-demand
compute, storage and other resources that can be accessed over the network
and that are reserved exclusively for them - either in their own data centre
or via a 3rd party.</p>
{%- endif -%}

{%- if slot == 'list_item_title_1' -%}
<h5>Rich portfolio of products</h5>
{%- endif -%}

{%- if slot == 'list_item_description_1' -%}
<p>Resell the full range of Canonical’s portfolio of private and public
cloud products: OpenStack, Kubernetes, IoT, support, security and
compliance for Ubuntu.</p>
{%- endif -%}

{%- if slot == 'list_item_title_2' -%}
<h5>Sales enablement</h5>
{%- endif -%}

{%- if slot == 'list_item_description_2' -%}
<p>Canonical can help train your field sales and presales teams and
provide you with sales collateral and permission to use the Canonical
and Ubuntu trademarks in your own materials.</p>
{%- endif -%}

{%- if slot == 'list_item_title_3' -%}
<h5>Access to Canonical partner portal</h5>
{%- endif -%}

{%- if slot == 'list_item_description_3' -%}
<p>We host a partner portal with product and solutions collaterals, agreed
pricing, incentives and a deal registration system.</p>
{%- endif -%}

{%- if slot == 'list_item_title_4' -%}
<h5>Training and certification</h5>
{%- endif -%}

{%- if slot == 'list_item_description_4' -%}
<p>Gain access to technology that is the foundation for digital
transformation and expand your business through marketing support and
alignment with a trusted brand</p>
{%- endif -%}

{%- if slot == 'list_item_title_5' -%}
<h5>Technical enablement</h5>
{%- endif -%}

{%- if slot == 'list_item_description_5' -%}
<p>We provide in-depth technical training for your customer engineering
teams with access to technical resources for your labs and customer
engagements.</p>
{%- endif -%}

{%- if slot == 'list_item_title_6' -%}
<h5>Go to market with Canonical</h5>
{%- endif -%}

{%- if slot == 'list_item_description_6' -%}
<p>Working with our dedicated partner team, get new joint marketing
opportunities and lead generation.</p>
{%- endif -%}

{%- if slot == 'cta' -%}
<a href="#" class="p-button">Learn more</a>
<a href="#">Contact us ›</a>
{%- endif -%}
{%- endcall -%}

{# 0 -180px #}

<section class="p-section--hero">
Expand Down
15 changes: 15 additions & 0 deletions webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@
# Set up application
# ===

# Vanilla Macro loader example

from jinja2 import ChoiceLoader, FileSystemLoader

# ChoiceLoader attempts loading templates from each given path in successive
# order
loader = ChoiceLoader([
FileSystemLoader('templates'),
FileSystemLoader('node_modules/vanilla-framework/templates/')
])
Comment on lines +175 to +178
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if a project has a file in templates with the exact same file path as a macro we publish that they'd like to use?

My assumption is the project's template will be used since it's listed first here. However this means we are slightly restricting the file structure of projects that use flask base.

This isn't a bad thing, but maybe we should add some logic that outputs warnings if any identical file-paths are found between these two directories?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'd been wondering the same thing - maybe the filenames of our macros should be namespaced somehow (vf.tiered_list.jinja or whatever)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'd been wondering the same thing - maybe the filenames of our macros should be namespaced somehow (vf.tiered_list.jinja or whatever)?

I'd support that.


app = FlaskBase(
__name__,
"ubuntu.com",
Expand All @@ -175,6 +186,10 @@
static_folder="../static",
)

# Loader supplied to jinja_loader effectively overwrites template_folder in
# base config
app.jinja_loader = loader

sentry = app.extensions["sentry"]
session = talisker.requests.get_session()
charmhub_session = requests.Session()
Expand Down
Loading