Skip to content

Instantly share code, notes, and snippets.

@librasteve
Created December 27, 2024 14:43
Show Gist options
  • Save librasteve/abceefcf62349c4c93259484c813eec9 to your computer and use it in GitHub Desktop.
Save librasteve/abceefcf62349c4c93259484c813eec9 to your computer and use it in GitHub Desktop.
MyCromps-Thead.rakumod
class Cell is export {
has $.data is required;
multi method new($data) {
$.new: :$data
}
method RENDER {
q:to/END/
<td><.data></td>
END
}
}
class Row is export {
has Cell() @.cells is required;
multi method new(@cells) {
$.new: :@cells
}
method RENDER {
q:to/END/
<tr>
<@.cells: $c>
<&Cell($c)>
</@>
</tr>
END
}
}
class HCell is export {
has $.data is required;
multi method new($data) {
$.new: :$data
}
method RENDER {
q:to/END/
<th><.data></th>
END
}
}
class THead is export {
has HCell() @.cells is required;
multi method new(@cells) {
$.new: :@cells
}
method RENDER {
q:to/END/
<thead>
<tr>
<@.cells: $c>
<&HCell($c)>
</@>
</tr>
</thead>
END
}
}
class MyTable is export {
has Row() @.rows is required;
has THead() $.thead;
multi method new(@rows, *%_) {
$.new: :@rows, |%_
}
method RENDER {
q:to/END/
<table class="striped">
<?.thead>
<&THead(.thead)>
</?>
<tbody>
<@.rows: $r>
<&Row($r)>
</@>
</tbody>
</table>
END
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment