poml 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/docs/tutorial/advanced/performance.md +695 -0
  3. data/docs/tutorial/advanced/tool-registration.md +776 -0
  4. data/docs/tutorial/basic-usage.md +351 -0
  5. data/docs/tutorial/components/chat-components.md +552 -0
  6. data/docs/tutorial/components/formatting.md +623 -0
  7. data/docs/tutorial/components/index.md +366 -0
  8. data/docs/tutorial/components/media-components.md +259 -0
  9. data/docs/tutorial/components/schema-components.md +668 -0
  10. data/docs/tutorial/index.md +184 -0
  11. data/docs/tutorial/output-formats.md +688 -0
  12. data/docs/tutorial/quickstart.md +30 -0
  13. data/docs/tutorial/template-engine.md +540 -0
  14. data/lib/poml/components/base.rb +146 -4
  15. data/lib/poml/components/content.rb +10 -3
  16. data/lib/poml/components/data.rb +539 -19
  17. data/lib/poml/components/examples.rb +235 -1
  18. data/lib/poml/components/formatting.rb +184 -18
  19. data/lib/poml/components/layout.rb +7 -2
  20. data/lib/poml/components/lists.rb +69 -35
  21. data/lib/poml/components/meta.rb +134 -5
  22. data/lib/poml/components/output_schema.rb +19 -1
  23. data/lib/poml/components/template.rb +72 -61
  24. data/lib/poml/components/text.rb +30 -1
  25. data/lib/poml/components/tool.rb +81 -0
  26. data/lib/poml/components/tool_definition.rb +339 -10
  27. data/lib/poml/components/tools.rb +14 -0
  28. data/lib/poml/components/utilities.rb +34 -18
  29. data/lib/poml/components.rb +19 -0
  30. data/lib/poml/context.rb +19 -4
  31. data/lib/poml/parser.rb +88 -63
  32. data/lib/poml/renderer.rb +191 -9
  33. data/lib/poml/template_engine.rb +138 -13
  34. data/lib/poml/version.rb +1 -1
  35. data/lib/poml.rb +16 -1
  36. data/readme.md +154 -27
  37. metadata +31 -4
  38. data/TUTORIAL.md +0 -987
