Search results

There are no results.

std.html.RegularElement

type pub inline RegularElement

A regular HTML element (e.g. the <p> element).

Instance methods

attr

Show source code
Hide source code
fn pub inline move attr(name: String, value: String) -> Self {
  html.add(' ')
  html.attr(name, value)
  self
}
fn pub inline move attr(name: String, value: String) -> Self

Adds an attribute to self.

Examples

import std.html (Html)

let doc = Html.empty

doc.p.attr('key', 'value').close
doc.to_string # => '<p key="value"></p>'

bool

Show source code
Hide source code
fn pub inline move bool(name: String, value: Bool) -> Self {
  if value { attr(name, '') } else { self }
}
fn pub inline move bool(name: String, value: Bool) -> Self

Adds a boolean attribute to self.

If value is true then the attribute is added, otherwise it's ignored.

Examples

import std.html (Html)

let doc = Html.empty

doc.input.attr('type', 'checkbox').bool('checked', true).close
doc.to_string # => '<input type="checkbox" checked>'

class

Show source code
Hide source code
fn pub inline move class(value: String) -> Self {
  attr('class', value)
}
fn pub inline move class(value: String) -> Self

Adds the class global attribute to self.

Examples

import std.html (Html)

let doc = Html.empty

doc.p.class('example').close
doc.to_string # => '<p class="example"></p>'

close

Show source code
Hide source code
fn pub inline move close {
  @open = false
  add_closing_tag
}
fn pub inline move close

Adds the closing tag for self and consumes it.

This method should be called when a RegularElement or VoidElement is created and other moving methods such as RegularElement.text aren't used.

Examples

import std.html (Html)

let doc = Html.empty

doc.link.close
doc.to_string # => '<link>'

data

Show source code
Hide source code
fn pub inline move data(name: String, value: String) -> Self {
  html.add(' data-')
  html.attr(name, value)
  self
}
fn pub inline move data(name: String, value: String) -> Self

Adds a data attribute to self.

Examples

import std.html (Html)

let doc = Html.empty

doc.p.data('key', 'value').close
doc.to_string # => '<p data-key="value"></p>'

id

Show source code
Hide source code
fn pub inline move id(value: String) -> Self {
  attr('id', value)
}
fn pub inline move id(value: String) -> Self

Adds the id global attribute to self.

Examples

import std.html (Html)

let doc = Html.empty

doc.p.id('example').close
doc.to_string # => '<p id="example"></p>'

lang

Show source code
Hide source code
fn pub inline move lang(value: String) -> Self {
  attr('lang', value)
}
fn pub inline move lang(value: String) -> Self

Adds the lang global attribute to self.

Examples

import std.html (Html)

let doc = Html.empty

doc.p.lang('example').close
doc.to_string # => '<p lang="example"></p>'

text

Show source code
Hide source code
fn pub inline move text[B: Bytes, T: ToSlice[B]](value: ref T) {
  @open = false
  @html.inner_text(@name, value)
}
fn pub inline move text[B: Bytes, T: ToSlice[B]](value: ref T)

Sets the contents of self to the given text, then closes self.

Examples

import std.html (Html)

let doc = Html.empty

doc.p.text('hello & world')
doc.to_string # => '<p>hello &amp; world</p>'

then

Show source code
Hide source code
fn pub inline move then(body: fn (mut Html)) {
  @open = false
  @html.enter(@name, body)
}
fn pub inline move then(body: fn (mut Html))

Closes the opening tag of self, calls the supplied closure then closes self.

This method may be used to "enter" or "descend" into an element.

Examples

import std.html (Html)

let doc = Html.empty

doc.p.then(fn (p) { p.strong.text('hello') })
doc.to_string # => '<p><strong>hello</strong></p>'

title

Show source code
Hide source code
fn pub inline move title(value: String) -> Self {
  attr('title', value)
}
fn pub inline move title(value: String) -> Self

Adds the title global attribute to self.

Examples

import std.html (Html)

let doc = Html.empty

doc.p.title('example').close
doc.to_string # => '<p title="example"></p>'

value

Show source code
Hide source code
fn pub inline move value[B: Bytes](value: ref B) {
  @open = false
  @html.add('>')
  @html.add(value)
  @html.closing_tag(@name)
}
fn pub inline move value[B: Bytes](value: ref B)

Sets the contents of self to the given literal value, then closes self.

Unlike RegularElement.text the given value is not escaped.

Examples

import std.html (Html)

let doc = Html.empty

doc.p.value('hello & world')
doc.to_string # => '<p>hello & world</p>'

Implemented traits

std.drop.

Drop

impl Drop for RegularElement