-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTextEngine.jl
More file actions
59 lines (46 loc) · 2.32 KB
/
TextEngine.jl
File metadata and controls
59 lines (46 loc) · 2.32 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
# ═══════════════════════════════════════════════════════════════════════════════
# Text Engine Module
# ═══════════════════════════════════════════════════════════════════════════════
"""
Registry of text-generating functions that can be called from INCLUDE_TEXT blocks.
All registered functions must accept string arguments and return a Markdown
string that will be inlined directly into the generated documentation.
"""
const TEXT_FUNCTIONS = Dict{String,Function}()
"""
register_text_handler!(name::String, func::Function)
Register a text-generating function in the global text registry.
"""
function register_text_handler!(name::AbstractString, func::Function)
TEXT_FUNCTIONS[String(name)] = func
return nothing
end
"""
call_text_function(function_name::String, args::Vector{String}, extra_args::Tuple=())
Safely call a registered text function with string arguments.
# Arguments
- `function_name::String`: Name of the function (must be in `TEXT_FUNCTIONS`)
- `args::Vector{String}`: Vector of string arguments from the template
- `extra_args::Tuple`: Extra arguments injected by the system (e.g., SRC_DIR)
# Returns
- `String`: Markdown content produced by the text function
# Throws
- `ErrorException` if function not found in registry
# Note
Arguments are passed as: `func(extra_args..., args...)` so that injected
dependencies (like `src_dir`) come first, following the Dependency Inversion Principle.
"""
function call_text_function(
function_name::AbstractString, args::Vector{<:AbstractString}, extra_args::Tuple=()
)
if !haskey(TEXT_FUNCTIONS, function_name)
available = join(sort(collect(keys(TEXT_FUNCTIONS))), ", ")
error(
"Function '$function_name' not found in TEXT_FUNCTIONS registry. Available: $available",
)
end
func = TEXT_FUNCTIONS[function_name]
DOC_DEBUG[] && @info " 📝 Calling $function_name($(join(args, ", ")))"
# Pass extra_args first (injected dependencies), then args (template arguments)
return func(extra_args..., args...)
end