@@ -0,0 +1,623 @@
1
+ # Formatting Components
2
+
3
+ POML provides comprehensive text formatting components that work seamlessly with templates and other POML features. These components support both block and inline rendering modes.
4
+
5
+ ## Format-Aware Rendering
6
+
7
+ Formatting components automatically adapt their output based on the specified output format:
8
+
9
+ ### Default (Markdown) Output
10
+
11
+ ```ruby
12
+ markup = <<~POML
13
+ <poml>
14
+ <h1>Main Title</h1>
15
+ <p>Text with <b>bold</b> and <i>italic</i> formatting.</p>
16
+ </poml>
17
+ POML
18
+
19
+ result = Poml.process(markup: markup)
20
+ puts result['content']
21
+ ```
22
+
23
+ **Output:**
24
+
25
+ ```text
26
+ # Main Title
27
+
28
+ Text with **bold** and *italic* formatting.
29
+ ```
30
+
31
+ ### HTML Output Format
32
+
33
+ ```ruby
34
+ markup = <<~POML
35
+ <poml>
36
+ <h1>Main Title</h1>
37
+ <p>Text with <b>bold</b> and <i>italic</i> formatting.</p>
38
+ <output format="html"/>
39
+ </poml>
40
+ POML
41
+
42
+ result = Poml.process(markup: markup)
43
+ puts result['output']
44
+ ```
45
+
46
+ **Output:**
47
+
48
+ ```html
49
+ <h1>Main Title</h1>
50
+ <p>Text with <b>bold</b> and <i>italic</i> formatting.</p>
51
+ ```
52
+
53
+ ### Text-Only Output
54
+
55
+ ```ruby
56
+ markup = <<~POML
57
+ <poml>
58
+ <h1>Main Title</h1>
59
+ <p>Text with <b>bold</b> and <i>italic</i> formatting.</p>
60
+ <output format="text"/>
61
+ </poml>
62
+ POML
63
+
64
+ result = Poml.process(markup: markup)
65
+ puts result['output']
66
+ ```
67
+
68
+ **Output:**
69
+
70
+ ```text
71
+ Main Title
72
+
73
+ Text with bold and italic formatting.
74
+ ```
75
+
76
+ ## Text Formatting
77
+
78
+ ### Bold Text - `<b>`
79
+
80
+ Make text **bold** for emphasis:
81
+
82
+ ```xml
83
+ <poml>
84
+ <p>This is <b>important information</b> to remember.</p>
85
+
86
+ <!-- Inline rendering for seamless flow -->
87
+ <p>The <b inline="true">critical step</b> requires attention.</p>
88
+
89
+ <!-- With template variables -->
90
+ <p><b>{{important_concept}}</b> is fundamental to understanding.</p>
91
+ </poml>
92
+ ```
93
+
94
+ **Output:**
95
+
96
+ ```
97
+ This is **important information** to remember.
98
+
99
+ The **critical step** requires attention.
100
+
101
+ **Machine Learning** is fundamental to understanding.
102
+ ```
103
+
104
+ ### Italic Text - `<i>`
105
+
106
+ Use *italic* text for emphasis or citations:
107
+
108
+ ```xml
109
+ <poml>
110
+ <p>According to <i>{{source_title}}</i>, the results show improvement.</p>
111
+
112
+ <!-- Technical terms -->
113
+ <p>The <i inline="true">algorithmic complexity</i> is O(n log n).</p>
114
+
115
+ <!-- Multiple emphasis levels -->
116
+ <p><i>Note:</i> <b>Critical</b> - Please review carefully.</p>
117
+ </poml>
118
+ ```
119
+
120
+ ### Underlined Text - `<u>`
121
+
122
+ Underline text for highlighting:
123
+
124
+ ```xml
125
+ <poml>
126
+ <p><u>Important:</u> All fields marked with * are required.</p>
127
+
128
+ <!-- Combined formatting -->
129
+ <p><b><u>{{section_title}}</u></b></p>
130
+ </poml>
131
+ ```
132
+
133
+ ### Strikethrough Text - `<s>`
134
+
135
+ Show deleted or outdated information:
136
+
137
+ ```xml
138
+ <poml>
139
+ <p>The original approach was <s>{{old_method}}</s> {{new_method}}.</p>
140
+
141
+ <!-- Corrections -->
142
+ <p>Price: <s>$99</s> <b>$79</b> (on sale)</p>
143
+ </poml>
144
+ ```
145
+
146
+ ### Inline Code - `<code>`
147
+
148
+ Format code snippets and technical terms:
149
+
150
+ ```xml
151
+ <poml>
152
+ <p>Use the <code>{{method_name}}</code> method to process data.</p>
153
+
154
+ <!-- Multi-line code blocks -->
155
+ <code>
156
+ def process_data(input)
157
+ {{processing_logic}}
158
+ end
159
+ </code>
160
+
161
+ <!-- Inline technical terms -->
162
+ <p>Set the <code inline="true">API_KEY</code> environment variable.</p>
163
+ </poml>
164
+ ```
165
+
166
+ **Output:**
167
+
168
+ ```
169
+ Use the `process_user_data` method to process data.
170
+
171
+ ```
172
+
173
+ def process_data(input)
174
+ input.map(&:transform).filter(&:valid?)
175
+ end
176
+
177
+ ```
178
+
179
+ Set the `API_KEY` environment variable.
180
+ ```
181
+
182
+ ## Headers
183
+
184
+ ### Header Levels - `<h1>` to `<h6>`
185
+
186
+ Create hierarchical content structure:
187
+
188
+ ```xml
189
+ <poml>
190
+ <h1>{{main_title}}</h1>
191
+
192
+ <h2>Overview</h2>
193
+ <p>Brief description of the topic.</p>
194
+
195
+ <h3>{{subsection_title}}</h3>
196
+ <p>Detailed information about {{specific_aspect}}.</p>
197
+
198
+ <h4>Implementation Details</h4>
199
+ <list>
200
+ <item>Step 1: {{step_one}}</item>
201
+ <item>Step 2: {{step_two}}</item>
202
+ </list>
203
+
204
+ <h5>Technical Notes</h5>
205
+ <p>Additional technical considerations.</p>
206
+
207
+ <h6>References</h6>
208
+ <p>See {{documentation_link}} for more details.</p>
209
+ </poml>
210
+ ```
211
+
212
+ **Output:**
213
+
214
+ ```markdown
215
+ # Machine Learning Pipeline
216
+
217
+ ## Overview
218
+ Brief description of the topic.
219
+
220
+ ### Data Preprocessing
221
+ Detailed information about feature engineering.
222
+
223
+ #### Implementation Details
224
+ - Step 1: Data collection and validation
225
+ - Step 2: Feature extraction and transformation
226
+
227
+ ##### Technical Notes
228
+ Additional technical considerations.
229
+
230
+ ###### References
231
+ See https://ml-docs.example.com for more details.
232
+ ```
233
+
234
+ ### Dynamic Headers
235
+
236
+ ```xml
237
+ <poml>
238
+ <for variable="section" items="{{documentation_sections}}">
239
+ <h2>{{section.title}}</h2>
240
+ <p>{{section.description}}</p>
241
+
242
+ <for variable="subsection" items="{{section.subsections}}">
243
+ <h3>{{subsection.title}}</h3>
244
+ <p>{{subsection.content}}</p>
245
+ </for>
246
+ </for>
247
+ </poml>
248
+ ```
249
+
250
+ ## Structural Elements
251
+
252
+ ### Line Breaks - `<br>`
253
+
254
+ Control line spacing and layout:
255
+
256
+ ```xml
257
+ <poml>
258
+ <p>First line<br>Second line</p>
259
+
260
+ <!-- Multiple breaks for spacing -->
261
+ <p>Section A content</p>
262
+ <br><br>
263
+ <p>Section B content with extra spacing</p>
264
+
265
+ <!-- Conditional breaks -->
266
+ <if condition="{{add_spacing}}">
267
+ <br>
268
+ </if>
269
+ </poml>
270
+ ```
271
+
272
+ ### Paragraphs - `<p>`
273
+
274
+ Structure text content:
275
+
276
+ ```xml
277
+ <poml>
278
+ <p>
279
+ This is a paragraph with <b>{{highlighted_term}}</b> and
280
+ <i>{{emphasized_concept}}</i>. It can contain multiple
281
+ formatting elements.
282
+ </p>
283
+
284
+ <p>
285
+ Another paragraph with <code>{{code_example}}</code> and
286
+ a reference to <u>{{important_document}}</u>.
287
+ </p>
288
+
289
+ <!-- Conditional paragraphs -->
290
+ <if condition="{{include_warning}}">
291
+ <p><b>Warning:</b> {{warning_message}}</p>
292
+ </if>
293
+ </poml>
294
+ ```
295
+
296
+ ## Advanced Formatting
297
+
298
+ ### Nested Formatting
299
+
300
+ Combine multiple formatting elements:
301
+
302
+ ```xml
303
+ <poml>
304
+ <p>
305
+ <b>
306
+ <i>Very important</i>
307
+ </b> information that requires
308
+ <u>
309
+ <code>special_attention()</code>
310
+ </u>
311
+ </p>
312
+
313
+ <!-- Complex combinations -->
314
+ <p>
315
+ Status: <b><u>{{status}}</u></b><br>
316
+ Method: <code><i>{{method_name}}</i></code><br>
317
+ Result: <s>{{old_result}}</s> → <b>{{new_result}}</b>
318
+ </p>
319
+ </poml>
320
+ ```
321
+
322
+ ### Inline Rendering Mode
323
+
324
+ Enable seamless text flow:
325
+
326
+ ```xml
327
+ <poml>
328
+ <p>
329
+ The method
330
+ <code inline="true">{{method_name}}</code>
331
+ returns a
332
+ <b inline="true">{{return_type}}</b>
333
+ value representing
334
+ <i inline="true">{{description}}</i>.
335
+ </p>
336
+
337
+ <!-- Without inline mode (default) -->
338
+ <p>
339
+ The method <code>{{method_name}}</code> returns
340
+ a <b>{{return_type}}</b> value.
341
+ </p>
342
+ </poml>
343
+ ```
344
+
345
+ **With inline="true":**
346
+
347
+ ```
348
+ The method process_data returns a DataResult value representing processed user information.
349
+ ```
350
+
351
+ **Without inline (default):**
352
+
353
+ ```
354
+ The method `process_data` returns
355
+ a **DataResult** value.
356
+ ```
357
+
358
+ ### Template Integration
359
+
360
+ Use formatting with template engine:
361
+
362
+ ```xml
363
+ <poml>
364
+ <for variable="item" items="{{task_list}}">
365
+ <p>
366
+ <if condition="{{item.priority}} == 'high'">
367
+ <b><u>{{item.title}}</u></b>
368
+ </if>
369
+ <if condition="{{item.priority}} == 'medium'">
370
+ <b>{{item.title}}</b>
371
+ </if>
372
+ <if condition="{{item.priority}} == 'low'">
373
+ <i>{{item.title}}</i>
374
+ </if>
375
+
376
+ <br>
377
+ <code>Status: {{item.status}}</code>
378
+
379
+ <if condition="{{item.notes}}">
380
+ <br><small>{{item.notes}}</small>
381
+ </if>
382
+ </p>
383
+ </for>
384
+ </poml>
385
+ ```
386
+
387
+ ### Conditional Formatting
388
+
389
+ Apply formatting based on conditions:
390
+
391
+ ```xml
392
+ <poml>
393
+ <p>
394
+ Result:
395
+ <if condition="{{success}}">
396
+ <b style="color: green">✅ {{result_message}}</b>
397
+ </if>
398
+ <if condition="!{{success}}">
399
+ <b style="color: red">❌ {{error_message}}</b>
400
+ </if>
401
+ </p>
402
+
403
+ <!-- Format based on data type -->
404
+ <for variable="field" items="{{data_fields}}">
405
+ <p>
406
+ {{field.name}}:
407
+ <if condition="{{field.type}} == 'string'">
408
+ <i>"{{field.value}}"</i>
409
+ </if>
410
+ <if condition="{{field.type}} == 'number'">
411
+ <code>{{field.value}}</code>
412
+ </if>
413
+ <if condition="{{field.type}} == 'boolean'">
414
+ <b>{{field.value}}</b>
415
+ </if>
416
+ </p>
417
+ </for>
418
+ </poml>
419
+ ```
420
+
421
+ ## Accessibility and Best Practices
422
+
423
+ ### Semantic Markup
424
+
425
+ Use appropriate formatting for meaning:
426
+
427
+ ```xml
428
+ <poml>
429
+ <!-- Good: Semantic usage -->
430
+ <h2>{{section_title}}</h2>
431
+ <p><b>Important:</b> {{critical_information}}</p>
432
+ <p>Reference: <i>{{citation}}</i></p>
433
+ <p>Command: <code>{{terminal_command}}</code></p>
434
+
435
+ <!-- Avoid: Formatting without meaning -->
436
+ <!-- Don't use <h1> just for large text -->
437
+ <!-- Don't use <b> for non-important text -->
438
+ </poml>
439
+ ```
440
+
441
+ ### Consistent Formatting
442
+
443
+ Establish formatting patterns:
444
+
445
+ ```xml
446
+ <poml>
447
+ <!-- API documentation pattern -->
448
+ <h3>{{endpoint_name}}</h3>
449
+ <p><code>{{http_method}} {{endpoint_path}}</code></p>
450
+ <p><b>Purpose:</b> {{endpoint_description}}</p>
451
+ <p><i>Authentication required:</i> {{auth_required}}</p>
452
+
453
+ <!-- Error message pattern -->
454
+ <p><b>Error:</b> <code>{{error_code}}</code></p>
455
+ <p><i>Description:</i> {{error_description}}</p>
456
+
457
+ <!-- Success message pattern -->
458
+ <p><b>✅ Success:</b> {{success_message}}</p>
459
+ </poml>
460
+ ```
461
+
462
+ ### Performance Considerations
463
+
464
+ Optimize formatting for large documents:
465
+
466
+ ```xml
467
+ <poml>
468
+ <!-- Efficient: Use inline for short text -->
469
+ <p>The <code inline="true">{{variable}}</code> contains data.</p>
470
+
471
+ <!-- Efficient: Batch similar formatting -->
472
+ <for variable="item" items="{{items}}">
473
+ <if condition="{{item.important}}">
474
+ <p><b>{{item.title}}</b> - {{item.description}}</p>
475
+ </if>
476
+ </for>
477
+
478
+ <!-- Less efficient: Excessive nesting -->
479
+ <!-- Avoid deep nesting when possible -->
480
+ </poml>
481
+ ```
482
+
483
+ ## Output Format Compatibility
484
+
485
+ ### All Formats
486
+
487
+ Basic formatting works across all output formats:
488
+
489
+ ```xml
490
+ <poml>
491
+ <p><b>Bold</b> and <i>italic</i> text.</p>
492
+ <code>code_example</code>
493
+ </poml>
494
+ ```
495
+
496
+ ### Raw Format
497
+
498
+ ```
499
+ **Bold** and *italic* text.
500
+ `code_example`
501
+ ```
502
+
503
+ ### Dict Format
504
+
505
+ ```ruby
506
+ {
507
+ "content" => "**Bold** and *italic* text.\n`code_example`",
508
+ "formatting" => ["bold", "italic", "code"]
509
+ }
510
+ ```
511
+
512
+ ### Chat Formats
513
+
514
+ ```ruby
515
+ {
516
+ "messages" => [
517
+ {
518
+ "role" => "user",
519
+ "content" => "**Bold** and *italic* text.\n`code_example`"
520
+ }
521
+ ]
522
+ }
523
+ ```
524
+
525
+ ## Common Patterns
526
+
527
+ ### Documentation Generation
528
+
529
+ ```xml
530
+ <poml>
531
+ <h1>{{api_name}} Documentation</h1>
532
+
533
+ <h2>Methods</h2>
534
+ <for variable="method" items="{{api_methods}}">
535
+ <h3><code>{{method.name}}</code></h3>
536
+ <p><i>{{method.description}}</i></p>
537
+
538
+ <h4>Parameters</h4>
539
+ <for variable="param" items="{{method.parameters}}">
540
+ <p>
541
+ <code>{{param.name}}</code>
542
+ <i>({{param.type}})</i> - {{param.description}}
543
+ <if condition="{{param.required}}">
544
+ <b>Required</b>
545
+ </if>
546
+ </p>
547
+ </for>
548
+
549
+ <h4>Example</h4>
550
+ <code>{{method.example}}</code>
551
+ </for>
552
+ </poml>
553
+ ```
554
+
555
+ ### Status Reports
556
+
557
+ ```xml
558
+ <poml>
559
+ <h2>System Status Report</h2>
560
+
561
+ <for variable="service" items="{{services}}">
562
+ <p>
563
+ <b>{{service.name}}:</b>
564
+ <if condition="{{service.status}} == 'operational'">
565
+ <b style="color: green">✅ Operational</b>
566
+ </if>
567
+ <if condition="{{service.status}} == 'degraded'">
568
+ <b style="color: orange">⚠️ Degraded</b>
569
+ </if>
570
+ <if condition="{{service.status}} == 'down'">
571
+ <b style="color: red">❌ Down</b>
572
+ </if>
573
+ </p>
574
+
575
+ <if condition="{{service.issues}}">
576
+ <p><i>Issues:</i> {{service.issues}}</p>
577
+ </if>
578
+ </for>
579
+ </poml>
580
+ ```
581
+
582
+ ### Code Review Comments
583
+
584
+ ```xml
585
+ <poml>
586
+ <h3>Code Review for {{file_name}}</h3>
587
+
588
+ <for variable="issue" items="{{code_issues}}">
589
+ <p>
590
+ <b>Line {{issue.line}}:</b>
591
+ <if condition="{{issue.severity}} == 'error'">
592
+ <b><u>Error</u></b>
593
+ </if>
594
+ <if condition="{{issue.severity}} == 'warning'">
595
+ <b>Warning</b>
596
+ </if>
597
+ <if condition="{{issue.severity}} == 'suggestion'">
598
+ <i>Suggestion</i>
599
+ </if>
600
+ </p>
601
+
602
+ <p>{{issue.description}}</p>
603
+
604
+ <if condition="{{issue.suggested_fix}}">
605
+ <p><b>Suggested fix:</b></p>
606
+ <code>{{issue.suggested_fix}}</code>
607
+ </if>
608
+ </for>
609
+ </poml>
610
+ ```
611
+
612
+ ## Next Steps
613
+
614
+ 1. **Practice Basic Formatting** - Start with simple `<b>`, `<i>`, `<code>` usage
615
+ 2. **Learn Template Integration** - Combine formatting with variables and conditions
616
+ 3. **Explore Advanced Components** - Move to [Data Components](data-components.md)
617
+ 4. **Master Layout** - Check [Component Overview](index.md) for structure patterns
618
+
619
+ For more advanced formatting techniques, see:
620
+
621
+ - [Template Engine](../template-engine.md) for dynamic formatting
622
+ - [Component Overview](index.md) for layout patterns
623
+ - [Advanced Techniques](../advanced/) for optimization tips