Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.
test_presentation_demo.py · 3.3 KB · 103 lines
| 1 | #!/usr/bin/env python3 |
| 2 | """ |
| 3 | Demo: Same data structure, multiple UI frameworks |
| 4 | Shows how DBBasic's presentation layer works |
| 5 | """ |
| 6 | |
| 7 | from presentation_layer import PresentationLayer |
| 8 | |
| 9 | # Define a simple UI structure as pure data |
| 10 | demo_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 |
| 81 | print("Generating Bootstrap version...") |
| 82 | bootstrap_html = PresentationLayer.render(demo_ui, 'bootstrap') |
| 83 | with open('demo_bootstrap.html', 'w') as f: |
| 84 | f.write(bootstrap_html) |
| 85 | print("✅ Created demo_bootstrap.html") |
| 86 | |
| 87 | # Render to Tailwind |
| 88 | print("\nGenerating Tailwind version...") |
| 89 | tailwind_html = PresentationLayer.render(demo_ui, 'tailwind') |
| 90 | with open('demo_tailwind.html', 'w') as f: |
| 91 | f.write(tailwind_html) |
| 92 | print("✅ Created demo_tailwind.html") |
| 93 | |
| 94 | print("\n" + "="*60) |
| 95 | print("SAME DATA STRUCTURE:") |
| 96 | print("="*60) |
| 97 | import json |
| 98 | print(json.dumps(demo_ui, indent=2)[:500] + "...") |
| 99 | |
| 100 | print("\n" + "="*60) |
| 101 | print("RENDERS TO DIFFERENT FRAMEWORKS!") |
| 102 | print("="*60) |
| 103 | print("Open demo_bootstrap.html and demo_tailwind.html to compare") |