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.119 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.118 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.117 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.116 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.115 tracks/perl6/lib/Exercism/Generator.pm6