Git Product home page Git Product logo

cro-webapp's People

Contributors

altai-man avatar jjatria avatar jnthn avatar jraspass avatar lukasvalle avatar patrickbkr avatar vendethiel avatar xliff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cro-webapp's Issues

How to test response from sub?

Given a sub defined elsewhere as something like
<:sub css> ... </:>
in another template 'css',
how do I test its return? I have tried

<:use 'css'>
start of template
<?&css><&css></?><!&css>default stuff</!>

This does not work because <? can only be followed by . or a variable.
I have also tried

... start of template
<?{&css eq ''}><&css><?{&css ne ''}>default stuff</?>

This also did not work.

It would be useful to be able to allocate some valid crotmp string, such as the return value of a sub, or perhaps a topic reference used more than once, to a variable.
Perhaps <:let $variable><&sub></:>
Then it would be easy to have <?$variable><$variable></?>

No way for join-like iteration

Say I have this:

<@fruits>
<.fruit-name> <DELIMITER>
</@>

It will render the items as 1 DELIM 2 DELIM 3 DELIM, but it would be nice to also have syntax for rendering 1 DELIM 2 DELIM 3 as in other template engines.

Accessing other templates with same data

Crotmp allows for subs and macros to be extracted into other templates.

This requires an explicit <:use > and then a call to the <:sub defined therein.

I want to define the <head> part of an HTML page using other templates that may be compiled separately.

Suppose for example jquery.crotmp is a template, and it will produce HTML. Eg.,

<script> blah blah </script>

In reality, the jquery.crotmp will itself need to be generated by the managing software depending on which jquery plugins are defined for that webpage. It makes sense to keep this separate from the rest of the <head ... template which will not change in structure from web page to webpage.

This seems to be a different type of call to the parts template that are called on multiple pages. In that a part is defined statically, but uses different data.

I would like to be able to define headblock.crotmp so that it accesses the compiled jquery.crotmp.

It seems from the documentation that I would need to write jquery.crotmp as

<:sub jquery><script> blah blah</script></:>

Then in headblock.crotmp write

<:use jquery.crotmp>
<head>
    <&jquery>
etc etc
</head>

But in fact, I need jquery-init jquery-top jquery-bottom css , each of which need separate use and call stanzas.

It seems that the parts functionality does not change this much.

Would it instead be possible to have <:require 'jquery.crotmp'> at the place the <&query> is positioned?
The current topic object would be provided to the required template.

Missing routine route-resource-resolver

The latest version of Cro::Webapp has the following block in Cro::Webapp::Template:

