// Generated by Lisette bindgen
// Source: text/template (Go stdlib)
// Go: 1.25.10
// Lisette: 0.3.0

import "go:io"
import "go:io/fs"
import "go:text/template/parse"

/// HTMLEscape writes to w the escaped HTML equivalent of the plain text data b.
pub fn HTMLEscape(w: io.Writer, b: Slice<byte>)

/// HTMLEscapeString returns the escaped HTML equivalent of the plain text data s.
pub fn HTMLEscapeString(s: string) -> string

/// HTMLEscaper returns the escaped HTML equivalent of the textual
/// representation of its arguments.
pub fn HTMLEscaper(args: VarArgs<Unknown>) -> string

/// IsTrue reports whether the value is 'true', in the sense of not the zero of its type,
/// and whether the value has a meaningful truth value. This is the definition of
/// truth used by if and other such actions.
pub fn IsTrue(val: Unknown) -> Option<bool>

/// JSEscape writes to w the escaped JavaScript equivalent of the plain text data b.
pub fn JSEscape(w: io.Writer, b: Slice<byte>)

/// JSEscapeString returns the escaped JavaScript equivalent of the plain text data s.
pub fn JSEscapeString(s: string) -> string

/// JSEscaper returns the escaped JavaScript equivalent of the textual
/// representation of its arguments.
pub fn JSEscaper(args: VarArgs<Unknown>) -> string

/// Must is a helper that wraps a call to a function returning ([*Template], error)
/// and panics if the error is non-nil. It is intended for use in variable
/// initializations such as
/// 
/// 	var t = template.Must(template.New("name").Parse("text"))
pub fn Must(t: Ref<Template>, err: error) -> Ref<Template>

/// New allocates a new, undefined template with the given name.
pub fn New(name: string) -> Ref<Template>

/// ParseFS is like [Template.ParseFiles] or [Template.ParseGlob] but reads from the file system fsys
/// instead of the host operating system's file system.
/// It accepts a list of glob patterns (see [path.Match]).
/// (Note that most file names serve as glob patterns matching only themselves.)
pub fn ParseFS(fsys: fs.FS, patterns: VarArgs<string>) -> Result<Ref<Template>, error>

/// ParseFiles creates a new [Template] and parses the template definitions from
/// the named files. The returned template's name will have the base name and
/// parsed contents of the first file. There must be at least one file.
/// If an error occurs, parsing stops and the returned *Template is nil.
/// 
/// When parsing multiple files with the same name in different directories,
/// the last one mentioned will be the one that results.
/// For instance, ParseFiles("a/foo", "b/foo") stores "b/foo" as the template
/// named "foo", while "a/foo" is unavailable.
pub fn ParseFiles(filenames: VarArgs<string>) -> Result<Ref<Template>, error>

/// ParseGlob creates a new [Template] and parses the template definitions from
/// the files identified by the pattern. The files are matched according to the
/// semantics of [filepath.Match], and the pattern must match at least one file.
/// The returned template will have the [filepath.Base] name and (parsed)
/// contents of the first file matched by the pattern. ParseGlob is equivalent to
/// calling [ParseFiles] with the list of files matched by the pattern.
/// 
/// When parsing multiple files with the same name in different directories,
/// the last one mentioned will be the one that results.
pub fn ParseGlob(pattern: string) -> Result<Ref<Template>, error>

/// URLQueryEscaper returns the escaped value of the textual representation of
/// its arguments in a form suitable for embedding in a URL query.
pub fn URLQueryEscaper(args: VarArgs<Unknown>) -> string

/// ExecError is the custom error type returned when Execute has an
/// error evaluating its template. (If a write error occurs, the actual
/// error is returned; it will not be of type ExecError.)
pub struct ExecError {
  pub Name: string,
  pub Err: error,
}

