lisette-stdlib 0.1.13

Little language inspired by Rust that compiles to Go
Documentation
// Generated by Lisette bindgen
// Source: html/template (Go stdlib)
// Go: 1.25.5
// Lisette: 0.1.12

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

pub enum ErrorCode: int {
  ErrAmbigContext = 1,
  ErrBadHTML = 2,
  ErrBranchEnd = 3,
  ErrEndContext = 4,
  ErrJSTemplate = 12,
  ErrNoSuchTemplate = 5,
  ErrOutputContext = 6,
  ErrPartialCharset = 7,
  ErrPartialEscape = 8,
  ErrPredefinedEscaper = 11,
  ErrRangeLoopReentry = 9,
  ErrSlashAmbig = 10,
  OK = 0,
}

pub const ErrAmbigContext: ErrorCode = 1

pub const ErrBadHTML: ErrorCode = 2

pub const ErrBranchEnd: ErrorCode = 3

pub const ErrEndContext: ErrorCode = 4

pub const ErrJSTemplate: ErrorCode = 12

pub const ErrNoSuchTemplate: ErrorCode = 5

pub const ErrOutputContext: ErrorCode = 6

pub const ErrPartialCharset: ErrorCode = 7

pub const ErrPartialEscape: ErrorCode = 8

pub const ErrPredefinedEscaper: ErrorCode = 11

pub const ErrRangeLoopReentry: ErrorCode = 9

pub const ErrSlashAmbig: ErrorCode = 10

pub const OK: ErrorCode = 0

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

/// 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<uint8>)

/// 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

pub fn Must(t: Ref<Template>, err: error) -> Ref<Template>

pub fn New(name: string) -> Ref<Template>

pub fn ParseFS(fs: fs.FS, patterns: VarArgs<string>) -> Result<Ref<Template>, error>

pub fn ParseFiles(filenames: VarArgs<string>) -> Result<Ref<Template>, error>

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

/// CSS encapsulates known safe content that matches any of:
///   1. The CSS3 stylesheet production, such as `p { color: purple }`.
///   2. The CSS3 rule production, such as `a[href=~"https:"].foo#bar`.
///   3. CSS3 declaration productions, such as `color: red; margin: 2px`.
///   4. The CSS3 value production, such as `rgba(0, 0, 255, 127)`.
/// See https://www.w3.org/TR/css3-syntax/#parsing and
/// https://web.archive.org/web/20090211114933/http://w3.org/TR/css3-syntax#style
/// 
/// Use of this type presents a security risk:
/// the encapsulated content should come from a trusted source,
/// as it will be included verbatim in the template output.
pub struct CSS(string)

/// Error describes a problem encountered during template Escaping.
pub struct Error {
  pub ErrorCode: ErrorCode,
  pub Node: Option<parse.Node>,
  pub Name: string,
  pub Line: int,
  pub Description: string,
}

pub type FuncMap = template.FuncMap

/// HTML encapsulates a known safe HTML document fragment.
/// It should not be used for HTML from a third-party, or HTML with
/// unclosed tags or comments. The outputs of a sound HTML sanitizer
/// and a template escaped by this package are fine for use with HTML.
/// 
/// Use of this type presents a security risk:
/// the encapsulated content should come from a trusted source,
/// as it will be included verbatim in the template output.
pub struct HTML(string)

/// HTMLAttr encapsulates an HTML attribute from a trusted source,
/// for example, ` dir="ltr"`.
/// 
/// Use of this type presents a security risk:
/// the encapsulated content should come from a trusted source,
/// as it will be included verbatim in the template output.
pub struct HTMLAttr(string)

/// JS encapsulates a known safe EcmaScript5 Expression, for example,
/// `(x + y * z())`.
/// Template authors are responsible for ensuring that typed expressions
/// do not break the intended precedence and that there is no
/// statement/expression ambiguity as when passing an expression like
/// "{ foo: bar() }\n['foo']()", which is both a valid Expression and a
/// valid Program with a very different meaning.
/// 
/// Use of this type presents a security risk:
/// the encapsulated content should come from a trusted source,
/// as it will be included verbatim in the template output.
/// 
/// Using JS to include valid but untrusted JSON is not safe.
/// A safe alternative is to parse the JSON with json.Unmarshal and then
/// pass the resultant object into the template, where it will be
/// converted to sanitized JSON when presented in a JavaScript context.
pub struct JS(string)

