App-Dapper
view release on metacpan or search on metacpan
`replace_last(a, b)` | [DSF] Replace the last occurrence of the string `a` with `b`
`return` | Returns the item from the inner most block, macro, or file. Similar to the `return` directive.
`search(s)` | Tests if the given pattern is in the string.
`sin` | Returns the sine of the item.
`size` | Always returns 1 for text variables.
`smart` | [DSF] Replace `---` with an em dash and `--` with an en dash
`split(s, n)` | Splits the item on regular expression `s` and returns an array with the chunks. If `n` is passed, processing stops after the first `n` chunks.
`sprintf(p, q, ...)` | Uses the pattern stored in self, and passes it to sprintf with the passed arguments. Opposite from the fmt vmethod.
`sqrt` | Returns the square root of the number.
`srand` | Calls the perl srand function to set the internal random seed. This will affect future calls to the rand vmethod.
`stderr` | Print the item to the current STDERR handle.
`substr(i, n)` | Returns a substring of item starting at `i` and going to the end of the string. If `n` is passed, the substring stops after `n` characters.
`trim` | Strips leading and trailing whitespace.
`uc` | Same as the upper command. Returns uppercased string.
`ucfirst` | Uppercase the leading letter.
`upper` | Return the string uppercased.
`uri` | Perform a very basic URI encoding.
`url` | Perform a URI encoding - but some characters such as `:` and `/` are left intact.
`xml_escape` | [DSF] Escape strings that may contain XML so the string can be included in XML files such as ATOM or RSS feeds
`xml` | Performs a very basic xml encoding (swaps out `&`, `<`, `>`, `'` and `"` with the corresponding xml entities).
t/21-deploy.t view on Meta::CPAN
ok(deploy(), 'second deploy');
is(`git --git-dir='$remote' rev-list --count gh-pages` + 0, 2, 'history kept');
$files = `git --git-dir='$remote' ls-tree -r --name-only gh-pages`;
like($files, qr/^new\.html$/m, 'new page published');
unlike($files, qr/^about\.html$/m, 'removed page removed');
make_site({ %site, '_config.yml' => "---\nname: x\ndeploy:\n github_pages:\n repo: $remote.missing\n" });
my $error;
{
open(my $stderr, '>&', \*STDERR);
open(STDERR, '>', File::Spec->devnull);
$error = eval { deploy(); 1 } ? '' : $@;
open(STDERR, '>&', $stderr);
}
like($error, qr/could not reach/, 'a repository that is not there');
};
subtest 'GitHub Pages where git has no name and email' => sub {
plan skip_all => 'git is not installed' unless $has_git;
my $remote = tempdir(CLEANUP => 1) . '/site.git';
system('git', 'init', '--quiet', '--bare', $remote) == 0 or plan skip_all => 'git init failed';
local $ENV{HOME} = tempdir(CLEANUP => 1);
local $ENV{GIT_CONFIG_NOSYSTEM} = 1;
t/52-mcp-protocol.t view on Meta::CPAN
'{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26"}}',
'{"jsonrpc":"2.0","method":"notifications/initialized"}',
'{"jsonrpc":"2.0","id":2,"method":"tools/list"}',
'garbage',
'{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"build","arguments":{}}}',
'{"jsonrpc":"2.0","id":4,"method":"resources/read","params":{"uri":"dapper://config"}}',
) . "\n";
spew("$io/requests", $input, ':raw');
my $other = tempdir(CLEANUP => 1);
chdir $other;
my $out = `"$^X" "-I$lib" "$dapper_bin" -C "$dir" mcp < "$io/requests" 2>"$io/stderr"`;
my $status = $? >> 8;
chdir $dir;
is($status, 0, 'exits 0 at the end of the input');
my @lines = split /\n/, $out;
is(scalar @lines, 5, 'five responses');
my @responses = map { $json->decode($_) } @lines;
is_deeply([ map { $_->{id} } @responses ], [1, 2, undef, 3, 4], 'in order, with their ids');
is($responses[0]->{result}->{protocolVersion}, '2025-03-26', 'initialize');
is(scalar @{ $responses[1]->{result}->{tools} }, 9, 'tools/list');
is($responses[2]->{error}->{code}, -32700, 'the parse error');
ok($responses[3]->{result}->{structuredContent}->{built}, 'build');
ok(-f "$dir/_output/index.html", 'built in the -C directory');
like($responses[4]->{result}->{contents}->[0]->{text}, qr/name: Test Site/, 'the project file from the -C directory');
is(slurp("$io/stderr"), '', 'a quiet build prints nothing on standard error');
};
subtest 'dapper mcp outside a project' => sub {
make_site({}, bare => 1);
my $dir = getcwd();
spew("$io/requests", qq({"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"site_info"}}\n{"jsonrpc":"2.0","id":2,"method":"resources/read","params":{"uri":"dapper://config"}}\n), ':raw');
my $out = `"$^X" "-I$lib" "$dapper_bin" -C "$dir" mcp < "$io/requests" 2>/dev/null`;
my @responses = map { $json->decode($_) } split /\n/, $out;
is(scalar @responses, 2, 'still answers');
ok($responses[0]->{result}->{isError}, 'tools report the missing project file as an error');
t/54-init-templates.t view on Meta::CPAN
my $out = '';
{
local *STDOUT;
open(STDOUT, '>', \$out) or die $!;
$code->();
}
return $out;
}
# Run code with standard error thrown away (git warns about shallow local clones)
sub without_stderr {
my ($code) = @_;
open(my $stderr, '>&', \*STDERR) or die $!;
open(STDERR, '>', File::Spec->devnull) or die $!;
my @result = eval { $code->() };
my $error = $@;
open(STDERR, '>&', $stderr) or die $!;
die $error if $error;
return wantarray ? @result : $result[0];
}
sub init_quietly {
my (@args) = @_;
local $App::Dapper::Utils::QUIET = 1;
return App::Dapper::Init::init(@args);
}
t/54-init-templates.t view on Meta::CPAN
my $work = "$base/work";
system('git', 'init', '-q', $work) == 0 or plan skip_all => 'git init failed';
spew("$work/_config.yml", "---\nname: From git\n");
spew("$work/_layout/index.html", "[% page.content %]");
spew("$work/_source/index.md", "---\ntitle: Home\n---\nHello from git.\n");
spew("$work/images/a.bin", "\x00\x01\x02\xff", ':raw');
system("cd '$work' && git add -A && git commit -q -m theme") == 0 or plan skip_all => 'git commit failed';
my $bare = "$base/theme.git";
system('git', 'clone', '-q', '--bare', $work, $bare) == 0 or plan skip_all => 'git clone --bare failed';
my ($files, $notes) = without_stderr(sub { App::Dapper::Init::template_files($bare) });
is_deeply([ sort keys %$files ], [qw(_config.yml _layout/index.html _source/index.md images/a.bin)], 'a bare repository ending in .git is cloned; .git is left out');
is($files->{'images/a.bin'}->{raw}, "\x00\x01\x02\xff", 'bytes kept');
is($notes, undef, 'no notes');
($files) = without_stderr(sub { App::Dapper::Init::template_files("file://$bare") });
ok($files->{'_source/index.md'}, 'a file:// URL ending in .git');
make_site({}, bare => 1);
my $d = App::Dapper->new();
$d->{quiet} = 1;
$d->{template} = $bare;
without_stderr(sub { capture_stdout(sub { $d->init() }) });
is(slurp('_source/index.md'), "---\ntitle: Home\n---\nHello from git.\n", 'init copies the clone');
ok(!-e '.git', 'without .git');
ok(-f 'AGENTS.md', 'and adds AGENTS.md');
like(slurp('AGENTS.md'), qr/# Working on From git/, 'about the site');
my $error;
{
open(my $stderr, '>&', \*STDERR);
open(STDERR, '>', File::Spec->devnull);
eval { App::Dapper::Init::template_files("$base/missing.git") };
$error = $@;
open(STDERR, '>&', $stderr);
}
is($error, "error: could not clone the template from $base/missing.git (is git installed, and is the URL right?)\n", 'a repository that is not there');
my ($plain) = eval { without_stderr(sub { App::Dapper::Init::template_files("file://$work") }) };
ok($plain && $plain->{'_source/index.md'}, 'a file:// URL without .git is cloned');
};
subtest 'a git URL without git' => sub {
local $ENV{PATH} = tempdir(CLEANUP => 1);
my $error;
{
open(my $stderr, '>&', \*STDERR);
open(STDERR, '>', File::Spec->devnull);
eval { App::Dapper::Init::template_files('/nowhere/theme.git') };
$error = $@;
open(STDERR, '>&', $stderr);
}
is($error, "error: could not clone the template from /nowhere/theme.git (is git installed, and is the URL right?)\n", 'asks whether git is installed');
};
done_testing();
t/57-deploy.t view on Meta::CPAN
local $ENV{GIT_AUTHOR_NAME} = 'Test';
local $ENV{GIT_AUTHOR_EMAIL} = 'test@example.com';
local $ENV{GIT_COMMITTER_NAME} = 'Test';
local $ENV{GIT_COMMITTER_EMAIL} = 'test@example.com';
local $ENV{GIT_CEILING_DIRECTORIES} = File::Spec->tmpdir;
my $remote = tempdir(CLEANUP => 1) . '/site.git';
system('git', 'init', '--quiet', '--bare', $remote) == 0 or plan skip_all => 'git init failed';
make_site({ %site, '_config.yml' => "---\nname: x\ndeploy:\n github_pages: true\n" });
{
open(my $stderr, '>&', \*STDERR);
open(STDERR, '>', File::Spec->devnull);
my $error = error_of(sub { deploy() });
open(STDERR, '>&', $stderr);
is($error, "error: deploy.github_pages in _config.yml needs a repo (or run dapper in a git repository with an origin)\n", 'without a repo or an origin');
}
is(system('git', 'init', '--quiet', '.'), 0, 'the site is a git repository');
is(system('git', 'remote', 'add', 'origin', $remote), 0, 'with an origin');
ok(deploy(), 'with the origin of the repository dapper runs in');
like(`git --git-dir='$remote' ls-tree -r --name-only gh-pages`, qr/^index\.html$/m, 'to gh-pages by default');
make_site({ %site, '_config.yml' => "---\nname: x\ndeploy:\n github_pages:\n repo: $remote\n cname: docs.example.com\n" });
ok(deploy(), 'with a cname');
( run in 1.874 second using v1.01-cache-2.11-cpan-60884a8df76 )