/// FuncMap is the type of the map defining the mapping from names to functions.
/// Each function must have either a single return value, or two return values of
/// which the second has type error. In that case, if the second (error)
/// return value evaluates to non-nil during execution, execution terminates and
/// Execute returns that error.
/// 
/// Errors returned by Execute wrap the underlying error; call [errors.As] to
/// unwrap them.
/// 
/// When template execution invokes a function with an argument list, that list
/// must be assignable to the function's parameter types. Functions meant to
/// apply to arguments of arbitrary type can use parameters of type interface{} or
/// of type [reflect.Value]. Similarly, functions meant to return a result of arbitrary
/// type can return interface{} or [reflect.Value].
pub struct FuncMap(Map<string, Unknown>)

/// Template is the representation of a parsed template. The *parse.Tree
/// field is exported only for use by [html/template] and should be treated
/// as unexported by all other clients.
pub struct Template {
  pub Tree: Option<Ref<parse.Tree>>,
}

impl ExecError {
  fn Error(self) -> string

  fn Unwrap(self) -> Option<error>
}

impl Template {
  /// AddParseTree associates the argument parse tree with the template t, giving
  /// it the specified name. If the template has not been defined, this tree becomes
  /// its definition. If it has been defined and already has that name, the existing
  /// definition is replaced; otherwise a new template is created, defined, and returned.
  fn AddParseTree(self: Ref<Template>, name: string, tree: Ref<parse.Tree>) -> Result<Ref<Template>, error>

  /// Clone returns a duplicate of the template, including all associated
  /// templates. The actual representation is not copied, but the name space of
  /// associated templates is, so further calls to [Template.Parse] in the copy will add
  /// templates to the copy but not to the original. Clone can be used to prepare
  /// common templates and use them with variant definitions for other templates
  /// by adding the variants after the clone is made.
  fn Clone(self: Ref<Template>) -> Result<Ref<Template>, error>

  /// Copy returns a copy of the [Tree]. Any parsing state is discarded.
  fn Copy(self: Ref<Template>) -> Ref<parse.Tree>

  /// DefinedTemplates returns a string listing the defined templates,
  /// prefixed by the string "; defined templates are: ". If there are none,
  /// it returns the empty string. For generating an error message here
  /// and in [html/template].
  fn DefinedTemplates(self: Ref<Template>) -> string

  /// Delims sets the action delimiters to the specified strings, to be used in
  /// subsequent calls to [Template.Parse], [Template.ParseFiles], or [Template.ParseGlob]. Nested template
  /// definitions will inherit the settings. An empty delimiter stands for the
  /// corresponding default: {{ or }}.
  /// The return value is the template, so calls can be chained.
  #[allow(unused_value)]
  fn Delims(self: Ref<Template>, left: string, right: string) -> Ref<Template>

  /// ErrorContext returns a textual representation of the location of the node in the input text.
  /// The receiver is only used when the node does not have a pointer to the tree inside,
  /// which can occur in old code.
  fn ErrorContext(self: Ref<Template>, n: parse.Node) -> (string, string)

  /// Execute applies a parsed template to the specified data object,
  /// and writes the output to wr.
  /// If an error occurs executing the template or writing its output,
  /// execution stops, but partial results may already have been written to
  /// the output writer.
  /// A template may be executed safely in parallel, although if parallel
  /// executions share a Writer the output may be interleaved.
  /// 
  /// If data is a [reflect.Value], the template applies to the concrete
  /// value that the reflect.Value holds, as in [fmt.Print].
  fn Execute(self: Ref<Template>, wr: io.Writer, data: Unknown) -> Result<(), error>

  /// ExecuteTemplate applies the template associated with t that has the given name
  /// to the specified data object and writes the output to wr.
  /// If an error occurs executing the template or writing its output,
  /// execution stops, but partial results may already have been written to
  /// the output writer.
  /// A template may be executed safely in parallel, although if parallel
  /// executions share a Writer the output may be interleaved.
  fn ExecuteTemplate(
    self: Ref<Template>,
    wr: io.Writer,
    name: string,
    data: Unknown,
  ) -> Result<(), error>

  /// Funcs adds the elements of the argument map to the template's function map.
  /// It must be called before the template is parsed.
  /// It panics if a value in the map is not a function with appropriate return
  /// type or if the name cannot be used syntactically as a function in a template.
  /// It is legal to overwrite elements of the map. The return value is the template,
  /// so calls can be chained.
  #[allow(unused_value)]
  fn Funcs(self: Ref<Template>, funcMap: FuncMap) -> Ref<Template>

