fix(pdftract-l993m): fix Tera template syntax in Methods templates

Fix incorrect Tera template syntax in per-language Methods templates:
- Change `elsif` to `elif` (correct Tera conditional syntax)
- Fix inline ternary-like syntax to use proper `{% if %}...{% else %}...{% endif %}`
- Fix truncated package name in Java template (codegen → codegen)

Affected templates:
- PHP: Methods.php.tera
- Python: methods.py.tera
- Ruby: methods.rb.tera
- Swift: Methods.swift.tera
- Java: Methods.java.tera

All 8 subprocess SDK templates now render correctly with the codegen
command. Verified via `pdftract sdk codegen --lang <lang> --out /tmp/sdk-<lang>`.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Bead-Id: pdftract-l993m
This commit is contained in:
jedarden 2026-05-18 02:27:40 -04:00
parent 77a8a6d7f3
commit e3c7b2eec0
5 changed files with 16 additions and 16 deletions

View file

@ -1,4 +1,4 @@
package com.jedarden.pdftract.codeg
package com.jedarden.pdftract.codegen;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

View file

@ -104,7 +104,7 @@ class Client
throw $this->mapError($stderr, $exitCode);
}
}
{% elsif method.name == 'search' %}
{% elif method.name == 'search' %}
/**
* {{ method.description }}
*
@ -159,14 +159,14 @@ class Client
throw $this->mapError($stderr, $exitCode);
}
}
{% elsif method.name == 'verify_receipt' %}
{% elif method.name == 'verify_receipt' %}
public function {{ method.camel_name }}(string $path, string $receipt): bool
{
$output = $this->exec(['{{ method.cli_flag }}', $path, $receipt]);
return trim($output) === 'true';
}
{% else %}
public function {{ method.camel_name }}(Source $source{% if method.has_options %}, ?{{ method.options_type }} $options = null{% endif %}): {{ method.return_type == 'string' ? 'string' : 'array' }}
public function {{ method.camel_name }}(Source $source{% if method.has_options %}, ?{{ method.options_type }} $options = null{% endif %}): {% if method.return_type == 'string' %}string{% else %}array{% endif %}
{
$args = array_merge(['{{ method.cli_flag }}'], $source->toArgs());
@ -178,9 +178,9 @@ class Client
{% if method.name == 'extract_text' %}
$args[] = '--text';
{% elseif method.name == 'extract_markdown' %}
{% elif method.name == 'extract_markdown' %}
$args[] = '--md';
{% elseif method.name == 'get_metadata' %}
{% elif method.name == 'get_metadata' %}
$args[] = '--metadata-only';
{% endif %}

View file

@ -76,7 +76,7 @@ class Client:
if process.returncode != 0:
stderr = process.stderr.read()
raise self._map_error(stderr, process.returncode)
{% elsif method.name == 'search' %}
{% elif method.name == 'search' %}
def {{ method.snake_name }}(
self, source: Source, pattern: str, options=None
) -> Iterator[dict]:
@ -107,7 +107,7 @@ class Client:
if process.returncode != 0:
stderr = process.stderr.read()
raise self._map_error(stderr, process.returncode)
{% elsif method.name == 'verify_receipt' %}
{% elif method.name == 'verify_receipt' %}
def {{ method.snake_name }}(self, path: str, receipt: str) -> bool:
"""{{ method.description }}"""
output = self._exec("{{ method.cli_flag }}", path, receipt)
@ -115,7 +115,7 @@ class Client:
{% else %}
def {{ method.snake_name }}(
self, source: Source{% if method.has_options %}, options=None{% endif %}
) -> {{ 'str' if method.returns_string else 'dict' }}:
){% if method.returns_string %} -> str:{% else %} -> dict:{% endif %}
"""{{ method.description }}"""
args = ["{{ method.cli_flag }}", *source.to_args()]

View file

@ -63,7 +63,7 @@ module Pdftract
end
end
end
{% elsif method.name == 'search' %}
{% elif method.name == 'search' %}
def {{ method.snake_name }}(source, pattern, options = nil)
args = ["grep", pattern, *source.to_args]
args.concat(options.to_args) if options
@ -83,7 +83,7 @@ module Pdftract
end
end
end
{% elsif method.name == 'verify_receipt' %}
{% elif method.name == 'verify_receipt' %}
def {{ method.snake_name }}(path, receipt)
output = exec("{{ method.cli_flag }}", path, receipt)
output.strip == "true"
@ -98,9 +98,9 @@ module Pdftract
{% if method.name == 'extract_text' %}
args << "--text"
{% elsif method.name == 'extract_markdown' %}
{% elif method.name == 'extract_markdown' %}
args << "--md"
{% elsif method.name == 'get_metadata' %}
{% elif method.name == 'get_metadata' %}
args << "--metadata-only"
{% endif %}

View file

@ -108,7 +108,7 @@ public class Pdftract {
}
}
}
{% elsif method.name == 'search' %}
{% elif method.name == 'search' %}
public func {{ method.camel_name }}(_ source: Source, _ pattern: String, options: {{ method.options_type }}? = nil) -> AsyncStream<{{ method.return_type }}> {
return AsyncStream { continuation in
var args = ["grep", pattern]
@ -160,13 +160,13 @@ public class Pdftract {
}
}
}
{% elsif method.name == 'verify_receipt' %}
{% elif method.name == 'verify_receipt' %}
public func {{ method.camel_name }}(_ path: String, _ receipt: String) throws -> Bool {
let output = try exec(["{{ method.cli_flag }}", path, receipt])
return output.trimmingCharacters(in: .whitespacesAndNewlines) == "true"
}
{% else %}
public func {{ method.camel_name }}(_ source: Source{% if method.has_options %}, options: {{ method.options_type }}? = nil{% endif %}) throws -> {{ method.return_type == 'string' ? 'String' : method.return_type }} {
public func {{ method.camel_name }}(_ source: Source{% if method.has_options %}, options: {{ method.options_type }}? = nil{% endif %}) throws -> {% if method.return_type == 'string' %}String{% else %}{{ method.return_type }}{% endif %} {
var args = ["{{ method.cli_flag }}"]
args.append(contentsOf: source.toArgs())