Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions scripts/example_gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func main() {
os.Stderr,
`Usage: %s <input_dir> <output_json>

Generates a FileNode[] JSON array from the direct children of <input_dir>,
wrapped in a "tmp" root directory. Only includes .bal and .toml files;
skips empty directories.
Generates a FileNode[] JSON array by recursively walking <input_dir>,
wrapped under a "tmp/examples" root directory. Only includes .bal and .toml
files; skips empty directories.
`,
filepath.Base(os.Args[0]),
)
Expand Down Expand Up @@ -110,7 +110,7 @@ func run(args []string) error {
return err
}

nodes = []Node{Dir("tmp", nodes)}
nodes = []Node{Dir("tmp", []Node{Dir("examples", nodes)})}

if err := writeJSON(outputPath, nodes); err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions web/bun.lock

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

2 changes: 2 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"immer": "^11.1.4",
"next-themes": "^0.4.6",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"react-hotkeys-hook": "^5.2.4",
"shadcn": "^4.0.7",
"shiki": "^4.0.2",
"sonner": "^2.0.7",
"tailwind-merge": "^3.5.0",
"tailwindcss": "^4.2.1",
"tw-animate-css": "^1.4.0",
Expand Down
32 changes: 19 additions & 13 deletions web/src/assets/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@
"name": "tmp",
"children": [
{
"kind": "file",
"name": "01-orders.bal",
"content": "import ballerina/io;\n\n// Shows pending orders with delivery fees\ntype Order record {|\n string id;\n string customer;\n int amount;\n string zone;\n|};\n\npublic function main() {\n Order[] orders = [\n {id: \"ORD001\", customer: \"Alice\", amount: 150, zone: \"Downtown\"},\n {id: \"ORD002\", customer: \"Bob\", amount: 75, zone: \"Suburb\"},\n {id: \"ORD003\", customer: \"Carol\", amount: 200, zone: \"Downtown\"}\n ];\n map\u003cint\u003e deliveryFee = {\"Downtown\": 5, \"Suburb\": 10};\n\n io:println(\"=== Pending Orders ===\");\n foreach int i in 0 ..\u003c orders.length() {\n Order ord = orders[i];\n io:println(i + 1, \". \", ord.id, \" | \",\n ord.customer, \" | $\", ord.amount,\n \" | \", ord.zone, \" (fee: $\", deliveryFee[ord.zone], \")\");\n }\n}\n\n"
},
{
"kind": "file",
"name": "02-response-aggregator.bal",
"content": "import ballerina/io;\n\n// Aggregates responses from multiple API endpoints, categorizes them by status\n// and flags, and processes mixed result types.\ntype ApiResponse record {|\n string ep;\n int status;\n int flags;\n any result;\n|};\n\npublic function main() {\n // Response flags\n int cached = 1 \u003c\u003c 0;\n int partial = 1 \u003c\u003c 1;\n int paginated = 1 \u003c\u003c 2;\n\n ApiResponse[] responses = [\n {ep: \"/users\", status: 200, flags: cached, result: 150},\n {ep: \"/orders\", status: 200, flags: cached + paginated, result: \"paginated\"},\n {ep: \"/products\", status: 206, flags: partial, result: 42}\n ];\n [string, int] healthCheck = [\"/health\", 200];\n\n io:println(\"Health Check: \", healthCheck[0], \" (\", healthCheck[1], \")\");\n\n foreach ApiResponse res in responses {\n io:println(\"\\nEndpoint: \", res.ep, \",\\n Status: \", res.status);\n\n if res.flags \u003e= paginated {\n io:println(\" [Paginated]\");\n } else if res.flags == cached {\n io:println(\" [Cached]\");\n } else {\n io:println(\" [Partial]\");\n }\n\n any result = res.result;\n if result is int {\n int count = \u003cint\u003eresult;\n io:println(\" Count: \", count);\n } else if result is string {\n io:println(\" Info: \", result);\n }\n }\n}\n"
},
{
"kind": "file",
"name": "03-fibonacci.bal",
"content": "import ballerina/io;\n\npublic function main() {\n int n = 10;\n int i = 0;\n while (i \u003c n) {\n io:println(\"F(\", i, \") = \", fibonacci(i));\n i += 1;\n }\n}\n\nfunction fibonacci(int n) returns int {\n if (n \u003c= 1) {\n return n;\n }\n int prev = 0;\n int curr = 1;\n int i = 2;\n while (i \u003c= n) {\n int next = prev + curr;\n prev = curr;\n curr = next;\n i += 1;\n }\n return curr;\n}\n"
"kind": "dir",
"name": "examples",
"children": [
{
"kind": "file",
"name": "01-orders.bal",
"content": "import ballerina/io;\n\n// Shows pending orders with delivery fees\ntype Order record {|\n string id;\n string customer;\n int amount;\n string zone;\n|};\n\npublic function main() {\n Order[] orders = [\n {id: \"ORD001\", customer: \"Alice\", amount: 150, zone: \"Downtown\"},\n {id: \"ORD002\", customer: \"Bob\", amount: 75, zone: \"Suburb\"},\n {id: \"ORD003\", customer: \"Carol\", amount: 200, zone: \"Downtown\"}\n ];\n map\u003cint\u003e deliveryFee = {\"Downtown\": 5, \"Suburb\": 10};\n\n io:println(\"=== Pending Orders ===\");\n foreach int i in 0 ..\u003c orders.length() {\n Order ord = orders[i];\n io:println(i + 1, \". \", ord.id, \" | \",\n ord.customer, \" | $\", ord.amount,\n \" | \", ord.zone, \" (fee: $\", deliveryFee[ord.zone], \")\");\n }\n}\n\n"
},
{
"kind": "file",
"name": "02-response-aggregator.bal",
"content": "import ballerina/io;\n\n// Aggregates responses from multiple API endpoints, categorizes them by status\n// and flags, and processes mixed result types.\ntype ApiResponse record {|\n string ep;\n int status;\n int flags;\n any result;\n|};\n\npublic function main() {\n // Response flags\n int cached = 1 \u003c\u003c 0;\n int partial = 1 \u003c\u003c 1;\n int paginated = 1 \u003c\u003c 2;\n\n ApiResponse[] responses = [\n {ep: \"/users\", status: 200, flags: cached, result: 150},\n {ep: \"/orders\", status: 200, flags: cached + paginated, result: \"paginated\"},\n {ep: \"/products\", status: 206, flags: partial, result: 42}\n ];\n [string, int] healthCheck = [\"/health\", 200];\n\n io:println(\"Health Check: \", healthCheck[0], \" (\", healthCheck[1], \")\");\n\n foreach ApiResponse res in responses {\n io:println(\"\\nEndpoint: \", res.ep, \",\\n Status: \", res.status);\n\n if res.flags \u003e= paginated {\n io:println(\" [Paginated]\");\n } else if res.flags == cached {\n io:println(\" [Cached]\");\n } else {\n io:println(\" [Partial]\");\n }\n\n any result = res.result;\n if result is int {\n int count = \u003cint\u003eresult;\n io:println(\" Count: \", count);\n } else if result is string {\n io:println(\" Info: \", result);\n }\n }\n}\n"
},
{
"kind": "file",
"name": "03-fibonacci.bal",
"content": "import ballerina/io;\n\npublic function main() {\n int n = 10;\n int i = 0;\n while (i \u003c n) {\n io:println(\"F(\", i, \") = \", fibonacci(i));\n i += 1;\n }\n}\n\nfunction fibonacci(int n) returns int {\n if (n \u003c= 1) {\n return n;\n }\n int prev = 0;\n int curr = 1;\n int i = 2;\n while (i \u003c= n) {\n int next = prev + curr;\n prev = curr;\n curr = next;\n i += 1;\n }\n return curr;\n}\n"
}
]
}
]
}
Expand Down
Loading