Skip to content

Commit 089e47b

Browse files
committed
Refactor texts app: jinja2, JSON helpers, tests
Reorganize and modernize the texts app: rename app package to 'swing_text', add a Jinja2 environment, and move/rename template files into a dedicated jinja2 package. Replace real site/contact values with example.com and update manifest/robots/security/humans entries. Rewrite helper_json with pathlib, UTF-8 handling and type hints; add read_json/write_json helpers. Update views to load brand, social and meta data from JSON and surface richer context (current_year, site, site_contact, social, meta). Extend URL patterns (additional text endpoints and manifest.json alias) and add comprehensive pytest-based tests for helpers, URLs and views. Remove legacy duplicate template files.
1 parent f2d1e8b commit 089e47b

36 files changed

Lines changed: 690 additions & 252 deletions

src/swing_text/apps.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
# =============================================================================
2424

2525
# Import | Standard Library
26-
from typing import Dict, List, Union
2726

2827

2928
# Import | Libraries
@@ -45,9 +44,8 @@ class TextsConfig(AppConfig):
4544
"""
4645

4746

48-
4947
# Full Python path to the application
50-
name = "website.texts"
48+
name = "swing_text"
5149

5250
# Short name for the application
5351
label = "texts"
@@ -67,7 +65,7 @@ class TextsConfig(AppConfig):
6765
# """
6866
# Apps Config Ready Function
6967
# """
70-
68+
7169
# Implicitly connect signal handlers decorated with @receiver.
7270
# from .. import signals
7371

src/swing_text/data/_brand.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
"contact" : {
1212
"url" :
1313
{
14-
"main" : "https://www.starling.associates/"
14+
"main" : "https://www.example.com/"
1515
},
1616
"phone" :
1717
{
1818
"mobile" : ""
1919
},
2020
"email" :
2121
{
22-
"main" : "info@starling.associates",
23-
"people" : "people@starling.associates"
22+
"main" : "info@example.com",
23+
"people" : "people@example.com"
2424
},
2525
"locations" :
2626
[
@@ -34,8 +34,8 @@
3434
"province": "Noord-Holland",
3535
"country": "The Netherlands",
3636
"phone": "+31 (0)20 2234658",
37-
"email": "info@starling.associates",
38-
"image" : "locations/starling_amsterdam.jpg",
37+
"email": "info@example.com",
38+
"image" : "locations/office_amsterdam.jpg",
3939
"google_map" : "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d1084.9204347769628!2d4.864936721209129!3d52.37832244426546!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47c5e30cdb797ce1%3A0xc64f2837b3ae5f2b!2sCentrale%20Markthal!5e0!3m2!1snl!2snl!4v1663139258129!5m2!1snl!2snl",
4040
"description" : ""
4141
},
@@ -49,8 +49,8 @@
4949
"province": "Zuid-Holland",
5050
"country": "The Netherlands",
5151
"phone": "",
52-
"email": "info@starling.associates",
53-
"image" : "locations/starling_rotterdam.jpg",
52+
"email": "info@example.com",
53+
"image" : "locations/office_rotterdam.jpg",
5454
"google_map" : "https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d615.0817345682342!2d4.4751986!3d51.9279899!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47c434a8f77ab6ab%3A0x2de24d4210bcaffe!2sSchiekade%20830%2C%203032%20AL%20Rotterdam!5e0!3m2!1snl!2snl!4v1663139189803!5m2!1snl!2snl",
5555
"description" : ""
5656
},
@@ -64,8 +64,8 @@
6464
"province": "Zuid-Holland",
6565
"country": "The Netherlands",
6666
"phone": "+31 (0)70 2051066",
67-
"email": "info@starling.associates",
68-
"image" : "locations/starling_the_hague.jpg",
67+
"email": "info@example.com",
68+
"image" : "locations/office_the_hague.jpg",
6969
"google_map" : "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d153.22948806145547!2d4.310559007340239!3d52.08570400000001!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47c5b73a23fb7c35%3A0xbd5a40c493150b3!2sNieuwe%20Schoolstraat%2052%2C%202514%20HZ%20Den%20Haag!5e0!3m2!1snl!2snl!4v1663139292813!5m2!1snl!2snl",
7070
"description" : ""
7171
}

