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.180 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.179 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.178 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.177 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.176 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.175 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.174 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.173 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.172 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.171 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.170 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.169 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.167 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.166 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.165 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.164 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.163 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.162 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.161 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.160 tracks/perl6/lib/Exercism/Generator.pm6