/// JSStr encapsulates a sequence of characters meant to be embedded
/// between quotes in a JavaScript expression.
/// The string must match a series of StringCharacters:
///   StringCharacter :: SourceCharacter but not `\` or LineTerminator
///                    | EscapeSequence
/// Note that LineContinuations are not allowed.
/// JSStr("foo\\nbar") is fine, but JSStr("foo\\\nbar") is not.
/// 
/// Use of this type presents a security risk:
/// the encapsulated content should come from a trusted source,
/// as it will be included verbatim in the template output.
pub struct JSStr(string)

/// Srcset encapsulates a known safe srcset attribute
/// (see https://w3c.github.io/html/semantics-embedded-content.html#element-attrdef-img-srcset).
/// 
/// Use of this type presents a security risk:
/// the encapsulated content should come from a trusted source,
/// as it will be included verbatim in the template output.
pub struct Srcset(string)

/// Template is a specialized Template from "text/template" that produces a safe
/// HTML document fragment.
pub struct Template {
  pub Tree: Option<Ref<parse.Tree>>,
}

/// URL encapsulates a known safe URL or URL substring (see RFC 3986).
/// A URL like `javascript:checkThatFormNotEditedBeforeLeavingPage()`
/// from a trusted source should go in the page, but by default dynamic
/// `javascript:` URLs are filtered out since they are a frequently
/// exploited injection vector.
/// 
/// Use of this type presents a security risk:
/// the encapsulated content should come from a trusted source,
/// as it will be included verbatim in the template output.
pub struct URL(string)

impl Error {
  fn Error(self: Ref<Error>) -> string
}

impl Template {
  /// AddParseTree creates a new template with the name and parse tree
  /// and associates it with t.
  /// 
  /// It returns an error if t or any associated template has already been executed.
  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. [Template.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.
  /// 
  /// It returns an error if t has already been executed.
  fn Clone(self: Ref<Template>) -> Result<Ref<Template>, error>

  /// DefinedTemplates returns a string listing the defined templates,
  /// prefixed by the string "; defined templates are: ". If there are none,
  /// it returns the empty string. Used to generate an error message.
  fn DefinedTemplates(self: Ref<Template>) -> string

  /// Delims sets the action delimiters to the specified strings, to be used in
  /// subsequent calls to [Template.Parse], [ParseFiles], or [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.
  fn Delims(self: Ref<Template>, left: string, right: string) -> Ref<Template>

  /// Execute applies a parsed template to the specified data object,
  /// writing 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 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. However, it is legal to overwrite elements of the map. The return
  /// value is the template, so calls can be chained.
  fn Funcs(self: Ref<Template>, funcMap: template.FuncMap) -> Ref<Template>

  /// Lookup returns the template with the given name that is associated with t,
  /// or nil if there is no such template.
  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 HTML 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.
  /// 
  /// If a template with the given name already exists, the new HTML template
  /// will replace it. The existing template will be reset and disassociated with
  /// t.
  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.
  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,
  /// before the first use of [Template.Execute] on t or any associated template.
  /// 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 fs
  /// instead of the host operating system's file system.
  /// It accepts a list of glob patterns.
  /// (Note that most file names serve as glob patterns matching only themselves.)
  fn ParseFS(self: Ref<Template>, fs: 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.
  /// 
  /// When parsing multiple files with the same name in different directories,
  /// the last one mentioned will be the one that results.
  /// 
  /// ParseFiles returns an error if t or any associated template has already been executed.
  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 t.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.
  /// 
  /// ParseGlob returns an error if t or any associated template has already been executed.
  fn ParseGlob(self: Ref<Template>, pattern: string) -> Result<Ref<Template>, error>

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