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 {
|
fn emit_node(node: &RsxNode) -> TokenStream {
|
||||||
match node {
|
match node {
|
||||||
RsxNode::Text { text, deps } => {
|
RsxNode::Text {
|
||||||
|
text,
|
||||||
|
deps,
|
||||||
|
plugins,
|
||||||
|
} => {
|
||||||
let deps_emit = emit_deps(deps);
|
let deps_emit = emit_deps(deps);
|
||||||
|
|
||||||
|
if plugins.len() == 0 {
|
||||||
quote! {
|
quote! {
|
||||||
scope.view(Arc::new({
|
scope.view(Arc::new({
|
||||||
#deps_emit
|
#deps_emit
|
||||||
move |ctx| ctx.draw_text(Point { x: 0, y: 0 }, &format!(#text))
|
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 {
|
RsxNode::Component {
|
||||||
|
|||||||
+14
-5
@@ -41,7 +41,11 @@ pub struct RsxProp {
|
|||||||
/// AST node representing different RSX constructs
|
/// AST node representing different RSX constructs
|
||||||
pub enum RsxNode {
|
pub enum RsxNode {
|
||||||
/// String literal: `"text"`
|
/// String literal: `"text"`
|
||||||
Text { text: LitStr, deps: Vec<Dep> },
|
Text {
|
||||||
|
plugins: Vec<ViewPlugin>,
|
||||||
|
text: LitStr,
|
||||||
|
deps: Vec<Dep>,
|
||||||
|
},
|
||||||
/// Expression node: `{expr}`
|
/// Expression node: `{expr}`
|
||||||
Expr(Expr),
|
Expr(Expr),
|
||||||
/// Component instantiation: `Component { prop: value, ... }`
|
/// Component instantiation: `Component { prop: value, ... }`
|
||||||
@@ -212,6 +216,8 @@ impl Parse for RsxNode {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let plugins = parse_plugins(input)?;
|
||||||
|
|
||||||
// "%$dep for $pat in $expr { $rsx }"
|
// "%$dep for $pat in $expr { $rsx }"
|
||||||
if input.peek(LitStr) {
|
if input.peek(LitStr) {
|
||||||
let text = input.parse()?;
|
let text = input.parse()?;
|
||||||
@@ -229,16 +235,19 @@ impl Parse for RsxNode {
|
|||||||
.collect(),
|
.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.
|
/// Parses Path or Path { ... } into RsxNode::Component.
|
||||||
fn parse_component_invocation(input: ParseStream) -> Result<RsxNode> {
|
fn parse_component_invocation(input: ParseStream, plugins: Vec<ViewPlugin>) -> Result<RsxNode> {
|
||||||
let plugins = parse_plugins(input)?;
|
|
||||||
let path: Path = input.parse()?;
|
let path: Path = input.parse()?;
|
||||||
|
|
||||||
if !input.peek(Brace) {
|
if !input.peek(Brace) {
|
||||||
|
|||||||
@@ -53,4 +53,13 @@ impl Scope {
|
|||||||
|
|
||||||
self.children.lock().unwrap().push((ctx, None));
|
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