Sha256: 5150035e4b32e83ea73b34fad261ea3cf0600f28d4efa5f130fd47ed624c4231

Contents?: true

Size: 890 Bytes

Versions: 65

Compression:

Stored size: 890 Bytes

Contents

unit class Exercism::Generator;
use Template::Mustache;

my $base-dir = $?FILE.IO.parent.add("../..");

has %.data;
has Str $.exercise;

submethod TWEAK {
  if $!exercise && (my $cdata =
    $base-dir.add: "problem-specifications/exercises/$!exercise/canonical-data.json") ~~ :f
  {
    %!data<cdata><json> = $cdata.slurp.trim;
  }
}

method cdata (--> Str:D) {
  %!data<cdata><json> ?? %!data<cdata><json> !! '';
}

method test (--> Str:D) {
  self!render;
}

method stub (--> Str:D) {
  self!render: %!data<stub> || '';
}

method examples (--> Hash()) {
  return %!data<examples>
    ?? %!data<examples>.map: {.key => self!render: .value}
    !! base => self!render: %!data<example>;
}

method !render (Str $module_file? --> Str:D) {
  Template::Mustache.render(
    $base-dir.add("templates/{$module_file.defined ?? 'module' !! 'test'}.mustache").slurp, %(|%!data, :$module_file)
  );
}

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.138 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.137 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.136 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.135 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.134 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.133 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.132 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.131 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.130 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.129 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.128 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.127 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.126 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.125 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.124 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.123 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.122 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.121 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.120 tracks/perl6/lib/Exercism/Generator.pm6