multi render-template(Str $template, $initial-topic, :%parts --> Str) is export {
    # Gather the route-specific locations and turn them into location descriptors
    # for the resolver to use.
    my @route-locations := try { router-plugin-get-configs($template-location-plugin) } // ();
    my Cro::WebApp::Template::Location @locations = @route-locations.map: {
        when TemplateResourcesLocation {
            my &resource-resolver = route-resource-resolver(error-sub => 'render-template');
            Cro::WebApp::Template::Location::Resource.new(:prefix(.prefix), :&resource-resolver)

Unfortunately the routine route-resource-resolver that is referenced above, does not exist.

`Can only use 'template' inside of a request handler` is thrown in middleware

My code is:

template-location 'templates';

route {
        after {
            template '404.crotmp', hash if .status == 404;
            template '500.crotmp', hash if .status == 500;
        }
...

and accessing it results in:

Can only use 'template' inside of a request handler
  in sub router-plugin-get-configs at /opt/rakudo-pkg/share/perl6/site/sources/BB802F84B227D34EB41F3FA87E22BD753F6E4033 (Cro::HTTP::Router) line 1373

which sounds a bit too restrictive maybe?

Allow providing defaults for optional arguments

I'm writing quite a few template subs/macros, and noticed it would save quite a bit of boilerplate if we could set default values on optional arguments. For now, all positionals are required and nameds are optional, so really this is just supporting defaults on nameds for now; we can decide we we want to allow optional positionals separately.

Templates with no passed objects

If I were to just call Template 'home.crotmp'; (without anything passed), it returns this error:

Calling template(Str) will never work with any of these multi signatures:
    ($template, $initial-topic --> Nil)

I propose it should just return the contents of the template at this point.

<@.something> is not supported

<@.list>
  <.[0]>
  <@.[1]>
    <$_><br/>
  </@>
</@>

Is not recognized. The error is:

Died with the exception:
    Template parse failed: confused at line 1 near '<@.list>
      <.[0]> 
      <@.[1]>
        <$_><br'

The following works fine however:

<@list>
  <.[0]>
  <@[1]>
    <$_><br/>
  </@>
</@>

It seems as if the <@.something> syntax is not recognized, even though <@something> is. The documentation states:

The <@foo> form is short for <@.foo>, and follows the same rules as <.foo> for resolution. It is also possible to write <@$foo> to iterate over a variable.

That suggests the syntax should be supported.

Extra data appearing in rendered template

Random data is appearing.
The problem appears when the template contains an attribute <.tail>

The following template

<section name="<.name>">
    <.target>
    <?.tail><.tail></?>
</section>

called using this code snippet

use v6.d;
use Cro::WebApp::Template;
my %parts;
my %params = (:target<targ>, :name<NAMED>, :contents('blah blah'));
say render-template('pod.crotmp', %params ,:%parts);

renders to

<section name="NAMED">
    blah blah
    contents    blah blah
</section>

The actual (extraneous) attribute that is rendered can change depending on the template compilation, so it appears to be random.

If <.tail> is eliminated, the problem disappears.

Can a variable be set within a template

Given a large local topic, would it be possible set a variable to an attribute?
suppose the topic is given to the template such that
inside the template $_ = ( attr => ( subkey => 'a' ))

<$foo := .attr>
then <$foo.subkey> would render as 'a'

Problems using Cro::WebApp::Template::Repository

I have written a custom repository to take crotmp strings from a HASH.
Several problems:

  1. All the in-module render-template methods use render-internal, which is not exported. So, in order to ensure that parts and warnings are all used, I had to copy and paste render-template.
  2. There is a prelude template that is not documented. It uses the RESOURCES repository. I have worked around this by using load-template in the resolve-absolute method of my custom repository, if a template is not in my compiled hash.

If all custom repositories should have the prelude, doesn't this indicate that a custom repository should be a subclass of a class with the prelude as state rather doing a role that doesn't have any state?

For reference, attaching the module renamed Build.txt from Cro::WebApp::Template::Build.rakumod
and a test file to illustrate its use, renamed 10-basic.txt from xt/10-basic.rakutest.
Build.txt
10-basic.txt

Test log for template-router-integration.t shows an exception stacktrace which is confusing

➜  cro-webapp git:(master) ✗ raku -Ilib t/template-router-integration.t 
ok 1 - 
ok 2 - Got expected default content type
ok 3 - Request to a template-served route works
ok 4 - 
ok 5 - Got expected default content type
ok 6 - Can use template without data
ok 7 - 
ok 8 - Got explicitly set content type when data
ok 9 - Template rendered OK
ok 10 - 
ok 11 - Got explicitly set content type when no data
ok 12 - Template rendered OK
# Subtest: Template locations do not leak from inner route block to outer
    1..2
Could not locate template 'literal.crotmp'
  in method resolve at /home/koto/Devel/cro-webapp/lib/Cro/WebApp/Template/Repository.pm6 (Cro::WebApp::Template::Repository) line 66
  in block  at /home/koto/.rakubrew/versions/moar-2021.05/install/share/perl6/site/sources/45334C557865A97D1ECA0D3F3A3FAF2017FCE553 (OO::Monitors) line 31
  in sub render-template at /home/koto/Devel/cro-webapp/lib/Cro/WebApp/Template.pm6 (Cro::WebApp::Template) line 56
  in sub template at /home/koto/Devel/cro-webapp/lib/Cro/WebApp/Template.pm6 (Cro::WebApp::Template) line 187
  in sub template at /home/koto/Devel/cro-webapp/lib/Cro/WebApp/Template.pm6 (Cro::WebApp::Template) line 194
  in block  at t/template-router-integration.t line 46
  in block  at /home/koto/.rakubrew/versions/moar-2021.05/install/share/perl6/site/sources/3A6026658FBAAD4D3FE8D607027D323A500AB5C3 (Cro::HTTP::Router) line 189
  in block  at /home/koto/.rakubrew/versions/moar-2021.05/install/share/perl6/site/sources/3A6026658FBAAD4D3FE8D607027D323A500AB5C3 (Cro::HTTP::Router) line 185

    ok 1 - code dies
    ok 2 - right exception type (X::Cro::HTTP::Error::Server)
ok 13 - Template locations do not leak from inner route block to outer
ok 14 - A global template location is available in the inner route block
ok 15 - Correct global template content
ok 16 - A global template location is available in the outer route block
ok 17 - Correct global template content
ok 18 - Templates located via resources work (no prefix)
ok 19 - Correct resource template content
ok 20 - Templates located via resources work (prefix without trailing slash)
ok 21 - Correct resource template content
ok 22 - Templates located via resources work (prefix with trailing slash)
ok 23 - Correct resource template content
ok 24 - Request relying on part provider is successful
ok 25 - Correct value from part provider used
ok 26 - Request using part provider override is successful
ok 27 - Correct value from override used
ok 28 - Request relying on auth-aware part provider is successful
ok 29 - Correct part provider is picked (not logged in)
ok 30 - Request relying on auth-aware part provider is successful
ok 31 - Correct part provider is picked (logged in)
1..31
➜  cro-webapp git:(master) ✗ 

There is a throws-like call and the test in fact pass, but when it's ran with zef test you get this:

➜  cro-webapp git:(master) ✗ zef test .
===> Testing: Cro::WebApp:ver<0.8.5>
[Cro::WebApp] Could not locate template 'literal.crotmp'
[Cro::WebApp]   in method resolve at /home/koto/Devel/cro-webapp/lib/Cro/WebApp/Template/Repository.pm6 (Cro::WebApp::Template::Repository) line 66
[Cro::WebApp]   in block  at /home/koto/.rakubrew/versions/moar-2021.05/install/share/perl6/site/sources/45334C557865A97D1ECA0D3F3A3FAF2017FCE553 (OO::Monitors) line 31
[Cro::WebApp]   in sub render-template at /home/koto/Devel/cro-webapp/lib/Cro/WebApp/Template.pm6 (Cro::WebApp::Template) line 56
[Cro::WebApp]   in sub template at /home/koto/Devel/cro-webapp/lib/Cro/WebApp/Template.pm6 (Cro::WebApp::Template) line 187
[Cro::WebApp]   in sub template at /home/koto/Devel/cro-webapp/lib/Cro/WebApp/Template.pm6 (Cro::WebApp::Template) line 194
[Cro::WebApp]   in block  at t/template-router-integration.t line 46
[Cro::WebApp]   in block  at /home/koto/.rakubrew/versions/moar-2021.05/install/share/perl6/site/sources/3A6026658FBAAD4D3FE8D607027D323A500AB5C3 (Cro::HTTP::Router) line 189
[Cro::WebApp]   in block  at /home/koto/.rakubrew/versions/moar-2021.05/install/share/perl6/site/sources/3A6026658FBAAD4D3FE8D607027D323A500AB5C3 (Cro::HTTP::Router) line 185
===> Testing [OK] for Cro::WebApp:ver<0.8.5>
➜  cro-webapp git:(master) ✗ 

I believe this trace should be hidden from the user.

Separate out semantics v. HTML/HTTP-specific bits of forms

The semantic bits of the forms implementation are valuable separately from the HTML/HTTP-specific bits. For example, it would be useful to be able to:

  • Validate that stored data still remains valid according to updated display form rules (or from a different point of view, that updates to the display form definitions do not make existing stored data invalid)
  • Validate that stored data has not become corrupt, or that proposed database changes will not make it so
  • Validate the same data sent via JSON or YAML instead of via HTTP form submission
  • Allow rendering the form and parsing the result using an alternate renderer or parser:
    • an HTML renderer that supports i18n and l10n
    • a JSON or YAML description passed to another microservice
    • a GTK or TUI interface

Please break the existing monolithic form implementation into semantic versus HTML/HTTP-specific layers to support the above.

Forms should support parsing into a Date

If you have an attribute of type Date, then it should parse it as part of parsing the form data. We can assume YYYY-MM-DD format, as specified for the HTML 5 date control. This will hopefully ease cases where we're then passing the form data on to be persisted, and the DB layer expects a Date.

How to template a comment

An HTML comment has the form <!-- text -->

But <!-- also meets the non-alphabetic rule, so is not treated as content.

Perhaps <!-- should be special cased to be considered Content view text?

Also <! is used for conditionals. Perhaps

Currently if I have 'some stuff' in %params, how do I get a comment?
Given a file 'comment.crotmp' with contents

<!-- <.contents> -->

The following Raku code

my %parts;
my %params = ( :contents<this is it> );
dd %params;
say render-template('comment.crotmp', %params, :%parts);

Yields

<!-- <.contents> -->

I'm trying to get

<!-- this is it -->

Documentation on variables unclear

The documentation on variables states The <$...> syntax can be used to refer to a variable. At that point in the documentation subroutines are not introduced yet. So it's easy to assume this refers to Raku variables accessible in the context of the render-template() call.

From my experience this is not how it works. Skimming through the webapp tests, there are no tests for this either. The only tests there are test accessing template subroutine parameters.

If I'm right with this, then the documentation should be more clear on what kind of variables can actually be accessed.

Create types for avoiding escaping

It would be very helpful if there were 2 types (maybe 2 roles) that when a template tag recipe an instance of that type,
it would automatically avoiding escaping it. Maybe it could be something like HSML and JAVASCRIPT roles and that would
automatically apply &HTML and &HTML-AND_JAVASCRIPT (maybe a &JAVASCRIPT if that exists), so when doing:

<.method-returning-html>

and the object on $_ has something like:

method method-returning-html {
   '<a href="http://pudim.com.br">Pudim</a>' does HTML
}

it would behave as it were:

<&HTML(.method-returning-html)>

and also existing:

class Link {
   has Str $.title;
   has Str $.href;

   method Str {
      qq'<a href="$!href">$!title</a>' does HTML
   }
}

if we have:

<.pudim-link>

and that returns something like:

method pudim-link { Link.new: :title<Pudim>, :href<http://pudim.com.br> }

it would be equivalent to:

<&HTML(.pudim-link.Str)>

and the same for JS

Handling of non-existent or empty fields

A topic object without an attribute needed by a template crashes when another method is available.

Use case: I want to set a .path attribute, if it exists, and the .name attribute if it does not.
The following template tries to access .path.
There is no problem if the topic object has a path attribute, but it fails if no path is available.

<footer>
    <div>Rendered from <span class="path">
    <?.path><.path></?>
    <!.path><.name></!></span></div>
</footer>

with

my %params = ( :name<Foo> );
dd %params;
say render-template('footer.crotmp', %params, :%parts);

generates

<footer>
    <div>Rendered from <span class="path">
    name        foo
    </span></div>
</footer>
Saw 1 occurrence of deprecated code.
================================================================================
Method path (from Cool) seen at:
  EVAL_1, lines 3,4
Please use IO instead.
--------------------------------------------------------------------------------
Please contact the author to have these occurrences of deprecated code
adapted, so that this message will disappear!

But when path is replaced by pathx we get

<footer>
    <div>Rendered from <span class="path">
    
    foo</span></div>
</footer>

Remove Cro::HTTP dependency

I think there is a usecase of using the Cro templating engine outside of a server application. So it might be worthwhile to make the dependency on Cro::HTTP optional as to not pull in the entire Cro stack.

Background: I'm building an application that creates an HTML page from a set of templates and input data and then turns it into a PDF using a dedicated HTML-to-print document rendering engine (yes, such things exist). That PDF is then sent via an email that will probably also be layed out with HTML. So there are two use-cases in one application for an HTML templating system outside of the context of a HTTP server. (Admittedly, this application actually is a web service, so in my specific case I don't mind the extra dependency on Cro::HTTP, but the general idea remains valid).

Everything inside <script> (also <style>?) has to be escaped automagically

JS bits containing <, e.g. a simple for loop or a condition are parsed as opener tags resulting in a failure:

                if (month.length < 2)
                    month = '0' + month;
                if (day.length < 2)
                    day = '0' + day;

leads to

    Template parse failed: malformed tag at line 54 near '< 2)
                        day = '0' + day'
      in method panic at /home/koto/.rakubrew/versions/moar-2021.05/install/share/perl6/site/sources/DEC52040CAB8F0AC21402372C4D99D4B9A2D7D0D (Cro::WebApp::Template::Parser) line 372
      in regex sequence-element:sym<literal-open-tag> at /home/koto/.rakubrew/versions/moar-2021.05/install/share/perl6/site/sources/DEC52040CAB8F0AC21402372C4D99D4B9A2D7D0D (Cro::WebApp::Template::Parser) line 38

WebApp::HTTP fails testing due to connection time-out

Using .github workflow with

      - run: zef install https://github.com/croservices/cro-core/archive/master.zip
      - run: zef install https://github.com/croservices/cro-tls/archive/master.zip
      - run: zef install https://github.com/croservices/cro-http/archive/master.zip

getting

===> Testing: Log::Timeline:ver<0.5.1>:auth<zef:jnthn>
===> Testing [OK] for Log::Timeline:ver<0.5.1>:auth<zef:jnthn>
===> Testing: Cro::HTTP:ver<0.8.7>:auth<zef:cro>
===> Testing [FAIL]: Cro::HTTP:ver<0.8.7>:auth<zef:cro>
Error: Process completed with exit code 1.

t/form-router-integration.t fails with Cro::WebApp:ver<0.8.3> [Needs Cro::HTTP:ver<0.8.3>]

Test t/form-router-integration.t fails with Cro::WebApp:ver<0.8.3> with Cro::HTTP:ver<0.7.6.1>. Solved when updated to Cro::HTTP:ver<0.8.3>. (Ups...! )

zef install Cro::WebApp::Template
===> Searching for: Cro::WebApp::Template
===> Testing: Cro::WebApp:ver<0.8.3>
[Cro::WebApp] # Failed test 'Can render a form in a template'
[Cro::WebApp] # at t/form-router-integration.t line 49
[Cro::WebApp] # Unable to parse URI '/render': Malformed scheme
[Cro::WebApp] # Failed test 'Have a CSRF token set as a cookie'
[Cro::WebApp] # at t/form-router-integration.t line 53
[Cro::WebApp] No such method 'body-text' for invocant of type 'Any'
[Cro::WebApp]   in block <unit> at t/form-router-integration.t line 54
===> Testing [FAIL]: Cro::WebApp:ver<0.8.3>
Aborting due to test failure: Cro::WebApp:ver<0.8.3> (use --force-test to override)

It works with Cro::WebApp:ver<0.8.2>

zef install 'Cro::WebApp:ver<0.8.2>' 
===> Searching for: Cro::WebApp:ver<0.8.2>
===> Testing: Cro::WebApp:ver<0.8.2>
===> Testing [OK] for Cro::WebApp:ver<0.8.2>
===> Installing: Cro::WebApp:ver<0.8.2>

None standard http headers are not supported?

Hi! I am trying to add these header to response:

    given response {
      .append-header('Content-type', 'image/svg+xml');
      .append-header('charset', 'utf-8');
    }

but get this error:

⚠ sparky Could not parse media type 'image/svg+xml,text/html; charset=utf-8'
⚠ sparky   in method parse at /Users/alex/.rakubrew/versions/moar-/share/perl6/site/sources/33C6742958D3C4ACCFAD0D9DD0C5533ADA26FF0F (Cro::MediaType) line 98

HTH

Some template syntax we were spitballing on in IRC

I've often lamented the fact that every template language I've used has been dumbly concerned with producing a text stream and then I have to use that to produce a structured document with that.

It would be awesome to use a template language that understands that the output is structured and therefore assumes a DOM up front. Cro::WebApp::Template may well be this thing.

The first clarification to make is whether there is any meaning to this syntax:

<TOKEN WORD WORD ...>

That is, any particular special tag opening, followed by space-separated arguments, or attributes. If there is anything that fits this pattern already, this risks overloading that, thus complicating the parser. I'd like to prioritise keeping the parser regular. (If the pseudo-syntax I used here is unclear, it should hopefully make sense as I explain what we discussed.)

In the hypothetical case that the above is currently not a meaningful syntax, we think it would be useful to define it thus:

With TOKEN as a variable or decorated variable (described below), treat WORD WORD ... as an HTML (or XML...) tag and process it based on TOKEN

Examples!

  • Simple iterator
    <@items li><$_></@>
  • Simple conditional
    <@items? ul><@items li> ...
  • Conditional wrapping
    <$_.link^? a href="<$_.link>"><$_.text></$>

I bet people will be inspired to come up with more examples. My personal favourite is conditional wrapping, because the structured nature of HTML collides with the byte-stream blindness of most template languages when it comes to the requirement to repeat a conditional to close a wrapping tag. I hate it!

Here's the above UL example in full!

<@items? ul>
  <@items li>
    <$_.link^? a href="<.link>">
      <.text>
    </$>
  </@>
</@>

The conditional-wrap could actually have an else, which I thought of while writing the list above: <$_.link^? a ... ! del> - in this version, if the "menu item" has no link then it is del'd, normally rendered as a strikethrough

One thing I'm not sure about is the closing tag: currently I'm using the sigil like the existing <@array> iterator, but I don't think it clarifies what is being closed. Potentially, a combination of the sigil and the operator might be better, so you can make sure you've balanced things right, and remove the right thing when a change is made: </@?>, </$^?>. Actually, now I think about it, this should also work with just <.link^?> so maybe the "name" of these tags are their operators and not their sigils, meaning they close like this </?> </^?>.

Note that the simple iterator would still close like </@> because it's really just a condensing of the existing iterator syntax.

Open to ideas!

Adding a literal '<' and '>' in a .crotmp file

If it's in the docs, I must have missed it.

Consider this bit of Javascript, I am trying to run through Cro::WebApp::Template:

for (i = 0; i <= pc; i++) {
  prefix = prefix + '../';
}

That fails the template parser. It's looking for a closing template tag because of the ge operation used, above.

Comments with HTML syntax inside are not parsed properly

Just add something like:

                      <!--<article class="message is-small">
                        <div class="message-body">-->
                        <!--</div>
                      </article>-->

Expected results: the comments are ignored;

Actual result:

Died with the exception:
    Template parse failed: malformed tag at line 315 near '<article class="message is-small">
         '
      in method panic at /home/koto/.rakubrew/versions/moar-2021.05/install/share/perl6/site/sources/DEC52040CAB8F0AC21402372C4D99D4B9A2D7D0D (Cro::WebApp::Template::Parser) line 372
      in regex sequence-element:sym<literal-open-tag> at /home/koto/.rakubrew/versions/moar-2021.05/install/share/perl6/site/sources/DEC52040CAB8F0AC21402372C4D99D4B9A2D7D0D (Cro::WebApp::Template::Parser) line 38
      in regex sequence-element at /home/koto/.rakubrew/versions/moar-2021.05/install/share/perl6/site/sources/DEC52040CAB8F0AC21402372C4D99D4B9A2D7D0D (Cro::WebApp::Template::Parser) line 28

Needs a version bump

Some pretty critical fixes are on master, but old version is cached for some because the version was not bumped.

Control of white space - wider problem

In #68 I wrote specifically about white space after conditionals. The response there is that conditionals are special cased.

But white space control is a bit deeper for templating languages because there are two forms of white space, namely white space in the template (to help understanding the logic of the template), and white space in the rendered code (to help understanding of the rendered code).

Currently, Crotmp seems to preserve the whitespace in the template except for conditionals, in that conditionals generate no EOL if they produce no content. The same does not seem to be true of other tabs.

Perhaps it might be possible to have explicit white space tags, such as <_> for a space <_t> for a tab or 4 spaces and <_n> for a new line. These are rendered as white space.

Whitespace in the template would then ignored. This seems to me to be more Raku-ish, eg whitespace in a regex.

An example to illustrate the current situation is a template that defines a sub at the top of the template, then calls it later.
It is useful to separate the sub declaration from the rest of the template, but this leads to white space in the rendered template at the top of the file.

<:sub dosomething>
<h1>This is a title</h1>
</:>

<html><body><&dosomething>
Blah blah
</body></html>

Support booleans in sub calls

<|page('Posts', 'posts', 1)> is ok but <|page('Posts', 'posts', True)> is not ok.
Using 1 for True and 0 for False is a bit C-y old-fashioned and I wonder if we should and can do better.

Suppressing EOL / whitespace

Use case: I need to have one set of HMTL if data is present, another if absent.
From the documentation, the only way I can do this as follows (note the disambiguation to ensure only the Hash key is tested)

<div id="<.name>">
<?.<tail>><.tail></?>
<!.<tail>>No tail</!>
</div>

HTML is produced as expected BUT there is always an extra line added in, either one corresponding to the <!....> stanza not generating a string, or the <?.... not generating a string.

HTML renderers remove whitespace, so it does not have an impact on users, but I find it difficult when developing and debugging HTML if there is excessive whitespace.

Is there a way to suppress whitespace?

Is there a better way in Crotmp to get alternate rendering depending on a boolean test?

Some warnings are LTA

Use of Nil in string context
  in sub escape-attribute at /Users/liz/Github/rakudo.moar/install/share/perl6/site/sources/6A3C744A4C03D3F2184D2210CC3CFBC8E0DBAFDA (Cro::WebApp::Template::AST) line 311

doesn't tell me anything about which line in the template, or in the generated code, this actually happened. Which makes trying to fix this warning really like looking for a needle in the proverbial haystack.

It would be nice if the warning would state that line in the template where it occurred.

Be more forgiving in smart deref on hashes

#15 is ultimately caused by smart-deref blowing up if the hash key isn't there, which we could work around by using .<row> I guess, but given how often I trip over this, it probably wants to be more forgiving and just produce Nil when used on a hash.

Repeated use of an attribute

I'm trying to match begin and end tags for headers, eg./
<h2>...</h2>
where the level (eg.2) is in an attribute.

The following template fails:

<h<?.level><.level></?>>
<.text>
</h<?.level><.level></?>>

The problem appears to bre related to <.level> being called repeatedly.
The full error message is as follows:

An operation first awaited:
  in sub compile-dir at /home/richard/.raku/sources/8727B7CE66F46D2210CCD9CE826288AA463FF9AC (Cro::WebApp::Template) line 108
  in sub template-location at /home/richard/.raku/sources/8727B7CE66F46D2210CCD9CE826288AA463FF9AC (Cro::WebApp::Template) line 102
  in block <unit> at do-templ.raku line 5

Died with the exception:
    Template parse failed: confused at line 3 near '</?>>'
      in method panic at /home/richard/.raku/sources/8262DE42E320C5C27BF8F4B9C4B9D431C700EDBE (Cro::WebApp::Template::Parser) line 425
      in regex TOP at /home/richard/.raku/sources/8262DE42E320C5C27BF8F4B9C4B9D431C700EDBE (Cro::WebApp::Template::Parser) line 21
      in sub load-template at /home/richard/.raku/sources/5B4AC652518EF031FD5F107F81DAA12BAB60A86B (Cro::WebApp::Template::Repository) line 134
      in code  at /home/richard/.raku/sources/5B4AC652518EF031FD5F107F81DAA12BAB60A86B (Cro::WebApp::Template::Repository) line 76

Provide means to trim return from <:sub ...> </:>

I've just been caught out by the return of a <:sub> including the \n at the end of the line when formatted like:

<:sub form-name($target)>
   resyncForm_<$target.dc-id>_<$target.channel-id>
</:>

Obviously if one is using that as an attribute value (as I was,) then that won't have the outcome desired.

Clearly one could format the sub as:

<:sub form-name($target)>resyncForm_<$target.dc-id>_<$target.channel-id></:>

To lose the \n but that's less than lovely.

Perhaps there could an additional attribute to the <:sub> (and the similar things,) which could cause the leading and trailing whitespace to be trimmed from the return. It would be nicer if this were in the template itself rather than in the calling code as it may want to be on a case by case basis.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.