  /// Lookup returns the template with the given name that is associated with t.
  /// It returns nil if there is no such template or the template has no definition.
  fn Lookup(self: Ref<Template>, name: string) -> Option<Ref<Template>>

  /// Name returns the name of the template.
  fn Name(self: Ref<Template>) -> string

  /// New allocates a new, undefined template associated with the given one and with the same
  /// delimiters. The association, which is transitive, allows one template to
  /// invoke another with a {{template}} action.
  /// 
  /// Because associated templates share underlying data, template construction
  /// cannot be done safely in parallel. Once the templates are constructed, they
  /// can be executed in parallel.
  fn New(self: Ref<Template>, name: string) -> Ref<Template>

  /// Option sets options for the template. Options are described by
  /// strings, either a simple string or "key=value". There can be at
  /// most one equals sign in an option string. If the option string
  /// is unrecognized or otherwise invalid, Option panics.
  /// 
  /// Known options:
  /// 
  /// missingkey: Control the behavior during execution if a map is
  /// indexed with a key that is not present in the map.
  /// 
  /// 	"missingkey=default" or "missingkey=invalid"
  /// 		The default behavior: Do nothing and continue execution.
  /// 		If printed, the result of the index operation is the string
  /// 		"<no value>".
  /// 	"missingkey=zero"
  /// 		The operation returns the zero value for the map type's element.
  /// 	"missingkey=error"
  /// 		Execution stops immediately with an error.
  #[allow(unused_value)]
  fn Option(self: Ref<Template>, opt: VarArgs<string>) -> Ref<Template>

  /// Parse parses text as a template body for t.
  /// Named template definitions ({{define ...}} or {{block ...}} statements) in text
  /// define additional templates associated with t and are removed from the
  /// definition of t itself.
  /// 
  /// Templates can be redefined in successive calls to Parse.
  /// A template definition with a body containing only white space and comments
  /// is considered empty and will not replace an existing template's body.
  /// This allows using Parse to add new named template definitions without
  /// overwriting the main template body.
  fn Parse(self: Ref<Template>, text: string) -> Result<Ref<Template>, error>

  /// ParseFS is like [Template.ParseFiles] or [Template.ParseGlob] but reads from the file system fsys
  /// instead of the host operating system's file system.
  /// It accepts a list of glob patterns (see [path.Match]).
  /// (Note that most file names serve as glob patterns matching only themselves.)
  fn ParseFS(self: Ref<Template>, fsys: fs.FS, patterns: VarArgs<string>) -> Result<Ref<Template>, error>

  /// ParseFiles parses the named files and associates the resulting templates with
  /// t. If an error occurs, parsing stops and the returned template is nil;
  /// otherwise it is t. There must be at least one file.
  /// Since the templates created by ParseFiles are named by the base
  /// (see [filepath.Base]) names of the argument files, t should usually have the
  /// name of one of the (base) names of the files. If it does not, depending on
  /// t's contents before calling ParseFiles, t.Execute may fail. In that
  /// case use t.ExecuteTemplate to execute a valid template.
  /// 
  /// When parsing multiple files with the same name in different directories,
  /// the last one mentioned will be the one that results.
  fn ParseFiles(self: Ref<Template>, filenames: VarArgs<string>) -> Result<Ref<Template>, error>

  /// ParseGlob parses the template definitions in the files identified by the
  /// pattern and associates the resulting templates with t. The files are matched
  /// according to the semantics of [filepath.Match], and the pattern must match at
  /// least one file. ParseGlob is equivalent to calling [Template.ParseFiles] with
  /// the list of files matched by the pattern.
  /// 
  /// When parsing multiple files with the same name in different directories,
  /// the last one mentioned will be the one that results.
  fn ParseGlob(self: Ref<Template>, pattern: string) -> Result<Ref<Template>, error>

  /// Templates returns a slice of defined templates associated with t.
  fn Templates(self: Ref<Template>) -> Slice<Ref<Template>>
}
