sub
register {
my
(
$self
,
$engine
) =
@_
;
$engine
->add_handler({
name
=>
'render'
,
tag
=>
'x-render'
,
attribute
=> [
'data-render'
],
handler
=> \
&create_directives
});
}
sub
create_directives {
my
(
$element
,
$ctx
) =
@_
;
my
$node
=
$element
->get(0);
$ctx
->rewind_directive_stack(
$element
);
my
$is_tag
=
$node
->localname eq
'x-render'
;
my
$render_instruction
=
$node
->getAttribute(
$is_tag
?
'data'
:
'data-render'
);
$node
->removeAttribute(
'data-render'
)
unless
$is_tag
;
my
$element_selector
=
$ctx
->selector_for(
$node
);
if
(
$render_instruction
=~ /^\s*\[\s*([\w._-]+)\s*\]\s*$/) {
my
$mod
=
$ctx
->_parse_matchspec_modifiers(
$render_instruction
);
$element_selector
=
'^'
.
$element_selector
if
$mod
->{replace} ||
$is_tag
;
$ctx
->push_at(
$element_selector
, $1);
}
else
{
foreach
my
$instruction
(
split
/\s+/,
$render_instruction
) {
my
$mod
=
$ctx
->_parse_matchspec_modifiers(
$instruction
);
my
(
$data_point
,
$attribute
) =
split
'@'
,
$instruction
;
my
$selector
=
$element_selector
;
$selector
.=
"\@$attribute"
if
defined
$attribute
;
$selector
.=
'+'
if
$mod
->{append};
$selector
=
'+'
.
$selector
if
$mod
->{prepend};
$selector
=
'^'
.
$selector
if
$mod
->{replace} ||
$is_tag
;
$ctx
->at(
$selector
,
$data_point
);
}
}
}
1;