Skip to content

Commit

Permalink
Merge pull request #38 from msifd/feat/namespace
Browse files Browse the repository at this point in the history
Add namespace support for element and attribute names
  • Loading branch information
lambda-fairy authored Jul 20, 2016
2 parents df4ed87 + 36a88bd commit 0f27b19
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
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

0 comments on commit 0f27b19

Please sign in to comment.