Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add namespace support for element and attribute names #38

Merged
merged 3 commits into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions maud_macros/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ macro_rules! question {
macro_rules! semi {
() => (TokenTree::Token(_, Token::Semi))
}
macro_rules! colon {
() => (TokenTree::Token(_, Token::Colon))
}
macro_rules! comma {
() => (TokenTree::Token(_, Token::Comma))
}
Expand Down Expand Up @@ -545,8 +548,8 @@ impl<'cx, 'a, 'i> Parser<'cx, 'a, 'i> {
Ok(())
}

/// Parses a HTML element or attribute name.
fn name(&mut self) -> PResult<String> {
/// Parses ident with minuses.
fn ident_with_minuses(&mut self) -> PResult<String> {
let mut s = match *self.input {
[ident!(_, name), ..] => {
self.shift(1);
Expand All @@ -562,6 +565,20 @@ impl<'cx, 'a, 'i> Parser<'cx, 'a, 'i> {
Ok(s)
}

/// Parses a HTML element or attribute name.
fn name(&mut self) -> PResult<String> {
let mut s = match self.ident_with_minuses() {
Ok(ident) => ident,
Err(e) => return Err(e),
};
if let [colon!(), ident!(_, _), ..] = *self.input {
self.shift(1);
s.push(':');
s.push_str(self.ident_with_minuses().unwrap().as_str());
}
Ok(s)
}

/// Parses the given token tree, returning a vector of statements.
fn block(&mut self, sp: Span, tts: &[TokenTree]) -> PResult<Vec<Stmt>> {
let mut parse = Parser {
Expand Down
7 changes: 7 additions & 0 deletions maud_macros/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ mod elements {
html!(s, div readonly? input type="checkbox" checked? /).unwrap();
assert_eq!(s, r#"<div readonly><input type="checkbox" checked></div>"#);
}

#[test]
fn namespaces() {
let mut s = String::new();
html!(s, pon-pon:controls-alpha a on:click="yay()" "Yay!").unwrap();
assert_eq!(s, r#"<pon-pon:controls-alpha><a on:click="yay()">Yay!</a></pon-pon:controls-alpha>"#);
}
}

mod splices {
Expand Down