Struct parsoid::Template[][src]

pub struct Template { /* fields omitted */ }

Represents a MediaWiki template ({{foo}})

How to access values from an existing template:

let code = client.transform_to_html("{{1x|test}}").await?;
// Get the `Template` instance
let template = code.filter_templates()?[0].clone();
assert_eq!(template.name(), "Template:1x".to_string());
assert_eq!(template.raw_name(), "./Template:1x".to_string());
assert_eq!(template.name_in_wikitext(), "1x".to_string());
assert_eq!(template.get_param("1"), Some("test".to_string()));

How to create and insert a new template:

let mut params = map::IndexMap::new();
params.insert("1".to_string(), "test".to_string());
let template = Template::new("1x", &params)?;
let code = Wikicode::new("");
template.append_on(&code);
let wikitext = client.transform_to_wikitext(&code).await?;
assert_eq!(wikitext, "{{1x|test}}".to_string());

You can also use Template::new_simple() if there are no parameters to pass.

Implementations

impl Template[src]

pub fn new_simple(name: &str) -> Self[src]

Create a new template with no parameters

pub fn new(name: &str, params: &IndexMap<String, String>) -> Result<Self>[src]

Create a new template

pub fn as_nodes(&self) -> Vec<&NodeRef>[src]

pub fn detach(&self)[src]

Remove this template from the document

pub fn prepend_on(&self, code: &NodeRef)[src]

Prepend this template into a node. Effectively calling node.prepend(template)

pub fn append_on(&self, code: &NodeRef)[src]

Append this template into a node. Effectively calling node.append(template)

pub fn insert_after_on(&self, code: &NodeRef)[src]

Insert this template after the node Effectively calling node.insert_after(template)

pub fn insert_before_on(&self, code: &NodeRef)[src]

Insert this template before the node Effectively calling node.insert_before(template)

pub fn remove_param(&self, name: &str) -> Result<()>[src]

pub fn set_param(&self, name: &str, wikitext: &str) -> Result<()>[src]

pub fn name_in_wikitext(&self) -> String[src]

Get the name of the template as it appears in wikitext

pub fn raw_name(&self) -> String[src]

Get the full name of the template, e.g. ./Template:Foo_bar or the parser function, e.g. ifeq.

pub fn name(&self) -> String[src]

Get a pretty normalized name of a template, e.g. Template:Foo bar or the parser function, e.g. ifeq

pub fn get_params(&self) -> IndexMap<String, String>[src]

Get a map of all parameters, named and unnamed

pub fn get_param(&self, name: &str) -> Option<String>[src]

Get the wikitext value of a specific parameter if it exists

pub fn get_param_in_wikitext(&self, name: &str) -> Option<String>[src]

Get the name of the parameter as it appears in the wikitext. For example given {{1x|param<!--comment-->name=value}} looking up paramname would return Some("param<!--comment->name").

pub fn is_template(&self) -> bool[src]

Whether it's a template (as opposed to a parser function)

pub fn is_parser_function(&self) -> bool[src]

Whether it's a parser function (as opposed to a template)

Trait Implementations

impl Clone for Template[src]

impl Debug for Template[src]

impl Display for Template[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.