src/swing_text/data/_social.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,62 @@
22
"social": [
33
{
44
"service": "500px",
5-
"profile": "https://www.500px.com/p/starling-cloud",
5+
"profile": "https://www.500px.com/p/example",
66
"active" : false
77
},
88
{
99
"service": "AngelList",
10-
"profile": "https://www.angel.co/starling-cloud",
10+
"profile": "https://www.angel.co/example",
1111
"active" : false
1212
},
1313
{
1414
"service": "Archinect",
15-
"profile": "https://archinect.com/starling_associates",
15+
"profile": "https://archinect.com/example",
1616
"active" : false
1717
},
1818
{
1919
"service": "Crunchbase",
20-
"profile": "https://www.crunchbase.com/organization/starling-cloud",
20+
"profile": "https://www.crunchbase.com/organization/example",
2121
"active" : false
2222
},
2323
{
2424
"service" : "Facebook",
25-
"profile" : "https://www.facebook.com/starlingclouds",
25+
"profile" : "https://www.facebook.com/example",
2626
"active" : true
2727
},
2828
{
2929
"service": "Figma",
30-
"profile": "https://www.figma.com/@starling",
30+
"profile": "https://www.figma.com/@example",
3131
"active" : false
3232
},
3333
{
3434
"service": "GitHub",
35-
"profile": "https://www.github.com/starling-associates",
35+
"profile": "https://www.github.com/example",
3636
"active" : true
3737
},
3838
{
3939
"service": "Instagram",
40-
"profile": "https://www.instagram.com/starling.cloud",
40+
"profile": "https://www.instagram.com/example",
4141
"active" : true
4242
},
4343
{
4444
"service": "Issuu",
45-
"profile": "https://www.issuu.com/starlingcloud",
45+
"profile": "https://www.issuu.com/example",
4646
"active" : false
4747
},
4848
{
4949
"service": "LinkedIn",
50-
"profile": "https://www.linkedin.com/company/starling-associates/",
50+
"profile": "https://www.linkedin.com/company/example/",
5151
"active" : true
5252
},
5353
{
5454
"service": "Pinterest",
55-
"profile": "https://www.pinterest.com/starlingcloud/",
55+
"profile": "https://www.pinterest.com/example/",
5656
"active" : false
5757
},
5858
{
5959
"service": "Vimeo",
60-
"profile": "https://www.vimeo.com/starlingcloud",
60+
"profile": "https://www.vimeo.com/example",
6161
"active" : true
6262
}
6363
]
Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Provides JSON file I/O utilities.
5+
"""
6+
17
import json
8+
from pathlib import Path
9+
from typing import Any, Union
210

311

4-
def read_file(path):
5-
file = open(path, "r")
6-
data = file.read()
7-
file.close()
8-
return data
12+
def read_file(path: Union[str, Path]) -> str:
13+
"""Read content from a file."""
14+
with open(path, "r", encoding="utf-8") as file:
15+
return file.read()
916

1017

11-
def read_json(path):
18+
def read_json(path: Union[str, Path]) -> dict[str, Any]:
19+
"""Read and parse JSON from a file."""
1220
return json.loads(read_file(path))
1321

1422

15-
def write_json(path, data):
16-
return write_file(path, json.dumps(data))
23+
def write_file(path: Union[str, Path], data: str) -> str:
24+
"""Write content to a file."""
25+
with open(path, "w", encoding="utf-8") as file:
26+
file.write(str(data))
27+
return data
1728

1829

19-
def write_file(path, data):
20-
file = open(path, "w")
21-
file.write(str(data))
22-
file.close()
23-
return data
30+
def write_json(path: Union[str, Path], data: dict[str, Any]) -> str:
31+
"""Write data as JSON to a file."""
32+
return write_file(path, json.dumps(data, indent=2))

src/swing_text/jinja2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Provides Jinja2 environment configuration.
5+
"""
6+
7+
from django.templatetags.static import static
8+
from django.urls import reverse
9+
from jinja2 import Environment
10+
11+
12+
def environment(**options):
13+
"""
14+
Create Jinja2 environment with Django integrations.
15+
"""
16+
env = Environment(**options)
17+
env.globals.update({
18+
"static": static,
19+
"url": reverse,
20+
})
21+
return env

src/swing_text/templates/_manifest.webmanifest renamed to src/swing_text/jinja2/_manifest.webmanifest

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "Scape Agency",
3-
"short_name": "Scape Agency",
2+
"name": "Scape Press",
3+
"short_name": "Scape Press",
44
"description": "",
55
"icons": [
66
{
@@ -61,4 +61,4 @@
6161
"icons": [{ "src": "", "sizes": "" }]
6262
}
6363
]
64-
}
64+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)