View plugins for literals
This commit is contained in:
+20
-1
@@ -146,15 +146,34 @@ fn emit_node_scope(node: &RsxNode) -> TokenStream {
|
||||
|
||||
fn emit_node(node: &RsxNode) -> TokenStream {
|
||||
match node {
|
||||
RsxNode::Text { text, deps } => {
|
||||
RsxNode::Text {
|
||||
text,
|
||||
deps,
|
||||
plugins,
|
||||
} => {
|
||||
let deps_emit = emit_deps(deps);
|
||||
|
||||
if plugins.len() == 0 {
|
||||
quote! {
|
||||
scope.view(Arc::new({
|
||||
#deps_emit
|
||||
move |ctx| ctx.draw_text(Point { x: 0, y: 0 }, &format!(#text))
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
let plugins_emit = emit_plugins(plugins);
|
||||
|
||||
quote! {
|
||||
scope.view_wrapped(Arc::new({
|
||||
#deps_emit
|
||||
move |ctx| ctx.draw_text(Point { x: 0, y: 0 }, &format!(#text))
|
||||
}), std::sync::Arc::new(|ctx, view| {
|
||||
let area = ctx.allocate(ctx.area.x, ctx.area.y, ctx.area.width, ctx.area.height);
|
||||
ctx.draw_view(area, view.clone());
|
||||
#plugins_emit
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RsxNode::Component {
|
||||
|
||||
+14
-5
@@ -41,7 +41,11 @@ pub struct RsxProp {
|
||||
/// AST node representing different RSX constructs
|
||||
pub enum RsxNode {
|
||||
/// String literal: `"text"`
|
||||
Text { text: LitStr, deps: Vec<Dep> },
|
||||
Text {
|
||||
plugins: Vec<ViewPlugin>,
|
||||
text: LitStr,
|
||||
deps: Vec<Dep>,
|
||||
},
|
||||
/// Expression node: `{expr}`
|
||||
Expr(Expr),
|
||||
/// Component instantiation: `Component { prop: value, ... }`
|
||||
@@ -212,6 +216,8 @@ impl Parse for RsxNode {
|
||||
});
|
||||
}
|
||||
|
||||
let plugins = parse_plugins(input)?;
|
||||
|
||||
// "%$dep for $pat in $expr { $rsx }"
|
||||
if input.peek(LitStr) {
|
||||
let text = input.parse()?;
|
||||
@@ -229,16 +235,19 @@ impl Parse for RsxNode {
|
||||
.collect(),
|
||||
);
|
||||
|
||||
return Ok(RsxNode::Text { text, deps });
|
||||
return Ok(RsxNode::Text {
|
||||
text,
|
||||
deps,
|
||||
plugins,
|
||||
});
|
||||
}
|
||||
|
||||
parse_component_invocation(input)
|
||||
parse_component_invocation(input, plugins)
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses Path or Path { ... } into RsxNode::Component.
|
||||
fn parse_component_invocation(input: ParseStream) -> Result<RsxNode> {
|
||||
let plugins = parse_plugins(input)?;
|
||||
fn parse_component_invocation(input: ParseStream, plugins: Vec<ViewPlugin>) -> Result<RsxNode> {
|
||||
let path: Path = input.parse()?;
|
||||
|
||||
if !input.peek(Brace) {
|
||||
|
||||
@@ -53,4 +53,13 @@ impl Scope {
|
||||
|
||||
self.children.lock().unwrap().push((ctx, None));
|
||||
}
|
||||
|
||||
/// Adds a view directly to this scope
|
||||
pub fn view_wrapped(self: &Arc<Self>, view: View, view_wrapper: ViewWrapper) {
|
||||
let ctx = Context::new(view, self.executor.clone());
|
||||
|
||||
ctx.refresh();
|
||||
|
||||
self.children.lock().unwrap().push((ctx, Some(view_wrapper)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user