"> <% $yield->() %>...">

Filtering content in text :: Xslate

In Mason, I can define a filter:

<%filter Div($class)>
        <div class="<% $class %>">
                <% $yield->() %>
        </div>
</%filter>

And later I could use it

% $.Div("row") {{
   1 The "$yield->()" method returns everything from here (free text)
%       $.Div("col") {{
                2 even could have another nested filter, etc...
%       }}
% }}

with the result

<div class="row">
    1 The "$yield->()" method returns everything from here (free text)
   <div class="col">
            2 even could have another nested filter, etc...   
   </div>
</div>

eg. The method $yield->()returns everything that is inside the closed filter.

Want to achieve the same functionality using Text :: Xslate , but don’t know how to do it.

The closest I found are macros where I could write:

: macro div -> ($cls,$str) {
<div class="<: $cls :>">
        <: $str :>
</div>
: }

and use it as

: div("row",
:       div("col",
:               "my string"
:       )
: )

but my stringmust be specified and :marked, so it’s not possible to use any free html text. For example. following stamps.

: div("row",

some free text here

:       div("col",
               nested
               here
:       )
: )

After a long introduction, the question is simple:

Text::Xslate - Mason $yield->(), ? (, , ?)

+6

Source: https://habr.com/ru/post/1016234/


All Articles