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.159 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.158 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.157 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.156 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.155 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.154 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.153 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.152 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.151 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.150 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.149 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.148 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.147 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.146 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.145 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.144 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.143 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.142 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.141 tracks/perl6/lib/Exercism/Generator.pm6
trackler-2.2.1.140 tracks/perl6/lib/Exercism/Generator.pm6