askrobots / dbbasic Public

Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.

0 downloads

dbbasic/test_presentation_demo.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add DBBasic crate engine logo and update README 0d628db 1 year, 2 months ago History
test_presentation_demo.py · 3.3 KB · 103 lines
1#!/usr/bin/env python3
2"""
3Demo: Same data structure, multiple UI frameworks
4Shows how DBBasic's presentation layer works
5"""
6
7from presentation_layer import PresentationLayer
8
9# Define a simple UI structure as pure data
10demo_ui = {
11 'type': 'page',
12 'title': 'DBBasic Demo - Same Data, Different Frameworks',
13 'components': [
14 {
15 'type': 'navbar',
16 'brand': 'DBBasic Demo',
17 'links': ['Dashboard', 'Data', 'Settings']
18 },
19 {
20 'type': 'alert',
21 'message': 'This page demonstrates how the same data structure renders in different UI frameworks',
22 'variant': 'info'
23 },
24 {
25 'type': 'hero',
26 'title': '🎨 Framework Flexibility',
27 'subtitle': 'One data structure, infinite possibilities'
28 },
29 {
30 'type': 'grid',
31 'columns': 2,
32 'items': [
33 {
34 'type': 'card',
35 'title': 'Bootstrap Version',
36 'category': 'Framework',
37 'description': 'Uses Bootstrap 5.3 classes and components',
38 'actions': ['deploy', 'preview']
39 },
40 {
41 'type': 'card',
42 'title': 'Tailwind Version',
43 'category': 'Framework',
44 'description': 'Uses Tailwind utility classes',
45 'actions': ['deploy', 'preview']
46 }
47 ]
48 },
49 {
50 'type': 'container',
51 'children': [
52 '<hr class="my-5">',
53 '<h2 class="text-center">Benefits of This Approach</h2>',
54 {
55 'type': 'grid',
56 'columns': 3,
57 'items': [
58 {
59 'type': 'card',
60 'title': '🤖 AI-Friendly',
61 'description': 'AI can generate UI by creating data structures'
62 },
63 {
64 'type': 'card',
65 'title': '🎨 Customizable',
66 'description': 'Users can add their own UI framework renderers'
67 },
68 {
69 'type': 'card',
70 'title': '🧹 Clean Code',
71 'description': 'No HTML mixed with Python business logic'
72 }
73 ]
74 }
75 ]
76 }
77 ]
78}
79
80# Render to Bootstrap
81print("Generating Bootstrap version...")
82bootstrap_html = PresentationLayer.render(demo_ui, 'bootstrap')
83with open('demo_bootstrap.html', 'w') as f:
84 f.write(bootstrap_html)
85print("✅ Created demo_bootstrap.html")
86
87# Render to Tailwind
88print("\nGenerating Tailwind version...")
89tailwind_html = PresentationLayer.render(demo_ui, 'tailwind')
90with open('demo_tailwind.html', 'w') as f:
91 f.write(tailwind_html)
92print("✅ Created demo_tailwind.html")
93
94print("\n" + "="*60)
95print("SAME DATA STRUCTURE:")
96print("="*60)
97import json
98print(json.dumps(demo_ui, indent=2)[:500] + "...")
99
100print("\n" + "="*60)
101print("RENDERS TO DIFFERENT FRAMEWORKS!")
102print("="*60)
103print("Open demo_bootstrap.html and demo_tailwind.html to compare")