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 support for clss selection #13

Merged
merged 2 commits into from Jun 1, 2013
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -85,9 +85,11 @@ Callbacks used to query the implementation-specific DOM
*/
pub trait SelectHandler<N> {
fn with_node_name<R>(&self, node: &N, f: &fn(&str) -> R) -> R;
fn with_node_classes<R>(&self, node: &N, f: &fn(Option<&str>) -> R) -> R;
fn with_node_id<R>(&self, node: &N, f: &fn(Option<&str>) -> R) -> R;
fn named_parent_node(&self, node: &N, name: &str) -> Option<N>;
fn parent_node(&self, node: &N) -> Option<N>;
fn node_has_class(&self, node: &N, &str) -> bool;
fn node_has_id(&self, node: &N, &str) -> bool;
fn named_ancestor_node(&self, node: &N, name: &str) -> Option<N>;
fn node_is_root(&self, node: &N) -> bool;
@@ -112,6 +114,21 @@ impl<N, H: SelectHandler<N>> n::s::CssSelectHandler<N> for SelectHandlerWrapper<
}
}

fn node_classes(&self, node: &N) -> Option<~[LwcString]> {
do self.inner_ref().with_node_classes(node) |node_classes_opt| {
do node_classes_opt.map |s| {
debug!("SelectHandlerWrapper::node_classes - classes: %?", *s);
let mut v = ~[];
for str::each_split_char(*s, ' ') |s| {
debug!("SelectHandlerWrapper::node_classes - class: %?", s);
if s != ~"" { v.push(lwcstr_from_rust_str(s)) }
}
debug!("SelectHandlerWrapper::classes: %?", v);
v
}
}
}

fn node_id(&self, node: &N) -> Option<LwcString> {
do self.inner_ref().with_node_id(node) |node_id_opt| {
node_id_opt.map(|s| lwcstr_from_rust_str(*s))
@@ -126,6 +143,10 @@ impl<N, H: SelectHandler<N>> n::s::CssSelectHandler<N> for SelectHandlerWrapper<
self.inner_ref().parent_node(node)
}

fn node_has_class(&self, node: &N, name: LwcString) -> bool {
self.inner_ref().node_has_class(node, name.to_str_slice())
}

fn node_has_id(&self, node: &N, name: LwcString) -> bool {
self.inner_ref().node_has_id(node, name.to_str_slice())
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.