Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion dart/dotprompt/lib/src/dotprompt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class Dotprompt {

/// Resolves partial references in a template.
Future<void> _resolvePartials(String template) async {
final partialPattern = RegExp(r"\{\{>\s*([a-zA-Z0-9_-]+)");
final partialPattern = RegExp(r"\{\{>\s*([a-zA-Z0-9_.-]+)");
final matches = partialPattern.allMatches(template);

for (final match in matches) {
Expand Down
2 changes: 1 addition & 1 deletion java/com/google/dotprompt/Dotprompt.java
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ private CompletableFuture<Void> resolvePartialsAsync(String template, Set<String
private Set<String> identifyPartials(String template) {
Set<String> partials = new HashSet<>();
// Match {{> partialName}} or {{> partialName context}}
Pattern pattern = Pattern.compile("\\{\\{>\\s*([a-zA-Z0-9_-]+)");
Pattern pattern = Pattern.compile("\\{\\{>\\s*([a-zA-Z0-9_.-]+)");
Matcher matcher = pattern.matcher(template);
while (matcher.find()) {
partials.add(matcher.group(1));
Expand Down
2 changes: 1 addition & 1 deletion rs/dotprompt/src/dotprompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ impl Dotprompt {
pub fn identify_partials(&self, template: &str) -> std::collections::HashSet<String> {
let mut partials = std::collections::HashSet::new();
// Simple regex-based partial detection: {{> partialName}}
let re = regex::Regex::new(r"\{\{>\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}")
let re = regex::Regex::new(r"\{\{>\s*([a-zA-Z_][a-zA-Z0-9_.]*)\s*\}\}")
.expect("internal regex pattern should compile");
for cap in re.captures_iter(template) {
if let Some(name) = cap.get(1) {
Expand Down
17 changes: 17 additions & 0 deletions spec/partials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@
content:
[{ text: "Hello from a partial! This is the main template.\n" }]

# Tests that partial names support the full filename regex: letters, digits,
# underscores, hyphens, and dots (e.g., topic-2.sub_topic).
- name: partial_name_with_full_regex
template: |
{{> Topic-2.sub_topic}} This is the main template.
partials:
Topic-2.sub_topic: "Hello from a complex-named partial!"
tests:
- desc: renders a partial whose name contains letters, digits, dots, underscores, and hyphens
data:
input: {}
expect:
messages:
- role: user
content:
[{ text: "Hello from a complex-named partial! This is the main template.\n" }]

# Tests partial rendering with context variables passed from the main template.
- name: partial_with_context
template: |
Expand Down