# Pastebin mejcKNv5 diff --git a/bin/lib/todo-routes.rakumod b/bin/lib/todo-routes.rakumod index de47a0d..918019e 100644 --- a/bin/lib/todo-routes.rakumod +++ b/bin/lib/todo-routes.rakumod @@ -4,6 +4,8 @@ use Cro::HTTP::Router; use Cro::WebApp::Template; use Todo; +unit module todo-routes; + sub todo-routes is export { route { #resources-from %?RESOURCES; diff --git a/lib/Cromponent.rakumod b/lib/Cromponent.rakumod index 1bb5708..62df257 100644 --- a/lib/Cromponent.rakumod +++ b/lib/Cromponent.rakumod @@ -137,34 +137,57 @@ sub compile-cromponent($cromponent) { .die } } - # If letting this commented, it gives this error when running: raku -Ilib -Ibin/lib -e 'use todo-routes' - # - # ❯ raku -Ilib -Ibin/lib -e 'use todo-routes' - #===SORRY!=== Error while compiling -e - #X::Comp::BeginTime.new(use-case => "evaluating a BEGIN", exception => X::Comp::AdHoc.new(pos => Any, filename => Any, line => Any, directive-filename => Any, column => Any, modules => [], is-compile-time => Any, pre => Any, post => Any, highexpect => [], payload => "lang-call cannot invoke object of type 'VMNull' belonging to no language"), pos => Any, filename => "/Users/fernando/Cromponent/EVAL_86", line => 1, directive-filename => Any, column => Any, modules => [], is-compile-time => Bool::True, pre => Any, post => Any, highexpect => []) - #===SORRY!=== Error while compiling /Users/fernando/Cromponent/EVAL_86 - #An exception X::Comp::AdHoc occurred while evaluating a BEGIN: - #lang-call cannot invoke object of type 'VMNull' belonging to no language - #at /Users/fernando/Cromponent/EVAL_86:1 - #Exception details: - # ===SORRY!=== Error while compiling - # lang-call cannot invoke object of type 'VMNull' belonging to no language - # at line - # - #at -e:1 - # - # if you uncomment this line, it will remobe prelude from the generated code, ahd the error will be: - #❯ raku -Ilib -Ibin/lib -e 'use todo-routes' - #===SORRY!=== Error while compiling -e - #Missing or wrong version of dependency 'EVAL_85' (from '/Users/fernando/Cromponent/bin/lib/todo-routes.rakumod (todo-routes)') - #at -e:1 - # - # But independently from this line, if you run: raku -Ilib -Ibin/lib -e 'use Todo' - # it worksw correctly - # - #$ast.children.shift; # Removes prelude from generated code + $ast does role :: { +my constant %escapes = %( + '&' => '&', + '<' => '<', + '>' => '>', + '"' => '"', + "'" => ''', +); + +multi escape-text(Mu:U $t, Mu $file, Mu $line) { + %*WARNINGS{"An expression at $file:$line evaluated to $t.^name()"}++; + '' +} + +multi escape-text(Mu:D $text, Mu $, Mu $) { + $text.Str.subst(/<[<>&]>/, { %escapes{.Str} }, :g) +} + +multi escape-attribute(Mu:U $t, Mu $file, Mu $line) { + %*WARNINGS{"An expression at $file:$line evaluted to $t.^name()"}++; + '' +} + +multi escape-attribute(Mu:D $attr, Mu $, Mu $) { + $attr.Str.subst(/<[&"']>/, { %escapes{.Str} }, :g) +} + method compile() { + dd $*TEMPLATE-REPOSITORY; + my $*IN-SUB = False; + my $*IN-FRAGMENT = False; + my $children-compiled = @.children.map(*.compile).join(", "); + use MONKEY-SEE-NO-EVAL; + multi sub trait_mod:(Routine $r, :$TEMPLATE-EXPORT-SUB!) { + %*TEMPLATE-EXPORTS{$r.name.substr('__TEMPLATE_SUB__'.chars)} = $r; + } + multi sub trait_mod:(Routine $r, :$TEMPLATE-EXPORT-MACRO!) { + %*TEMPLATE-EXPORTS{$r.name.substr('__TEMPLATE_MACRO__'.chars)} = $r; + } + multi sub trait_mod:(Routine $r, :$TEMPLATE-EXPORT-FRAGMENT!) { + %*TEMPLATE-EXPORTS{$r.name.substr('__TEMPLATE_FRAGMENT__'.chars)} = $r; + } + my %*TEMPLATE-EXPORTS = :sub{}, :macro{}, :fragment{}; + my $code = 'sub ($_) { join "", (' ~ $children-compiled ~ ') }'; + warn $code; + my $renderer = EVAL $code; + return Map.new((:$renderer, exports => %*TEMPLATE-EXPORTS, :@.used-files)); + } + } + $ast.children.shift; my $compiled = $ast.compile; - #dd $compiled; + dd $compiled; $compiled } @@ -232,10 +255,11 @@ sub cromponent-library($component) is export { ) } + multi EXPORT(--> Map()) { '&trait_mod:' => &trait_mod:, '&EXPORT' => sub { - [|@components-sub, |@components-macro].map({ |cromponent-library $_ }).Map + [|@components-sub, |@components-macro].flatmap({ |cromponent-library $_ }).Map }, }