Skip to content

Commit

Permalink
WIP: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Aug 20, 2024
1 parent 7bb72e6 commit 3b9c2d2
Show file tree
Hide file tree
Showing 18 changed files with 455 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
- name: Wait for response
uses: nev7n/wait_for_response@v1
with:
url: http://localhost:5001/ready/
url: http://localhost:5001/healthcheck/live/
- name: Run the tests
run: node test-fixtures.mjs || exit 1
6 changes: 3 additions & 3 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Wait for response
uses: nev7n/wait_for_response@v1
with:
url: http://localhost:5001/ready/
url: http://localhost:5001/healthcheck/live/
- name: Run the tests
run: node test-fixtures.mjs || exit 1

Expand All @@ -35,12 +35,12 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
python-version: "3.x"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
uses: pypa/gh-action-pypi-publish@release/v1
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.html
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://github.com/nationalarchives/tna-frontend-jinja/compare/v0.2.8...HEAD)

### Added

### Changed

### Deprecated

### Removed

### Fixed

### Security

## [0.2.8](https://github.com/nationalarchives/tna-frontend-jinja/compare/v0.2.7...v0.2.8) - 2024-08-16
Expand Down Expand Up @@ -311,4 +316,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## 0.1.0 - 2023-11-28

Initial release made to PyPi
Initial release made to PyPi
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
services:
app:
build:
# context: test
dockerfile: test/Dockerfile
environment:
- ENVIRONMENT=develop
Expand All @@ -12,3 +11,7 @@ services:
volumes:
- ./test:/app
- ./tna_frontend_jinja:/home/app/tna_frontend_jinja
dev:
image: ghcr.io/nationalarchives/tna-python-dev:preview
volumes:
- ./:/app
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"scripts": {
"prettier": "npx --yes prettier --write '*.{mjs,json}'",
"test": "node test-fixtures.mjs"
},
"dependencies": {
Expand Down
22 changes: 19 additions & 3 deletions test/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
import os
import sys

from flask import Flask

from .components import bp as components_bp
from .utilities import bp as utilities_bp
from .forms import bp as forms_bp
# from .forms.routes import WTFormsHelpers
from .templates import bp as templates_bp
from .utilities import bp as utilities_bp


sys.path.append('/home/app/')

from tna_frontend_jinja.wtforms.widgets import WTFormsHelpers

app = Flask(__name__, template_folder="/home/app/tna_frontend_jinja/templates")

app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY")

@app.route("/ready/")
def ready():

@app.route("/healthcheck/live/")
def healthcheck():
return "ok"


app.register_blueprint(components_bp, url_prefix="/components")
app.register_blueprint(utilities_bp, url_prefix="/utilities")
app.register_blueprint(templates_bp, url_prefix="/templates")
app.register_blueprint(forms_bp, url_prefix="/forms")

WTFormsHelpers(app)
2 changes: 1 addition & 1 deletion test/app/components/routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from app.components import bp

from app.components import bp
from flask import render_template, request


Expand Down
5 changes: 5 additions & 0 deletions test/app/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from flask import Blueprint

bp = Blueprint("forms", __name__, template_folder="test-templates")

from app.forms import routes # noqa: E402,F401
36 changes: 36 additions & 0 deletions test/app/forms/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys
from app.forms import bp
from flask import redirect, render_template, url_for
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import Email, InputRequired, Length

sys.path.append('/home/app/')
from tna_frontend_jinja.wtforms.widgets import GovTextInput, GovSubmitInput


class ExampleForm(FlaskForm):
email_address = StringField(
"Email address",
widget=GovTextInput(),
validators=[
InputRequired(message="Enter an email address"),
Length(
max=256, message="Email address must be 256 characters or fewer"
),
Email(
message="Enter an email address in the correct format, like [email protected]"
),
],
description="We’ll only use this to send you a receipt",
)

submit = SubmitField("Continue", widget=GovSubmitInput())


@bp.route("/", methods=["GET", "POST"])
def index():
form = ExampleForm()
if form.validate_on_submit():
return redirect(url_for("forms.index"))
return render_template("example-form.html", form=form)
44 changes: 44 additions & 0 deletions test/app/forms/test-templates/example-form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% extends "layouts/base.html" %}

{%- from 'components/error-summary/macro.html' import tnaErrorSummary -%}

{% block pageTitle %}{%- if form and form.errors %}Error: {% endif -%}Example form – GOV.UK Frontend WTForms Demo{% endblock %}

{% block stylesheets %}
<link rel="stylesheet" href="https://use.typekit.net/kaq6qqh.css">
<link href="https://cdn.jsdelivr.net/npm/@nationalarchives/[email protected]/nationalarchives/all.css" rel="stylesheet" integrity="sha384-GFKsKURhzcIk6FnRgNbpibhx4qgCtEI8HV1kJ/4NkO0t3FFIWKnP7UlantvRj6FP" crossorigin="anonymous">
{% endblock %}

{% block cookies %}
{% endblock %}

{% block content %}
<div class="tna-container tna-section">
<div class="tna-column tna-column--width-2-3 tna-column--width-5-6-medium tna-column--full-small tna-column--full-tiny">
{% if form.errors %}
{{ tnaErrorSummary(wtforms_errors(form)) }}
{% endif %}
<h1 class="tna-heading-xl">Example form</h1>
<form action="" method="post" novalidate>
{{ form.csrf_token }}
{{ form.email_address(params={
'headingLevel': 2,
'type': 'email',
'autofill': 'email',
'spellcheck': False
}) }}
<div class="tna-button-group">
{{ form.submit }}
</div>
</form>
</div>
</div>
{% endblock %}

{% block bodyEnd %}
<script src="https://cdn.jsdelivr.net/npm/@nationalarchives/[email protected]/nationalarchives/all.js" integrity="sha384-s768ALHSnzGU2X2ENYTrlF+CfnKaa3Us1eU78VrZ4eTKwLjWob1Wbb9tIT2xfmBq" crossorigin="anonymous"></script>
<script>
// Initialise all TNA components
window.TNAFrontend.initAll();
</script>
{% endblock %}
2 changes: 1 addition & 1 deletion test/app/templates/routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from app.templates import bp

from app.templates import bp
from flask import render_template, request


Expand Down
2 changes: 1 addition & 1 deletion test/app/utilities/routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from app.utilities import bp

from app.utilities import bp
from flask import render_template, request


Expand Down
59 changes: 58 additions & 1 deletion test/poetry.lock

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

4 changes: 3 additions & 1 deletion test/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ readme = "README.md"
python = "^3.12"
Flask = "^3.0.3"
Flask-WTF = "^1.2.1"

deepmerge = "^1.1.1"
markupsafe = "^2.1.5"
email-validator = "^2.2.0"

[build-system]
requires = ["poetry-core"]
Expand Down
2 changes: 2 additions & 0 deletions tna_frontend_jinja/templates/wtforms/button.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{%- from "components/button/macro.html" import tnaButton -%}
{{ tnaButton(params) }}
2 changes: 2 additions & 0 deletions tna_frontend_jinja/templates/wtforms/text-input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{%- from "components/text-input/macro.html" import tnaTextInput -%}
{{ tnaTextInput(params) }}
Loading

0 comments on commit 3b9c2d2

Please sign in to comment.