Struct parsoid::Template [−][src]
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", ¶ms)?; 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
Auto Trait Implementations
impl !RefUnwindSafe for Template
[src]
impl !Send for Template
[src]
impl !Sync for Template
[src]
impl Unpin for Template
[src]
impl !UnwindSafe for Template
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,