-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimple_dsl_example.py
More file actions
89 lines (69 loc) · 2.92 KB
/
simple_dsl_example.py
File metadata and controls
89 lines (69 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
"""
Simple DSL Example
This demonstrates the new Logseq Builder DSL with a basic example.
"""
import sys
from pathlib import Path
# Add the parent directory to Python path
sys.path.insert(0, str(Path(__file__).parent.parent))
from logseq_py.builders import PageBuilder, TaskBuilder, CodeBlockBuilder, QuoteBuilder, TableBuilder
def main():
"""Demonstrate the DSL builders."""
print("🎯 Logseq DSL Example")
# Create a page using the fluent interface
page = (PageBuilder("DSL Example Page")
.author("DSL Demo")
.created()
.page_type("example")
.tags("dsl", "demo", "builders")
# Add content using method chaining
.heading(1, "Welcome to the DSL!")
.text("This page demonstrates the new builder patterns.")
.empty_line()
.heading(2, "Task Management")
.text("Tasks created with TaskBuilder:"))
# Add tasks using TaskBuilder
page.add(TaskBuilder("Learn the new DSL").todo().high_priority())
page.add(TaskBuilder("Create example content").doing().medium_priority().effort("2h"))
page.add(TaskBuilder("Share with the team").todo().low_priority().context("email"))
# Add code example
page.empty_line().heading(2, "Code Example")
code_block = (page.code_block("python")
.comment("Example of using the DSL")
.line("page = (PageBuilder('My Page')")
.line(" .author('Me')")
.line(" .heading(1, 'Hello World!')")
.line(" .text('Content here'))")
.blank_line()
.line("task = TaskBuilder('Do something').todo().high_priority()")
.line("page.add(task)"))
# Add quote
page.empty_line().heading(2, "Quote Example")
quote_block = (page.quote()
.line("The best way to predict the future is to create it.")
.author("Peter Drucker"))
# Add table
page.empty_line().heading(2, "Table Example")
table = (page.table()
.headers("Feature", "Status", "Priority")
.row("Core DSL", "✅ Complete", "High")
.row("Advanced Features", "🔄 In Progress", "Medium")
.row("Documentation", "📝 Planned", "Low"))
page.empty_line().separator().empty_line()
page.text("*Generated with the Logseq Builder DSL!* 🚀")
# Build and output
content = page.build()
print("\n" + "="*50)
print("GENERATED CONTENT:")
print("="*50)
print(content)
print("="*50)
# Write to file for inspection
output_file = Path(__file__).parent / "dsl_example_output.md"
with open(output_file, "w") as f:
f.write(content)
print(f"\n✅ Content written to: {output_file}")
print("🎉 DSL example completed successfully!")
if __name__ == "__main__":
main()